#ifndef __RV_IMIO_H_INCLUDED_
#define __RV_IMIO_H_INCLUDED_



#define IMIO_API  WINAPI

#include <tchar.h>

 
#include <rvb\img.h> 



#define RV_IMIO_READ_ONLY    1
#define RV_IMIO_CREATE_NEW   (1<<1)
#define RV_IMIO_CACHE        (1<<2)
#define RV_IMIO_DEFUALT      RV_IMIO_READ_ONLY

//image file format
#define RV_IFF_BMP     _T("bmp")
#define RV_IFF_ICO      _T("ico")
#define RV_IFF_JPG      _T("jpg")
#define RV_IFF_JPEG     _T("jpeg")
#define RV_IFF_JNG      _T("jng")
#define RV_IFF_KOALA    _T("koa")
#define RV_IFF_LBM      _T("lbm")
#define RV_IFF_IFF      _T("iff")
#define RV_IFF_MNG      _T("mng")
#define RV_IFF_PBM      _T("pbm")
#define RV_IFF_PBMRAW   _T("pbm")
#define RV_IFF_PCD          _T("pcd")
#define RV_IFF_PCX          _T("pcx")
#define RV_IFF_PGM          _T("pgm")
#define RV_IFF_PGMRAW       _T("pgm")
#define RV_IFF_PNG          _T("png")
#define RV_IFF_PPM          _T("ppm")
#define RV_IFF_PPMRAW       _T("ppm")
#define RV_IFF_RAS          _T("ras")
#define RV_IFF_TARGA          _T("targa")
#define RV_IFF_TGA            _T("tga")
#define RV_IFF_TIFF          _T("tiff")
#define RV_IFF_TIF           _T("tif")
#define RV_IFF_WBMP          _T("wbmp")
#define RV_IFF_PSD          _T("psd")
#define RV_IFF_CUT          _T("cut")
#define RV_IFF_XBM          _T("xbm")
#define RV_IFF_XPM          _T("xpm")
#define RV_IFF_DDS          _T("dds")
#define RV_IFF_GIF          _T("gif")
#define RV_IFF_HDR          _T("hdr")
#define RV_IFF_FAXG3        _T("faxg3")
#define RV_IFF_SGI          _T("sgi")
#define RV_IFF_EXR          _T("exr")
#define RV_IFF_J2K          _T("j2k")
#define RV_IFF_JP2          _T("jp2")
#define RV_IFF_PFM          _T("pfm")
#define RV_IFF_PICT          _T("pict")
#define RV_IFF_RAW          _T("raw")


#define RV_IFF_DEFAULT      NULL
 
 


//memory image format
#define RV_IMF_DEFAULT	  -1 
#define RV_IMF_BMP		  0 
#define RV_IMF_ICO		  1 
#define RV_IMF_JPEG       2 
#define RV_IMF_JPG        RV_IMF_JPEG
#define RV_IMF_JNG        3
#define RV_IMF_KOALA      4
#define RV_IMF_LBM        5
#define RV_IMF_IFF        RV_IMF_LBM
#define RV_IMF_MNG		  6
#define RV_IMF_PBM		  7
#define RV_IMF_PBMRAW	  8
#define RV_IMF_PCD		  9
#define RV_IMF_PCX		  10
#define RV_IMF_PGM		  11
#define RV_IMF_PGMRAW     12
#define RV_IMF_PNG		  13 
#define RV_IMF_PPM		  14 
#define RV_IMF_PPMRAW	  15
#define RV_IMF_RAS		  16
#define RV_IMF_TARGA	  17
#define RV_IMF_TGA         RV_IMF_TARGA
#define RV_IMF_TIFF	      18 
#define RV_IMF_TIF        RV_IMF_TIFF
#define RV_IMF_WBMP	      19 
#define RV_IMF_PSD	      20 
#define RV_IMF_CUT	      21
#define RV_IMF_XBM	      22 
#define RV_IMF_XPM	      23
#define RV_IMF_DDS	      24
#define RV_IMF_GIF        25
#define RV_IMF_HDR	      26
#define RV_IMF_FAXG3	  27
#define RV_IMF_SGI	      28
#define RV_IMF_EXR	      29
#define RV_IMF_J2K	      30
#define RV_IMF_JP2	  	  31
#define RV_IMF_PFM	  	  32
#define RV_IMF_PICT	  	  33
#define RV_IMF_RAW	      34

 

 
 
