Update of /cvsroot/vba/VisualBoyAdvance/win32/include/cximage In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28367/include/cximage Added Files: xfile.h ximabmp.h ximadefs.h ximage.h ximagif.h ximaico.h ximaiter.h ximaj2k.h ximajas.h ximajbg.h ximajpg.h ximamng.h ximapcx.h ximapng.h ximatga.h ximatif.h ximawbmp.h ximawmf.h xiofile.h xmemfile.h Log Message: Added support for JPEG/PNG skin images --- NEW FILE: xfile.h --- /* * File: xfile.h * Purpose: General Purpose File Class */ /* === C R E D I T S & D I S C L A I M E R S ============== * Permission is given by the author to freely redistribute and include * this code in any program as long as this credit is given where due. * * CxFile (c) 11/May/2002 Davide Pizzolato - www.xdp.it * CxFile version 2.00 23/Aug/2002 * See the file history.htm for the complete bugfix and news report. * * Special thanks to Chris Shearer Cooper for new features, enhancements and bugfixes * * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. * * Use at your own risk! * ========================================================== */ #if !defined(__xfile_h) #define __xfile_h #ifdef WIN32 #include <windows.h> #endif #include <stdio.h> #include <stdlib.h> #include "ximadefs.h" class DLL_EXP CxFile { public: CxFile(void) { }; virtual ~CxFile() { }; virtual bool Close() = 0; virtual size_t Read(void *buffer, size_t size, size_t count) = 0; virtual size_t Write(const void *buffer, size_t size, size_t count) = 0; virtual bool Seek(long offset, int origin) = 0; virtual long Tell() = 0; virtual long Size() = 0; virtual bool Flush() = 0; virtual bool Eof() = 0; virtual long Error() = 0; virtual bool PutC(unsigned char c) { // Default implementation size_t nWrote = Write(&c, 1, 1); return (bool)(nWrote == 1); } virtual long GetC() = 0; }; #endif //__xfile_h --- NEW FILE: ximabmp.h --- /* * File: ximabmp.h * Purpose: BMP Image Class Loader and Writer */ /* === C R E D I T S & D I S C L A I M E R S ============== * CxImageBMP (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it * Permission is given by the author to freely redistribute and include * this code in any program as long as this credit is given where due. * * CxImage version 5.99a 08/Feb/2004 * See the file history.htm for the complete bugfix and news report. * * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes * * original CImageBMP and CImageIterator implementation are: * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx> * * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. * * Use at your own risk! * ========================================================== */ #if !defined(__ximaBMP_h) #define __ximaBMP_h #include "ximage.h" const int RLE_COMMAND = 0; const int RLE_ENDOFLINE = 0; const int RLE_ENDOFBITMAP = 1; const int RLE_DELTA = 2; #if !defined(BI_RLE8) #define BI_RLE8 1L #endif #if !defined(BI_RLE4) #define BI_RLE4 2L #endif #if CXIMAGE_SUPPORT_BMP class CxImageBMP: public CxImage { public: CxImageBMP(): CxImage(CXIMAGE_FORMAT_BMP) {}; bool Decode(CxFile * hFile); bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } #if CXIMAGE_SUPPORT_ENCODE bool Encode(CxFile * hFile); bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } #endif // CXIMAGE_SUPPORT_ENCODE protected: bool DibReadBitmapInfo(CxFile* fh, BITMAPINFOHEADER *pdib); }; #define BFT_ICON 0x4349 /* 'IC' */ #define BFT_BITMAP 0x4d42 /* 'BM' */ #define BFT_CURSOR 0x5450 /* 'PT' */ #ifndef WIDTHBYTES #define WIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */ #endif #define DibWidthBytesN(lpbi, n) (UINT)WIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n)) #define DibWidthBytes(lpbi) DibWidthBytesN(lpbi, (lpbi)->biBitCount) #define DibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \ ? ((DWORD)(UINT)DibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \ : (lpbi)->biSizeImage) #define DibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \ ? (int)(1 << (int)(lpbi)->biBitCount) \ : (int)(lpbi)->biClrUsed) #define FixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \ (lpbi)->biSizeImage = DibSizeImage(lpbi); \ if ((lpbi)->biClrUsed == 0) \ (lpbi)->biClrUsed = DibNumColors(lpbi); \ #endif #endif --- NEW FILE: ximadefs.h --- #if !defined(__ximadefs_h) #define __ximadefs_h #if defined(_AFXDLL)||defined(_USRDLL) #define DLL_EXP __declspec(dllexport) #elif defined(_MSC_VER)&&(_MSC_VER<1200) #define DLL_EXP __declspec(dllimport) #else #define DLL_EXP #endif #if CXIMAGE_SUPPORT_JP2 || CXIMAGE_SUPPORT_JPC || CXIMAGE_SUPPORT_PGX || CXIMAGE_SUPPORT_PNM || CXIMAGE_SUPPORT_RAS #define CXIMAGE_SUPPORT_JASPER 1 #else #define CXIMAGE_SUPPORT_JASPER 0 #endif #if CXIMAGE_SUPPORT_DSP #undef CXIMAGE_SUPPORT_TRANSFORMATION #define CXIMAGE_SUPPORT_TRANSFORMATION 1 #endif #if CXIMAGE_SUPPORT_TRANSFORMATION || CXIMAGE_SUPPORT_TIF || CXIMAGE_SUPPORT_TGA || CXIMAGE_SUPPORT_BMP || CXIMAGE_SUPPORT_WINDOWS #define CXIMAGE_SUPPORT_BASICTRANSFORMATIONS 1 #endif #if CXIMAGE_SUPPORT_WINCE #undef CXIMAGE_SUPPORT_WMF #define CXIMAGE_SUPPORT_WMF 0 #undef CXIMAGE_SUPPORT_WINDOWS #define CXIMAGE_SUPPORT_WINDOWS 0 #endif #ifndef WIN32 #undef CXIMAGE_SUPPORT_WINDOWS #define CXIMAGE_SUPPORT_WINDOWS 0 #endif #ifndef min #define min(a,b) (((a)<(b))?(a):(b)) #endif #ifndef max #define max(a,b) (((a)>(b))?(a):(b)) #endif #ifdef WIN32 #include <windows.h> //#include <tchar.h> #endif #include <stdio.h> #include <math.h> #ifdef __BORLANDC__ #define _complex complex #define _cabs cabs #endif #ifndef WIN32 #include <stdlib.h> #include <string.h> #include <ctype.h> typedef unsigned char BYTE; typedef unsigned short WORD; typedef unsigned long DWORD; typedef unsigned int UINT; typedef DWORD COLORREF; typedef unsigned int HANDLE; typedef void* HRGN; #define BOOL bool #define TRUE true #define FALSE false typedef struct tagRECT { long left; long top; long right; long bottom; } RECT; typedef struct tagPOINT { long x; long y; } POINT; typedef struct tagRGBQUAD { BYTE rgbBlue; BYTE rgbGreen; BYTE rgbRed; BYTE rgbReserved; } RGBQUAD; #pragma pack(1) typedef struct tagBITMAPINFOHEADER{ DWORD biSize; long biWidth; long biHeight; WORD biPlanes; WORD biBitCount; DWORD biCompression; DWORD biSizeImage; long biXPelsPerMeter; long biYPelsPerMeter; DWORD biClrUsed; DWORD biClrImportant; } BITMAPINFOHEADER; typedef struct tagBITMAPFILEHEADER { WORD bfType; DWORD bfSize; WORD bfReserved1; WORD bfReserved2; DWORD bfOffBits; } BITMAPFILEHEADER; typedef struct tagBITMAPCOREHEADER { DWORD bcSize; WORD bcWidth; WORD bcHeight; WORD bcPlanes; WORD bcBitCount; } BITMAPCOREHEADER; typedef struct tagRGBTRIPLE { BYTE rgbtBlue; BYTE rgbtGreen; BYTE rgbtRed; } RGBTRIPLE; #pragma pack() #define BI_RGB 0L #define BI_RLE8 1L #define BI_RLE4 2L #define BI_BITFIELDS 3L #define GetRValue(rgb) ((BYTE)(rgb)) #define GetGValue(rgb) ((BYTE)(((WORD)(rgb)) >> 8)) #define GetBValue(rgb) ((BYTE)((rgb)>>16)) #define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) #ifndef _COMPLEX_DEFINED typedef struct tagcomplex { double x,y; } _complex; #endif #define _cabs(c) sqrt(c.x*c.x+c.y*c.y) #endif #endif //__ximadefs --- NEW FILE: ximage.h --- /* * File: ximage.h * Purpose: General Purpose Image Class */ /* === C R E D I T S & D I S C L A I M E R S ============== * Permission is given by the author to freely redistribute and include * this code in any program as long as this credit is given where due. * * CxImage (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it * CxImage version 5.99a 08/Feb/2004 * See the file history.htm for the complete bugfix and news report. * * original CImage and CImageIterator implementation are: * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx> * * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. * * Use at your own risk! * ========================================================== */ #if !defined(__CXIMAGE_H) #define __CXIMAGE_H #if _MSC_VER > 1000 #pragma once #endif ///////////////////////////////////////////////////////////////////////////// // CxImage supported features #define CXIMAGE_SUPPORT_ALPHA 1 #define CXIMAGE_SUPPORT_SELECTION 0 #define CXIMAGE_SUPPORT_TRANSFORMATION 0 #define CXIMAGE_SUPPORT_DSP 0 #define CXIMAGE_SUPPORT_LAYERS 0 #define CXIMAGE_SUPPORT_DECODE 1 #define CXIMAGE_SUPPORT_ENCODE 0 //<vho><T.Peck> #define CXIMAGE_SUPPORT_WINDOWS 1 #define CXIMAGE_SUPPORT_WINCE 0 //<T.Peck> ///////////////////////////////////////////////////////////////////////////// // CxImage supported formats #define CXIMAGE_SUPPORT_BMP 1 #define CXIMAGE_SUPPORT_GIF 0 #define CXIMAGE_SUPPORT_JPG 1 #define CXIMAGE_SUPPORT_PNG 1 #define CXIMAGE_SUPPORT_MNG 0 #define CXIMAGE_SUPPORT_ICO 0 #define CXIMAGE_SUPPORT_TIF 0 #define CXIMAGE_SUPPORT_TGA 0 #define CXIMAGE_SUPPORT_PCX 0 #define CXIMAGE_SUPPORT_WBMP 0 #define CXIMAGE_SUPPORT_WMF 0 #define CXIMAGE_SUPPORT_J2K 0 // Beta, use JP2 #define CXIMAGE_SUPPORT_JBG 0 // GPL'd see ../jbig/copying.txt & ../jbig/patents.htm #define CXIMAGE_SUPPORT_JP2 0 #define CXIMAGE_SUPPORT_JPC 0 #define CXIMAGE_SUPPORT_PGX 0 #define CXIMAGE_SUPPORT_PNM 0 #define CXIMAGE_SUPPORT_RAS 0 ///////////////////////////////////////////////////////////////////////////// #include <TCHAR.h> // For UNICODE support #include "xfile.h" #include "xiofile.h" #include "xmemfile.h" #include "ximadefs.h" //<vho> adjust some #define ///////////////////////////////////////////////////////////////////////////// // CxImage formats enumerator enum ENUM_CXIMAGE_FORMATS{ CXIMAGE_FORMAT_UNKNOWN, #if CXIMAGE_SUPPORT_BMP CXIMAGE_FORMAT_BMP, #endif #if CXIMAGE_SUPPORT_GIF CXIMAGE_FORMAT_GIF, #endif #if CXIMAGE_SUPPORT_JPG CXIMAGE_FORMAT_JPG, #endif #if CXIMAGE_SUPPORT_PNG CXIMAGE_FORMAT_PNG, #endif #if CXIMAGE_SUPPORT_MNG CXIMAGE_FORMAT_MNG, #endif #if CXIMAGE_SUPPORT_ICO CXIMAGE_FORMAT_ICO, #endif #if CXIMAGE_SUPPORT_TIF CXIMAGE_FORMAT_TIF, #endif #if CXIMAGE_SUPPORT_TGA CXIMAGE_FORMAT_TGA, #endif #if CXIMAGE_SUPPORT_PCX CXIMAGE_FORMAT_PCX, #endif #if CXIMAGE_SUPPORT_WBMP CXIMAGE_FORMAT_WBMP, #endif #if CXIMAGE_SUPPORT_WMF CXIMAGE_FORMAT_WMF, #endif #if CXIMAGE_SUPPORT_J2K CXIMAGE_FORMAT_J2K, #endif #if CXIMAGE_SUPPORT_JBG CXIMAGE_FORMAT_JBG, #endif #if CXIMAGE_SUPPORT_JP2 CXIMAGE_FORMAT_JP2, #endif #if CXIMAGE_SUPPORT_JPC CXIMAGE_FORMAT_JPC, #endif #if CXIMAGE_SUPPORT_PGX CXIMAGE_FORMAT_PGX, #endif #if CXIMAGE_SUPPORT_PNM CXIMAGE_FORMAT_PNM, #endif #if CXIMAGE_SUPPORT_RAS CXIMAGE_FORMAT_RAS, #endif CMAX_IMAGE_FORMATS }; //color to grey mapping <H. Muelner> <jurgene> //#define RGB2GRAY(r,g,b) (((b)*114 + (g)*587 + (r)*299)/1000) #define RGB2GRAY(r,g,b) (((b)*117 + (g)*601 + (r)*306) >> 10) struct rgb_color { BYTE r,g,b; }; // <VATI> text placement data // members must be initialized with the InitTextInfo(&this) function. typedef struct DLL_EXP tagCxTextInfo { char text[4096]; // text LOGFONT lfont; // font and codepage data COLORREF fcolor; // foreground color long align; // DT_CENTER, DT_RIGHT, DT_LEFT aligment for multiline text BYTE opaque; // text has background or hasn't. Default is true. // data for background (ignored if .opaque==FALSE) COLORREF bcolor; // background color float b_opacity; // opacity value for background between 0.0-1.0 Default is 0. (opaque) BYTE b_outline; // outline width for background (zero: no outline) BYTE b_round; // rounding radius for background rectangle. % of the height, between 0-50. Default is 10. // (backgr. always has a frame: width = 3 pixel + 10% of height by default.) } CXTEXTINFO; ///////////////////////////////////////////////////////////////////////////// // CxImage class ///////////////////////////////////////////////////////////////////////////// class DLL_EXP CxImage { //extensible information collector typedef struct tagCxImageInfo { DWORD dwEffWidth; //DWORD aligned scan line width BYTE* pImage; //THE IMAGE BITS CxImage* pGhost; //if this is a ghost, pGhost points to the body CxImage* pParent; //if this is a layer, pParent points to the body DWORD dwType; //original image format char szLastError[256]; //debugging long nProgress; //monitor long nEscape; //escape long nBkgndIndex; //used for GIF, PNG, MNG RGBQUAD nBkgndColor; //used for RGB transparency BYTE nQuality; //used for JPEG BYTE nScale; //used for JPEG <ignacio> long nFrame; //used for TIF, GIF, MNG : actual frame long nNumFrames; //used for TIF, GIF, MNG : total number of frames DWORD dwFrameDelay; //used for GIF, MNG long xDPI; //horizontal resolution long yDPI; //vertical resolution RECT rSelectionBox; //bounding rectangle BYTE nAlphaMax; //max opacity (fade) bool bAlphaPaletteEnabled; //true if alpha values in the palette are enabled. bool bEnabled; //enables the painting functions long xOffset; long yOffset; DWORD dwCodecOption; //for GIF, TIF : 0=def.1=unc,2=fax3,3=fax4,4=pack,5=jpg RGBQUAD last_c; //for GetNearestIndex optimization BYTE last_c_index; bool last_c_isvalid; long nNumLayers; DWORD dwFlags; // 0x??00000 = reserved, 0x00??0000 = blend mode, 0x0000???? = layer id - user flags } CXIMAGEINFO; public: //constructors CxImage(DWORD imagetype = 0); CxImage(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0); CxImage(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true); CxImage(const TCHAR * filename, DWORD imagetype); // For UNICODE support: char -> TCHAR // CxImage(const char * filename, DWORD imagetype); CxImage(FILE * stream, DWORD imagetype); CxImage(CxFile * stream, DWORD imagetype); CxImage(BYTE * buffer, DWORD size, DWORD imagetype); virtual ~CxImage() { Destroy(); }; CxImage& operator = (const CxImage&); //initializzation void* Create(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0); bool Destroy(); void Clear(BYTE bval=0); void Copy(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true); bool Transfer(CxImage &from); bool CreateFromArray(BYTE* pArray,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage); bool CreateFromMatrix(BYTE** ppMatrix,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage); //Attributes long GetSize(); BYTE* GetBits(DWORD row = 0); BYTE GetColorType(); void* GetDIB() const {return pDib;} DWORD GetHeight() const {return head.biHeight;} DWORD GetWidth() const {return head.biWidth;} DWORD GetEffWidth() const {return info.dwEffWidth;} DWORD GetNumColors() const {return head.biClrUsed;} WORD GetBpp() const {return head.biBitCount;} DWORD GetType() const {return info.dwType;} char* GetLastError() {return info.szLastError;} const TCHAR* GetVersion(); DWORD GetFrameDelay() const {return info.dwFrameDelay;} void SetFrameDelay(DWORD d) {info.dwFrameDelay=d;} void GetOffset(long *x,long *y) {*x=info.xOffset; *y=info.yOffset;} void SetOffset(long x,long y) {info.xOffset=x; info.yOffset=y;} BYTE GetJpegQuality() const {return info.nQuality;} void SetJpegQuality(BYTE q) {info.nQuality = q;} //<ignacio> used for scaling down during JPEG decoding valid numbers are 1, 2, 4, 8 BYTE GetJpegScale() const {return info.nScale;} void SetJpegScale(BYTE q) {info.nScale = q;} long GetXDPI() const {return info.xDPI;} long GetYDPI() const {return info.yDPI;} void SetXDPI(long dpi); void SetYDPI(long dpi); DWORD GetClrImportant() const {return head.biClrImportant;} void SetClrImportant(DWORD ncolors = 0); long GetProgress() const {return info.nProgress;} long GetEscape() const {return info.nEscape;} void SetProgress(long p) {info.nProgress = p;} void SetEscape(long i) {info.nEscape = i;} long GetTransIndex() const {return info.nBkgndIndex;} RGBQUAD GetTransColor(); void SetTransIndex(long idx) {info.nBkgndIndex = idx;} void SetTransColor(RGBQUAD rgb) {rgb.rgbReserved=0; info.nBkgndColor = rgb;} bool IsTransparent() const {return info.nBkgndIndex>=0;} // <vho> DWORD GetCodecOption() const {return info.dwCodecOption;} void SetCodecOption(DWORD opt) {info.dwCodecOption = opt;} DWORD GetFlags() const {return info.dwFlags;} void SetFlags(DWORD flags, bool bLockReservedFlags = true); //void* GetUserData() const {return info.pUserData;} //void SetUserData(void* pUserData) {info.pUserData = pUserData;} //palette operations bool IsGrayScale(); bool IsIndexed() {return head.biClrUsed!=0;} DWORD GetPaletteSize(); RGBQUAD* GetPalette() const; RGBQUAD GetPaletteColor(BYTE idx); bool GetPaletteColor(BYTE i, BYTE* r, BYTE* g, BYTE* b); BYTE GetNearestIndex(RGBQUAD c); void BlendPalette(COLORREF cr,long perc); void SetGrayPalette(); void SetPalette(DWORD n, BYTE *r, BYTE *g, BYTE *b); void SetPalette(RGBQUAD* pPal,DWORD nColors=256); void SetPalette(rgb_color *rgb,DWORD nColors=256); void SetPaletteColor(BYTE idx, BYTE r, BYTE g, BYTE b, BYTE alpha=0); void SetPaletteColor(BYTE idx, RGBQUAD c); void SetPaletteColor(BYTE idx, COLORREF cr); void SwapIndex(BYTE idx1, BYTE idx2); void SetStdPalette(); //pixel operations bool IsInside(long x, long y); bool IsTransparent(long x,long y); RGBQUAD GetPixelColor(long x,long y, bool bGetAlpha = true); BYTE GetPixelIndex(long x,long y); BYTE GetPixelGray(long x, long y); void SetPixelColor(long x,long y,RGBQUAD c, bool bSetAlpha = false); void SetPixelColor(long x,long y,COLORREF cr); void SetPixelIndex(long x,long y,BYTE i); void DrawLine(int StartX, int EndX, int StartY, int EndY, RGBQUAD color, bool bSetAlpha=false); void DrawLine(int StartX, int EndX, int StartY, int EndY, COLORREF cr); //painting operations #if CXIMAGE_SUPPORT_WINCE long Blt(HDC pDC, long x=0, long y=0); #endif #if CXIMAGE_SUPPORT_WINDOWS HBITMAP MakeBitmap(HDC hdc = NULL); HANDLE CopyToHandle(); bool CreateFromHANDLE(HANDLE hMem); //Windows objects (clipboard) bool CreateFromHBITMAP(HBITMAP hbmp, HPALETTE hpal=0); //Windows resource bool CreateFromHICON(HICON hico); long Draw(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1, RECT* pClipRect = 0); long Draw(HDC hdc, const RECT& rect, RECT* pClipRect=NULL) { return Draw(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, pClipRect); } long Stretch(HDC hdc, long xoffset, long yoffset, long xsize, long ysize, DWORD dwRop = SRCCOPY); long Stretch(HDC hdc, const RECT& rect, DWORD dwRop = SRCCOPY) { return Stretch(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, dwRop); } long Tile(HDC hdc, RECT *rc); long Draw2(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1); long Draw2(HDC hdc, const RECT& rect) { return Draw2(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); } //long DrawString(HDC hdc, long x, long y, const char* text, RGBQUAD color, const char* font, long lSize=0, long lWeight=400, BYTE bItalic=0, BYTE bUnderline=0, bool bSetAlpha=false); long DrawString(HDC hdc, long x, long y, const TCHAR* text, RGBQUAD color, const TCHAR* font, long lSize=0, long lWeight=400, BYTE bItalic=0, BYTE bUnderline=0, bool bSetAlpha=false); // <VATI> extensions long DrawStringEx(HDC hdc, long x, long y, CXTEXTINFO *pTextType, bool bSetAlpha=false ); void InitTextInfo( CXTEXTINFO *txt ); #endif //CXIMAGE_SUPPORT_WINDOWS // file operations #if CXIMAGE_SUPPORT_DECODE #ifdef WIN32 //bool Load(LPCWSTR filename, DWORD imagetype=0); bool LoadResource(HRSRC hRes, DWORD imagetype, HMODULE hModule=NULL); #endif // For UNICODE support: char -> TCHAR bool Load(const TCHAR* filename, DWORD imagetype=0); //bool Load(const char * filename, DWORD imagetype=0); bool Decode(FILE * hFile, DWORD imagetype); bool Decode(CxFile * hFile, DWORD imagetype); bool Decode(BYTE * buffer, DWORD size, DWORD imagetype); #endif //CXIMAGE_SUPPORT_DECODE #if CXIMAGE_SUPPORT_ENCODE protected: bool EncodeSafeCheck(CxFile *hFile); public: #ifdef WIN32 //bool Save(LPCWSTR filename, DWORD imagetype=0); #endif // For UNICODE support: char -> TCHAR bool Save(const TCHAR* filename, DWORD imagetype=0); //bool Save(const char * filename, DWORD imagetype=0); bool Encode(FILE * hFile, DWORD imagetype); bool Encode(CxFile * hFile, DWORD imagetype); bool Encode(CxFile * hFile, CxImage ** pImages, int pagecount, DWORD imagetype); bool Encode(FILE *hFile, CxImage ** pImages, int pagecount, DWORD imagetype); bool Encode(BYTE * &buffer, long &size, DWORD imagetype); #endif //CXIMAGE_SUPPORT_ENCODE //misc. bool IsValid() const {return pDib!=0;} bool IsEnabled() const {return info.bEnabled;} void Enable(bool enable=true){info.bEnabled=enable;} // frame operations long GetNumFrames() const {return info.nNumFrames;} long GetFrame() const {return info.nFrame;} void SetFrame(long nFrame) {info.nFrame=nFrame;} #if CXIMAGE_SUPPORT_BASICTRANSFORMATIONS bool GrayScale(); bool Flip(); bool Mirror(); bool Negative(); bool RotateLeft(CxImage* iDst = NULL); bool RotateRight(CxImage* iDst = NULL); #endif //CXIMAGE_SUPPORT_BASICTRANSFORMATIONS #if CXIMAGE_SUPPORT_TRANSFORMATION // image operations bool Rotate(float angle, CxImage* iDst = NULL); bool Rotate180(CxImage* iDst = NULL); bool Resample(long newx, long newy, int mode = 1, CxImage* iDst = NULL); bool DecreaseBpp(DWORD nbit, bool errordiffusion, RGBQUAD* ppal = 0, DWORD clrimportant = 0); bool IncreaseBpp(DWORD nbit); bool Dither(long method = 0); bool Crop(long left, long top, long right, long bottom, CxImage* iDst = NULL); bool Crop(const RECT& rect, CxImage* iDst = NULL) { return Crop(rect.left, rect.top, rect.right, rect.bottom, iDst); } bool CropRotatedRectangle( long topx, long topy, long width, long height, float angle, CxImage* iDst = NULL); bool Skew(float xgain, float ygain, long xpivot=0, long ypivot=0); bool Expand(long left, long top, long right, long bottom, RGBQUAD canvascolor, CxImage* iDst = 0); bool Expand(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0); bool Thumbnail(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0); bool CircleTransform(int type,long rmax=0,float Koeff=1.0f); protected: float b3spline(float x); public: #endif //CXIMAGE_SUPPORT_TRANSFORMATION #if CXIMAGE_SUPPORT_DSP bool Contour(); bool HistogramStretch(long method = 0); bool HistogramEqualize(); bool HistogramNormalize(); bool HistogramRoot(); bool HistogramLog(); long Histogram(long* red, long* green = 0, long* blue = 0, long* gray = 0, long colorspace = 0); bool Jitter(long radius=2); bool Repair(float radius = 0.25f, long niterations = 1, long colorspace = 0); bool Combine(CxImage* r,CxImage* g,CxImage* b,CxImage* a, long colorspace = 0); bool FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage* dstImag, long direction = 1, bool bForceFFT = true, bool bMagnitude = true); bool Noise(long level); bool Median(long Ksize=3); bool Gamma(float gamma); bool ShiftRGB(long r, long g, long b); bool Threshold(BYTE level); bool Colorize(BYTE hue, BYTE sat); bool Light(long brightness, long contrast = 0); float Mean(); bool Filter(long* kernel, long Ksize, long Kfactor, long Koffset); bool Erode(long Ksize=2); bool Dilate(long Ksize=2); void HuePalette(float correction=1); enum ImageOpType { OpAdd, OpAnd, OpXor, OpOr, OpMask, OpSrcCopy, OpDstCopy, OpSub, OpSrcBlend }; void Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset = 0, long lYOffset = 0); void MixFrom(CxImage & imagesrc2, long lXOffset, long lYOffset); bool UnsharpMask(float radius = 5.0, float amount = 0.5, int threshold = 0); bool Lut(BYTE* pLut); bool Lut(BYTE* pLutR, BYTE* pLutG, BYTE* pLutB, BYTE* pLutA = 0); protected: bool IsPowerof2(long x); bool FFT(int dir,int m,double *x,double *y); bool DFT(int dir,long m,double *x1,double *y1,double *x2,double *y2); bool RepairChannel(CxImage *ch, float radius); // <nipper> int gen_convolve_matrix (float radius, float **cmatrix_p); float* gen_lookup_table (float *cmatrix, int cmatrix_length); void blur_line (float *ctable, float *cmatrix, int cmatrix_length, BYTE* cur_col, BYTE* dest_col, int y, long bytes); public: //color conversion utilities bool SplitRGB(CxImage* r,CxImage* g,CxImage* b); bool SplitYUV(CxImage* y,CxImage* u,CxImage* v); bool SplitHSL(CxImage* h,CxImage* s,CxImage* l); bool SplitYIQ(CxImage* y,CxImage* i,CxImage* q); bool SplitXYZ(CxImage* x,CxImage* y,CxImage* z); bool SplitCMYK(CxImage* c,CxImage* m,CxImage* y,CxImage* k); RGBQUAD HSLtoRGB(COLORREF cHSLColor); RGBQUAD RGBtoHSL(RGBQUAD lRGBColor); RGBQUAD HSLtoRGB(RGBQUAD lHSLColor); RGBQUAD YUVtoRGB(RGBQUAD lYUVColor); RGBQUAD RGBtoYUV(RGBQUAD lRGBColor); RGBQUAD YIQtoRGB(RGBQUAD lYIQColor); RGBQUAD RGBtoYIQ(RGBQUAD lRGBColor); RGBQUAD XYZtoRGB(RGBQUAD lXYZColor); RGBQUAD RGBtoXYZ(RGBQUAD lRGBColor); #endif //CXIMAGE_SUPPORT_DSP RGBQUAD RGBtoRGBQUAD(COLORREF cr); COLORREF RGBQUADtoRGB (RGBQUAD c); #if CXIMAGE_SUPPORT_SELECTION //selection bool SelectionClear(); bool SelectionCreate(); bool SelectionDelete(); bool SelectionInvert(); bool SelectionAddRect(RECT r); bool SelectionAddEllipse(RECT r); bool SelectionAddPolygon(POINT *points, long npoints); bool SelectionAddColor(RGBQUAD c); bool SelectionAddPixel(int x, int y); bool SelectionCopy(CxImage &from); bool SelectionIsInside(long x, long y); bool SelectionIsValid(){return pSelection!=0;} void SelectionGetBox(RECT& r){memcpy(&r,&info.rSelectionBox,sizeof(RECT));} bool SelectionToHRGN(HRGN& region); #endif //CXIMAGE_SUPPORT_SELECTION #if CXIMAGE_SUPPORT_ALPHA //Alpha void AlphaClear(); void AlphaCreate(); void AlphaDelete(); void AlphaInvert(); bool AlphaMirror(); bool AlphaFlip(); bool AlphaCopy(CxImage &from); bool AlphaSplit(CxImage *dest); void AlphaStrip(); void AlphaSet(BYTE level); bool AlphaSet(CxImage &from); void AlphaSet(long x,long y,BYTE level); BYTE AlphaGet(long x,long y); BYTE AlphaGetMax() const {return info.nAlphaMax;} void AlphaSetMax(BYTE nAlphaMax) {info.nAlphaMax=nAlphaMax;} bool AlphaIsValid(){return pAlpha!=0;} BYTE* AlphaGetBits() const {return pAlpha;} void AlphaPaletteClear(); void AlphaPaletteEnable(bool enable=true){info.bAlphaPaletteEnabled=enable;} bool AlphaPaletteIsEnabled(){return info.bAlphaPaletteEnabled;} bool AlphaPaletteIsValid(); bool AlphaPaletteSplit(CxImage *dest); #endif //CXIMAGE_SUPPORT_ALPHA #if CXIMAGE_SUPPORT_LAYERS bool LayerCreate(long position = -1); bool LayerDelete(long position = -1); void LayerDeleteAll(); CxImage* GetLayer(long position); CxImage* GetParent() const {return info.pParent;} long GetNumLayers() const {return info.nNumLayers;} #endif //CXIMAGE_SUPPORT_LAYERS protected: void Startup(DWORD imagetype = 0); void CopyInfo(const CxImage &src); void Ghost(CxImage *src); void RGBtoBGR(BYTE *buffer, int length); float HueToRGB(float n1,float n2, float hue); void Bitfield2RGB(BYTE *src, WORD redmask, WORD greenmask, WORD bluemask, BYTE bpp); static int CompareColors(const void *elem1, const void *elem2); void* pDib; //contains the header, the palette, the pixels BITMAPINFOHEADER head; //standard header CXIMAGEINFO info; //extended information BYTE* pSelection; //selected region BYTE* pAlpha; //alpha channel CxImage** pLayers; //generic layers }; //////////////////////////////////////////////////////////////////////////// #define CXIMAGE_MAX_MEMORY 256000000 #define CXIMAGE_ERR_NOFILE "null file handler" #define CXIMAGE_ERR_NOIMAGE "null image!!!" //////////////////////////////////////////////////////////////////////////// #endif // !defined(__CXIMAGE_H) --- NEW FILE: ximagif.h --- /* * File: ximagif.h * Purpose: GIF Image Class Loader and Writer */ /* === C R E D I T S & D I S C L A I M E R S ============== * CxImageGIF (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it * Permission is given by the author to freely redistribute and include * this code in any program as long as this credit is given where due. * * CxImage version 5.99a 08/Feb/2004 * See the file history.htm for the complete bugfix and news report. * * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes * * original CImageGIF and CImageIterator implementation are: * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx> * * 6/15/97 Randy Spann: Added GIF87a writing support * R....@Co... * * DECODE.C - An LZW decoder for GIF * Copyright (C) 1987, by Steven A. Bennett * Copyright (C) 1994, C++ version by Alejandro Aguilar Sierra * * In accordance with the above, I want to credit Steve Wilhite who wrote * the code which this is heavily inspired by... * * GIF and 'Graphics Interchange Format' are trademarks (tm) of * Compuserve, Incorporated, an H&R Block Company. * * Release Notes: This file contains a decoder routine for GIF images * which is similar, structurally, to the original routine by Steve Wilhite. * It is, however, somewhat noticably faster in most cases. * * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. * * Use at your own risk! * ========================================================== */ #if !defined(__ximaGIF_h) #define __ximaGIF_h #include "ximage.h" #if CXIMAGE_SUPPORT_GIF typedef short int code_int; /* Various error codes used by decoder */ #define OUT_OF_MEMORY -10 #define BAD_CODE_SIZE -20 #define READ_ERROR -1 #define WRITE_ERROR -2 #define OPEN_ERROR -3 #define CREATE_ERROR -4 #define MAX_CODES 4095 #define GIFBUFTAM 16384 #define TRANSPARENCY_CODE 0xF9 //LZW GIF Image compression #define MAXBITSCODES 12 #define HSIZE 5003 /* 80% occupancy */ #define MAXCODE(n_bits) (((code_int) 1 << (n_bits)) - 1) #define HashTabOf(i) htab[i] #define CodeTabOf(i) codetab[i] class CImageIterator; class DLL_EXP CxImageGIF: public CxImage { #pragma pack(1) typedef struct tag_gifgce{ BYTE transpcolflag:1; BYTE userinputflag:1; BYTE dispmeth:3; BYTE res:3; WORD delaytime; BYTE transpcolindex; } struct_gifgce; typedef struct tag_dscgif{ /* Logic Screen Descriptor */ char header[6]; /* Firma and version */ WORD scrwidth; WORD scrheight; char pflds; char bcindx; char pxasrat; } struct_dscgif; typedef struct tag_image{ /* Image Descriptor */ WORD l; WORD t; WORD w; WORD h; BYTE pf; } struct_image; typedef struct tag_TabCol{ /* Tabla de colores */ short colres; /* color resolution */ short sogct; /* size of global color table */ rgb_color paleta[256]; /* paleta */ } struct_TabCol; typedef struct tag_RLE{ int rl_pixel; int rl_basecode; int rl_count; int rl_table_pixel; int rl_table_max; int just_cleared; int out_bits; int out_bits_init; int out_count; int out_bump; int out_bump_init; int out_clear; int out_clear_init; int max_ocodes; int code_clear; int code_eof; unsigned int obuf; int obits; unsigned char oblock[256]; int oblen; } struct_RLE; #pragma pack() public: CxImageGIF(): CxImage(CXIMAGE_FORMAT_GIF) {m_loops=0; m_dispmeth=0; m_comment[0]='\0';} // bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_GIF);} // bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_GIF);} bool Decode(CxFile * fp); bool Decode(FILE *fp) { CxIOFile file(fp); return Decode(&file); } #if CXIMAGE_SUPPORT_ENCODE bool Encode(CxFile * fp); bool Encode(CxFile * fp, CxImage ** pImages, int pagecount, bool bLocalColorMap = false); bool Encode(FILE *fp) { CxIOFile file(fp); return Encode(&file); } bool Encode(FILE *fp, CxImage ** pImages, int pagecount, bool bLocalColorMap = false) { CxIOFile file(fp); return Encode(&file, pImages, pagecount, bLocalColorMap); } #endif // CXIMAGE_SUPPORT_ENCODE void SetLoops(int loops); long GetLoops(); void SetComment(const char* sz_comment_in); void GetComment(char* sz_comment_out); void SetDisposalMethod(int dm); long GetDisposalMethod(); protected: bool DecodeExtension(CxFile *fp); void EncodeHeader(CxFile *fp); void EncodeLoopExtension(CxFile *fp); void EncodeExtension(CxFile *fp); void EncodeBody(CxFile *fp, bool bLocalColorMap = false); void EncodeComment(CxFile *fp); bool EncodeRGB(CxFile *fp); void GifMix(CxImage & imgsrc2, long lxOffset, long lyOffset); struct_gifgce gifgce; int curx, cury; long CountDown; unsigned long cur_accum; int cur_bits; int interlaced, iypos, istep, iheight, ipass; int ibf; int ibfmax; BYTE buf[GIFBUFTAM + 1]; // Implementation int GifNextPixel (); void Putword (int w, CxFile* fp ); void compressNONE (int init_bits, CxFile* outfile); void compressLZW (int init_bits, CxFile* outfile); void output (code_int code ); void cl_hash (long hsize); void char_out (int c); void flush_char (); short init_exp(short size); short get_next_code(CxFile*); short decoder(CxFile*, CImageIterator* iter, short linewidth, int &bad_code_count); int get_byte(CxFile*); int out_line(CImageIterator* iter, unsigned char *pixels, int linelen); int get_num_frames(CxFile *f,struct_TabCol* TabColSrc); short curr_size; /* The current code size */ short clear; /* Value for a clear code */ short ending; /* Value for a ending code */ short newcodes; /* First available code */ short top_slot; /* Highest code for current size */ short slot; /* Last read code */ /* The following static variables are used * for seperating out codes */ short navail_bytes; /* # bytes left in block */ short nbits_left; /* # bits left in current BYTE */ BYTE b1; /* Current BYTE */ BYTE byte_buff[257]; /* Current block */ BYTE *pbytes; /* Pointer to next BYTE in block */ /* The reason we have these seperated like this instead of using * a structure like the original Wilhite code did, is because this * stuff generally produces significantly faster code when compiled... * This code is full of similar speedups... (For a good book on writing * C for speed or for space optomisation, see Efficient C by Tom Plum, * published by Plum-Hall Associates...) */ BYTE stack[MAX_CODES + 1]; /* Stack for storing pixels */ BYTE suffix[MAX_CODES + 1]; /* Suffix table */ WORD prefix[MAX_CODES + 1]; /* Prefix linked list */ //LZW GIF Image compression routines long htab [HSIZE]; unsigned short codetab [HSIZE]; int n_bits; /* number of bits/code */ code_int maxcode; /* maximum code, given n_bits */ code_int free_ent; /* first unused entry */ int clear_flg; int g_init_bits; CxFile* g_outfile; int ClearCode; int EOFCode; int a_count; char accum[256]; char m_comment[256]; int m_loops; int m_dispmeth; //RLE compression routines void compressRLE( int init_bits, CxFile* outfile); void rle_clear(struct_RLE* rle); void rle_flush(struct_RLE* rle); void rle_flush_withtable(int count, struct_RLE* rle); void rle_flush_clearorrep(int count, struct_RLE* rle); void rle_flush_fromclear(int count,struct_RLE* rle); void rle_output_plain(int c,struct_RLE* rle); void rle_reset_out_clear(struct_RLE* rle); unsigned int rle_compute_triangle_count(unsigned int count, unsigned int nrepcodes); unsigned int rle_isqrt(unsigned int x); void rle_write_block(struct_RLE* rle); void rle_block_out(unsigned char c, struct_RLE* rle); void rle_block_flush(struct_RLE* rle); void rle_output(int val, struct_RLE* rle); void rle_output_flush(struct_RLE* rle); }; #endif #endif --- NEW FILE: ximaico.h --- /* * File: ximaico.h * Purpose: ICON Image Class Loader and Writer */ /* === C R E D I T S & D I S C L A I M E R S ============== * CxImageICO (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it * Permission is given by the author to freely redistribute and include * this code in any program as long as this credit is given where due. * * CxImage version 5.99a 08/Feb/2004 * See the file history.htm for the complete bugfix and news report. * * Parts of the code come from FreeImage 2 * Design and implementation by Floris van den Berg <flvdberg(at)wxs(dot)nl> * * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. * * Use at your own risk! * ========================================================== */ #if !defined(__ximaICO_h) #define __ximaICO_h #include "ximage.h" #if CXIMAGE_SUPPORT_ICO class CxImageICO: public CxImage { typedef struct tagIconDirectoryEntry { BYTE bWidth; BYTE bHeight; BYTE bColorCount; BYTE bReserved; WORD wPlanes; WORD wBitCount; DWORD dwBytesInRes; DWORD dwImageOffset; } ICONDIRENTRY; typedef struct tagIconDir { WORD idReserved; WORD idType; WORD idCount; } ICONHEADER; public: CxImageICO(): CxImage(CXIMAGE_FORMAT_ICO) {} // bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_ICO);} // bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_ICO);} bool Decode(CxFile * hFile); bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } #if CXIMAGE_SUPPORT_ENCODE bool Encode(CxFile * hFile); bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } #endif // CXIMAGE_SUPPORT_ENCODE }; #endif #endif --- NEW FILE: ximaiter.h --- /* * File: ImaIter.h * Purpose: Declaration of the Platform Independent Image Base Class * Author: Alejandro Aguilar Sierra * Created: 1995 * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx> * * 07/08/2001 Davide Pizzolato - www.xdp.it * - removed slow loops * - added safe checks * * Permission is given by the author to freely redistribute and include * this code in any program as long as this credit is given where due. * * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. * * Use at your own risk! * ========================================================== */ #if !defined(__ImaIter_h) #define __ImaIter_h #include "ximage.h" #include "ximadefs.h" class CImageIterator { friend class CxImage; protected: int Itx, Ity; // Counters int Stepx, Stepy; BYTE* IterImage; // Image pointer CxImage *ima; public: // Constructors CImageIterator ( void ); CImageIterator ( CxImage *image ); operator CxImage* (); // Iterators BOOL ItOK (); void Reset (); void Upset (); void SetRow(BYTE *buf, int n); void GetRow(BYTE *buf, int n); BYTE GetByte( ) { return IterImage[Itx]; } void SetByte(BYTE b) { IterImage[Itx] = b; } BYTE* GetRow(void); BYTE* GetRow(int n); BOOL NextRow(); BOOL PrevRow(); BOOL NextByte(); BOOL PrevByte(); void SetSteps(int x, int y=0) { Stepx = x; Stepy = y; } void GetSteps(int *x, int *y) { *x = Stepx; *y = Stepy; } BOOL NextStep(); BOOL PrevStep(); void SetY(int y); /* AD - for interlace */ int GetY() {return Ity;} BOOL GetCol(BYTE* pCol, DWORD x); BOOL SetCol(BYTE* pCol, DWORD x); }; ///////////////////////////////////////////////////////////////////// inline CImageIterator::CImageIterator(void) { ima = 0; IterImage = 0; Itx = Ity = 0; Stepx = Stepy = 0; } ///////////////////////////////////////////////////////////////////// inline CImageIterator::CImageIterator(CxImage *imageImpl): ima(imageImpl) { if (ima) IterImage = ima->GetBits(); Itx = Ity = 0; Stepx = Stepy = 0; } ///////////////////////////////////////////////////////////////////// inline CImageIterator::operator CxImage* () { return ima; } ///////////////////////////////////////////////////////////////////// inline BOOL CImageIterator::ItOK () { if (ima) return ima->IsInside(Itx, Ity); else return FALSE; } ///////////////////////////////////////////////////////////////////// inline void CImageIterator::Reset() { if (ima) IterImage = ima->GetBits(); else IterImage=0; Itx = Ity = 0; } ///////////////////////////////////////////////////////////////////// inline void CImageIterator::Upset() { Itx = 0; Ity = ima->GetHeight()-1; IterImage = ima->GetBits() + ima->GetEffWidth()*(ima->GetHeight()-1); } ///////////////////////////////////////////////////////////////////// inline BOOL CImageIterator::NextRow() { if (++Ity >= (int)ima->GetHeight()) return 0; IterImage += ima->GetEffWidth(); return 1; } ///////////////////////////////////////////////////////////////////// inline BOOL CImageIterator::PrevRow() { if (--Ity < 0) return 0; IterImage -= ima->GetEffWidth(); return 1; } /* AD - for interlace */ inline void CImageIterator::SetY(int y) { if ((y < 0) || (y > (int)ima->GetHeight())) return; Ity = y; IterImage = ima->GetBits() + ima->GetEffWidth()*y; } ///////////////////////////////////////////////////////////////////// inline void CImageIterator::SetRow(BYTE *buf, int n) { if (n<0) n = (int)ima->GetEffWidth(); else n = min(n,(int)ima->GetEffWidth()); if (IterImage) memcpy(IterImage,buf,n); } ///////////////////////////////////////////////////////////////////// inline void CImageIterator::GetRow(BYTE *buf, int n) { if ((buf!=NULL)&&(n>0)) memcpy(buf,IterImage,n); } ///////////////////////////////////////////////////////////////////// inline BYTE* CImageIterator::GetRow() { return IterImage; } ///////////////////////////////////////////////////////////////////// inline BYTE* CImageIterator::GetRow(int n) { SetY(n); return IterImage; } ///////////////////////////////////////////////////////////////////// inline BOOL CImageIterator::NextByte() { if (++Itx < (int)ima->GetEffWidth()) return 1; else if (++Ity < (int)ima->GetHeight()){ IterImage += ima->GetEffWidth(); Itx = 0; return 1; } else return 0; } ///////////////////////////////////////////////////////////////////// inline BOOL CImageIterator::PrevByte() { if (--Itx >= 0) return 1; else if (--Ity >= 0){ IterImage -= ima->GetEffWidth(); Itx = 0; return 1; } else return 0; } ///////////////////////////////////////////////////////////////////// inline BOOL CImageIterator::NextStep() { Itx += Stepx; if (Itx < (int)ima->GetEffWidth()) return 1; else { Ity += Stepy; if (Ity < (int)ima->GetHeight()){ IterImage += ima->GetEffWidth(); Itx = 0; return 1; } else return 0; } } ///////////////////////////////////////////////////////////////////// inline BOOL CImageIterator::PrevStep() { Itx -= Stepx; if (Itx >= 0) return 1; else { Ity -= Stepy; if (Ity >= 0 && Ity < (int)ima->GetHeight()) { IterImage -= ima->GetEffWidth(); Itx = 0; return 1; } else return 0; } } ///////////////////////////////////////////////////////////////////// inline BOOL CImageIterator::GetCol(BYTE* pCol, DWORD x) { if ((pCol==0)||(ima->GetBpp()<8)||(x>=ima->GetWidth())) return 0; DWORD h = ima->GetHeight(); DWORD line = ima->GetEffWidth(); BYTE bytes = ima->GetBpp()>>3; BYTE* pSrc; for (DWORD y=0;y<h;y++){ pSrc = ima->GetBits(y) + x*bytes; for (BYTE w=0;w<bytes;w++){ *pCol++=*pSrc++; } } return 1; } ///////////////////////////////////////////////////////////////////// inline BOOL CImageIterator::SetCol(BYTE* pCol, DWORD x) { if ((pCol==0)||(ima->GetBpp()<8)||(x>=ima->GetWidth())) return 0; DWORD h = ima->GetHeight(); DWORD line = ima->GetEffWidth(); BYTE bytes = ima->GetBpp()>>3; BYTE* pSrc; for (DWORD y=0;y<h;y++){ pSrc = ima->GetBits(y) + x*bytes; for (BYTE w=0;w<bytes;w++){ *pSrc++=*pCol++; } } return 1; } ///////////////////////////////////////////////////////////////////// #endif --- NEW FILE: ximaj2k.h --- /* * File: ximaj2k.h * Purpose: J2K Image Class Loader and Writer */ /* === C R E D I T S & D I S C L A I M E R S ============== * CxImageJ2K (c) 04/Aug/2002 Davide Pizzolato - www.xdp.it * Permission is given by the author to freely redistribute and include * this code in any program as long as this credit is given where due. * * CxImage version 5.99a 08/Feb/2004 * See the file history.htm for the complete bugfix and news report. * * based on LIBJ2K Copyright (c) 2001-2002, David Janssens - All rights reserved. * * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. * * Use at your own risk! * ========================================================== */ #if !defined(__ximaJ2K_h) #define __ximaJ2K_h #include "ximage.h" #if CXIMAGE_SUPPORT_J2K #define LIBJ2K_EXPORTS extern "C" { #include "../j2k/j2k.h" }; class CxImageJ2K: public CxImage { public: CxImageJ2K(): CxImage(CXIMAGE_FORMAT_J2K) {} // bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_J2K);} // bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_J2K);} bool Decode(CxFile * hFile); bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } #if CXIMAGE_SUPPORT_ENCODE bool Encode(CxFile * hFile); bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } #endif // CXIMAGE_SUPPORT_ENCODE protected: void j2k_calc_explicit_stepsizes(j2k_tccp_t *tccp, int prec); void j2k_encode_stepsize(int stepsize, int numbps, int *expn, int *mant); int j2k_floorlog2(int a); }; #endif #endif --- NEW FILE: ximajas.h --- /* * File: ximajas.h * Purpose: Jasper Image Class Loader and Writer */ /* === C R E D I T S & D I S C L A I M E R S ============== * CxImageJAS (c) 12/Apr/2003 Davide Pizzolato - www.xdp.it * Permission is given by the author to freely redistribute and include * this code in any program as long as this credit is given where due. * * CxImage version 5.99a 08/Feb/2004 * See the file history.htm for the complete bugfix and news report. * * based on JasPer Copyright (c) 2001-2003 Michael David Adams - All rights reserved. * * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. * * Use at your own risk! * ========================================================== */ #if !defined(__ximaJAS_h) #define __ximaJAS_h #include "ximage.h" #if CXIMAGE_SUPPORT_JASPER #include "..\jasper\include\jasper\jasper.h" class CxImageJAS: public CxImage { public: CxImageJAS(): CxImage(0) {} // bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,0);} // bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,0);} bool Decode(CxFile * hFile, DWORD imagetype = 0); bool Decode(FILE *hFile, DWORD imagetype = 0) { CxIOFile file(hFile); return Decode(&file,imagetype); } #if CXIMAGE_SUPPORT_ENCODE bool Encode(CxFile * hFile, DWORD imagetype = 0); bool Encode(FILE *hFile, DWORD imagetype = 0) { CxIOFile file(hFile); return Encode(&file,imagetype); } #endif // CXIMAGE_SUPPORT_ENCODE protected: class CxFileJas { public: CxFileJas(CxFile* pFile,jas_stream_t *stream) { if (stream->obj_) jas_free(stream->obj_); stream->obj_ = pFile; stream->ops_->close_ = JasClose; stream->ops_->read_ = JasRead; stream->ops_->seek_ = JasSeek; stream->ops_->write_ = JasWrite; } static int JasRead(jas_stream_obj_t *obj, char *buf, int cnt) { return ((CxFile*)obj)->Read(buf,1,cnt); } static int JasWrite(jas_stream_obj_t *obj, char *buf, int cnt) { return ((CxFile*)obj)->Write(buf,1,cnt); } static long JasSeek(jas_stream_obj_t *obj, long offset, int origin) { return ((CxFile*)obj)->Seek(offset,origin); } static int JasClose(jas_stream_obj_t *obj) { return 1; } }; }; #endif #endif --- NEW FILE: ximajbg.h --- /* * File: ximajbg.h * Purpose: JBG Image Class Loader and Writer */ /* === C R E D I T S & D I S C L A I M E R S ============== * CxImageJBG (c) 18/Aug/2002 Davide Pizzolato - www.xdp.it * Permission is given by the author to freely redistribute and include * this code in any program as long as this credit is given where due. * * CxImage version 5.99a 08/Feb/2004 * See the file history.htm for the complete bugfix and news report. * * based on LIBJBG Copyright (c) 2002, Markus Kuhn - All rights reserved. * * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. * * Use at your own risk! * ========================================================== */ #if !defined(__ximaJBG_h) #define __ximaJBG_h #include "ximage.h" #if CXIMAGE_SUPPORT_JBG extern "C" { #include "../jbig/jbig.h" }; class CxImageJBG: public CxImage { public: CxImageJBG(): CxImage(CXIMAGE_FORMAT_JBG) {} // bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_JBG);} // bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_JBG);} bool Decode(CxFile * hFile); bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } #if CXIMAGE_SUPPORT_ENCODE bool Encode(CxFile * hFile); bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } #endif // CXIMAGE_SUPPORT_ENCODE protected: static void jbig_data_out(BYTE *buffer, unsigned int len, void *file) {((CxFile*)file)->Write(buffer,len,1);} }; #endif #endif --- NEW FILE: ximajpg.h --- /* * File: ximajpg.h * Purpose: JPG Image Class Loader and Writer */ /* === C R E D I T S & D I S C L A I M E R S ============== * CxImageJPG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it * Permission is given by the author to freely redistribute and include * this code in any program as long as this credit is given where due. * * CxImage version 5.99a 08/Feb/2004 * See the file history.htm for the complete bugfix and news report. * * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes * * Special thanks to Chris Shearer Cooper for CxFileJpg tips & code * * EXIF support based on jhead-1.8 by Matthias Wandel <mwandel(at)rim(dot)net> * * original CImageJPG and CImageIterator implementation are: * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx> * * This software is based in part on the work of the Independent JPEG Group. * Copyright (C) 1991-1998, Thomas G. Lane. * * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. * * Use at your own risk! * ========================================================== */ #if !defined(__ximaJPEG_h) #define __ixmaJPEG_h #include "ximage.h" #if CXIMAGE_SUPPORT_JPG #define CXIMAGEJPG_SUPPORT_EXIF 1 extern "C" { #include "../jpeg/jpeglib.h" #include "../jpeg/jerror.h" } class DLL_EXP CxImageJPG: public CxImage { public: CxImageJPG(); ~CxImageJPG() {}; // bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_JPG);} // bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_JPG);} bool Decode(CxFile * hFile); bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } #if CXIMAGE_SUPPORT_ENCODE bool Encode(CxFile * hFile); bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } #endif // CXIMAGE_SUPPORT_ENCODE /* * EXIF support based on jhead-1.8 by Matthias Wandel <mwandel(at)rim(dot)net> */ #if CXIMAGEJPG_SUPPORT_EXIF #define MAX_COMMENT 1000 #define MAX_SECTIONS 20 typedef struct tag_ExifInfo { char Version [5]; char CameraMake [32]; char CameraModel [40]; char DateTime [20]; int Height, Width; int Orientation; int IsColor; int Process; int FlashUsed; float FocalLength; float ExposureTime; float ApertureFNumber; float Distance; float CCDWidth; float ExposureBias; int Whitebalance; int MeteringMode; int ExposureProgram; int ISOequivalent; int CompressionLevel; float FocalplaneXRes; float FocalplaneYRes; float FocalplaneUnits; float Xresolution; float Yresolution; float ResolutionUnit; float Brightness; char Comments[MAX_COMMENT]; unsigned char * ThumbnailPointer; /* Pointer at the thumbnail */ unsigned ThumbnailSize; /* Size of thumbnail. */ bool IsExif; } EXIFINFO; //-------------------------------------------------------------------------- // JPEG markers consist of one or more 0xFF bytes, followed by a marker // code byte (which is not an FF). Here are the marker codes of interest // in this program. (See jdmarker.c for a more complete list.) //-------------------------------------------------------------------------- #define M_SOF0 0xC0 // Start Of Frame N #define M_SOF1 0xC1 // N indicates which compression process #define M_SOF2 0xC2 // Only SOF0-SOF2 are now in common use #define M_SOF3 0xC3 #define M_SOF5 0xC5 // NB: codes C4 and CC are NOT SOF markers #define M_SOF6 0xC6 #define M_SOF7 0xC7 #define M_SOF9 0xC9 #define M_SOF10 0xCA #define M_SOF11 0xCB #define M_SOF13 0xCD #define M_SOF14 0xCE #define M_SOF15 0xCF #define M_SOI 0xD8 // Start Of Image (beginning of datastream) #define M_EOI 0xD9 // End Of Image (end of datastream) #define M_SOS 0xDA // Start Of Scan (begins compressed data) #define M_JFIF 0xE0 // Jfif marker #define M_EXIF 0xE1 // Exif marker #define M_COM 0xFE // COMment class CxExifInfo { typedef struct tag_Section_t{ BYTE* Data; int Type; unsigned Size; } Section_t; public: EXIFINFO* m_exifi... [truncated message content] |