#ifndef IMAGEIO_H
#define IMAGEIO_H

/*
**	$VER: imageio.h 2.2 (6.12.99)
**
**	Public structures and defintions for imageio.library.
**
**	© Paul Huxham
*/

#ifndef EXEC_TYPES_H
#include "exec/types.h"
#endif

#ifndef DOS_DOS_H
#include <dos/dos.h>
#endif

#ifndef UTILITY_TAGITEM_H
#include <utility/tagitem.h>
#endif

/*========================================================================*/
/* Public object handle */

/* Used for imageio access */
struct ImageHandle
{
	ULONG private;
};

/*========================================================================*/
/* Public filetype list:
		Returned as an array of structs with filetype == NULL at end of list */
struct ImageFormat
{
	UBYTE filetype; // Defined below

	UBYTE reserved0;
	WORD reserved1;

	ULONG end; // If not NULL then there are more entries in the array
	ULONG reserved2, reserved3, reserved4;
	ULONG writeable; // If non NULL, image is writeable
	ULONG reserved5;
	ULONG reserved6;
};

/* Image write type list:
		Returned as an array of structs with filetype == NULL at end of list */
struct ImageWriteType
{
	UBYTE filetype; // Defined below

	char *text; // Text representative of save format

	ULONG userdata; // Image type context data
};

/*========================================================================*/
/* Colour spaces, retreive these as UBYTEs */
enum
{
	IRCS_UNKNOWN = 0,
	IRCS_RGB, // RGB triplets
	IRCS_GREY, // Greyscale
	IRCS_ARGB, // ARGB quads
	IRCS_RGBA, // ARGB quads
};

/* For return buffer as a particular type */
#define IRCS_ASLOADED IRCS_UNKNOWN

/*========================================================================*/
/* Filetypes */
enum
{
	IMGF_UNKNOWN = 0, IMGF_ANIM, IMGF_BMP, IMGF_FAXX, IMGF_GIF, IMGF_ICON, IMGF_ILBM, IMGF_IFF24, IMGF_JPEG,
	IMGF_MACPAINT, IMGF_PBM, IMGF_PCD, IMGF_PCX, IMGF_PICT, IMGF_PNG, IMGF_POSTSCRIPT, IMGF_TARGA,
	IMGF_TIFF, IMGF_YCRCB, IMGF_YUVN, IMGF_SCREEN, IMGF_MPEG, IMGF_IMG, IMGF_PNM,

	/* These entries MUST be last */
	IMGF_SUPERVIEW = 253, /* Is not really a filetype by itself */
	IMGF_DATATYPE = 254, /* Is not really a filetype by itself */
	IMGF_MEMORY = 255 /* A buffer stored already in memory */
};
// These MUST remain the same as proof.library

/*========================================================================*/
/* Public callback hooks */

/* The storage hook is called once for each scanline in the image.
		a0 contains a UBYTE pointer to the scanline to copy
		d0 contains a ULONG with the scanline number of this data (1 being
				first scanline)
		d1 contains a ULONG with the number of bytes in this row
		a1 contains the userdata

	If the hook returns a non NULL value, the reading will be aborted -
	You should NOT call any functions other than FreeImage() on that object.
*/

typedef ULONG (*IMGS_HOOK)( void *, ULONG, ULONG, void * );
typedef __asm ULONG (*IMGS_HOOK_PROTO)( register __a0 void *, register __d0 ULONG, register __d1 ULONG, register __a1 void * );

/* The progress hook is called once for each scanline in the image (during
		reading).
		d0 contains a ULONG with the current scanline number (1-n).
		d1 contains a ULONG with the total number of scanlines.
		a0 contains the userdata

	If the hook returns a non NULL value, the reading will be aborted -
	You should NOT call any functions other than FreeImage() on that object.
*/

typedef ULONG (*IMGP_HOOK)( ULONG, ULONG, void * );
typedef __asm ULONG (*IMGP_HOOK_PROTO)( register __d0 ULONG, register __d1 ULONG, register __a0 void * );

