/* << HighC V1.7 >> [FM-TOWNS] **********************************************
*
*	.PVS → TIFF 保存
*	----------------------------------------------------------------------
*	Programmed by Y.Hirata ( NIFTY-ID: NAB03321  パオパオ )
*
*	NOTE: TAB=4
****************************************************************************/

#ifndef _TIFFHEAD_DEFINED
	#define	_TIFFHEAD_DEFINED

	#include <stdio.h>

	typedef unsigned char		UCHAR ;
	typedef unsigned short int	USHORT ;
	typedef unsigned int		UINT ;
	typedef unsigned long		ULONG ;

	typedef struct _TIFF_HEAD {
		USHORT	fmt ;							/*  ﾌｫｰﾏｯﾄ('II')		*/
		USHORT	ver ;							/*  ﾊﾞｰｼﾞｮﾝ(42)			*/
		ULONG	off ;							/*  IFDｵﾌｾｯﾄ(8)			*/
	} TIFF_HEAD ;

	typedef struct _TIFF_IFD {
		USHORT	tag ;							/*  ﾀｸﾞ種別				*/
		USHORT	type ;							/*  ﾌｨｰﾙﾄﾞﾀｲﾌﾟ			*/
		ULONG	len ;							/*  ﾌｨｰﾙﾄﾞ長			*/
		ULONG	val ;							/*  値またはｵﾌｾｯﾄ		*/
	} TIFF_IFD ;

	typedef struct _TIFF_16 {
		TIFF_HEAD	head ;			/*  +0			*/
		USHORT		ntag ;			/*  +8			*/
		TIFF_IFD	tag[16] ;		/*  +10(0Ah)	*/
		ULONG		tagend ;		/*  +202(CAh)	*/
		UCHAR		zero1[50] ;		/*  +206(CEh)	*/
		USHORT		red[16] ;		/*  +256(100h)	*/
		USHORT		green[16] ;		/*  +288(120h)	*/
		USHORT		blue[16] ;		/*  +320(140h)	*/
		UCHAR		zero2[144] ;	/*  +352(160h)	*/
		ULONG		xreso[2] ;		/*  +496(1F0h)	*/
		ULONG		yreso[2] ;		/*  +504(1F8h)	*/
//		UCHAR		data[0] ;		/*  +512(200h)	*/
	} TIFF_16 ;

	typedef struct _TIFF_32K {
		TIFF_HEAD	head ;			/*  +0			*/
		USHORT		ntag ;			/*  +8			*/
		TIFF_IFD	tag[15] ;		/*  +10(0Ah)	*/
		ULONG		tagend ;		/*  +190(BEh)	*/
		UCHAR		zero1[302] ;	/*  +194(C2h)	*/
		ULONG		xreso[2] ;		/*  +496(1F0h)	*/
		ULONG		yreso[2] ;		/*  +504(1F8h)	*/
//		UCHAR		data[0] ;		/*  +512(200h)	*/
	} TIFF_32K ;

	typedef struct _TIFF_256 {
		TIFF_HEAD	head ;			/*  +0			*/
		USHORT		ntag ;			/*  +8			*/
		TIFF_IFD	tag[16] ;		/*  +10(0Ah)	*/
		ULONG		tagend ;		/*  +202(CAh)	*/
		UCHAR		zero1[290] ;	/*  +206(CEh)	*/
		ULONG		xreso[2] ;		/*  +496(1F0h)	*/
		ULONG		yreso[2] ;		/*  +504(1F8h)	*/
		USHORT		red[256] ;		/*  +512(200h)	*/
		USHORT		green[256] ;	/*  +1024(400h)	*/
		USHORT		blue[256] ;		/*  +1536(600h)	*/
//		UCHAR		data[0] ;		/*  +2048(800h)	*/
	} TIFF_256 ;

	void make16Header( int sx,int sy ) ;
	void make256Header( int sx,int sy ) ;
	void make32KHeader( int sx,int sy ) ;
	void savesize( int sw ) ;
	int padding( int size,FILE *fp ) ;
	int resolution( ULONG r1,ULONG r2,ULONG r3,ULONG r4,FILE *fp ) ;
	USHORT palcnv( UCHAR pal ) ;
	int header16_save( FILE *fp ) ;
	int header256_save( FILE *fp ) ;
	int header32K_save( FILE *fp ) ;
	int header_save( FILE *fp ) ;
	int vramdata_save( FILE *fp ) ;
	int dos_save( FILE *fp ) ;
	int vram_save( FILE *fp ) ;
	int tiff_create( void ) ;
	void mode_report( FILE *fp ) ;
	int tiff_save( void ) ;

#endif

/*	HISTORY
-----------------------------------------------------------------------------
*	1994.01.13 : CREATE
---------------------------------------------------------------------------*/