//encode and decode flags
#define RV_LOAD_NOPIXELS       0x8000 // loading: load the image header only (not supported by all plugins)   
#define RV_BMP_DEFAULT          0
#define RV_BMP_SAVE_RLE         1
#define RV_CUT_DEFAULT          0
#define RV_DDS_DEFAULT			0
#define RV_EXR_DEFAULT			0		// save data as half with piz-based wavelet compression
#define RV_EXR_FLOAT			0x0001	// save data as float instead of as half (not recommended)
#define RV_EXR_NONE			    0x0002	// save with no compression
#define RV_EXR_ZIP				0x0004	// save with zlib compression, in blocks of 16 scan lines
#define RV_EXR_PIZ				0x0008	// save with piz-based wavelet compression
#define RV_EXR_PXR24			0x0010	// save with lossy 24-bit float compression
#define RV_EXR_B44				0x0020	// save with lossy 44% float compression - goes to 22% when combined with EXR_LC
#define RV_EXR_LC				0x0040	// save images with one luminance and two chroma channels, rather than as RGB (lossy compression)
#define RV_FAXG3_DEFAULT		0

//GIF
#define RV_GIF_DEFAULT   0
#define RV_GIF_LOAD256   1//若图象为2色或16色，则将其作为具有未使用的调色板入口的256色图象来载入
#define RV_GIF_PLAYBACK  2//载入图象时'播放'GIF以产生每一桢(以32bpp的方式),而不是返回原始桢数据

//GIF disposal type
#define RV_GIF_DISPOSAL_UNSPECIFIED  0
#define RV_GIF_DISPOSAL_LEAVE        1 
#define RV_GIF_DISPOSAL_BACKGROUND   2 
#define RV_GIF_DISPOSAL_PREVIOUS     3 


//ICO
#define RV_ICO_MAKEALPHA  1//载入图象时将其转换为32位，并从AND-掩码中产生一个alpha通道
//JPEG 
#define RV_JPEG_DEFAULT        0		// loading (see JPEG_FAST); saving (see JPEG_QUALITYGOOD|JPEG_SUBSAMPLING_420)
#define RV_JPEG_FAST           0x0001	// load the file as fast as possible, sacrificing some quality
#define RV_JPEG_ACCURATE       0x0002	// load the file with the best quality, sacrificing some speed
#define RV_JPEG_CMYK			0x0004	// load separated CMYK "as is" (use | to combine with other load flags)
#define RV_JPEG_EXIFROTATE      0x0008      //Load and rotate according to Exif 'Orientation' tag if available
//PCD 
#define RV_PCD_DEFAULT         0
#define RV_PCD_BASE            1		// load the bitmap sized 768 x 512
#define RV_PCD_BASEDIV4        2		// load the bitmap sized 384 x 256
#define RV_PCD_BASEDIV16       3		// load the bitmap sized 192 x 128
//PNG 
#define RV_PNG_DEFAULT         0
//TGA 
#define RV_TGA_DEFAULT       0
#define RV_TGA_LOAD_RGB888   1       // If set the loader converts RGB555 and ARGB8888 -> RGB888.
//JPEG
#define RV_JPEG_EXIFROTATE		0x0008	// load and rotate according to Exif 'Orientation' tag if available
#define RV_JPEG_QUALITYSUPERB  0x80	// save with superb quality (100:1)
#define RV_JPEG_QUALITYGOOD    0x0100	// save with good quality (75:1)
#define RV_JPEG_QUALITYNORMAL  0x0200	// save with normal quality (50:1)
#define RV_JPEG_QUALITYAVERAGE 0x0400	// save with average quality (25:1)
#define RV_JPEG_QUALITYBAD     0x0800	// save with bad quality (10:1)
        //1|100间的整数x: 以x:1的品质保存

#define RV_JPEG_PROGRESSIVE	0x2000	// save as a progressive-JPEG (use | to combine with other save flags)
#define RV_JPEG_SUBSAMPLING_411 0x1000		// save with high 4x1 chroma subsampling (4:1:1) 
#define RV_JPEG_SUBSAMPLING_420 0x4000		// save with medium 2x2 medium chroma subsampling (4:2:0) - default value
#define RV_JPEG_SUBSAMPLING_422 0x8000		// save with low 2x1 chroma subsampling (4:2:2) 
#define RV_JPEG_SUBSAMPLING_444 0x10000	// save with no chroma subsampling (4:4:4)
#define RV_JPEG_OPTIMIZE		0x20000		// on saving, compute optimal Huffman coding tables (can reduce a few percent of file size)
#define RV_JPEG_BASELINE		0x40000		// save basic JPEG, without metadata or any markers

