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