#ifndef LIBRARIES_PERSONAL_IO_H
#define LIBRARIES_PERSONAL_IO_H TRUE
/*
**  $VER: personal_io.h 5.0 (22.5.96)
**  Includes Release 5.0
**
**  Interface definitions for PersonalIO applications.
**
**  Copyright © 1995, 1996 Cloanto Italia srl
**	    All Rights Reserved
*/
#ifndef EXEC_TYPES_H
#include <exec/types.h>
#endif /* EXEC_TYPES_H */

#ifndef	GRAPHICS_GFX_H
#include <graphics/gfx.h>
#endif /* GRAPHICS_GFX_H */

#define IOLIB_VERSION	5	/* current interface version */


/*
 *  Picture type description structure
 */
struct DataInfo
{
	WORD Version;		/* client program interface version */
	ULONG Code;		/* picture type code */
	ULONG Flags;		/* attributes */
	ULONG ProcessData;	/* data items processable */
	LONG  Priority;		/* sort priority */
	UBYTE Name[40];		/* full name */
	UBYTE ShortName[16];	/* short name */
	UBYTE FileSuffix[3][16];/* file name suffixes ('.' included) */
	UBYTE *HandshakeText;	/* handshaking string */
	UBYTE pad[28];
};

/* DataInfo Code */
#define DIC_ANYDATA  0xFFFFFFFF	/* Load operations (PictureInfo.Data.Code):
				 * the client program is asking
				 * for any picture type to be loaded. */

/* DataInfo Flags */
#define DIF_LOAD	0x00000001  /* planar images can be loaded */
#define DIF_LOAD_24	0x00000002  /* 24bit chunky images can be loaded */
#define DIF_SAVE	0x00000004  /* planar images can be saved */
#define DIF_SAVE_24	0x00000008  /* 24bit chunky images can be saved */
#define DIF_LOADFILE	0x00000010  /* the data are read from file */
#define DIF_SAVEFILE	0x00000020  /* the data are written to file */
#define DIF_RECOGNIZE	0x00000040  /* image files can be recognized */
#define DIF_ENCRYPTED	0x00000080  /* the data are encrypted */
#define DIF_CUSTOMIO	0x00000100  /* custom file I/O */
#define DIF_LOADOPTS	0x00000200  /* options for ReadPicture() */
#define DIF_SAVEOPTS	0x00000400  /* options for WritePicture() */
#define DIF_SELFLOPT	0x00000800  /* custom load-options handling */
#define DIF_SELFSOPT	0x00001000  /* custom save-options handling */
#define DIF_CONVERTED	0x00002000  /* the data come from a foreign library */

/* DataInfo ProcessData */
#define PCDT_FORMAT	0x00000001  /* Width, Height, Depth */
#define PCDT_IMAGE	0x00000002  /* BitMap */
#define PCDT_MASK	0x00000004  /* MaskPlane */
#define PCDT_PALETTE	0x00000008  /* Palette */
#define PCDT_PRJINFO	0x00000010  /* ProjInfo */
#define PCDT_DPI	0x00000020  /* HorizDPI, VertDPI */
#define PCDT_DISPID	0x00000040  /* DisplayID */
#define PCDT_HANDLE	0x00000080  /* HandleX, HandleY */
#define PCDT_EDGES	0x00000100  /* LeftEdge, TopEdge */
#define PCDT_SRCDIM	0x00000200  /* SourceWidth, SourceHeight */
#define PCDT_TRANSPT	0x00000400  /* TranspType */
#define PCDT_TRANSPC	0x00000800  /* TransparentColor */


/*
 *   Picture data/resource structure
 */
struct PictureInfo
{
	/*
	 *  Section 1: I/O information
	 */
	WORD Version;			/* client program interface version */
	UBYTE *FileName;		/* file being read/written */
	UBYTE FileHead[128];		/* first bytes from file */
	struct DataInfo Data;		/* picture type selected */
	ULONG ProcessData;		/* data to read/write */
	ULONG ProcessedData;		/* data read/written */
	ULONG Flags;			/* unused */
	APTR  Parameters;		/* unused */
	APTR  User1, User2, User3;	/* user extensions */

	/*
	 *  Section 2: picture information
	 */
	WORD Width, Height;		/* image width and height */
	UBYTE Depth;			/* image depth (bits per pixels) */
	UBYTE pad1;
	WORD HandleX, HandleY;		/* handle (hot spot) */
	WORD HorizDPI, VertDPI;		/* ratio (dots per inch) */
	WORD LeftEdge, TopEdge;		/* source coordinates */
	WORD SourceWidth, SourceHeight;	/* source format */
	UBYTE TranspType;		/* transparency type */
	UBYTE TransparentColor;		/* transparent color */
	ULONG DisplayID;		/* screen display mode */
	ULONG pad2[10];