#define RV_KOALA_DEFAULT       0
#define RV_LBM_DEFAULT         0
#define RV_MNG_DEFAULT         0

#define RV_PCX_DEFAULT         0
#define RV_PFM_DEFAULT         0
#define RV_PICT_DEFAULT        0

//PNG
#define RV_PNG_Z_BEST_SPEED			0x0001	// save using ZLib level 1 compression flag (default value is 6)
#define RV_PNG_Z_DEFAULT_COMPRESSION	0x0006	// save using ZLib level 6 compression flag (default recommended value)
#define RV_PNG_Z_BEST_COMPRESSION		0x0009	// save using ZLib level 9 compression flag (default value is 6)
#define RV_PNG_Z_NO_COMPRESSION		0x0100	// save without ZLib compression
#define RV_PNM_DEFAULT         0
//PSD
#define RV_PSD_DEFAULT         0
#define RV_PSD_CMYK			1		// reads tags for separated CMYK (default is conversion to RGB)
#define RV_PSD_LAB				2		// reads tags for CIELab (default is conversion to RGB)
//ras
#define RV_RAS_DEFAULT         0
 //TIFF 
#define RV_TIFF_DEFAULT         0
#define RV_TIFF_CMYK			0x0001	// reads/stores tags for separated CMYK (use | to combine with compression flags)
//WBMP
#define RV_WBMP_DEFAULT         0
 

//METADATA MODEL 
#define RV_MDM_COMMENTS		      0 	// single comment or keywords
#define RV_MDM_EXIF_MAIN		  1 	// Exif-TIFF metadata
#define RV_MDM_EXIF_EXIF		  2 	// Exif-specific metadata
#define RV_MDM_EXIF_GPS		      3     // Exif GPS metadata
#define RV_MDM_EXIF_MAKERNOTE     4 	// Exif maker note metadata
#define RV_MDM_EXIF_INTEROP	      5 	// Exif interoperability metadata
#define RV_MDM_IPTC			      6 	// IPTC/NAA metadata
#define RV_MDM_XMP			      7 	// Abobe XMP metadata
#define RV_MDM_GEOTIFF		      8 	// GeoTIFF metadata
#define RV_MDM_ANIMATION		  9 	// Animation metadata
#define RV_MDM_EXIF_RAW		      11
 


typedef  HANDLE    HIMAGEPAGE;
typedef  HANDLE    HMULTIIMAGEPAGE;

//quantize color
#define RV_QC_DEFAULT     -1 
#define RV_QC_WUQUANT      0 //
#define RV_QC_NNQUANT      1 //


//metadata type
enum {  
    RV_MT_NOTYPE		= 0,	// placeholder 
	RV_MT_BYTE		= 1,	// 8-bit unsigned integer 
	RV_MT_ASCII		= 2,	// 8-bit bytes w/ last byte null 
	RV_MT_SHORT		= 3,	// 16-bit unsigned integer 
	RV_MT_LONG		= 4,	// 32-bit unsigned integer 
	RV_MT_RATIONAL	= 5,	// 64-bit unsigned fraction 
	RV_MT_SBYTE		= 6,	// 8-bit signed integer 
	RV_MT_UNDEFINED	= 7,	// 8-bit untyped data 
	RV_MT_SSHORT		= 8,	// 16-bit signed integer 
	RV_MT_SLONG		= 9,	// 32-bit signed integer 
	RV_MT_SRATIONAL	= 10,	// 64-bit signed fraction 
	RV_MT_FLOAT		= 11,	// 32-bit IEEE floating point 
	RV_MT_DOUBLE		= 12,	// 64-bit IEEE floating point 
	RV_MT_IFD		= 13,	// 32-bit unsigned integer (offset) 
	RV_MT_PALETTE	= 14,	// 32-bit RGBQUAD 
	RV_MT_LONG8		= 16,	// 64-bit unsigned integer 
	RV_MT_SLONG8		= 17,	// 64-bit signed integer
	RV_MT_IFD8		= 18	// 64-bit unsigned integer (offset)
};

//从指定的位置装载不同格式的图象文件,并创建一个新的RVB图象对象。
extern "C" RvImage IMIO_API rvLoadImage(const TCHAR *strFileName, const TCHAR* strFormat=RV_IFF_DEFAULT, int flag=0);

