ximage.h
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 21k
Category:

Graph program

Development Platform:

Visual C++

  1. /*
  2.  * File: ximage.h
  3.  * Purpose: General Purpose Image Class 
  4.  */
  5. /* === C R E D I T S  &  D I S C L A I M E R S ==============
  6.  * Permission is given by the author to freely redistribute and include
  7.  * this code in any program as long as this credit is given where due.
  8.  *
  9.  * CxImage (c)  07/Aug/2001 Davide Pizzolato - www.xdp.it
  10.  * CxImage version 5.99a 08/Feb/2004
  11.  * See the file history.htm for the complete bugfix and news report.
  12.  *
  13.  * original CImage and CImageIterator implementation are:
  14.  * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>
  15.  *
  16.  * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
  17.  * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
  18.  * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
  19.  * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
  20.  * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
  21.  * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
  22.  * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
  23.  * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
  24.  * THIS DISCLAIMER.
  25.  *
  26.  * Use at your own risk!
  27.  * ==========================================================
  28.  */
  29. #if !defined(__CXIMAGE_H)
  30. #define __CXIMAGE_H
  31. #if _MSC_VER > 1000
  32. #pragma once
  33. #endif 
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CxImage supported features
  36. #define CXIMAGE_SUPPORT_ALPHA          1
  37. #define CXIMAGE_SUPPORT_SELECTION      1
  38. #define CXIMAGE_SUPPORT_TRANSFORMATION 1
  39. #define CXIMAGE_SUPPORT_DSP            1
  40. #define CXIMAGE_SUPPORT_LAYERS    1
  41. #define CXIMAGE_SUPPORT_DECODE 1
  42. #define CXIMAGE_SUPPORT_ENCODE 1 //<vho><T.Peck>
  43. #define CXIMAGE_SUPPORT_WINDOWS 1
  44. #define CXIMAGE_SUPPORT_WINCE   0 //<T.Peck>
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CxImage supported formats
  47. #define CXIMAGE_SUPPORT_BMP 1
  48. #define CXIMAGE_SUPPORT_GIF 1
  49. #define CXIMAGE_SUPPORT_JPG 1
  50. #define CXIMAGE_SUPPORT_PNG 1
  51. #define CXIMAGE_SUPPORT_MNG 0
  52. #define CXIMAGE_SUPPORT_ICO 1
  53. #define CXIMAGE_SUPPORT_TIF 1
  54. #define CXIMAGE_SUPPORT_TGA 1
  55. #define CXIMAGE_SUPPORT_PCX 1
  56. #define CXIMAGE_SUPPORT_WBMP 1
  57. #define CXIMAGE_SUPPORT_WMF 1
  58. #define CXIMAGE_SUPPORT_J2K 0 // Beta, use JP2
  59. #define CXIMAGE_SUPPORT_JBG 0 // GPL'd see ../jbig/copying.txt & ../jbig/patents.htm
  60. #define CXIMAGE_SUPPORT_JP2 0
  61. #define CXIMAGE_SUPPORT_JPC 0
  62. #define CXIMAGE_SUPPORT_PGX 0
  63. #define CXIMAGE_SUPPORT_PNM 0
  64. #define CXIMAGE_SUPPORT_RAS 0
  65. /////////////////////////////////////////////////////////////////////////////
  66. #include <TCHAR.h> // For UNICODE support
  67. #include "xfile.h"
  68. #include "xiofile.h"
  69. #include "xmemfile.h"
  70. #include "ximadefs.h" //<vho> adjust some #define
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CxImage formats enumerator
  73. enum ENUM_CXIMAGE_FORMATS{
  74. CXIMAGE_FORMAT_UNKNOWN,
  75. #if CXIMAGE_SUPPORT_BMP
  76. CXIMAGE_FORMAT_BMP,
  77. #endif
  78. #if CXIMAGE_SUPPORT_GIF
  79. CXIMAGE_FORMAT_GIF,
  80. #endif
  81. #if CXIMAGE_SUPPORT_JPG
  82. CXIMAGE_FORMAT_JPG,
  83. #endif
  84. #if CXIMAGE_SUPPORT_PNG
  85. CXIMAGE_FORMAT_PNG,
  86. #endif
  87. #if CXIMAGE_SUPPORT_MNG
  88. CXIMAGE_FORMAT_MNG,
  89. #endif
  90. #if CXIMAGE_SUPPORT_ICO
  91. CXIMAGE_FORMAT_ICO,
  92. #endif
  93. #if CXIMAGE_SUPPORT_TIF
  94. CXIMAGE_FORMAT_TIF,
  95. #endif
  96. #if CXIMAGE_SUPPORT_TGA
  97. CXIMAGE_FORMAT_TGA,
  98. #endif
  99. #if CXIMAGE_SUPPORT_PCX
  100. CXIMAGE_FORMAT_PCX,
  101. #endif
  102. #if CXIMAGE_SUPPORT_WBMP
  103. CXIMAGE_FORMAT_WBMP,
  104. #endif
  105. #if CXIMAGE_SUPPORT_WMF
  106. CXIMAGE_FORMAT_WMF,
  107. #endif
  108. #if CXIMAGE_SUPPORT_J2K
  109. CXIMAGE_FORMAT_J2K,
  110. #endif
  111. #if CXIMAGE_SUPPORT_JBG
  112. CXIMAGE_FORMAT_JBG,
  113. #endif
  114. #if CXIMAGE_SUPPORT_JP2
  115. CXIMAGE_FORMAT_JP2,
  116. #endif
  117. #if CXIMAGE_SUPPORT_JPC
  118. CXIMAGE_FORMAT_JPC,
  119. #endif
  120. #if CXIMAGE_SUPPORT_PGX
  121. CXIMAGE_FORMAT_PGX,
  122. #endif
  123. #if CXIMAGE_SUPPORT_PNM
  124. CXIMAGE_FORMAT_PNM,
  125. #endif
  126. #if CXIMAGE_SUPPORT_RAS
  127. CXIMAGE_FORMAT_RAS,
  128. #endif
  129. CMAX_IMAGE_FORMATS
  130. };
  131. //color to grey mapping <H. Muelner> <jurgene>
  132. //#define RGB2GRAY(r,g,b) (((b)*114 + (g)*587 + (r)*299)/1000)
  133. #define RGB2GRAY(r,g,b) (((b)*117 + (g)*601 + (r)*306) >> 10)
  134. struct rgb_color { BYTE r,g,b; };
  135. // <VATI> text placement data
  136. // members must be initialized with the InitTextInfo(&this) function.
  137. typedef struct DLL_EXP tagCxTextInfo
  138. {
  139. char     text[4096];      // text
  140. LOGFONT  lfont;           // font and codepage data
  141.     COLORREF fcolor;          // foreground color
  142.     long     align;           // DT_CENTER, DT_RIGHT, DT_LEFT aligment for multiline text
  143.     BYTE     opaque;          // text has background or hasn't. Default is true.
  144.              // data for background (ignored if .opaque==FALSE) 
  145.     COLORREF bcolor;          // background color
  146.     float    b_opacity;       // opacity value for background between 0.0-1.0 Default is 0. (opaque)
  147.     BYTE     b_outline;       // outline width for background (zero: no outline)
  148.     BYTE     b_round;         // rounding radius for background rectangle. % of the height, between 0-50. Default is 10.
  149.                               // (backgr. always has a frame: width = 3 pixel + 10% of height by default.)
  150. }  CXTEXTINFO;
  151. /////////////////////////////////////////////////////////////////////////////
  152. // CxImage class
  153. /////////////////////////////////////////////////////////////////////////////
  154. class DLL_EXP CxImage
  155. {
  156. //extensible information collector
  157. typedef struct tagCxImageInfo {
  158. DWORD dwEffWidth; //DWORD aligned scan line width
  159. BYTE* pImage; //THE IMAGE BITS
  160. CxImage* pGhost; //if this is a ghost, pGhost points to the body
  161. CxImage* pParent; //if this is a layer, pParent points to the body
  162. DWORD dwType; //original image format
  163. char szLastError[256]; //debugging
  164. long nProgress; //monitor
  165. long nEscape; //escape
  166. long nBkgndIndex; //used for GIF, PNG, MNG
  167. RGBQUAD nBkgndColor; //used for RGB transparency
  168. BYTE nQuality; //used for JPEG
  169. BYTE nScale; //used for JPEG <ignacio>
  170. long nFrame; //used for TIF, GIF, MNG : actual frame
  171. long nNumFrames; //used for TIF, GIF, MNG : total number of frames
  172. DWORD dwFrameDelay; //used for GIF, MNG
  173. long xDPI; //horizontal resolution
  174. long yDPI; //vertical resolution
  175. RECT rSelectionBox; //bounding rectangle
  176. BYTE nAlphaMax; //max opacity (fade)
  177. bool bAlphaPaletteEnabled; //true if alpha values in the palette are enabled.
  178. bool bEnabled; //enables the painting functions
  179. long xOffset;
  180. long yOffset;
  181. DWORD dwCodecOption; //for GIF, TIF : 0=def.1=unc,2=fax3,3=fax4,4=pack,5=jpg
  182. RGBQUAD last_c; //for GetNearestIndex optimization
  183. BYTE last_c_index;
  184. bool last_c_isvalid;
  185. long nNumLayers;
  186. DWORD dwFlags; // 0x??00000 = reserved, 0x00??0000 = blend mode, 0x0000???? = layer id - user flags
  187. } CXIMAGEINFO;
  188. public:
  189. //constructors
  190. CxImage(DWORD imagetype = 0);
  191. CxImage(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0);
  192. CxImage(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);
  193. CxImage(const TCHAR * filename, DWORD imagetype); // For UNICODE support: char -> TCHAR
  194. // CxImage(const char * filename, DWORD imagetype);
  195. CxImage(FILE * stream, DWORD imagetype);
  196. CxImage(CxFile * stream, DWORD imagetype);
  197. CxImage(BYTE * buffer, DWORD size, DWORD imagetype);
  198. virtual ~CxImage() { Destroy(); if (m_hMeta) ::DeleteEnhMetaFile(m_hMeta);};
  199. CxImage& operator = (const CxImage&);
  200. //initializzation
  201. void* Create(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0);
  202. bool Destroy();
  203. void Clear(BYTE bval=0);
  204. void Copy(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);
  205. bool Transfer(CxImage &from);
  206. bool CreateFromArray(BYTE* pArray,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage);
  207. bool CreateFromMatrix(BYTE** ppMatrix,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage);
  208. //Attributes
  209. long GetSize();
  210. BYTE* GetBits(DWORD row = 0);
  211. BYTE GetColorType();
  212. void* GetDIB() const {return pDib;}
  213. DWORD GetHeight() const {return head.biHeight;}
  214. DWORD GetWidth() const {return head.biWidth;}
  215. DWORD GetEffWidth() const {return info.dwEffWidth;}
  216. DWORD GetNumColors() const {return head.biClrUsed;}
  217. WORD GetBpp() const {return head.biBitCount;}
  218. DWORD GetType() const {return info.dwType;}
  219. char* GetLastError() {return info.szLastError;}
  220. const TCHAR* GetVersion();
  221. DWORD GetFrameDelay() const {return info.dwFrameDelay;}
  222. void SetFrameDelay(DWORD d) {info.dwFrameDelay=d;}
  223. void GetOffset(long *x,long *y) {*x=info.xOffset; *y=info.yOffset;}
  224. void SetOffset(long x,long y) {info.xOffset=x; info.yOffset=y;}
  225. BYTE GetJpegQuality() const {return info.nQuality;}
  226. void SetJpegQuality(BYTE q) {info.nQuality = q;}
  227. //<ignacio> used for scaling down during JPEG decoding valid numbers are 1, 2, 4, 8
  228. BYTE GetJpegScale() const {return info.nScale;}
  229. void SetJpegScale(BYTE q) {info.nScale = q;}
  230. long GetXDPI() const {return info.xDPI;}
  231. long GetYDPI() const {return info.yDPI;}
  232. void SetXDPI(long dpi);
  233. void SetYDPI(long dpi);
  234. DWORD GetClrImportant() const {return head.biClrImportant;}
  235. void SetClrImportant(DWORD ncolors = 0);
  236. long GetProgress() const {return info.nProgress;}
  237. long GetEscape()     const {return info.nEscape;}
  238. void SetProgress(long p) {info.nProgress = p;}
  239. void SetEscape(long i)   {info.nEscape = i;}
  240. long GetTransIndex() const {return info.nBkgndIndex;}
  241. RGBQUAD GetTransColor();
  242. void SetTransIndex(long idx) {info.nBkgndIndex = idx;}
  243. void SetTransColor(RGBQUAD rgb) {rgb.rgbReserved=0; info.nBkgndColor = rgb;}
  244. bool IsTransparent() const {return info.nBkgndIndex>=0;} // <vho>
  245. DWORD GetCodecOption() const {return info.dwCodecOption;}
  246. void SetCodecOption(DWORD opt) {info.dwCodecOption = opt;}
  247. DWORD GetFlags() const {return info.dwFlags;}
  248. void SetFlags(DWORD flags, bool bLockReservedFlags = true);
  249. //void* GetUserData() const {return info.pUserData;}
  250. //void SetUserData(void* pUserData) {info.pUserData = pUserData;}
  251. //palette operations
  252. bool IsGrayScale();
  253. bool IsIndexed() {return head.biClrUsed!=0;}
  254. DWORD GetPaletteSize();
  255. RGBQUAD* GetPalette() const;
  256. RGBQUAD GetPaletteColor(BYTE idx);
  257. bool GetPaletteColor(BYTE i, BYTE* r, BYTE* g, BYTE* b);
  258. BYTE GetNearestIndex(RGBQUAD c);
  259. void BlendPalette(COLORREF cr,long perc);
  260. void SetGrayPalette();
  261. void SetPalette(DWORD n, BYTE *r, BYTE *g, BYTE *b);
  262. void SetPalette(RGBQUAD* pPal,DWORD nColors=256);
  263. void SetPalette(rgb_color *rgb,DWORD nColors=256);
  264. void SetPaletteColor(BYTE idx, BYTE r, BYTE g, BYTE b, BYTE alpha=0);
  265. void SetPaletteColor(BYTE idx, RGBQUAD c);
  266. void SetPaletteColor(BYTE idx, COLORREF cr);
  267. void SwapIndex(BYTE idx1, BYTE idx2);
  268. void SetStdPalette();
  269. //pixel operations
  270. bool IsInside(long x, long y);
  271. bool IsTransparent(long x,long y);
  272. RGBQUAD GetPixelColor(long x,long y, bool bGetAlpha = true);
  273. BYTE GetPixelIndex(long x,long y);
  274. BYTE GetPixelGray(long x, long y);
  275. void SetPixelColor(long x,long y,RGBQUAD c, bool bSetAlpha = false);
  276. void SetPixelColor(long x,long y,COLORREF cr);
  277. void SetPixelIndex(long x,long y,BYTE i);
  278. void DrawLine(int StartX, int EndX, int StartY, int EndY, RGBQUAD color, bool bSetAlpha=false);
  279. void DrawLine(int StartX, int EndX, int StartY, int EndY, COLORREF cr);
  280. //painting operations
  281. #if CXIMAGE_SUPPORT_WINCE
  282. long Blt(HDC pDC, long x=0, long y=0);
  283. #endif
  284. #if CXIMAGE_SUPPORT_WINDOWS
  285. HBITMAP MakeBitmap(HDC hdc = NULL);
  286. HANDLE CopyToHandle();
  287. bool CreateFromHANDLE(HANDLE hMem); //Windows objects (clipboard)
  288. bool CreateFromHBITMAP(HBITMAP hbmp, HPALETTE hpal=0); //Windows resource
  289. bool CreateFromHICON(HICON hico);
  290. long Draw(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1, RECT* pClipRect = 0);
  291. 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); }
  292. long Stretch(HDC hdc, long xoffset, long yoffset, long xsize, long ysize, DWORD dwRop = SRCCOPY);
  293. 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); }
  294. long Tile(HDC hdc, RECT *rc);
  295. long Draw2(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1);
  296. long Draw2(HDC hdc, const RECT& rect) { return Draw2(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); }
  297. //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);
  298. 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);
  299. // <VATI> extensions
  300. long    DrawStringEx(HDC hdc, long x, long y, CXTEXTINFO *pTextType, bool bSetAlpha=false );
  301. void    InitTextInfo( CXTEXTINFO *txt );
  302. #endif //CXIMAGE_SUPPORT_WINDOWS
  303. // file operations
  304. #if CXIMAGE_SUPPORT_DECODE
  305. #ifdef WIN32
  306. //bool Load(LPCWSTR filename, DWORD imagetype=0);
  307. bool LoadResource(HRSRC hRes, DWORD imagetype, HMODULE hModule=NULL);
  308. #endif
  309. // For UNICODE support: char -> TCHAR
  310. bool Load(const TCHAR* filename, DWORD imagetype=0);
  311. //bool Load(const char * filename, DWORD imagetype=0);
  312. bool Decode(FILE * hFile, DWORD imagetype);
  313. bool Decode(CxFile * hFile, DWORD imagetype);
  314. bool Decode(BYTE * buffer, DWORD size, DWORD imagetype);
  315. #endif //CXIMAGE_SUPPORT_DECODE
  316. #if CXIMAGE_SUPPORT_ENCODE
  317. protected:
  318. bool EncodeSafeCheck(CxFile *hFile);
  319. public:
  320. #ifdef WIN32
  321. //bool Save(LPCWSTR filename, DWORD imagetype=0);
  322. #endif
  323. // For UNICODE support: char -> TCHAR
  324. bool Save(const TCHAR* filename, DWORD imagetype=0);
  325. //bool Save(const char * filename, DWORD imagetype=0);
  326. bool Encode(FILE * hFile, DWORD imagetype);
  327. bool Encode(CxFile * hFile, DWORD imagetype);
  328. bool Encode(CxFile * hFile, CxImage ** pImages, int pagecount, DWORD imagetype);
  329. bool Encode(FILE *hFile, CxImage ** pImages, int pagecount, DWORD imagetype);
  330. bool Encode(BYTE * &buffer, long &size, DWORD imagetype);
  331. #endif //CXIMAGE_SUPPORT_ENCODE
  332. //misc.
  333. bool IsValid() const {return pDib!=0;}
  334. bool IsEnabled() const {return info.bEnabled;}
  335. void Enable(bool enable=true){info.bEnabled=enable;}
  336. // frame operations
  337. long GetNumFrames() const {return info.nNumFrames;}
  338. long GetFrame() const {return info.nFrame;}
  339. void SetFrame(long nFrame) {info.nFrame=nFrame;}
  340. #if CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
  341. bool GrayScale();
  342. bool Flip();
  343. bool Mirror();
  344. bool Negative();
  345. bool RotateLeft(CxImage* iDst = NULL);
  346. bool RotateRight(CxImage* iDst = NULL);
  347. #endif //CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
  348. #if CXIMAGE_SUPPORT_TRANSFORMATION
  349. // image operations
  350. bool Rotate(float angle, CxImage* iDst = NULL);
  351. bool Rotate180(CxImage* iDst = NULL);
  352. bool Resample(long newx, long newy, int mode = 1, CxImage* iDst = NULL);
  353. bool DecreaseBpp(DWORD nbit, bool errordiffusion, RGBQUAD* ppal = 0, DWORD clrimportant = 0);
  354. bool IncreaseBpp(DWORD nbit);
  355. bool Dither(long method = 0);
  356. bool Crop(long left, long top, long right, long bottom, CxImage* iDst = NULL);
  357. bool Crop(const RECT& rect, CxImage* iDst = NULL) { return Crop(rect.left, rect.top, rect.right, rect.bottom, iDst); }
  358. bool CropRotatedRectangle( long topx, long topy, long width, long height, float angle, CxImage* iDst = NULL);
  359. bool Skew(float xgain, float ygain, long xpivot=0, long ypivot=0);
  360. bool Expand(long left, long top, long right, long bottom, RGBQUAD canvascolor, CxImage* iDst = 0);
  361. bool Expand(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0);
  362. bool Thumbnail(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0);
  363. bool CircleTransform(int type,long rmax=0,float Koeff=1.0f);
  364. protected:
  365. float b3spline(float x);
  366. public:
  367. #endif //CXIMAGE_SUPPORT_TRANSFORMATION
  368. #if CXIMAGE_SUPPORT_DSP
  369. bool Contour();
  370. bool HistogramStretch(long method = 0);
  371. bool HistogramEqualize();
  372. bool HistogramNormalize();
  373. bool HistogramRoot();
  374. bool HistogramLog();
  375. long Histogram(long* red, long* green = 0, long* blue = 0, long* gray = 0, long colorspace = 0);
  376. bool Jitter(long radius=2);
  377. bool Repair(float radius = 0.25f, long niterations = 1, long colorspace = 0);
  378. bool Combine(CxImage* r,CxImage* g,CxImage* b,CxImage* a, long colorspace = 0);
  379. bool FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage* dstImag, long direction = 1, bool bForceFFT = true, bool bMagnitude = true);
  380. bool Noise(long level);
  381. bool Median(long Ksize=3);
  382. bool Gamma(float gamma);
  383. bool ShiftRGB(long r, long g, long b);
  384. bool Threshold(BYTE level);
  385. bool Colorize(BYTE hue, BYTE sat);
  386. bool Light(long brightness, long contrast = 0);
  387. float Mean();
  388. bool Filter(long* kernel, long Ksize, long Kfactor, long Koffset);
  389. bool Erode(long Ksize=2);
  390. bool Dilate(long Ksize=2);
  391. void HuePalette(float correction=1);
  392. enum ImageOpType { OpAdd, OpAnd, OpXor, OpOr, OpMask, OpSrcCopy, OpDstCopy, OpSub, OpSrcBlend };
  393. void Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset = 0, long lYOffset = 0);
  394. void MixFrom(CxImage & imagesrc2, long lXOffset, long lYOffset);
  395. bool UnsharpMask(float radius = 5.0, float amount = 0.5, int threshold = 0);
  396. bool Lut(BYTE* pLut);
  397. bool Lut(BYTE* pLutR, BYTE* pLutG, BYTE* pLutB, BYTE* pLutA = 0);
  398. protected:
  399. bool IsPowerof2(long x);
  400. bool FFT(int dir,int m,double *x,double *y);
  401. bool DFT(int dir,long m,double *x1,double *y1,double *x2,double *y2);
  402. bool RepairChannel(CxImage *ch, float radius);
  403. // <nipper>
  404. int gen_convolve_matrix (float radius, float **cmatrix_p);
  405. float* gen_lookup_table (float *cmatrix, int cmatrix_length);
  406. void blur_line (float *ctable, float *cmatrix, int cmatrix_length, BYTE* cur_col, BYTE* dest_col, int y, long bytes);
  407. public:
  408. //color conversion utilities
  409. bool SplitRGB(CxImage* r,CxImage* g,CxImage* b);
  410. bool SplitYUV(CxImage* y,CxImage* u,CxImage* v);
  411. bool SplitHSL(CxImage* h,CxImage* s,CxImage* l);
  412. bool SplitYIQ(CxImage* y,CxImage* i,CxImage* q);
  413. bool SplitXYZ(CxImage* x,CxImage* y,CxImage* z);
  414. bool SplitCMYK(CxImage* c,CxImage* m,CxImage* y,CxImage* k);
  415. RGBQUAD HSLtoRGB(COLORREF cHSLColor);
  416. RGBQUAD RGBtoHSL(RGBQUAD lRGBColor);
  417. RGBQUAD HSLtoRGB(RGBQUAD lHSLColor);
  418. RGBQUAD YUVtoRGB(RGBQUAD lYUVColor);
  419. RGBQUAD RGBtoYUV(RGBQUAD lRGBColor);
  420. RGBQUAD YIQtoRGB(RGBQUAD lYIQColor);
  421. RGBQUAD RGBtoYIQ(RGBQUAD lRGBColor);
  422. RGBQUAD XYZtoRGB(RGBQUAD lXYZColor);
  423. RGBQUAD RGBtoXYZ(RGBQUAD lRGBColor);
  424. #endif //CXIMAGE_SUPPORT_DSP
  425. RGBQUAD RGBtoRGBQUAD(COLORREF cr);
  426. COLORREF RGBQUADtoRGB (RGBQUAD c);
  427. #if CXIMAGE_SUPPORT_SELECTION
  428. //selection
  429. bool SelectionClear();
  430. bool SelectionCreate();
  431. bool SelectionDelete();
  432. bool SelectionInvert();
  433. bool SelectionAddRect(RECT r);
  434. bool SelectionAddEllipse(RECT r);
  435. bool SelectionAddPolygon(POINT *points, long npoints);
  436. bool SelectionAddColor(RGBQUAD c);
  437. bool SelectionAddPixel(int x, int y);
  438. bool SelectionCopy(CxImage &from);
  439. bool SelectionIsInside(long x, long y);
  440. bool SelectionIsValid(){return pSelection!=0;}
  441. void SelectionGetBox(RECT& r){memcpy(&r,&info.rSelectionBox,sizeof(RECT));}
  442. bool SelectionToHRGN(HRGN& region);
  443. #endif //CXIMAGE_SUPPORT_SELECTION
  444. #if CXIMAGE_SUPPORT_ALPHA
  445. //Alpha
  446. void AlphaClear();
  447. void AlphaCreate();
  448. void AlphaDelete();
  449. void AlphaInvert();
  450. bool AlphaMirror();
  451. bool AlphaFlip();
  452. bool AlphaCopy(CxImage &from);
  453. bool AlphaSplit(CxImage *dest);
  454. void AlphaStrip();
  455. void AlphaSet(BYTE level);
  456. bool AlphaSet(CxImage &from);
  457. void AlphaSet(long x,long y,BYTE level);
  458. BYTE AlphaGet(long x,long y);
  459. BYTE AlphaGetMax() const {return info.nAlphaMax;}
  460. void AlphaSetMax(BYTE nAlphaMax) {info.nAlphaMax=nAlphaMax;}
  461. bool AlphaIsValid(){return pAlpha!=0;}
  462. BYTE* AlphaGetBits() const {return pAlpha;}
  463. void AlphaPaletteClear();
  464. void AlphaPaletteEnable(bool enable=true){info.bAlphaPaletteEnabled=enable;}
  465. bool AlphaPaletteIsEnabled(){return info.bAlphaPaletteEnabled;}
  466. bool AlphaPaletteIsValid();
  467. bool AlphaPaletteSplit(CxImage *dest);
  468. #endif //CXIMAGE_SUPPORT_ALPHA
  469. #if CXIMAGE_SUPPORT_LAYERS
  470. bool LayerCreate(long position = -1);
  471. bool LayerDelete(long position = -1);
  472. void LayerDeleteAll();
  473. CxImage* GetLayer(long position);
  474. CxImage* GetParent() const {return info.pParent;}
  475. long GetNumLayers() const {return info.nNumLayers;}
  476. #endif //CXIMAGE_SUPPORT_LAYERS
  477. protected:
  478. void Startup(DWORD imagetype = 0);
  479. void CopyInfo(const CxImage &src);
  480. void Ghost(CxImage *src);
  481. void RGBtoBGR(BYTE *buffer, int length);
  482. float HueToRGB(float n1,float n2, float hue);
  483. void Bitfield2RGB(BYTE *src, WORD redmask, WORD greenmask, WORD bluemask, BYTE bpp);
  484. static int CompareColors(const void *elem1, const void *elem2);
  485. void* pDib; //contains the header, the palette, the pixels
  486.     BITMAPINFOHEADER    head; //standard header
  487. CXIMAGEINFO info; //extended information
  488. BYTE* pSelection; //selected region
  489. BYTE* pAlpha; //alpha channel
  490. CxImage** pLayers; //generic layers
  491. ///RA
  492. public:
  493. HENHMETAFILE m_hMeta;
  494. METAHEADER      m_wmfHeader;
  495. METAFILEPICT    m_wmfPict;
  496. };
  497. ////////////////////////////////////////////////////////////////////////////
  498. #define CXIMAGE_MAX_MEMORY 256000000
  499. #define CXIMAGE_ERR_NOFILE "null file handler"
  500. #define CXIMAGE_ERR_NOIMAGE "null image!!!"
  501. ////////////////////////////////////////////////////////////////////////////
  502. #endif // !defined(__CXIMAGE_H)