/* The render hook is called once for each decompressed scanline in the
		image.
		a0 contains a UBYTE pointer to the scanline data
		d0 contains a ULONG with the scanline number of this data (1 being
				first scanline)
		d1 contains a ULONG with the number of bytes in this row
		a1 contains the userdata

	If the hook returns a non NULL value, the reading will be aborted -
	You should NOT call any functions other than FreeImage() on that object.
*/

typedef ULONG (*IMGR_HOOK)( void *, ULONG, ULONG, void * );
typedef __asm ULONG (*IMGR_HOOK_PROTO)( register __a0 void *, register __d0 ULONG, register __d1 ULONG, register __a1 void * );

/*========================================================================*/
/* ImageIO tagbase */
#define IMG_TB ( TAG_USER + 0x80000 )

/* ImageIO tags requiring V1.0 */
#define IMG_SrcMemStream IMG_TB + 1 /* Pointer to stream data in memory (UBYTE *) */
#define IMG_SrcMemStreamSize IMG_TB + 2 /* Length in bytes of data stream (ULONG) */
#define IMG_SrcFile IMG_TB + 3 /* Pointer to an open file (BPTR) */
#define IMG_ImageBuffer IMG_TB + 4 /* Pointer to a memory block (UBYTE *) */
#define IMG_StorageHook IMG_TB + 5 /* Pointer to a function to store scan lines */
#define IMG_StorageUserData IMG_TB + 6 /* Pointer to user data (void *) */
#define IMG_ProgressHook IMG_TB + 7 /* Pointer to a function to display progress status */
#define IMG_ProgressUserData IMG_TB + 8 /* Pointer to user data (void *) */
#define IMG_RenderHook IMG_TB + 9 /* Pointer to a function to render decoded scan lines */
#define IMG_RenderUserData IMG_TB + 10 /* Pointer to user data (void *) */
#define IMG_MemoryPool IMG_TB + 11 /* All de/allocs are on this memory pool (void *) [U] */
#define IMG_ScaleNum IMG_TB + 12 /* Numerator for scaling (ULONG) */
#define IMG_TestScaleNum IMG_TB + 13 /* Test numerator for scaling (ULONG) [USE] */
#define IMG_ScaleDenom IMG_TB + 14 /* Denomenator for scaling (ULONG) */
#define IMG_TestScaleDenom IMG_TB + 15 /* Test denomenator for scaling (ULONG) [USE] */
#define IMG_Width IMG_TB + 16 /* Width of image in pixels (ULONG *) */
#define IMG_Height IMG_TB + 17 /* Height of image in pixels (ULONG *) */
#define IMG_BytesPerPixel IMG_TB + 18 /* Number of bytes per image pixel (ULONG *) */
#define IMG_RowSize IMG_TB + 19 /* Size of one row (ULONG *) [GET only] */
#define IMG_ColourSpace IMG_TB + 20 /* Type of image data (UBYTE *) [GET only] */
#define IMG_ImageType IMG_TB + 21 /* Image type, defined above (UBYTE *) */
#define IMG_AsciiImageType IMG_TB + 22 /* Ascii image type (char *, minimum 8 characters in length) */

/* These tags are passed to the image loading if it is of the same type */
#define IMG_JPEG_DCTMethod IMG_TB + 23 /* The DCT processing method */