//指定的位置装载不同格式的图象文件,将图象数据装载到指定的RVB对象。
extern "C" BOOL IMIO_API    rvLoadImageEx(RvImage image, const TCHAR *strFileName, const TCHAR* strFormat=RV_IFF_DEFAULT, int flag=0);

//将指定的RVB对象的图象数据进行编码,并保存为指定格式的文件。
extern "C" BOOL  IMIO_API   rvSaveImage(const RvImage image, const TCHAR *strFileName, const TCHAR* strFormat=RV_IFF_DEFAULT , int flag=0);

//读取内存中的图象。创建新的RVB图象。
extern "C" RvImage IMIO_API  rvLoadImageInMemory(void* pData, UINT size, int nFormat=RV_IMF_DEFAULT, int flag=0);

//读取内存中的图象,将图象数据保存到已有的RVB图象对象里面。
extern "C" BOOL  IMIO_API    rvLoadImageInMemoryEx(RvImage image, void* pData, UINT size, int nFormat=RV_IMF_DEFAULT, int flag=0);

//将RVB图象对象转换成指定的格式,并输出到内存。
//注意不同的格式支持的rvb图象格式不一样，如jpg只能支持RGB或GRAY图象。
extern "C" UINT IMIO_API   rvExportImageToMemory(RvImage image,  int nFormat, void* pBuffer, UINT size, int flag =0);


//打开多页文件如TIF,GIF等,创建多页对象。
extern "C" HMULTIIMAGEPAGE IMIO_API  rvOpenMultiImagePage(const TCHAR *strFileName, const TCHAR* strFormat=RV_IFF_DEFAULT,  int fio = RV_IMIO_DEFUALT, int flag=0);

//打开多页文件如TIF,GIF等,创建多页对象。
extern "C" HMULTIIMAGEPAGE IMIO_API rvOpenMultiImagePageInMemory(const TCHAR *data, UINT size, int nFormat=RV_IMF_DEFAULT,int flag=0);

//销毁多页对象
extern "C" void IMIO_API  rvCloseMultiImagePage(HMULTIIMAGEPAGE hMultiImagePage);

//获取多页图象中的页数
extern "C" int  IMIO_API     rvGetMultiImagePageCount(HMULTIIMAGEPAGE hMultiImagePage);

//将指定的多页图象中的某一页锁住,并返回该页。注意由该函数返回的单页必须有rvUnlockMultiImagePage解锁。
extern "C" HIMAGEPAGE IMIO_API   rvLockMultiImagePage(HMULTIIMAGEPAGE hMultiImagePage, int index);

//将锁住的页解锁。
extern "C" void IMIO_API   rvUnlockMultiImagePage (HMULTIIMAGEPAGE hMultiImagePage, HIMAGEPAGE  hImagePage, BOOL bChanged=FALSE);

//打开指定位置的图象文件,创建一个单页对象,并返回。注意：该函数返回的单页对象必须调用rvCloseImagePage进行关闭。
extern "C" HIMAGEPAGE IMIO_API rvOpenImagePage(const TCHAR *strFileName, const TCHAR* strFormat=RV_IFF_DEFAULT,int flag=0);

//创建一个单页对象,读取内存区的数据对象,并返回。注意：该函数返回的单页对象必须调用rvCloseImagePage进行关闭。
extern "C" HIMAGEPAGE IMIO_API rvOpenImagePageInMemory(const TCHAR *data, UINT size, int nFormat=RV_IMF_DEFAULT ,int flag=0);

//关闭单页对象。
extern "C" void IMIO_API   rvCloseImagePage(HIMAGEPAGE hImagePage);


//从IMAGEPAGE里面装载图象
extern "C" RvImage IMIO_API rvLoadFromImagePage(const HIMAGEPAGE hImagePage);
//从IMAGEPAGE里面装载图象
extern "C" BOOL  IMIO_API rvLoadFromImagePageEx(const HIMAGEPAGE hImagePage, RvImage image);

//将rvb图象格式的数据处处到IMAGEPAGE。两对象的大小必须相同: 宽度，高度，深度
extern "C" BOOL IMIO_API rvExportToImagePageEx(const RvImage image, HIMAGEPAGE hImagePage );

extern "C" HIMAGEPAGE IMIO_API rvExportToImagePage(const RvImage image  );

//获取单页的图象数据区的开始地址。
extern "C" RvByte* IMIO_API   rvGetImagePageBits (HIMAGEPAGE hImagePage);