	/*
	 *  Section 3: picture resources
	 */
	struct BitMap *BMap;		/* image bitmap */
	PLANEPTR MaskPlane;		/* stencil/alpha plane */
	struct Color *Palette;		/* color palette */
	struct ProjectInfo *ProjInfo;	/* project information */
	ULONG pad3[10];

	/*
	 *  Section 4: preview information
	 */
	UBYTE PreviewDepth;		/* preview screen depth */
	UBYTE pad4;
	struct Color *PreviewPalette;	/* preview screen colors (HAM) */
	ULONG PreviewDisplayID;		/* preview screen mode (HAM) */
	ULONG pad5[10];

	/*
	 *  Section 5: client program information
	 */
	LONG  UILanguage;		/* active language */
	UBYTE **LibUIText;		/* IO library strings */
	ULONG pad6[10];

	/*
	 *  Section 6: library bases
	 */
	struct ExecBase *SysBase;
	struct DosLibrary *DOSBase;
	struct GfxBase *GfxBase;
	struct IntuitionBase *IntuitionBase;
	struct Library *IconBase;
	ULONG pad7[10];

	/*
	 *  Section 7: function pointers
	 */
	BOOL  (*ReadFile) (UBYTE *buffer, LONG bytes);		// functions
	BOOL  (*WriteFile) (UBYTE *buffer, LONG bytes);
	LONG  (*SeekFile) (WORD mode, LONG bytes);
	BOOL  (*BumpProgress) (void);
	UBYTE (*FastReadPix) (struct BitMap *bmap, WORD x, WORD y);
	void  (*FastWritePix) (struct BitMap *bmap, WORD x, WORD y, UBYTE col);
	void  (*ChunkyToBMap) (UBYTE *pixbuf, struct BitMap *bmap, LONG offs);
	void  (*CommentToProjInfo) (UBYTE *buffer, struct ProjectInfo *pinfo);
	BOOL  (*ProjInfoToComment) (struct ProjectInfo *pinfo, UBYTE *buffer, WORD maxsize, BOOL do_auth, BOOL do_cpyr, BOOL do_note);
	UBYTE (*CryptKeyChar) (BOOL reset);
	WORD  (*CryptKeySign) (void);
	void  (*PreviewRow) (struct BitMap *bmap, WORD y);
	struct BitMap *(*CreateBitMap)(WORD width, WORD height, UBYTE depth, UWORD flags);
	void  (*DeleteBitMap)(struct BitMap *bmap);
	/* V4 functions */
	UBYTE *(*GetProjectInfo) (struct ProjectInfo *pinfo, WORD type);
	BOOL  (*SetProjectInfo) (struct ProjectInfo *pinfo, WORD type, UBYTE *string);
	BOOL  (*ProjectInfoToComment) (struct ProjectInfo *pinfo, UBYTE *buffer, WORD maxsize, ULONG do_flags);
};




/*
 *   Option structure
 */
struct DataOption
{
	WORD  Version;		/* client program interface version */
	WORD  Type;		/* option type */
	UBYTE Name[40];		/* option name */
	LONG  UITextStr;	/* client program user interface text */
	ULONG Flags;		/* attributes */
	LONG  Value;		/* current value */
	LONG  Min, Max, Default;/* minimum, maximum and default values */
	UBYTE String[80];	/* current string */
	UBYTE pad[32];
};

/* DataOption Type */
#define DOT_INTSTR	0  /* integer value (string gadget) */
#define DOT_INTSLIDE	1  /* integer value (proportional gadget) */
#define DOT_10000STR	2  /* value in 1/10000s (string gadget) */
#define DOT_BOOL	3  /* boolean value (checkbox gadget) */
#define DOT_STRING	4  /* string (string gadget) */
#define DOT_COLSLIDE	5  /* depth value (proportional gadget) */

/* DataOption UITextStr */
#define DOUI_WIDTH	0  /* Width: */
#define DOUI_HEIGHT	1  /* Height: */
#define DOUI_DEPTH	2  /* Depth: */
#define DOUI_COLUMNS	3  /* Columns: */
#define DOUI_ROWS	4  /* Rows: */
#define DOUI_COMPR	5  /* Compression: */
#define DOUI_MAXCOMP	6  /* Max Compression: */
#define DOUI_QUALITY	7  /* Quality: */
#define DOUI_SMOOTH	8  /* Smooth: */
#define DOUI_SCRFMT	9  /* Screen Format: */
#define DOUI_PROGDSP	10 /* Progressive Display: */
#define DOUI_AUTO	11 /* Automatic: */
#define DOUI_PADBYTE	12 /* Pad Byte: */
#define DOUI_BINARY	13 /* Binary: */
#define DOUI_FORMAT	14 /* Format: */
#define DOUI_COLORS	15 /* Colors: */
#define DOUI_GRAINNS	16 /* Graininess: */
#define DOUI_RSEED 	17 /* Random Seed: */
#define DOUI_GRAYS	18 /* Gray shades: */
#define DOUI_CMPTIB	19 /* Compatibility: */
#define DOUI_PARAM1	20 /* Parameter 1: */
#define DOUI_PARAM2	21 /* Parameter 2: */
#define DOUI_PARAM3	22 /* Parameter 3: */
#define DOUI_NONE	-1

