3 * Purpose: General Purpose Image Class
\r
6 --------------------------------------------------------------------------------
\r
8 COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
\r
10 CxImage version 6.0.0 02/Feb/2008
\r
12 CxImage : Copyright (C) 2001 - 2008, Davide Pizzolato
\r
14 Original CImage and CImageIterator implementation are:
\r
15 Copyright (C) 1995, Alejandro Aguilar Sierra (asierra(at)servidor(dot)unam(dot)mx)
\r
17 Covered code is provided under this license on an "as is" basis, without warranty
\r
18 of any kind, either expressed or implied, including, without limitation, warranties
\r
19 that the covered code is free of defects, merchantable, fit for a particular purpose
\r
20 or non-infringing. The entire risk as to the quality and performance of the covered
\r
21 code is with you. Should any covered code prove defective in any respect, you (not
\r
22 the initial developer or any other contributor) assume the cost of any necessary
\r
23 servicing, repair or correction. This disclaimer of warranty constitutes an essential
\r
24 part of this license. No use of any covered code is authorized hereunder except under
\r
27 Permission is hereby granted to use, copy, modify, and distribute this
\r
28 source code, or portions hereof, for any purpose, including commercial applications,
\r
29 freely and without fee, subject to the following restrictions:
\r
31 1. The origin of this software must not be misrepresented; you must not
\r
32 claim that you wrote the original software. If you use this software
\r
33 in a product, an acknowledgment in the product documentation would be
\r
34 appreciated but is not required.
\r
36 2. Altered source versions must be plainly marked as such, and must not be
\r
37 misrepresented as being the original software.
\r
39 3. This notice may not be removed or altered from any source distribution.
\r
41 --------------------------------------------------------------------------------
\r
43 Other information about CxImage, and the latest version, can be found at the
\r
44 CxImage home page: http://www.xdp.it/cximage/
\r
46 --------------------------------------------------------------------------------
\r
48 #if !defined(__CXIMAGE_H)
\r
55 /////////////////////////////////////////////////////////////////////////////
\r
57 #include "xiofile.h"
\r
58 #include "xmemfile.h"
\r
59 #include "ximadef.h" //<vho> adjust some #define
\r
61 /* see "ximacfg.h" for CxImage configuration options */
\r
63 /////////////////////////////////////////////////////////////////////////////
\r
64 // CxImage formats enumerator
\r
65 enum ENUM_CXIMAGE_FORMATS{
\r
66 CXIMAGE_FORMAT_UNKNOWN = 0,
\r
67 #if CXIMAGE_SUPPORT_BMP
\r
68 CXIMAGE_FORMAT_BMP = 1,
\r
70 #if CXIMAGE_SUPPORT_GIF
\r
71 CXIMAGE_FORMAT_GIF = 2,
\r
73 #if CXIMAGE_SUPPORT_JPG
\r
74 CXIMAGE_FORMAT_JPG = 3,
\r
76 #if CXIMAGE_SUPPORT_PNG
\r
77 CXIMAGE_FORMAT_PNG = 4,
\r
79 #if CXIMAGE_SUPPORT_ICO
\r
80 CXIMAGE_FORMAT_ICO = 5,
\r
82 #if CXIMAGE_SUPPORT_TIF
\r
83 CXIMAGE_FORMAT_TIF = 6,
\r
85 #if CXIMAGE_SUPPORT_TGA
\r
86 CXIMAGE_FORMAT_TGA = 7,
\r
88 #if CXIMAGE_SUPPORT_PCX
\r
89 CXIMAGE_FORMAT_PCX = 8,
\r
91 #if CXIMAGE_SUPPORT_WBMP
\r
92 CXIMAGE_FORMAT_WBMP = 9,
\r
94 #if CXIMAGE_SUPPORT_WMF
\r
95 CXIMAGE_FORMAT_WMF = 10,
\r
97 #if CXIMAGE_SUPPORT_JP2
\r
98 CXIMAGE_FORMAT_JP2 = 11,
\r
100 #if CXIMAGE_SUPPORT_JPC
\r
101 CXIMAGE_FORMAT_JPC = 12,
\r
103 #if CXIMAGE_SUPPORT_PGX
\r
104 CXIMAGE_FORMAT_PGX = 13,
\r
106 #if CXIMAGE_SUPPORT_PNM
\r
107 CXIMAGE_FORMAT_PNM = 14,
\r
109 #if CXIMAGE_SUPPORT_RAS
\r
110 CXIMAGE_FORMAT_RAS = 15,
\r
112 #if CXIMAGE_SUPPORT_JBG
\r
113 CXIMAGE_FORMAT_JBG = 16,
\r
115 #if CXIMAGE_SUPPORT_MNG
\r
116 CXIMAGE_FORMAT_MNG = 17,
\r
118 #if CXIMAGE_SUPPORT_SKA
\r
119 CXIMAGE_FORMAT_SKA = 18,
\r
121 #if CXIMAGE_SUPPORT_RAW
\r
122 CXIMAGE_FORMAT_RAW = 19,
\r
124 CMAX_IMAGE_FORMATS = CXIMAGE_SUPPORT_BMP + CXIMAGE_SUPPORT_GIF + CXIMAGE_SUPPORT_JPG +
\r
125 CXIMAGE_SUPPORT_PNG + CXIMAGE_SUPPORT_MNG + CXIMAGE_SUPPORT_ICO +
\r
126 CXIMAGE_SUPPORT_TIF + CXIMAGE_SUPPORT_TGA + CXIMAGE_SUPPORT_PCX +
\r
127 CXIMAGE_SUPPORT_WBMP+ CXIMAGE_SUPPORT_WMF +
\r
128 CXIMAGE_SUPPORT_JBG + CXIMAGE_SUPPORT_JP2 + CXIMAGE_SUPPORT_JPC +
\r
129 CXIMAGE_SUPPORT_PGX + CXIMAGE_SUPPORT_PNM + CXIMAGE_SUPPORT_RAS +
\r
130 CXIMAGE_SUPPORT_SKA + CXIMAGE_SUPPORT_RAW + 1
\r
133 /////////////////////////////////////////////////////////////////////////////
\r
135 /////////////////////////////////////////////////////////////////////////////
\r
136 class DLL_EXP CxImage
\r
138 //extensible information collector
\r
139 typedef struct tagCxImageInfo {
\r
140 DWORD dwEffWidth; ///< DWORD aligned scan line width
\r
141 BYTE* pImage; ///< THE IMAGE BITS
\r
142 CxImage* pGhost; ///< if this is a ghost, pGhost points to the body
\r
143 CxImage* pParent; ///< if this is a layer, pParent points to the body
\r
144 DWORD dwType; ///< original image format
\r
145 char szLastError[256]; ///< debugging
\r
146 long nProgress; ///< monitor
\r
147 long nEscape; ///< escape
\r
148 long nBkgndIndex; ///< used for GIF, PNG, MNG
\r
149 RGBQUAD nBkgndColor; ///< used for RGB transparency
\r
150 float fQuality; ///< used for JPEG, JPEG2000 (0.0f ... 100.0f)
\r
151 BYTE nJpegScale; ///< used for JPEG [ignacio]
\r
152 long nFrame; ///< used for TIF, GIF, MNG : actual frame
\r
153 long nNumFrames; ///< used for TIF, GIF, MNG : total number of frames
\r
154 DWORD dwFrameDelay; ///< used for GIF, MNG
\r
155 long xDPI; ///< horizontal resolution
\r
156 long yDPI; ///< vertical resolution
\r
157 RECT rSelectionBox; ///< bounding rectangle
\r
158 BYTE nAlphaMax; ///< max opacity (fade)
\r
159 bool bAlphaPaletteEnabled; ///< true if alpha values in the palette are enabled.
\r
160 bool bEnabled; ///< enables the painting functions
\r
163 DWORD dwCodecOpt[CMAX_IMAGE_FORMATS]; ///< for GIF, TIF : 0=def.1=unc,2=fax3,3=fax4,4=pack,5=jpg
\r
164 RGBQUAD last_c; ///< for GetNearestIndex optimization
\r
166 bool last_c_isvalid;
\r
168 DWORD dwFlags; ///< 0x??00000 = reserved, 0x00??0000 = blend mode, 0x0000???? = layer id - user flags
\r
170 bool bGetAllFrames;
\r
171 bool bLittleEndianHost;
\r
176 //public structures
\r
177 struct rgb_color { BYTE r,g,b; };
\r
179 #if CXIMAGE_SUPPORT_WINDOWS
\r
180 // <VATI> text placement data
\r
181 // members must be initialized with the InitTextInfo(&this) function.
\r
182 typedef struct tagCxTextInfo
\r
184 #if defined (_WIN32_WCE)
\r
185 TCHAR text[256]; ///< text for windows CE
\r
187 TCHAR text[4096]; ///< text (char -> TCHAR for UNICODE [Cesar M])
\r
189 LOGFONT lfont; ///< font and codepage data
\r
190 COLORREF fcolor; ///< foreground color
\r
191 long align; ///< DT_CENTER, DT_RIGHT, DT_LEFT aligment for multiline text
\r
192 BYTE smooth; ///< text smoothing option. Default is false.
\r
193 BYTE opaque; ///< text has background or hasn't. Default is true.
\r
194 ///< data for background (ignored if .opaque==FALSE)
\r
195 COLORREF bcolor; ///< background color
\r
196 float b_opacity; ///< opacity value for background between 0.0-1.0 Default is 0. (opaque)
\r
197 BYTE b_outline; ///< outline width for background (zero: no outline)
\r
198 BYTE b_round; ///< rounding radius for background rectangle. % of the height, between 0-50. Default is 10.
\r
199 ///< (backgr. always has a frame: width = 3 pixel + 10% of height by default.)
\r
204 /** \addtogroup Constructors */ //@{
\r
205 CxImage(DWORD imagetype = 0);
\r
206 CxImage(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0);
\r
207 CxImage(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);
\r
208 CxImage(const TCHAR * filename, DWORD imagetype); // For UNICODE support: char -> TCHAR
\r
209 CxImage(FILE * stream, DWORD imagetype);
\r
210 CxImage(CxFile * stream, DWORD imagetype);
\r
211 CxImage(BYTE * buffer, DWORD size, DWORD imagetype);
\r
212 virtual ~CxImage() { DestroyFrames(); Destroy(); };
\r
213 CxImage& operator = (const CxImage&);
\r
216 /** \addtogroup Initialization */ //@{
\r
217 void* Create(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0);
\r
219 bool DestroyFrames();
\r
220 void Clear(BYTE bval=0);
\r
221 void Copy(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);
\r
222 bool Transfer(CxImage &from, bool bTransferFrames = true);
\r
223 bool CreateFromArray(BYTE* pArray,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage);
\r
224 bool CreateFromMatrix(BYTE** ppMatrix,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage);
\r
225 void FreeMemory(void* memblock);
\r
227 DWORD Dump(BYTE * dst);
\r
228 DWORD UnDump(const BYTE * src);
\r
233 /** \addtogroup Attributes */ //@{
\r
235 BYTE* GetBits(DWORD row = 0);
\r
236 BYTE GetColorType();
\r
237 void* GetDIB() const;
\r
238 DWORD GetHeight() const;
\r
239 DWORD GetWidth() const;
\r
240 DWORD GetEffWidth() const;
\r
241 DWORD GetNumColors() const;
\r
242 WORD GetBpp() const;
\r
243 DWORD GetType() const;
\r
244 const char* GetLastError();
\r
245 static const TCHAR* GetVersion();
\r
246 static const float GetVersionNumber();
\r
248 DWORD GetFrameDelay() const;
\r
249 void SetFrameDelay(DWORD d);
\r
251 void GetOffset(long *x,long *y);
\r
252 void SetOffset(long x,long y);
\r
254 BYTE GetJpegQuality() const;
\r
255 void SetJpegQuality(BYTE q);
\r
256 float GetJpegQualityF() const;
\r
257 void SetJpegQualityF(float q);
\r
259 BYTE GetJpegScale() const;
\r
260 void SetJpegScale(BYTE q);
\r
262 long GetXDPI() const;
\r
263 long GetYDPI() const;
\r
264 void SetXDPI(long dpi);
\r
265 void SetYDPI(long dpi);
\r
267 DWORD GetClrImportant() const;
\r
268 void SetClrImportant(DWORD ncolors = 0);
\r
270 long GetProgress() const;
\r
271 long GetEscape() const;
\r
272 void SetProgress(long p);
\r
273 void SetEscape(long i);
\r
275 long GetTransIndex() const;
\r
276 RGBQUAD GetTransColor();
\r
277 void SetTransIndex(long idx);
\r
278 void SetTransColor(RGBQUAD rgb);
\r
279 bool IsTransparent() const;
\r
281 DWORD GetCodecOption(DWORD imagetype = 0);
\r
282 bool SetCodecOption(DWORD opt, DWORD imagetype = 0);
\r
284 DWORD GetFlags() const;
\r
285 void SetFlags(DWORD flags, bool bLockReservedFlags = true);
\r
287 BYTE GetDisposalMethod() const;
\r
288 void SetDisposalMethod(BYTE dm);
\r
290 bool SetType(DWORD type);
\r
292 static DWORD GetNumTypes();
\r
293 static DWORD GetTypeIdFromName(const TCHAR* ext);
\r
294 static DWORD GetTypeIdFromIndex(const DWORD index);
\r
295 static DWORD GetTypeIndexFromId(const DWORD id);
\r
297 bool GetRetreiveAllFrames() const;
\r
298 void SetRetreiveAllFrames(bool flag);
\r
299 CxImage * GetFrame(long nFrame) const;
\r
301 //void* GetUserData() const {return info.pUserData;}
\r
302 //void SetUserData(void* pUserData) {info.pUserData = pUserData;}
\r
305 /** \addtogroup Palette
\r
306 * These functions have no effects on RGB images and in this case the returned value is always 0.
\r
308 bool IsGrayScale();
\r
309 bool IsIndexed() const;
\r
310 bool IsSamePalette(CxImage &img, bool bCheckAlpha = true);
\r
311 DWORD GetPaletteSize();
\r
312 RGBQUAD* GetPalette() const;
\r
313 RGBQUAD GetPaletteColor(BYTE idx);
\r
314 bool GetPaletteColor(BYTE i, BYTE* r, BYTE* g, BYTE* b);
\r
315 BYTE GetNearestIndex(RGBQUAD c);
\r
316 void BlendPalette(COLORREF cr,long perc);
\r
317 void SetGrayPalette();
\r
318 void SetPalette(DWORD n, BYTE *r, BYTE *g, BYTE *b);
\r
319 void SetPalette(RGBQUAD* pPal,DWORD nColors=256);
\r
320 void SetPalette(rgb_color *rgb,DWORD nColors=256);
\r
321 void SetPaletteColor(BYTE idx, BYTE r, BYTE g, BYTE b, BYTE alpha=0);
\r
322 void SetPaletteColor(BYTE idx, RGBQUAD c);
\r
323 void SetPaletteColor(BYTE idx, COLORREF cr);
\r
324 void SwapIndex(BYTE idx1, BYTE idx2);
\r
325 void SwapRGB2BGR();
\r
326 void SetStdPalette();
\r
329 /** \addtogroup Pixel */ //@{
\r
330 bool IsInside(long x, long y);
\r
331 bool IsTransparent(long x,long y);
\r
332 bool GetTransparentMask(CxImage* iDst = 0);
\r
333 RGBQUAD GetPixelColor(long x,long y, bool bGetAlpha = true);
\r
334 BYTE GetPixelIndex(long x,long y);
\r
335 BYTE GetPixelGray(long x, long y);
\r
336 void SetPixelColor(long x,long y,RGBQUAD c, bool bSetAlpha = false);
\r
337 void SetPixelColor(long x,long y,COLORREF cr);
\r
338 void SetPixelIndex(long x,long y,BYTE i);
\r
339 void DrawLine(int StartX, int EndX, int StartY, int EndY, RGBQUAD color, bool bSetAlpha=false);
\r
340 void DrawLine(int StartX, int EndX, int StartY, int EndY, COLORREF cr);
\r
341 void BlendPixelColor(long x,long y,RGBQUAD c, float blend, bool bSetAlpha = false);
\r
345 /** \addtogroup Protected */ //@{
\r
346 BYTE BlindGetPixelIndex(const long x,const long y);
\r
347 RGBQUAD BlindGetPixelColor(const long x,const long y, bool bGetAlpha = true);
\r
348 void *BlindGetPixelPointer(const long x,const long y);
\r
349 void BlindSetPixelColor(long x,long y,RGBQUAD c, bool bSetAlpha = false);
\r
350 void BlindSetPixelIndex(long x,long y,BYTE i);
\r
355 #if CXIMAGE_SUPPORT_INTERPOLATION
\r
356 /** \addtogroup Interpolation */ //@{
\r
357 //overflow methods:
\r
358 enum OverflowMethod {
\r
366 void OverflowCoordinates(float &x, float &y, OverflowMethod const ofMethod);
\r
367 void OverflowCoordinates(long &x, long &y, OverflowMethod const ofMethod);
\r
368 RGBQUAD GetPixelColorWithOverflow(long x, long y, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0);
\r
369 //interpolation methods:
\r
370 enum InterpolationMethod {
\r
371 IM_NEAREST_NEIGHBOUR=1,
\r
390 RGBQUAD GetPixelColorInterpolated(float x,float y, InterpolationMethod const inMethod=IM_BILINEAR, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0);
\r
391 RGBQUAD GetAreaColorInterpolated(float const xc, float const yc, float const w, float const h, InterpolationMethod const inMethod, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0);
\r
395 /** \addtogroup Protected */ //@{
\r
396 void AddAveragingCont(RGBQUAD const &color, float const surf, float &rr, float &gg, float &bb, float &aa);
\r
399 /** \addtogroup Kernels */ //@{
\r
401 static float KernelBSpline(const float x);
\r
402 static float KernelLinear(const float t);
\r
403 static float KernelCubic(const float t);
\r
404 static float KernelGeneralizedCubic(const float t, const float a=-1);
\r
405 static float KernelLanczosSinc(const float t, const float r = 3);
\r
406 static float KernelBox(const float x);
\r
407 static float KernelHermite(const float x);
\r
408 static float KernelHamming(const float x);
\r
409 static float KernelSinc(const float x);
\r
410 static float KernelBlackman(const float x);
\r
411 static float KernelBessel_J1(const float x);
\r
412 static float KernelBessel_P1(const float x);
\r
413 static float KernelBessel_Q1(const float x);
\r
414 static float KernelBessel_Order1(float x);
\r
415 static float KernelBessel(const float x);
\r
416 static float KernelGaussian(const float x);
\r
417 static float KernelQuadratic(const float x);
\r
418 static float KernelMitchell(const float x);
\r
419 static float KernelCatrom(const float x);
\r
420 static float KernelHanning(const float x);
\r
421 static float KernelPower(const float x, const float a = 2);
\r
423 #endif //CXIMAGE_SUPPORT_INTERPOLATION
\r
425 /** \addtogroup Painting */ //@{
\r
426 #if CXIMAGE_SUPPORT_WINDOWS
\r
427 long Blt(HDC pDC, long x=0, long y=0);
\r
428 HBITMAP MakeBitmap(HDC hdc = NULL);
\r
429 HANDLE CopyToHandle();
\r
430 bool CreateFromHANDLE(HANDLE hMem); //Windows objects (clipboard)
\r
431 bool CreateFromHBITMAP(HBITMAP hbmp, HPALETTE hpal=0); //Windows resource
\r
432 bool CreateFromHICON(HICON hico);
\r
433 long Draw(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1, RECT* pClipRect = 0, bool bSmooth = false);
\r
434 long Draw(HDC hdc, const RECT& rect, RECT* pClipRect=NULL, bool bSmooth = false);
\r
435 long Stretch(HDC hdc, long xoffset, long yoffset, long xsize, long ysize, DWORD dwRop = SRCCOPY);
\r
436 long Stretch(HDC hdc, const RECT& rect, DWORD dwRop = SRCCOPY);
\r
437 long Tile(HDC hdc, RECT *rc);
\r
438 long Draw2(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1);
\r
439 long Draw2(HDC hdc, const RECT& rect);
\r
440 //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);
\r
441 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);
\r
442 // <VATI> extensions
\r
443 long DrawStringEx(HDC hdc, long x, long y, CXTEXTINFO *pTextType, bool bSetAlpha=false );
\r
444 void InitTextInfo( CXTEXTINFO *txt );
\r
445 #endif //CXIMAGE_SUPPORT_WINDOWS
\r
449 #if CXIMAGE_SUPPORT_DECODE
\r
450 /** \addtogroup Decode */ //@{
\r
452 //bool Load(LPCWSTR filename, DWORD imagetype=0);
\r
453 bool LoadResource(HRSRC hRes, DWORD imagetype, HMODULE hModule=NULL);
\r
455 // For UNICODE support: char -> TCHAR
\r
456 bool Load(const TCHAR* filename, DWORD imagetype=0);
\r
457 //bool Load(const char * filename, DWORD imagetype=0);
\r
458 bool Decode(FILE * hFile, DWORD imagetype);
\r
459 bool Decode(CxFile * hFile, DWORD imagetype);
\r
460 bool Decode(BYTE * buffer, DWORD size, DWORD imagetype);
\r
462 bool CheckFormat(CxFile * hFile, DWORD imagetype = 0);
\r
463 bool CheckFormat(BYTE * buffer, DWORD size, DWORD imagetype = 0);
\r
465 #endif //CXIMAGE_SUPPORT_DECODE
\r
467 #if CXIMAGE_SUPPORT_ENCODE
\r
469 /** \addtogroup Protected */ //@{
\r
470 bool EncodeSafeCheck(CxFile *hFile);
\r
474 /** \addtogroup Encode */ //@{
\r
476 //bool Save(LPCWSTR filename, DWORD imagetype=0);
\r
478 // For UNICODE support: char -> TCHAR
\r
479 bool Save(const TCHAR* filename, DWORD imagetype);
\r
480 //bool Save(const char * filename, DWORD imagetype=0);
\r
481 bool Encode(FILE * hFile, DWORD imagetype);
\r
482 bool Encode(CxFile * hFile, DWORD imagetype);
\r
483 bool Encode(CxFile * hFile, CxImage ** pImages, int pagecount, DWORD imagetype);
\r
484 bool Encode(FILE *hFile, CxImage ** pImages, int pagecount, DWORD imagetype);
\r
485 bool Encode(BYTE * &buffer, long &size, DWORD imagetype);
\r
487 bool Encode2RGBA(CxFile *hFile, bool bFlipY = false);
\r
488 bool Encode2RGBA(BYTE * &buffer, long &size, bool bFlipY = false);
\r
490 #endif //CXIMAGE_SUPPORT_ENCODE
\r
492 /** \addtogroup Attributes */ //@{
\r
494 bool IsValid() const;
\r
495 bool IsEnabled() const;
\r
496 void Enable(bool enable=true);
\r
498 // frame operations
\r
499 long GetNumFrames() const;
\r
500 long GetFrame() const;
\r
501 void SetFrame(long nFrame);
\r
504 #if CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
\r
505 /** \addtogroup BasicTransformations */ //@{
\r
507 bool Flip(bool bFlipSelection = false, bool bFlipAlpha = true);
\r
508 bool Mirror(bool bMirrorSelection = false, bool bMirrorAlpha = true);
\r
510 bool RotateLeft(CxImage* iDst = NULL);
\r
511 bool RotateRight(CxImage* iDst = NULL);
\r
513 #endif //CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
\r
515 #if CXIMAGE_SUPPORT_TRANSFORMATION
\r
516 /** \addtogroup Transformations */ //@{
\r
517 // image operations
\r
518 bool Rotate(float angle, CxImage* iDst = NULL);
\r
519 bool Rotate2(float angle, CxImage *iDst = NULL, InterpolationMethod inMethod=IM_BILINEAR,
\r
520 OverflowMethod ofMethod=OM_BACKGROUND, RGBQUAD *replColor=0,
\r
521 bool const optimizeRightAngles=true, bool const bKeepOriginalSize=false);
\r
522 bool Rotate180(CxImage* iDst = NULL);
\r
523 bool Resample(long newx, long newy, int mode = 1, CxImage* iDst = NULL);
\r
524 bool Resample2(long newx, long newy, InterpolationMethod const inMethod=IM_BICUBIC2,
\r
525 OverflowMethod const ofMethod=OM_REPEAT, CxImage* const iDst = NULL,
\r
526 bool const disableAveraging=false);
\r
527 bool DecreaseBpp(DWORD nbit, bool errordiffusion, RGBQUAD* ppal = 0, DWORD clrimportant = 0);
\r
528 bool IncreaseBpp(DWORD nbit);
\r
529 bool Dither(long method = 0);
\r
530 bool Crop(long left, long top, long right, long bottom, CxImage* iDst = NULL);
\r
531 bool Crop(const RECT& rect, CxImage* iDst = NULL);
\r
532 bool CropRotatedRectangle( long topx, long topy, long width, long height, float angle, CxImage* iDst = NULL);
\r
533 bool Skew(float xgain, float ygain, long xpivot=0, long ypivot=0, bool bEnableInterpolation = false);
\r
534 bool Expand(long left, long top, long right, long bottom, RGBQUAD canvascolor, CxImage* iDst = 0);
\r
535 bool Expand(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0);
\r
536 bool Thumbnail(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0);
\r
537 bool CircleTransform(int type,long rmax=0,float Koeff=1.0f);
\r
538 bool RedEyeRemove(float strength = 0.8f);
\r
539 bool QIShrink(long newx, long newy, CxImage* const iDst = NULL, bool bChangeBpp = false);
\r
542 #endif //CXIMAGE_SUPPORT_TRANSFORMATION
\r
544 #if CXIMAGE_SUPPORT_DSP
\r
545 /** \addtogroup DSP */ //@{
\r
547 bool HistogramStretch(long method = 0, double threshold = 0);
\r
548 bool HistogramEqualize();
\r
549 bool HistogramNormalize();
\r
550 bool HistogramRoot();
\r
551 bool HistogramLog();
\r
552 long Histogram(long* red, long* green = 0, long* blue = 0, long* gray = 0, long colorspace = 0);
\r
553 bool Jitter(long radius=2);
\r
554 bool Repair(float radius = 0.25f, long niterations = 1, long colorspace = 0);
\r
555 bool Combine(CxImage* r,CxImage* g,CxImage* b,CxImage* a, long colorspace = 0);
\r
556 bool FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage* dstImag, long direction = 1, bool bForceFFT = true, bool bMagnitude = true);
\r
557 bool Noise(long level);
\r
558 bool Median(long Ksize=3);
\r
559 bool Gamma(float gamma);
\r
560 bool GammaRGB(float gammaR, float gammaG, float gammaB);
\r
561 bool ShiftRGB(long r, long g, long b);
\r
562 bool Threshold(BYTE level);
\r
563 bool Threshold(CxImage* pThresholdMask);
\r
564 bool Threshold2(BYTE level, bool bDirection, RGBQUAD nBkgndColor, bool bSetAlpha = false);
\r
565 bool Colorize(BYTE hue, BYTE sat, float blend = 1.0f);
\r
566 bool Light(long brightness, long contrast = 0);
\r
568 bool Filter(long* kernel, long Ksize, long Kfactor, long Koffset);
\r
569 bool Erode(long Ksize=2);
\r
570 bool Dilate(long Ksize=2);
\r
571 bool Edge(long Ksize=2);
\r
572 void HuePalette(float correction=1);
\r
573 enum ImageOpType { OpAdd, OpAnd, OpXor, OpOr, OpMask, OpSrcCopy, OpDstCopy, OpSub, OpSrcBlend, OpScreen, OpAvg };
\r
574 void Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset = 0, long lYOffset = 0, bool bMixAlpha = false);
\r
575 void MixFrom(CxImage & imagesrc2, long lXOffset, long lYOffset);
\r
576 bool UnsharpMask(float radius = 5.0f, float amount = 0.5f, int threshold = 0);
\r
577 bool Lut(BYTE* pLut);
\r
578 bool Lut(BYTE* pLutR, BYTE* pLutG, BYTE* pLutB, BYTE* pLutA = 0);
\r
579 bool GaussianBlur(float radius = 1.0f, CxImage* iDst = 0);
\r
580 bool TextBlur(BYTE threshold = 100, BYTE decay = 2, BYTE max_depth = 5, bool bBlurHorizontal = true, bool bBlurVertical = true, CxImage* iDst = 0);
\r
581 bool SelectiveBlur(float radius = 1.0f, BYTE threshold = 25, CxImage* iDst = 0);
\r
582 bool Solarize(BYTE level = 128, bool bLinkedChannels = true);
\r
583 bool FloodFill(const long xStart, const long yStart, const RGBQUAD cFillColor, const BYTE tolerance = 0,
\r
584 BYTE nOpacity = 255, const bool bSelectFilledArea = false, const BYTE nSelectionLevel = 255);
\r
585 bool Saturate(const long saturation, const long colorspace = 1);
\r
586 bool ConvertColorSpace(const long dstColorSpace, const long srcColorSpace);
\r
587 int OptimalThreshold(long method = 0, RECT * pBox = 0, CxImage* pContrastMask = 0);
\r
588 bool AdaptiveThreshold(long method = 0, long nBoxSize = 64, CxImage* pContrastMask = 0, long nBias = 0, float fGlobalLocalBalance = 0.5f);
\r
593 /** \addtogroup Protected */ //@{
\r
594 bool IsPowerof2(long x);
\r
595 bool FFT(int dir,int m,double *x,double *y);
\r
596 bool DFT(int dir,long m,double *x1,double *y1,double *x2,double *y2);
\r
597 bool RepairChannel(CxImage *ch, float radius);
\r
599 int gen_convolve_matrix (float radius, float **cmatrix_p);
\r
600 float* gen_lookup_table (float *cmatrix, int cmatrix_length);
\r
601 void blur_line (float *ctable, float *cmatrix, int cmatrix_length, BYTE* cur_col, BYTE* dest_col, int y, long bytes);
\r
602 void blur_text (BYTE threshold, BYTE decay, BYTE max_depth, CxImage* iSrc, CxImage* iDst, BYTE bytes);
\r
606 /** \addtogroup ColorSpace */ //@{
\r
607 bool SplitRGB(CxImage* r,CxImage* g,CxImage* b);
\r
608 bool SplitYUV(CxImage* y,CxImage* u,CxImage* v);
\r
609 bool SplitHSL(CxImage* h,CxImage* s,CxImage* l);
\r
610 bool SplitYIQ(CxImage* y,CxImage* i,CxImage* q);
\r
611 bool SplitXYZ(CxImage* x,CxImage* y,CxImage* z);
\r
612 bool SplitCMYK(CxImage* c,CxImage* m,CxImage* y,CxImage* k);
\r
613 static RGBQUAD HSLtoRGB(COLORREF cHSLColor);
\r
614 static RGBQUAD RGBtoHSL(RGBQUAD lRGBColor);
\r
615 static RGBQUAD HSLtoRGB(RGBQUAD lHSLColor);
\r
616 static RGBQUAD YUVtoRGB(RGBQUAD lYUVColor);
\r
617 static RGBQUAD RGBtoYUV(RGBQUAD lRGBColor);
\r
618 static RGBQUAD YIQtoRGB(RGBQUAD lYIQColor);
\r
619 static RGBQUAD RGBtoYIQ(RGBQUAD lRGBColor);
\r
620 static RGBQUAD XYZtoRGB(RGBQUAD lXYZColor);
\r
621 static RGBQUAD RGBtoXYZ(RGBQUAD lRGBColor);
\r
622 #endif //CXIMAGE_SUPPORT_DSP
\r
623 static RGBQUAD RGBtoRGBQUAD(COLORREF cr);
\r
624 static COLORREF RGBQUADtoRGB (RGBQUAD c);
\r
627 #if CXIMAGE_SUPPORT_SELECTION
\r
628 /** \addtogroup Selection */ //@{
\r
629 bool SelectionClear(BYTE level = 0);
\r
630 bool SelectionCreate();
\r
631 bool SelectionDelete();
\r
632 bool SelectionInvert();
\r
633 bool SelectionMirror();
\r
634 bool SelectionFlip();
\r
635 bool SelectionAddRect(RECT r, BYTE level = 255);
\r
636 bool SelectionAddEllipse(RECT r, BYTE level = 255);
\r
637 bool SelectionAddPolygon(POINT *points, long npoints, BYTE level = 255);
\r
638 bool SelectionAddColor(RGBQUAD c, BYTE level = 255);
\r
639 bool SelectionAddPixel(long x, long y, BYTE level = 255);
\r
640 bool SelectionCopy(CxImage &from);
\r
641 bool SelectionIsInside(long x, long y);
\r
642 bool SelectionIsValid();
\r
643 void SelectionGetBox(RECT& r);
\r
644 bool SelectionToHRGN(HRGN& region);
\r
645 bool SelectionSplit(CxImage *dest);
\r
646 BYTE SelectionGet(const long x,const long y);
\r
647 bool SelectionSet(CxImage &from);
\r
648 void SelectionRebuildBox();
\r
649 BYTE* SelectionGetPointer(const long x = 0,const long y = 0);
\r
653 /** \addtogroup Protected */ //@{
\r
654 bool BlindSelectionIsInside(long x, long y);
\r
655 BYTE BlindSelectionGet(const long x,const long y);
\r
656 void SelectionSet(const long x,const long y,const BYTE level);
\r
661 #endif //CXIMAGE_SUPPORT_SELECTION
\r
663 #if CXIMAGE_SUPPORT_ALPHA
\r
664 /** \addtogroup Alpha */ //@{
\r
666 bool AlphaCreate();
\r
667 void AlphaDelete();
\r
668 void AlphaInvert();
\r
669 bool AlphaMirror();
\r
671 bool AlphaCopy(CxImage &from);
\r
672 bool AlphaSplit(CxImage *dest);
\r
674 void AlphaSet(BYTE level);
\r
675 bool AlphaSet(CxImage &from);
\r
676 void AlphaSet(const long x,const long y,const BYTE level);
\r
677 BYTE AlphaGet(const long x,const long y);
\r
678 BYTE AlphaGetMax() const;
\r
679 void AlphaSetMax(BYTE nAlphaMax);
\r
680 bool AlphaIsValid();
\r
681 BYTE* AlphaGetPointer(const long x = 0,const long y = 0);
\r
682 bool AlphaFromTransparency();
\r
684 void AlphaPaletteClear();
\r
685 void AlphaPaletteEnable(bool enable=true);
\r
686 bool AlphaPaletteIsEnabled();
\r
687 bool AlphaPaletteIsValid();
\r
688 bool AlphaPaletteSplit(CxImage *dest);
\r
692 /** \addtogroup Protected */ //@{
\r
693 BYTE BlindAlphaGet(const long x,const long y);
\r
695 #endif //CXIMAGE_SUPPORT_ALPHA
\r
698 #if CXIMAGE_SUPPORT_LAYERS
\r
699 /** \addtogroup Layers */ //@{
\r
700 bool LayerCreate(long position = -1);
\r
701 bool LayerDelete(long position = -1);
\r
702 void LayerDeleteAll();
\r
703 CxImage* GetLayer(long position);
\r
704 CxImage* GetParent() const;
\r
705 long GetNumLayers() const;
\r
706 long LayerDrawAll(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1, RECT* pClipRect = 0, bool bSmooth = false);
\r
707 long LayerDrawAll(HDC hdc, const RECT& rect, RECT* pClipRect=NULL, bool bSmooth = false);
\r
709 #endif //CXIMAGE_SUPPORT_LAYERS
\r
712 /** \addtogroup Protected */ //@{
\r
713 void Startup(DWORD imagetype = 0);
\r
714 void CopyInfo(const CxImage &src);
\r
715 void Ghost(const CxImage *src);
\r
716 void RGBtoBGR(BYTE *buffer, int length);
\r
717 static float HueToRGB(float n1,float n2, float hue);
\r
718 void Bitfield2RGB(BYTE *src, DWORD redmask, DWORD greenmask, DWORD bluemask, BYTE bpp);
\r
719 static int CompareColors(const void *elem1, const void *elem2);
\r
720 short ntohs(const short word);
\r
721 long ntohl(const long dword);
\r
722 void bihtoh(BITMAPINFOHEADER* bih);
\r
724 void* pDib; //contains the header, the palette, the pixels
\r
725 BITMAPINFOHEADER head; //standard header
\r
726 CXIMAGEINFO info; //extended information
\r
727 BYTE* pSelection; //selected region
\r
728 BYTE* pAlpha; //alpha channel
\r
729 CxImage** ppLayers; //generic layers
\r
730 CxImage** ppFrames;
\r
734 ////////////////////////////////////////////////////////////////////////////
\r
735 #endif // !defined(__CXIMAGE_H)
\r