//颜色采样
extern "C" void IMIO_API     rvQuantizeImagePageColor(HIMAGEPAGE hImagePage, int method = RV_QC_WUQUANT );

//颜色采样，如果有透明层(32),支持背景颜色转换
extern "C" void IMIO_API     rvQuantizeImagePageColorEx(HIMAGEPAGE hImagePage, int method  , RvRgba backColor );


//添加单页图像
extern "C" void IMIO_API     rvAppendImagePage(HMULTIIMAGEPAGE hMultiImagePage, HIMAGEPAGE hImagePage  );

 


//获取单页的图象的像素位（每个像素由多少位组成）
extern "C" int IMIO_API   rvGetImagePageBPP (HIMAGEPAGE hImagePage);

//以像素为单位返回位图宽度。
extern "C" int IMIO_API rvGetImagePageWidth (HIMAGEPAGE hImagePage);

//以像素为单位返回位图高度。
extern "C" int IMIO_API rvGetImagePageHeight(HIMAGEPAGE hImagePage);

//以字节为单位返回位图宽度。
extern "C" int IMIO_API rvGetImagePageLine(HIMAGEPAGE hImagePage);

//以字节为单位返回对齐到下一个32位字节边界 的位图宽度,又称位深度或线宽度(stride)或扫描宽度。
extern "C" int IMIO_API rvGetImagePagePitch(HIMAGEPAGE hImagePage);

//返回内存中一个FIBITMAP的DIB分量的大小,即BITMAPINFOHEADER+调色板+数据位(注意这不是FIBITMAP的真正大小,仅是其DIB分量的大小)。
extern "C" int IMIO_API rvGetImagePageSize(HIMAGEPAGE hImagePage);

//返回指向位图调色板的指针。如果位图没有调色板(即当像素的位深度大于8时),该函数返回NULL。
extern "C" RGBQUAD* IMIO_API rvGetImagePagePalette(HIMAGEPAGE hImagePage);

//返回在一个位图中使用的颜色数。对于配色位图,该函数返回调色板大小,而对于多色位图（high-colour bitmap）返回0。
extern "C" int IMIO_API  rvGetImagePageColorsUsed(HIMAGEPAGE hImagePage);

//返回指向一个FIBITMAP中的DIB分量的BITMAPINFOHEADER结构的指针。
extern "C" BITMAPINFOHEADER* IMIO_API rvGetImagePageInfoHeader(HIMAGEPAGE hImagePage);

//等同于FreeImage GetInfoHeader，但返回的是指向一个BITMAPINFO结构的指针，而不是指向一个BITMAPINFOHEADER结构的指针
extern "C" BITMAPINFO* IMIO_API rvGetImagePageInfo(HIMAGEPAGE hImagePage);

//读取单页图象的属性,该属性数据类型为整数类型。
extern "C" BOOL IMIO_API  rvReadImagePagePropertyInt(HIMAGEPAGE hImagePage, int nModel, const TCHAR* strName, int* pVal);

//读取单页图象的属性,该属性数据类型为无符号整数类型。
extern "C" BOOL  IMIO_API rvReadImagePagePropertyUint(HIMAGEPAGE hImagePage, int nModel, const TCHAR* strName, unsigned int* pVal);

//读取单页文件的属性,该属性数据类型为浮点类型。
extern "C" BOOL IMIO_API  rvReadImagePagePropertyDouble(HIMAGEPAGE hImagePage, int nModel, const TCHAR* strName, double* pVal);

//读取单页图象的属性,该属性数据类型为字符串类型。
extern "C" BOOL IMIO_API  rvReadImagePagePropertyString(HIMAGEPAGE hImagePage, int nModel,  const TCHAR* strName,TCHAR* pVal, int size);

//写入单页图象的属性,该属性数据类型为整数类型。
//RV_MT_NOTYPE
extern "C" BOOL IMIO_API  rvWriteImagePagePropertyInt(HIMAGEPAGE hImagePage, int nModel, int dataType ,  const TCHAR* strName, int val);



//读取内存BITMAP图象数据，数据区不包含格式信息。
extern "C" RvImage  IMIO_API rvLoadBitmapInMemory(BITMAPINFO* pBitmapInfo, void* pData, UINT dataSize);


//读取内存BITMAP图象数据。
extern "C" BOOL   IMIO_API   rvLoadBitmapInMemoryEx(RvImage image, BITMAPINFO* pBitmapInfo, void* pData, UINT dataSize);

 
 



#endif   //__RV_IMIO_H_INCLUDED_
