source: liacs/MIR2010/SourceCode/cximage/ximage.h@ 192

Last change on this file since 192 was 95, checked in by Rick van der Zwet, 15 years ago

Bad boy, improper move of directory

File size: 27.8 KB
Line 
1/*
2 * File: ximage.h
3 * Purpose: General Purpose Image Class
4 */
5/*
6 --------------------------------------------------------------------------------
7
8 COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
9
10 CxImage version 6.0.0 02/Feb/2008
11
12 CxImage : Copyright (C) 2001 - 2008, Davide Pizzolato
13
14 Original CImage and CImageIterator implementation are:
15 Copyright (C) 1995, Alejandro Aguilar Sierra (asierra(at)servidor(dot)unam(dot)mx)
16
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
25 this disclaimer.
26
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:
30
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.
35
36 2. Altered source versions must be plainly marked as such, and must not be
37 misrepresented as being the original software.
38
39 3. This notice may not be removed or altered from any source distribution.
40
41 --------------------------------------------------------------------------------
42
43 Other information about CxImage, and the latest version, can be found at the
44 CxImage home page: http://www.xdp.it/cximage/
45
46 --------------------------------------------------------------------------------
47 */
48#if !defined(__CXIMAGE_H)
49#define __CXIMAGE_H
50
51#if _MSC_VER > 1000
52#pragma once
53#endif
54
55/////////////////////////////////////////////////////////////////////////////
56#include "xfile.h"
57#include "xiofile.h"
58#include "xmemfile.h"
59#include "ximadef.h" //<vho> adjust some #define
60
61/* see "ximacfg.h" for CxImage configuration options */
62
63/////////////////////////////////////////////////////////////////////////////
64// CxImage formats enumerator
65enum ENUM_CXIMAGE_FORMATS{
66CXIMAGE_FORMAT_UNKNOWN = 0,
67#if CXIMAGE_SUPPORT_BMP
68CXIMAGE_FORMAT_BMP = 1,
69#endif
70#if CXIMAGE_SUPPORT_GIF
71CXIMAGE_FORMAT_GIF = 2,
72#endif
73#if CXIMAGE_SUPPORT_JPG
74CXIMAGE_FORMAT_JPG = 3,
75#endif
76#if CXIMAGE_SUPPORT_PNG
77CXIMAGE_FORMAT_PNG = 4,
78#endif
79#if CXIMAGE_SUPPORT_ICO
80CXIMAGE_FORMAT_ICO = 5,
81#endif
82#if CXIMAGE_SUPPORT_TIF
83CXIMAGE_FORMAT_TIF = 6,
84#endif
85#if CXIMAGE_SUPPORT_TGA
86CXIMAGE_FORMAT_TGA = 7,
87#endif
88#if CXIMAGE_SUPPORT_PCX
89CXIMAGE_FORMAT_PCX = 8,
90#endif
91#if CXIMAGE_SUPPORT_WBMP
92CXIMAGE_FORMAT_WBMP = 9,
93#endif
94#if CXIMAGE_SUPPORT_WMF
95CXIMAGE_FORMAT_WMF = 10,
96#endif
97#if CXIMAGE_SUPPORT_JP2
98CXIMAGE_FORMAT_JP2 = 11,
99#endif
100#if CXIMAGE_SUPPORT_JPC
101CXIMAGE_FORMAT_JPC = 12,
102#endif
103#if CXIMAGE_SUPPORT_PGX
104CXIMAGE_FORMAT_PGX = 13,
105#endif
106#if CXIMAGE_SUPPORT_PNM
107CXIMAGE_FORMAT_PNM = 14,
108#endif
109#if CXIMAGE_SUPPORT_RAS
110CXIMAGE_FORMAT_RAS = 15,
111#endif
112#if CXIMAGE_SUPPORT_JBG
113CXIMAGE_FORMAT_JBG = 16,
114#endif
115#if CXIMAGE_SUPPORT_MNG
116CXIMAGE_FORMAT_MNG = 17,
117#endif
118#if CXIMAGE_SUPPORT_SKA
119CXIMAGE_FORMAT_SKA = 18,
120#endif
121#if CXIMAGE_SUPPORT_RAW
122CXIMAGE_FORMAT_RAW = 19,
123#endif
124CMAX_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
131};
132
133/////////////////////////////////////////////////////////////////////////////
134// CxImage class
135/////////////////////////////////////////////////////////////////////////////
136class DLL_EXP CxImage
137{
138//extensible information collector
139typedef 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
161 long xOffset;
162 long yOffset;
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
165 BYTE last_c_index;
166 bool last_c_isvalid;
167 long nNumLayers;
168 DWORD dwFlags; ///< 0x??00000 = reserved, 0x00??0000 = blend mode, 0x0000???? = layer id - user flags
169 BYTE dispmeth;
170 bool bGetAllFrames;
171 bool bLittleEndianHost;
172
173} CXIMAGEINFO;
174
175public:
176 //public structures
177struct rgb_color { BYTE r,g,b; };
178
179#if CXIMAGE_SUPPORT_WINDOWS
180// <VATI> text placement data
181// members must be initialized with the InitTextInfo(&this) function.
182typedef struct tagCxTextInfo
183{
184#if defined (_WIN32_WCE)
185 TCHAR text[256]; ///< text for windows CE
186#else
187 TCHAR text[4096]; ///< text (char -> TCHAR for UNICODE [Cesar M])
188#endif
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.)
200} CXTEXTINFO;
201#endif
202
203public:
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&);
214//@}
215
216/** \addtogroup Initialization */ //@{
217 void* Create(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0);
218 bool Destroy();
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);
226
227 DWORD Dump(BYTE * dst);
228 DWORD UnDump(const BYTE * src);
229 DWORD DumpSize();
230
231//@}
232
233/** \addtogroup Attributes */ //@{
234 long GetSize();
235 BYTE* GetBits(DWORD row = 0);
236 BYTE GetColorType();
237 void* GetDIB() const;
238 DWORD GetHeight() const;
239 DWORD GetWidth() const;
240 DWORD GetEffWidth() const;
241 DWORD GetNumColors() const;
242 WORD GetBpp() const;
243 DWORD GetType() const;
244 const char* GetLastError();
245 static const TCHAR* GetVersion();
246 static const float GetVersionNumber();
247
248 DWORD GetFrameDelay() const;
249 void SetFrameDelay(DWORD d);
250
251 void GetOffset(long *x,long *y);
252 void SetOffset(long x,long y);
253
254 BYTE GetJpegQuality() const;
255 void SetJpegQuality(BYTE q);
256 float GetJpegQualityF() const;
257 void SetJpegQualityF(float q);
258
259 BYTE GetJpegScale() const;
260 void SetJpegScale(BYTE q);
261
262 long GetXDPI() const;
263 long GetYDPI() const;
264 void SetXDPI(long dpi);
265 void SetYDPI(long dpi);
266
267 DWORD GetClrImportant() const;
268 void SetClrImportant(DWORD ncolors = 0);
269
270 long GetProgress() const;
271 long GetEscape() const;
272 void SetProgress(long p);
273 void SetEscape(long i);
274
275 long GetTransIndex() const;
276 RGBQUAD GetTransColor();
277 void SetTransIndex(long idx);
278 void SetTransColor(RGBQUAD rgb);
279 bool IsTransparent() const;
280
281 DWORD GetCodecOption(DWORD imagetype = 0);
282 bool SetCodecOption(DWORD opt, DWORD imagetype = 0);
283
284 DWORD GetFlags() const;
285 void SetFlags(DWORD flags, bool bLockReservedFlags = true);
286
287 BYTE GetDisposalMethod() const;
288 void SetDisposalMethod(BYTE dm);
289
290 bool SetType(DWORD type);
291
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);
296
297 bool GetRetreiveAllFrames() const;
298 void SetRetreiveAllFrames(bool flag);
299 CxImage * GetFrame(long nFrame) const;
300
301 //void* GetUserData() const {return info.pUserData;}
302 //void SetUserData(void* pUserData) {info.pUserData = pUserData;}
303//@}
304
305/** \addtogroup Palette
306 * These functions have no effects on RGB images and in this case the returned value is always 0.
307 * @{ */
308 bool IsGrayScale();
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);
325 void SwapRGB2BGR();
326 void SetStdPalette();
327//@}
328
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);
342//@}
343
344// BT: make these methods public, we need them
345//protected:
346/** \addtogroup Blind */ //@{
347 BYTE BlindGetPixelIndex(const long x,const long y);
348 RGBQUAD BlindGetPixelColor(const long x,const long y, bool bGetAlpha = true);
349 void *BlindGetPixelPointer(const long x,const long y);
350 void BlindSetPixelColor(long x,long y,RGBQUAD c, bool bSetAlpha = false);
351 void BlindSetPixelIndex(long x,long y,BYTE i);
352//@}
353
354public:
355
356#if CXIMAGE_SUPPORT_INTERPOLATION
357/** \addtogroup Interpolation */ //@{
358 //overflow methods:
359 enum OverflowMethod {
360 OM_COLOR=1,
361 OM_BACKGROUND=2,
362 OM_TRANSPARENT=3,
363 OM_WRAP=4,
364 OM_REPEAT=5,
365 OM_MIRROR=6
366 };
367 void OverflowCoordinates(float &x, float &y, OverflowMethod const ofMethod);
368 void OverflowCoordinates(long &x, long &y, OverflowMethod const ofMethod);
369 RGBQUAD GetPixelColorWithOverflow(long x, long y, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0);
370 //interpolation methods:
371 enum InterpolationMethod {
372 IM_NEAREST_NEIGHBOUR=1,
373 IM_BILINEAR =2,
374 IM_BSPLINE =3,
375 IM_BICUBIC =4,
376 IM_BICUBIC2 =5,
377 IM_LANCZOS =6,
378 IM_BOX =7,
379 IM_HERMITE =8,
380 IM_HAMMING =9,
381 IM_SINC =10,
382 IM_BLACKMAN =11,
383 IM_BESSEL =12,
384 IM_GAUSSIAN =13,
385 IM_QUADRATIC =14,
386 IM_MITCHELL =15,
387 IM_CATROM =16,
388 IM_HANNING =17,
389 IM_POWER =18
390 };
391 RGBQUAD GetPixelColorInterpolated(float x,float y, InterpolationMethod const inMethod=IM_BILINEAR, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0);
392 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);
393//@}
394
395protected:
396/** \addtogroup Protected */ //@{
397 void AddAveragingCont(RGBQUAD const &color, float const surf, float &rr, float &gg, float &bb, float &aa);
398//@}
399
400/** \addtogroup Kernels */ //@{
401public:
402 static float KernelBSpline(const float x);
403 static float KernelLinear(const float t);
404 static float KernelCubic(const float t);
405 static float KernelGeneralizedCubic(const float t, const float a=-1);
406 static float KernelLanczosSinc(const float t, const float r = 3);
407 static float KernelBox(const float x);
408 static float KernelHermite(const float x);
409 static float KernelHamming(const float x);
410 static float KernelSinc(const float x);
411 static float KernelBlackman(const float x);
412 static float KernelBessel_J1(const float x);
413 static float KernelBessel_P1(const float x);
414 static float KernelBessel_Q1(const float x);
415 static float KernelBessel_Order1(float x);
416 static float KernelBessel(const float x);
417 static float KernelGaussian(const float x);
418 static float KernelQuadratic(const float x);
419 static float KernelMitchell(const float x);
420 static float KernelCatrom(const float x);
421 static float KernelHanning(const float x);
422 static float KernelPower(const float x, const float a = 2);
423//@}
424#endif //CXIMAGE_SUPPORT_INTERPOLATION
425
426/** \addtogroup Painting */ //@{
427#if CXIMAGE_SUPPORT_WINDOWS
428 long Blt(HDC pDC, long x=0, long y=0);
429 HBITMAP MakeBitmap(HDC hdc = NULL);
430 HANDLE CopyToHandle();
431 bool CreateFromHANDLE(HANDLE hMem); //Windows objects (clipboard)
432 bool CreateFromHBITMAP(HBITMAP hbmp, HPALETTE hpal=0); //Windows resource
433 bool CreateFromHICON(HICON hico);
434 long Draw(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1, RECT* pClipRect = 0, bool bSmooth = false);
435 long Draw(HDC hdc, const RECT& rect, RECT* pClipRect=NULL, bool bSmooth = false);
436 long Stretch(HDC hdc, long xoffset, long yoffset, long xsize, long ysize, DWORD dwRop = SRCCOPY);
437 long Stretch(HDC hdc, const RECT& rect, DWORD dwRop = SRCCOPY);
438 long Tile(HDC hdc, RECT *rc);
439 long Draw2(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1);
440 long Draw2(HDC hdc, const RECT& rect);
441 //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);
442 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 // <VATI> extensions
444 long DrawStringEx(HDC hdc, long x, long y, CXTEXTINFO *pTextType, bool bSetAlpha=false );
445 void InitTextInfo( CXTEXTINFO *txt );
446#endif //CXIMAGE_SUPPORT_WINDOWS
447//@}
448
449 // file operations
450#if CXIMAGE_SUPPORT_DECODE
451/** \addtogroup Decode */ //@{
452#ifdef WIN32
453 //bool Load(LPCWSTR filename, DWORD imagetype=0);
454 bool LoadResource(HRSRC hRes, DWORD imagetype, HMODULE hModule=NULL);
455#endif
456 // For UNICODE support: char -> TCHAR
457 bool Load(const TCHAR* filename, DWORD imagetype=0);
458 //bool Load(const char * filename, DWORD imagetype=0);
459 bool Decode(FILE * hFile, DWORD imagetype);
460 bool Decode(CxFile * hFile, DWORD imagetype);
461 bool Decode(BYTE * buffer, DWORD size, DWORD imagetype);
462
463 bool CheckFormat(CxFile * hFile, DWORD imagetype = 0);
464 bool CheckFormat(BYTE * buffer, DWORD size, DWORD imagetype = 0);
465//@}
466#endif //CXIMAGE_SUPPORT_DECODE
467
468#if CXIMAGE_SUPPORT_ENCODE
469protected:
470/** \addtogroup Protected */ //@{
471 bool EncodeSafeCheck(CxFile *hFile);
472//@}
473
474public:
475/** \addtogroup Encode */ //@{
476#ifdef WIN32
477 //bool Save(LPCWSTR filename, DWORD imagetype=0);
478#endif
479 // For UNICODE support: char -> TCHAR
480 bool Save(const TCHAR* filename, DWORD imagetype);
481 //bool Save(const char * filename, DWORD imagetype=0);
482 bool Encode(FILE * hFile, DWORD imagetype);
483 bool Encode(CxFile * hFile, DWORD imagetype);
484 bool Encode(CxFile * hFile, CxImage ** pImages, int pagecount, DWORD imagetype);
485 bool Encode(FILE *hFile, CxImage ** pImages, int pagecount, DWORD imagetype);
486 bool Encode(BYTE * &buffer, long &size, DWORD imagetype);
487
488 bool Encode2RGBA(CxFile *hFile, bool bFlipY = false);
489 bool Encode2RGBA(BYTE * &buffer, long &size, bool bFlipY = false);
490//@}
491#endif //CXIMAGE_SUPPORT_ENCODE
492
493/** \addtogroup Attributes */ //@{
494 //misc.
495 bool IsValid() const;
496 bool IsEnabled() const;
497 void Enable(bool enable=true);
498
499 // frame operations
500 long GetNumFrames() const;
501 long GetFrame() const;
502 void SetFrame(long nFrame);
503//@}
504
505#if CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
506/** \addtogroup BasicTransformations */ //@{
507 bool GrayScale();
508 bool Flip(bool bFlipSelection = false, bool bFlipAlpha = true);
509 bool Mirror(bool bMirrorSelection = false, bool bMirrorAlpha = true);
510 bool Negative();
511 bool RotateLeft(CxImage* iDst = NULL);
512 bool RotateRight(CxImage* iDst = NULL);
513//@}
514#endif //CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
515
516#if CXIMAGE_SUPPORT_TRANSFORMATION
517/** \addtogroup Transformations */ //@{
518 // image operations
519 bool Rotate(float angle, CxImage* iDst = NULL);
520 bool Rotate2(float angle, CxImage *iDst = NULL, InterpolationMethod inMethod=IM_BILINEAR,
521 OverflowMethod ofMethod=OM_BACKGROUND, RGBQUAD *replColor=0,
522 bool const optimizeRightAngles=true, bool const bKeepOriginalSize=false);
523 bool Rotate180(CxImage* iDst = NULL);
524 bool Resample(long newx, long newy, int mode = 1, CxImage* iDst = NULL);
525 bool Resample2(long newx, long newy, InterpolationMethod const inMethod=IM_BICUBIC2,
526 OverflowMethod const ofMethod=OM_REPEAT, CxImage* const iDst = NULL,
527 bool const disableAveraging=false);
528 bool DecreaseBpp(DWORD nbit, bool errordiffusion, RGBQUAD* ppal = 0, DWORD clrimportant = 0);
529 bool IncreaseBpp(DWORD nbit);
530 bool Dither(long method = 0);
531 bool Crop(long left, long top, long right, long bottom, CxImage* iDst = NULL);
532 bool Crop(const RECT& rect, CxImage* iDst = NULL);
533 bool CropRotatedRectangle( long topx, long topy, long width, long height, float angle, CxImage* iDst = NULL);
534 bool Skew(float xgain, float ygain, long xpivot=0, long ypivot=0, bool bEnableInterpolation = false);
535 bool Expand(long left, long top, long right, long bottom, RGBQUAD canvascolor, CxImage* iDst = 0);
536 bool Expand(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0);
537 bool Thumbnail(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0);
538 bool CircleTransform(int type,long rmax=0,float Koeff=1.0f);
539 bool RedEyeRemove(float strength = 0.8f);
540 bool QIShrink(long newx, long newy, CxImage* const iDst = NULL, bool bChangeBpp = false);
541
542//@}
543#endif //CXIMAGE_SUPPORT_TRANSFORMATION
544
545#if CXIMAGE_SUPPORT_DSP
546/** \addtogroup DSP */ //@{
547 bool Contour();
548 bool HistogramStretch(long method = 0, double threshold = 0);
549 bool HistogramEqualize();
550 bool HistogramNormalize();
551 bool HistogramRoot();
552 bool HistogramLog();
553 long Histogram(long* red, long* green = 0, long* blue = 0, long* gray = 0, long colorspace = 0);
554 bool Jitter(long radius=2);
555 bool Repair(float radius = 0.25f, long niterations = 1, long colorspace = 0);
556 bool Combine(CxImage* r,CxImage* g,CxImage* b,CxImage* a, long colorspace = 0);
557 bool FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage* dstImag, long direction = 1, bool bForceFFT = true, bool bMagnitude = true);
558 bool Noise(long level);
559 bool Median(long Ksize=3);
560 bool Gamma(float gamma);
561 bool GammaRGB(float gammaR, float gammaG, float gammaB);
562 bool ShiftRGB(long r, long g, long b);
563 bool Threshold(BYTE level);
564 bool Threshold(CxImage* pThresholdMask);
565 bool Threshold2(BYTE level, bool bDirection, RGBQUAD nBkgndColor, bool bSetAlpha = false);
566 bool Colorize(BYTE hue, BYTE sat, float blend = 1.0f);
567 bool Light(long brightness, long contrast = 0);
568 float Mean();
569 bool Filter(long* kernel, long Ksize, long Kfactor, long Koffset);
570 bool Erode(long Ksize=2);
571 bool Dilate(long Ksize=2);
572 bool Edge(long Ksize=2);
573 void HuePalette(float correction=1);
574 enum ImageOpType { OpAdd, OpAnd, OpXor, OpOr, OpMask, OpSrcCopy, OpDstCopy, OpSub, OpSrcBlend, OpScreen, OpAvg };
575 void Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset = 0, long lYOffset = 0, bool bMixAlpha = false);
576 void MixFrom(CxImage & imagesrc2, long lXOffset, long lYOffset);
577 bool UnsharpMask(float radius = 5.0f, float amount = 0.5f, int threshold = 0);
578 bool Lut(BYTE* pLut);
579 bool Lut(BYTE* pLutR, BYTE* pLutG, BYTE* pLutB, BYTE* pLutA = 0);
580 bool GaussianBlur(float radius = 1.0f, CxImage* iDst = 0);
581 bool TextBlur(BYTE threshold = 100, BYTE decay = 2, BYTE max_depth = 5, bool bBlurHorizontal = true, bool bBlurVertical = true, CxImage* iDst = 0);
582 bool SelectiveBlur(float radius = 1.0f, BYTE threshold = 25, CxImage* iDst = 0);
583 bool Solarize(BYTE level = 128, bool bLinkedChannels = true);
584 bool FloodFill(const long xStart, const long yStart, const RGBQUAD cFillColor, const BYTE tolerance = 0,
585 BYTE nOpacity = 255, const bool bSelectFilledArea = false, const BYTE nSelectionLevel = 255);
586 bool Saturate(const long saturation, const long colorspace = 1);
587 bool ConvertColorSpace(const long dstColorSpace, const long srcColorSpace);
588 int OptimalThreshold(long method = 0, RECT * pBox = 0, CxImage* pContrastMask = 0);
589 bool AdaptiveThreshold(long method = 0, long nBoxSize = 64, CxImage* pContrastMask = 0, long nBias = 0, float fGlobalLocalBalance = 0.5f);
590
591//@}
592
593protected:
594/** \addtogroup Protected */ //@{
595 bool IsPowerof2(long x);
596 bool FFT(int dir,int m,double *x,double *y);
597 bool DFT(int dir,long m,double *x1,double *y1,double *x2,double *y2);
598 bool RepairChannel(CxImage *ch, float radius);
599 // <nipper>
600 int gen_convolve_matrix (float radius, float **cmatrix_p);
601 float* gen_lookup_table (float *cmatrix, int cmatrix_length);
602 void blur_line (float *ctable, float *cmatrix, int cmatrix_length, BYTE* cur_col, BYTE* dest_col, int y, long bytes);
603 void blur_text (BYTE threshold, BYTE decay, BYTE max_depth, CxImage* iSrc, CxImage* iDst, BYTE bytes);
604//@}
605
606public:
607/** \addtogroup ColorSpace */ //@{
608 bool SplitRGB(CxImage* r,CxImage* g,CxImage* b);
609 bool SplitYUV(CxImage* y,CxImage* u,CxImage* v);
610 bool SplitHSL(CxImage* h,CxImage* s,CxImage* l);
611 bool SplitYIQ(CxImage* y,CxImage* i,CxImage* q);
612 bool SplitXYZ(CxImage* x,CxImage* y,CxImage* z);
613 bool SplitCMYK(CxImage* c,CxImage* m,CxImage* y,CxImage* k);
614 static RGBQUAD HSLtoRGB(COLORREF cHSLColor);
615 static RGBQUAD RGBtoHSL(RGBQUAD lRGBColor);
616 static RGBQUAD HSLtoRGB(RGBQUAD lHSLColor);
617 static RGBQUAD YUVtoRGB(RGBQUAD lYUVColor);
618 static RGBQUAD RGBtoYUV(RGBQUAD lRGBColor);
619 static RGBQUAD YIQtoRGB(RGBQUAD lYIQColor);
620 static RGBQUAD RGBtoYIQ(RGBQUAD lRGBColor);
621 static RGBQUAD XYZtoRGB(RGBQUAD lXYZColor);
622 static RGBQUAD RGBtoXYZ(RGBQUAD lRGBColor);
623#endif //CXIMAGE_SUPPORT_DSP
624 static RGBQUAD RGBtoRGBQUAD(COLORREF cr);
625 static COLORREF RGBQUADtoRGB (RGBQUAD c);
626//@}
627
628#if CXIMAGE_SUPPORT_SELECTION
629/** \addtogroup Selection */ //@{
630 bool SelectionClear(BYTE level = 0);
631 bool SelectionCreate();
632 bool SelectionDelete();
633 bool SelectionInvert();
634 bool SelectionMirror();
635 bool SelectionFlip();
636 bool SelectionAddRect(RECT r, BYTE level = 255);
637 bool SelectionAddEllipse(RECT r, BYTE level = 255);
638 bool SelectionAddPolygon(POINT *points, long npoints, BYTE level = 255);
639 bool SelectionAddColor(RGBQUAD c, BYTE level = 255);
640 bool SelectionAddPixel(long x, long y, BYTE level = 255);
641 bool SelectionCopy(CxImage &from);
642 bool SelectionIsInside(long x, long y);
643 bool SelectionIsValid();
644 void SelectionGetBox(RECT& r);
645 bool SelectionToHRGN(HRGN& region);
646 bool SelectionSplit(CxImage *dest);
647 BYTE SelectionGet(const long x,const long y);
648 bool SelectionSet(CxImage &from);
649 void SelectionRebuildBox();
650 BYTE* SelectionGetPointer(const long x = 0,const long y = 0);
651//@}
652
653protected:
654/** \addtogroup Protected */ //@{
655 bool BlindSelectionIsInside(long x, long y);
656 BYTE BlindSelectionGet(const long x,const long y);
657 void SelectionSet(const long x,const long y,const BYTE level);
658//@}
659
660public:
661
662#endif //CXIMAGE_SUPPORT_SELECTION
663
664#if CXIMAGE_SUPPORT_ALPHA
665/** \addtogroup Alpha */ //@{
666 void AlphaClear();
667 bool AlphaCreate();
668 void AlphaDelete();
669 void AlphaInvert();
670 bool AlphaMirror();
671 bool AlphaFlip();
672 bool AlphaCopy(CxImage &from);
673 bool AlphaSplit(CxImage *dest);
674 void AlphaStrip();
675 void AlphaSet(BYTE level);
676 bool AlphaSet(CxImage &from);
677 void AlphaSet(const long x,const long y,const BYTE level);
678 BYTE AlphaGet(const long x,const long y);
679 BYTE AlphaGetMax() const;
680 void AlphaSetMax(BYTE nAlphaMax);
681 bool AlphaIsValid();
682 BYTE* AlphaGetPointer(const long x = 0,const long y = 0);
683 bool AlphaFromTransparency();
684
685 void AlphaPaletteClear();
686 void AlphaPaletteEnable(bool enable=true);
687 bool AlphaPaletteIsEnabled();
688 bool AlphaPaletteIsValid();
689 bool AlphaPaletteSplit(CxImage *dest);
690//@}
691
692protected:
693/** \addtogroup Protected */ //@{
694 BYTE BlindAlphaGet(const long x,const long y);
695//@}
696#endif //CXIMAGE_SUPPORT_ALPHA
697
698public:
699#if CXIMAGE_SUPPORT_LAYERS
700/** \addtogroup Layers */ //@{
701 bool LayerCreate(long position = -1);
702 bool LayerDelete(long position = -1);
703 void LayerDeleteAll();
704 CxImage* GetLayer(long position);
705 CxImage* GetParent() const;
706 long GetNumLayers() const;
707 long LayerDrawAll(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1, RECT* pClipRect = 0, bool bSmooth = false);
708 long LayerDrawAll(HDC hdc, const RECT& rect, RECT* pClipRect=NULL, bool bSmooth = false);
709//@}
710#endif //CXIMAGE_SUPPORT_LAYERS
711
712protected:
713/** \addtogroup Protected */ //@{
714 void Startup(DWORD imagetype = 0);
715 void CopyInfo(const CxImage &src);
716 void Ghost(const CxImage *src);
717 void RGBtoBGR(BYTE *buffer, int length);
718 static float HueToRGB(float n1,float n2, float hue);
719 void Bitfield2RGB(BYTE *src, DWORD redmask, DWORD greenmask, DWORD bluemask, BYTE bpp);
720 static int CompareColors(const void *elem1, const void *elem2);
721 short ntohs(const short word);
722 long ntohl(const long dword);
723 void bihtoh(BITMAPINFOHEADER* bih);
724
725 void* pDib; //contains the header, the palette, the pixels
726 BITMAPINFOHEADER head; //standard header
727 CXIMAGEINFO info; //extended information
728 BYTE* pSelection; //selected region
729 BYTE* pAlpha; //alpha channel
730 CxImage** ppLayers; //generic layers
731 CxImage** ppFrames;
732//@}
733};
734
735////////////////////////////////////////////////////////////////////////////
736#endif // !defined(__CXIMAGE_H)
Note: See TracBrowser for help on using the repository browser.