/* DataOption Flags */
#define DOF_LOADOPTION	0x00000001  /* ReadPicture() option */




/*
 *   Color palette structure
 */
struct Color
{
	UBYTE Red, Green, Blue;	/* color components */
	UBYTE EFlag;		/* unused */
};




/*
 *   Project information structure
 *
 *   Note: This information must be accessed directly up to version 3 of
 *   the client I/O interface, and must instead be accessed via the
 *   GetProjectInfo() and SetProjectInfo() functions starting from clients
 *   having version 4 or higher.
 */
#define PRJINF_AUTSIZE   80
#define PRJINF_COPYRSIZE 80
#define PRJINF_ANNOTSIZE 80

struct ProjectInfo
{
	UWORD FromFile;   /* private: do not change */
	UBYTE Author[PRJINF_AUTSIZE];
	UBYTE Copyright[PRJINF_COPYRSIZE];
	UBYTE Annotation[PRJINF_ANNOTSIZE];
	/* V4: Data beyond this point! */
};




/* SetProjectInfo() type */
#define AUTHOR_INFO	0
#define COPYRIGHT_INFO	1
#define ANNOTATION_INFO	2

/* ProjectInfoToComment() do_flags */
#define AUTHOR_INFOF		(1<<0)
#define COPYRIGHT_INFOF		(1<<1)
#define ANNOTATION_INFOF	(1<<2)

/* SeekFile() mode */
#define SKF_ABSOLUTE		0	// seek from position 0
#define SKF_FROMCURR		1	// seek from current position

/* FastReadPix() FastWritePix() x */
#define FBMP_INIT	-1	/* initialize bitmap reading/writing */
#define FBMP_FLUSH	-2	/* flushes row buffer (FastWritePix()) */

/* CreateBitMap() flags */
#define CB_CLEAR	0x0001	/* clear all bitmap memory */
#define CB_CLEAN	0x0002	/* clear unused (rightmost) bitmap memory */
#define CB_KEEPWB	0x0004	/* do not use virtual memory */
#define CB_ANYMEM	0x0008	/* use any memory */
#define CB_FASTMEM	0x0010	/* use fast memory only */
#define CB_LONGW	0x0020	/* BytesPerRow forced to a multiple of 4 */
#define CB_CHIPMEM	0x0040	/* use chip memory only */

/*
 * SetOption(dinfo, SOPT_SELFLOPT) activates
 * the library load-option interface (DIF_SELFLOPT picture types only)
 */
#define SOPT_SELFLOPT	((struct DataOption *)0L)

/*
 * SetOption(dinfo, SOPT_SELFSOPT) activates
 * the library save-option interface (DIF_SELFSOPT picture types only)
 */
#define SOPT_SELFSOPT	((struct DataOption *)0xFFFFFFFF)




/*
 *  GetPictureInfo(), ReadPicture(), WritePicture() return codes
 */
#define PIOERR_OK	0  /* no error / file recognized */
#define PIOERR_CANCEL	1  /* user cancelled */
#define PIOERR_PARTIAL	2  /* image data partially loaded */
#define PIOERR_BADVER	3  /* a newer interface version is required */
#define PIOERR_BADTYPE	4  /* file not recognized */
#define PIOERR_FILE_ERR	5  /* file I/O error */
#define PIOERR_NODATA	6  /* the file does not contain the required data */
#define PIOERR_NOMEMORY	7  /* not enough memory */
#define PIOERR_NODECRYP	8  /* decryption impossible */
#define PIOERR_UIMGTYP	9  /* unsupported image type */
#define PIOERR_UKCMPR	10 /* uncknown compression */
#define PIOERR_BADDATA	11 /* error in file data */




/*
 *  Picture type and option storage structures
 *
 *  Note: these are not part of the library interface, but instead
 *        are just a storage system for library implementations.
 */
struct DataInfoEntry
{
	ULONG Code;		/* picture type code */
	ULONG Flags;		/* attributes */
	ULONG ProcessData;	/* data items processable */
	LONG  Priority;		/* sort priority */
	UBYTE *Name;		/* full name */
	UBYTE *ShortName;	/* short name */
	UBYTE *FileSuffix[3];	/* file name suffixes ('.' included) */
};

struct DataOptionEntry
{
	WORD  Type;		/* option type */
	UBYTE *Name;		/* option name */
	LONG  UITextStr;	/* client program user interface text */
	ULONG Flags;		/* attributes */
	LONG  Value;		/* current value */
	LONG  Min, Max, Default;/* minimum, maximum and default values */
	UBYTE String[80];	/* current string */
};


#endif /* LIBRARIES_PERSONAL_IO_H */