#define IMG_JPEG_Quality IMG_TB + 24 /* Jpeg save quality 1-100 () */
#define IMG_JPEG_Progressive IMG_TB + 25 /* Save in progressive format (BOOL) */
#define IMG_QuerySaveable IMG_TB + 26 /* *Query* saveable in this format (UBYTE *) */
#define IMG_RGBBuffer IMG_TB + 27 /* Points to an existing RGB buffer in memory (UBYTE *) */
#define IMG_AllowEncoded IMG_TB + 28 /* Allow the decoding of ascii encoded files, defaults to FALSE. Overrides users preferences (BOOL) */
#define IMG_MakeReturnedBuffer IMG_TB + 29 /* Make the returned buffer pointer this type (UBYTE) - see colour spaces (NOT IMPLEMENTED) */
#define IMG_WriteType IMG_TB + 30 /* Write the image as this type (UBYTE) - see filetype list (useful only for datatypes and superview) */
#define IMG_IsDecoded IMG_TB + 31 /* Is the image loaded from a decoded file format (eg UU) (BOOL) [G] */
#define IMG_DecodedName IMG_TB + 32 /* Copy into this char *, the filename of the encodedfile (char *) [G] */
#define IMG_WriteDecodedFile IMG_TB + 33 /* Write the decoded file to this path/filename (char *) */

#define IMG_ImagePlanar IMG_TB + 34 /* Image data is planar [G] ULONG * */
#define IMG_ImageChunky IMG_TB + 35 /* Image data is chunky [G] ULONG * */
#define IMG_ImageHAM6 IMG_TB + 36 /* Image data is HAM6 [G] ULONG * */
#define IMG_ImageHalfBrite IMG_TB + 37 /* Image data is HALFBRITE [G] ULONG **/
#define IMG_ImageHAM8 IMG_TB + 38 /* Image data is HAM8 [G] ULONG * */
#define IMG_Image24Bit IMG_TB + 39 /* Image data is 24BIT [G] ULONG * */
#define IMG_ImagePalette IMG_TB + 40 /* Image data is 24BIT [G] ULONG * */
#define IMG_ImageGrey IMG_TB + 41 /* Image data has grey scale palette [G] ULONG * */
#define IMG_ImageFormat IMG_TB + 42 /* Flags field of ilbm image [G] UBYTE * */
#define IMG_ImageDepth IMG_TB + 43 /* Colour depth of ilbm image [G] UBYTE * */

/*========================================================================*/
/* JPEG DCT methods */
enum
{
	JPEG_DCT_ISLOW, // Slow but accurate integer algorithm (default)
	JPEG_DCT_IFAST, // Faster, less accurate integer method
	JPEG_DCT_FLOAT // Floating-point: accurate, fast on fast hardware
};

/*========================================================================*/
/* Defined error return codes */
#define IMGERR_NONE 0 /* No error */
#define IMGERR_NOMEMORY 1 /* Insufficient memory */
#define IMGERR_NOHANDLE 2 /* No image handle supplied */
#define IMGERR_CREATEOBJECT 3 /* Failed to create image object */
#define IMGERR_READFAILURE 4 /* Failed to read image */
#define IMGERR_NOSRCSTREAM 5 /* No source stream to read */
#define IMGERR_READABORTED 6 /* Reading aborted by user hook */
#define IMGERR_ALREADYREAD 7 /* Handle has already been read */
#define IMGERR_NOTKNOWN 8 /* The stream is in an unknown format */
#define IMGERR_CORRUPT 9 /* The stream is corrupt */
#define IMGERR_BADHANDLE 10 /* Handle not initialized correctly (internal) */
#define IMGERR_NOINFO 11 /* Cant get image information from the handle */
#define IMGERR_NOBUFFER 12 /* No image buffer */
#define IMGERR_MISSINGTARGET 13 /* Missing target variable pointer */
#define IMGERR_NOTLOADED 14 /* The image is not loaded yet */
#define IMGERR_BADSCALESIZE 15 /* Out of range scaling parameters */
#define IMGERR_SAVENOTSUPPORTED 16 /* Saving in this format not supported */
#define IMGERR_FILEEXISTS 17 /* Save file already exists - not saved */
#define IMGERR_WRITEABORTED 18 /* Writing aborted by user hook */
#define IMGERR_WRITEFAILURE 19 /* Failed to write image */
#define IMGERR_NOTENCODED 20 /* Image is not ascii encoded */
#define IMGERR_NOFILENAME 21 /* No path/filename supplied */

#endif /* IMAGEIO_H */
