PageRenderTime 65ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/CamStudio/CxImage/CxImage/ximage.h

https://github.com/rdp/camstudio-clone
C Header | 807 lines | 607 code | 70 blank | 130 comment | 0 complexity | fa58473bfe6cba690238e0846b0ea33f MD5 | raw file
  1. /*
  2. * File: ximage.h
  3. * Purpose: General Purpose Image Class
  4. */
  5. /*
  6. --------------------------------------------------------------------------------
  7. COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
  8. CxImage version 7.0.1 07/Jan/2011
  9. CxImage : Copyright (C) 2001 - 2010, Davide Pizzolato
  10. Original CImage and CImageIterator implementation are:
  11. Copyright (C) 1995, Alejandro Aguilar Sierra (asierra(at)servidor(dot)unam(dot)mx)
  12. Covered code is provided under this license on an "as is" basis, without warranty
  13. of any kind, either expressed or implied, including, without limitation, warranties
  14. that the covered code is free of defects, merchantable, fit for a particular purpose
  15. or non-infringing. The entire risk as to the quality and performance of the covered
  16. code is with you. Should any covered code prove defective in any respect, you (not
  17. the initial developer or any other contributor) assume the cost of any necessary
  18. servicing, repair or correction. This disclaimer of warranty constitutes an essential
  19. part of this license. No use of any covered code is authorized hereunder except under
  20. this disclaimer.
  21. Permission is hereby granted to use, copy, modify, and distribute this
  22. source code, or portions hereof, for any purpose, including commercial applications,
  23. freely and without fee, subject to the following restrictions:
  24. 1. The origin of this software must not be misrepresented; you must not
  25. claim that you wrote the original software. If you use this software
  26. in a product, an acknowledgment in the product documentation would be
  27. appreciated but is not required.
  28. 2. Altered source versions must be plainly marked as such, and must not be
  29. misrepresented as being the original software.
  30. 3. This notice may not be removed or altered from any source distribution.
  31. --------------------------------------------------------------------------------
  32. Other information about CxImage, and the latest version, can be found at the
  33. CxImage home page: http://www.xdp.it/cximage/
  34. --------------------------------------------------------------------------------
  35. */
  36. #if !defined(__CXIMAGE_H)
  37. #define __CXIMAGE_H
  38. #if _MSC_VER > 1000
  39. #pragma once
  40. #endif
  41. #ifdef _LINUX
  42. #define _XOPEN_SOURCE
  43. #include <unistd.h>
  44. #include <arpa/inet.h>
  45. #endif
  46. /////////////////////////////////////////////////////////////////////////////
  47. #include "xfile.h"
  48. #include "xiofile.h"
  49. #include "xmemfile.h"
  50. #include "ximadef.h" //<vho> adjust some #define
  51. /* see "ximacfg.h" for CxImage configuration options */
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CxImage formats enumerator
  54. enum ENUM_CXIMAGE_FORMATS{
  55. CXIMAGE_FORMAT_UNKNOWN = 0,
  56. #if CXIMAGE_SUPPORT_BMP
  57. CXIMAGE_FORMAT_BMP = 1,
  58. #endif
  59. #if CXIMAGE_SUPPORT_GIF
  60. CXIMAGE_FORMAT_GIF = 2,
  61. #endif
  62. #if CXIMAGE_SUPPORT_JPG
  63. CXIMAGE_FORMAT_JPG = 3,
  64. #endif
  65. #if CXIMAGE_SUPPORT_PNG
  66. CXIMAGE_FORMAT_PNG = 4,
  67. #endif
  68. #if CXIMAGE_SUPPORT_ICO
  69. CXIMAGE_FORMAT_ICO = 5,
  70. #endif
  71. #if CXIMAGE_SUPPORT_TIF
  72. CXIMAGE_FORMAT_TIF = 6,
  73. #endif
  74. #if CXIMAGE_SUPPORT_TGA
  75. CXIMAGE_FORMAT_TGA = 7,
  76. #endif
  77. #if CXIMAGE_SUPPORT_PCX
  78. CXIMAGE_FORMAT_PCX = 8,
  79. #endif
  80. #if CXIMAGE_SUPPORT_WBMP
  81. CXIMAGE_FORMAT_WBMP = 9,
  82. #endif
  83. #if CXIMAGE_SUPPORT_WMF
  84. CXIMAGE_FORMAT_WMF = 10,
  85. #endif
  86. #if CXIMAGE_SUPPORT_JP2
  87. CXIMAGE_FORMAT_JP2 = 11,
  88. #endif
  89. #if CXIMAGE_SUPPORT_JPC
  90. CXIMAGE_FORMAT_JPC = 12,
  91. #endif
  92. #if CXIMAGE_SUPPORT_PGX
  93. CXIMAGE_FORMAT_PGX = 13,
  94. #endif
  95. #if CXIMAGE_SUPPORT_PNM
  96. CXIMAGE_FORMAT_PNM = 14,
  97. #endif
  98. #if CXIMAGE_SUPPORT_RAS
  99. CXIMAGE_FORMAT_RAS = 15,
  100. #endif
  101. #if CXIMAGE_SUPPORT_JBG
  102. CXIMAGE_FORMAT_JBG = 16,
  103. #endif
  104. #if CXIMAGE_SUPPORT_MNG
  105. CXIMAGE_FORMAT_MNG = 17,
  106. #endif
  107. #if CXIMAGE_SUPPORT_SKA
  108. CXIMAGE_FORMAT_SKA = 18,
  109. #endif
  110. #if CXIMAGE_SUPPORT_RAW
  111. CXIMAGE_FORMAT_RAW = 19,
  112. #endif
  113. #if CXIMAGE_SUPPORT_PSD
  114. CXIMAGE_FORMAT_PSD = 20,
  115. #endif
  116. CMAX_IMAGE_FORMATS = CXIMAGE_SUPPORT_BMP + CXIMAGE_SUPPORT_GIF + CXIMAGE_SUPPORT_JPG +
  117. CXIMAGE_SUPPORT_PNG + CXIMAGE_SUPPORT_MNG + CXIMAGE_SUPPORT_ICO +
  118. CXIMAGE_SUPPORT_TIF + CXIMAGE_SUPPORT_TGA + CXIMAGE_SUPPORT_PCX +
  119. CXIMAGE_SUPPORT_WBMP+ CXIMAGE_SUPPORT_WMF +
  120. CXIMAGE_SUPPORT_JBG + CXIMAGE_SUPPORT_JP2 + CXIMAGE_SUPPORT_JPC +
  121. CXIMAGE_SUPPORT_PGX + CXIMAGE_SUPPORT_PNM + CXIMAGE_SUPPORT_RAS +
  122. CXIMAGE_SUPPORT_SKA + CXIMAGE_SUPPORT_RAW + CXIMAGE_SUPPORT_PSD + 1
  123. };
  124. #if CXIMAGE_SUPPORT_EXIF
  125. #define MAX_COMMENT 255
  126. #define MAX_SECTIONS 20
  127. typedef struct tag_ExifInfo {
  128. char Version [5];
  129. char CameraMake [32];
  130. char CameraModel [40];
  131. char DateTime [20];
  132. int32_t Height, Width;
  133. int32_t Orientation;
  134. int32_t IsColor;
  135. int32_t Process;
  136. int32_t FlashUsed;
  137. float FocalLength;
  138. float ExposureTime;
  139. float ApertureFNumber;
  140. float Distance;
  141. float CCDWidth;
  142. float ExposureBias;
  143. int32_t Whitebalance;
  144. int32_t MeteringMode;
  145. int32_t ExposureProgram;
  146. int32_t ISOequivalent;
  147. int32_t CompressionLevel;
  148. float FocalplaneXRes;
  149. float FocalplaneYRes;
  150. float FocalplaneUnits;
  151. float Xresolution;
  152. float Yresolution;
  153. float ResolutionUnit;
  154. float Brightness;
  155. char Comments[MAX_COMMENT+1];
  156. uint8_t * ThumbnailPointer; /* Pointer at the thumbnail */
  157. unsigned ThumbnailSize; /* Size of thumbnail. */
  158. bool IsExif;
  159. } EXIFINFO;
  160. #endif //CXIMAGE_SUPPORT_EXIF
  161. /////////////////////////////////////////////////////////////////////////////
  162. // CxImage class
  163. /////////////////////////////////////////////////////////////////////////////
  164. class DLL_EXP CxImage
  165. {
  166. //extensible information collector
  167. typedef struct tagCxImageInfo {
  168. uint32_t dwEffWidth; ///< uint32_t aligned scan line width
  169. uint8_t* pImage; ///< THE IMAGE BITS
  170. CxImage* pGhost; ///< if this is a ghost, pGhost points to the body
  171. CxImage* pParent; ///< if this is a layer, pParent points to the body
  172. uint32_t dwType; ///< original image format
  173. char szLastError[256]; ///< debugging
  174. int32_t nProgress; ///< monitor
  175. int32_t nEscape; ///< escape
  176. int32_t nBkgndIndex; ///< used for GIF, PNG, MNG
  177. RGBQUAD nBkgndColor; ///< used for RGB transparency
  178. float fQuality; ///< used for JPEG, JPEG2000 (0.0f ... 100.0f)
  179. uint8_t nJpegScale; ///< used for JPEG [ignacio]
  180. int32_t nFrame; ///< used for TIF, GIF, MNG : actual frame
  181. int32_t nNumFrames; ///< used for TIF, GIF, MNG : total number of frames
  182. uint32_t dwFrameDelay; ///< used for GIF, MNG
  183. int32_t xDPI; ///< horizontal resolution
  184. int32_t yDPI; ///< vertical resolution
  185. RECT rSelectionBox; ///< bounding rectangle
  186. uint8_t nAlphaMax; ///< max opacity (fade)
  187. bool bAlphaPaletteEnabled; ///< true if alpha values in the palette are enabled.
  188. bool bEnabled; ///< enables the painting functions
  189. int32_t xOffset;
  190. int32_t yOffset;
  191. uint32_t dwCodecOpt[CMAX_IMAGE_FORMATS]; ///< for GIF, TIF : 0=def.1=unc,2=fax3,3=fax4,4=pack,5=jpg
  192. RGBQUAD last_c; ///< for GetNearestIndex optimization
  193. uint8_t last_c_index;
  194. bool last_c_isvalid;
  195. int32_t nNumLayers;
  196. uint32_t dwFlags; ///< 0x??00000 = reserved, 0x00??0000 = blend mode, 0x0000???? = layer id - user flags
  197. uint8_t dispmeth;
  198. bool bGetAllFrames;
  199. bool bLittleEndianHost;
  200. #if CXIMAGE_SUPPORT_EXIF
  201. EXIFINFO ExifInfo;
  202. #endif
  203. } CXIMAGEINFO;
  204. public:
  205. //public structures
  206. struct rgb_color { uint8_t r,g,b; };
  207. #if CXIMAGE_SUPPORT_WINDOWS
  208. // <VATI> text placement data
  209. // members must be initialized with the InitTextInfo(&this) function.
  210. typedef struct tagCxTextInfo
  211. {
  212. #if defined (_WIN32_WCE)
  213. TCHAR text[256]; ///< text for windows CE
  214. #else
  215. TCHAR text[4096]; ///< text (char -> TCHAR for UNICODE [Cesar M])
  216. #endif
  217. LOGFONT lfont; ///< font and codepage data
  218. COLORREF fcolor; ///< foreground color
  219. int32_t align; ///< DT_CENTER, DT_RIGHT, DT_LEFT aligment for multiline text
  220. uint8_t smooth; ///< text smoothing option. Default is false.
  221. uint8_t opaque; ///< text has background or hasn't. Default is true.
  222. ///< data for background (ignored if .opaque==FALSE)
  223. COLORREF bcolor; ///< background color
  224. float b_opacity; ///< opacity value for background between 0.0-1.0 Default is 0. (opaque)
  225. uint8_t b_outline; ///< outline width for background (zero: no outline)
  226. uint8_t b_round; ///< rounding radius for background rectangle. % of the height, between 0-50. Default is 10.
  227. ///< (backgr. always has a frame: width = 3 pixel + 10% of height by default.)
  228. } CXTEXTINFO;
  229. #endif
  230. public:
  231. /** \addtogroup Constructors */ //@{
  232. CxImage(uint32_t imagetype = 0);
  233. CxImage(uint32_t dwWidth, uint32_t dwHeight, uint32_t wBpp, uint32_t imagetype = 0);
  234. CxImage(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);
  235. #if CXIMAGE_SUPPORT_DECODE
  236. CxImage(const TCHAR * filename, uint32_t imagetype); // For UNICODE support: char -> TCHAR
  237. CxImage(FILE * stream, uint32_t imagetype);
  238. CxImage(CxFile * stream, uint32_t imagetype);
  239. CxImage(uint8_t * buffer, uint32_t size, uint32_t imagetype);
  240. #endif
  241. virtual ~CxImage() { DestroyFrames(); Destroy(); };
  242. CxImage& operator = (const CxImage&);
  243. //@}
  244. /** \addtogroup Initialization */ //@{
  245. void* Create(uint32_t dwWidth, uint32_t dwHeight, uint32_t wBpp, uint32_t imagetype = 0);
  246. bool Destroy();
  247. bool DestroyFrames();
  248. void Clear(uint8_t bval=0);
  249. void Copy(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);
  250. bool Transfer(CxImage &from, bool bTransferFrames = true);
  251. bool CreateFromArray(uint8_t* pArray,uint32_t dwWidth,uint32_t dwHeight,uint32_t dwBitsperpixel, uint32_t dwBytesperline, bool bFlipImage);
  252. bool CreateFromMatrix(uint8_t** ppMatrix,uint32_t dwWidth,uint32_t dwHeight,uint32_t dwBitsperpixel, uint32_t dwBytesperline, bool bFlipImage);
  253. void FreeMemory(void* memblock);
  254. uint32_t Dump(uint8_t * dst);
  255. uint32_t UnDump(const uint8_t * src);
  256. uint32_t DumpSize();
  257. //@}
  258. /** \addtogroup Attributes */ //@{
  259. int32_t GetSize();
  260. uint8_t* GetBits(uint32_t row = 0);
  261. uint8_t GetColorType();
  262. void* GetDIB() const;
  263. uint32_t GetHeight() const;
  264. uint32_t GetWidth() const;
  265. uint32_t GetEffWidth() const;
  266. uint32_t GetNumColors() const;
  267. uint16_t GetBpp() const;
  268. uint32_t GetType() const;
  269. const char* GetLastError();
  270. static const TCHAR* GetVersion();
  271. static const float GetVersionNumber();
  272. uint32_t GetFrameDelay() const;
  273. void SetFrameDelay(uint32_t d);
  274. void GetOffset(int32_t *x,int32_t *y);
  275. void SetOffset(int32_t x,int32_t y);
  276. uint8_t GetJpegQuality() const;
  277. void SetJpegQuality(uint8_t q);
  278. float GetJpegQualityF() const;
  279. void SetJpegQualityF(float q);
  280. uint8_t GetJpegScale() const;
  281. void SetJpegScale(uint8_t q);
  282. #if CXIMAGE_SUPPORT_EXIF
  283. EXIFINFO *GetExifInfo() {return &info.ExifInfo;};
  284. bool GetExifThumbnail(const TCHAR *filename, const TCHAR *outname, int32_t imageType);
  285. #if CXIMAGE_SUPPORT_TRANSFORMATION
  286. bool RotateExif(int32_t orientation = 0);
  287. #endif
  288. #endif
  289. int32_t GetXDPI() const;
  290. int32_t GetYDPI() const;
  291. void SetXDPI(int32_t dpi);
  292. void SetYDPI(int32_t dpi);
  293. uint32_t GetClrImportant() const;
  294. void SetClrImportant(uint32_t ncolors = 0);
  295. int32_t GetProgress() const;
  296. int32_t GetEscape() const;
  297. void SetProgress(int32_t p);
  298. void SetEscape(int32_t i);
  299. int32_t GetTransIndex() const;
  300. RGBQUAD GetTransColor();
  301. void SetTransIndex(int32_t idx);
  302. void SetTransColor(RGBQUAD rgb);
  303. bool IsTransparent() const;
  304. uint32_t GetCodecOption(uint32_t imagetype = 0);
  305. bool SetCodecOption(uint32_t opt, uint32_t imagetype = 0);
  306. uint32_t GetFlags() const;
  307. void SetFlags(uint32_t flags, bool bLockReservedFlags = true);
  308. uint8_t GetDisposalMethod() const;
  309. void SetDisposalMethod(uint8_t dm);
  310. bool SetType(uint32_t type);
  311. static uint32_t GetNumTypes();
  312. static uint32_t GetTypeIdFromName(const TCHAR* ext);
  313. static uint32_t GetTypeIdFromIndex(const uint32_t index);
  314. static uint32_t GetTypeIndexFromId(const uint32_t id);
  315. bool GetRetreiveAllFrames() const;
  316. void SetRetreiveAllFrames(bool flag);
  317. CxImage * GetFrame(int32_t nFrame) const;
  318. //void* GetUserData() const {return info.pUserData;}
  319. //void SetUserData(void* pUserData) {info.pUserData = pUserData;}
  320. //@}
  321. /** \addtogroup Palette
  322. * These functions have no effects on RGB images and in this case the returned value is always 0.
  323. * @{ */
  324. bool IsGrayScale();
  325. bool IsIndexed() const;
  326. bool IsSamePalette(CxImage &img, bool bCheckAlpha = true);
  327. uint32_t GetPaletteSize();
  328. RGBQUAD* GetPalette() const;
  329. RGBQUAD GetPaletteColor(uint8_t idx);
  330. bool GetPaletteColor(uint8_t i, uint8_t* r, uint8_t* g, uint8_t* b);
  331. uint8_t GetNearestIndex(RGBQUAD c);
  332. void BlendPalette(COLORREF cr,int32_t perc);
  333. void SetGrayPalette();
  334. void SetPalette(uint32_t n, uint8_t *r, uint8_t *g, uint8_t *b);
  335. void SetPalette(RGBQUAD* pPal,uint32_t nColors=256);
  336. void SetPalette(rgb_color *rgb,uint32_t nColors=256);
  337. void SetPaletteColor(uint8_t idx, uint8_t r, uint8_t g, uint8_t b, uint8_t alpha=0);
  338. void SetPaletteColor(uint8_t idx, RGBQUAD c);
  339. void SetPaletteColor(uint8_t idx, COLORREF cr);
  340. void SwapIndex(uint8_t idx1, uint8_t idx2);
  341. void SwapRGB2BGR();
  342. void SetStdPalette();
  343. //@}
  344. /** \addtogroup Pixel */ //@{
  345. bool IsInside(int32_t x, int32_t y);
  346. bool IsTransparent(int32_t x,int32_t y);
  347. bool GetTransparentMask(CxImage* iDst = 0);
  348. RGBQUAD GetPixelColor(int32_t x,int32_t y, bool bGetAlpha = true);
  349. uint8_t GetPixelIndex(int32_t x,int32_t y);
  350. uint8_t GetPixelGray(int32_t x, int32_t y);
  351. void SetPixelColor(int32_t x,int32_t y,RGBQUAD c, bool bSetAlpha = false);
  352. void SetPixelColor(int32_t x,int32_t y,COLORREF cr);
  353. void SetPixelIndex(int32_t x,int32_t y,uint8_t i);
  354. void DrawLine(int32_t StartX, int32_t EndX, int32_t StartY, int32_t EndY, RGBQUAD color, bool bSetAlpha=false);
  355. void DrawLine(int32_t StartX, int32_t EndX, int32_t StartY, int32_t EndY, COLORREF cr);
  356. void BlendPixelColor(int32_t x,int32_t y,RGBQUAD c, float blend, bool bSetAlpha = false);
  357. //@}
  358. protected:
  359. /** \addtogroup Protected */ //@{
  360. uint8_t BlindGetPixelIndex(const int32_t x,const int32_t y);
  361. RGBQUAD BlindGetPixelColor(const int32_t x,const int32_t y, bool bGetAlpha = true);
  362. void *BlindGetPixelPointer(const int32_t x,const int32_t y);
  363. void BlindSetPixelColor(int32_t x,int32_t y,RGBQUAD c, bool bSetAlpha = false);
  364. void BlindSetPixelIndex(int32_t x,int32_t y,uint8_t i);
  365. //@}
  366. public:
  367. #if CXIMAGE_SUPPORT_INTERPOLATION
  368. /** \addtogroup Interpolation */ //@{
  369. //overflow methods:
  370. enum OverflowMethod {
  371. OM_COLOR=1,
  372. OM_BACKGROUND=2,
  373. OM_TRANSPARENT=3,
  374. OM_WRAP=4,
  375. OM_REPEAT=5,
  376. OM_MIRROR=6
  377. };
  378. void OverflowCoordinates(float &x, float &y, OverflowMethod const ofMethod);
  379. void OverflowCoordinates(int32_t &x, int32_t &y, OverflowMethod const ofMethod);
  380. RGBQUAD GetPixelColorWithOverflow(int32_t x, int32_t y, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0);
  381. //interpolation methods:
  382. enum InterpolationMethod {
  383. IM_NEAREST_NEIGHBOUR=1,
  384. IM_BILINEAR =2,
  385. IM_BSPLINE =3,
  386. IM_BICUBIC =4,
  387. IM_BICUBIC2 =5,
  388. IM_LANCZOS =6,
  389. IM_BOX =7,
  390. IM_HERMITE =8,
  391. IM_HAMMING =9,
  392. IM_SINC =10,
  393. IM_BLACKMAN =11,
  394. IM_BESSEL =12,
  395. IM_GAUSSIAN =13,
  396. IM_QUADRATIC =14,
  397. IM_MITCHELL =15,
  398. IM_CATROM =16,
  399. IM_HANNING =17,
  400. IM_POWER =18
  401. };
  402. RGBQUAD GetPixelColorInterpolated(float x,float y, InterpolationMethod const inMethod=IM_BILINEAR, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0);
  403. 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);
  404. //@}
  405. protected:
  406. /** \addtogroup Protected */ //@{
  407. void AddAveragingCont(RGBQUAD const &color, float const surf, float &rr, float &gg, float &bb, float &aa);
  408. //@}
  409. /** \addtogroup Kernels */ //@{
  410. public:
  411. static float KernelBSpline(const float x);
  412. static float KernelLinear(const float t);
  413. static float KernelCubic(const float t);
  414. static float KernelGeneralizedCubic(const float t, const float a=-1);
  415. static float KernelLanczosSinc(const float t, const float r = 3);
  416. static float KernelBox(const float x);
  417. static float KernelHermite(const float x);
  418. static float KernelHamming(const float x);
  419. static float KernelSinc(const float x);
  420. static float KernelBlackman(const float x);
  421. static float KernelBessel_J1(const float x);
  422. static float KernelBessel_P1(const float x);
  423. static float KernelBessel_Q1(const float x);
  424. static float KernelBessel_Order1(float x);
  425. static float KernelBessel(const float x);
  426. static float KernelGaussian(const float x);
  427. static float KernelQuadratic(const float x);
  428. static float KernelMitchell(const float x);
  429. static float KernelCatrom(const float x);
  430. static float KernelHanning(const float x);
  431. static float KernelPower(const float x, const float a = 2);
  432. //@}
  433. #endif //CXIMAGE_SUPPORT_INTERPOLATION
  434. /** \addtogroup Painting */ //@{
  435. #if CXIMAGE_SUPPORT_WINDOWS
  436. int32_t Blt(HDC pDC, int32_t x=0, int32_t y=0);
  437. HBITMAP Draw2HBITMAP(HDC hdc, int32_t x, int32_t y, int32_t cx, int32_t cy, RECT* pClipRect, bool bSmooth);
  438. HBITMAP MakeBitmap(HDC hdc = NULL, bool bTransparency = false);
  439. HICON MakeIcon(HDC hdc = NULL, bool bTransparency = false);
  440. HANDLE CopyToHandle();
  441. bool CreateFromHANDLE(HANDLE hMem); //Windows objects (clipboard)
  442. bool CreateFromHBITMAP(HBITMAP hbmp, HPALETTE hpal=0, bool bTransparency = false); //Windows resource
  443. bool CreateFromHICON(HICON hico, bool bTransparency = false);
  444. int32_t Draw(HDC hdc, int32_t x=0, int32_t y=0, int32_t cx = -1, int32_t cy = -1, RECT* pClipRect = 0, bool bSmooth = false, bool bFlipY = false);
  445. int32_t Draw(HDC hdc, const RECT& rect, RECT* pClipRect=NULL, bool bSmooth = false, bool bFlipY = false);
  446. int32_t Stretch(HDC hdc, int32_t xoffset, int32_t yoffset, int32_t xsize, int32_t ysize, uint32_t dwRop = SRCCOPY);
  447. int32_t Stretch(HDC hdc, const RECT& rect, uint32_t dwRop = SRCCOPY);
  448. int32_t Tile(HDC hdc, RECT *rc);
  449. int32_t Draw2(HDC hdc, int32_t x=0, int32_t y=0, int32_t cx = -1, int32_t cy = -1);
  450. int32_t Draw2(HDC hdc, const RECT& rect);
  451. //int32_t DrawString(HDC hdc, int32_t x, int32_t y, const char* text, RGBQUAD color, const char* font, int32_t lSize=0, int32_t lWeight=400, uint8_t bItalic=0, uint8_t bUnderline=0, bool bSetAlpha=false);
  452. int32_t DrawString(HDC hdc, int32_t x, int32_t y, const TCHAR* text, RGBQUAD color, const TCHAR* font, int32_t lSize=0, int32_t lWeight=400, uint8_t bItalic=0, uint8_t bUnderline=0, bool bSetAlpha=false);
  453. // <VATI> extensions
  454. int32_t DrawStringEx(HDC hdc, int32_t x, int32_t y, CXTEXTINFO *pTextType, bool bSetAlpha=false );
  455. void InitTextInfo( CXTEXTINFO *txt );
  456. protected:
  457. bool IsHBITMAPAlphaValid( HBITMAP hbmp );
  458. public:
  459. #endif //CXIMAGE_SUPPORT_WINDOWS
  460. //@}
  461. // file operations
  462. #if CXIMAGE_SUPPORT_DECODE
  463. /** \addtogroup Decode */ //@{
  464. #ifdef WIN32
  465. //bool Load(LPCWSTR filename, uint32_t imagetype=0);
  466. bool LoadResource(HRSRC hRes, uint32_t imagetype, HMODULE hModule=NULL);
  467. #endif
  468. // For UNICODE support: char -> TCHAR
  469. bool Load(const TCHAR* filename, uint32_t imagetype=0);
  470. //bool Load(const char * filename, uint32_t imagetype=0);
  471. bool Decode(FILE * hFile, uint32_t imagetype);
  472. bool Decode(CxFile * hFile, uint32_t imagetype);
  473. bool Decode(uint8_t * buffer, uint32_t size, uint32_t imagetype);
  474. bool CheckFormat(CxFile * hFile, uint32_t imagetype = 0);
  475. bool CheckFormat(uint8_t * buffer, uint32_t size, uint32_t imagetype = 0);
  476. //@}
  477. #endif //CXIMAGE_SUPPORT_DECODE
  478. #if CXIMAGE_SUPPORT_ENCODE
  479. protected:
  480. /** \addtogroup Protected */ //@{
  481. bool EncodeSafeCheck(CxFile *hFile);
  482. //@}
  483. public:
  484. /** \addtogroup Encode */ //@{
  485. #ifdef WIN32
  486. //bool Save(LPCWSTR filename, uint32_t imagetype=0);
  487. #endif
  488. // For UNICODE support: char -> TCHAR
  489. bool Save(const TCHAR* filename, uint32_t imagetype);
  490. //bool Save(const char * filename, uint32_t imagetype=0);
  491. bool Encode(FILE * hFile, uint32_t imagetype);
  492. bool Encode(CxFile * hFile, uint32_t imagetype);
  493. bool Encode(CxFile * hFile, CxImage ** pImages, int32_t pagecount, uint32_t imagetype);
  494. bool Encode(FILE *hFile, CxImage ** pImages, int32_t pagecount, uint32_t imagetype);
  495. bool Encode(uint8_t * &buffer, int32_t &size, uint32_t imagetype);
  496. bool Encode2RGBA(CxFile *hFile, bool bFlipY = false);
  497. bool Encode2RGBA(uint8_t * &buffer, int32_t &size, bool bFlipY = false);
  498. //@}
  499. #endif //CXIMAGE_SUPPORT_ENCODE
  500. /** \addtogroup Attributes */ //@{
  501. //misc.
  502. bool IsValid() const;
  503. bool IsEnabled() const;
  504. void Enable(bool enable=true);
  505. // frame operations
  506. int32_t GetNumFrames() const;
  507. int32_t GetFrame() const;
  508. void SetFrame(int32_t nFrame);
  509. //@}
  510. #if CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
  511. /** \addtogroup BasicTransformations */ //@{
  512. bool GrayScale();
  513. bool Flip(bool bFlipSelection = false, bool bFlipAlpha = true);
  514. bool Mirror(bool bMirrorSelection = false, bool bMirrorAlpha = true);
  515. bool Negative();
  516. bool RotateLeft(CxImage* iDst = NULL);
  517. bool RotateRight(CxImage* iDst = NULL);
  518. bool IncreaseBpp(uint32_t nbit);
  519. //@}
  520. #endif //CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
  521. #if CXIMAGE_SUPPORT_TRANSFORMATION
  522. /** \addtogroup Transformations */ //@{
  523. // image operations
  524. bool Rotate(float angle, CxImage* iDst = NULL);
  525. bool Rotate2(float angle, CxImage *iDst = NULL, InterpolationMethod inMethod=IM_BILINEAR,
  526. OverflowMethod ofMethod=OM_BACKGROUND, RGBQUAD *replColor=0,
  527. bool const optimizeRightAngles=true, bool const bKeepOriginalSize=false);
  528. bool Rotate180(CxImage* iDst = NULL);
  529. bool Resample(int32_t newx, int32_t newy, int32_t mode = 1, CxImage* iDst = NULL);
  530. bool Resample2(int32_t newx, int32_t newy, InterpolationMethod const inMethod=IM_BICUBIC2,
  531. OverflowMethod const ofMethod=OM_REPEAT, CxImage* const iDst = NULL,
  532. bool const disableAveraging=false);
  533. bool DecreaseBpp(uint32_t nbit, bool errordiffusion, RGBQUAD* ppal = 0, uint32_t clrimportant = 0);
  534. bool Dither(int32_t method = 0);
  535. bool Crop(int32_t left, int32_t top, int32_t right, int32_t bottom, CxImage* iDst = NULL);
  536. bool Crop(const RECT& rect, CxImage* iDst = NULL);
  537. bool CropRotatedRectangle( int32_t topx, int32_t topy, int32_t width, int32_t height, float angle, CxImage* iDst = NULL);
  538. bool Skew(float xgain, float ygain, int32_t xpivot=0, int32_t ypivot=0, bool bEnableInterpolation = false);
  539. bool Expand(int32_t left, int32_t top, int32_t right, int32_t bottom, RGBQUAD canvascolor, CxImage* iDst = 0);
  540. bool Expand(int32_t newx, int32_t newy, RGBQUAD canvascolor, CxImage* iDst = 0);
  541. bool Thumbnail(int32_t newx, int32_t newy, RGBQUAD canvascolor, CxImage* iDst = 0);
  542. bool CircleTransform(int32_t type,int32_t rmax=0,float Koeff=1.0f);
  543. bool QIShrink(int32_t newx, int32_t newy, CxImage* const iDst = NULL, bool bChangeBpp = false);
  544. //@}
  545. #endif //CXIMAGE_SUPPORT_TRANSFORMATION
  546. #if CXIMAGE_SUPPORT_DSP
  547. /** \addtogroup DSP */ //@{
  548. bool Contour();
  549. bool HistogramStretch(int32_t method = 0, double threshold = 0);
  550. bool HistogramEqualize();
  551. bool HistogramNormalize();
  552. bool HistogramRoot();
  553. bool HistogramLog();
  554. int32_t Histogram(int32_t* red, int32_t* green = 0, int32_t* blue = 0, int32_t* gray = 0, int32_t colorspace = 0);
  555. bool Jitter(int32_t radius=2);
  556. bool Repair(float radius = 0.25f, int32_t niterations = 1, int32_t colorspace = 0);
  557. bool Combine(CxImage* r,CxImage* g,CxImage* b,CxImage* a, int32_t colorspace = 0);
  558. bool FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage* dstImag, int32_t direction = 1, bool bForceFFT = true, bool bMagnitude = true);
  559. bool Noise(int32_t level);
  560. bool Median(int32_t Ksize=3);
  561. bool Gamma(float gamma);
  562. bool GammaRGB(float gammaR, float gammaG, float gammaB);
  563. bool ShiftRGB(int32_t r, int32_t g, int32_t b);
  564. bool Threshold(uint8_t level);
  565. bool Threshold(CxImage* pThresholdMask);
  566. bool Threshold2(uint8_t level, bool bDirection, RGBQUAD nBkgndColor, bool bSetAlpha = false);
  567. bool Colorize(uint8_t hue, uint8_t sat, float blend = 1.0f);
  568. bool Light(int32_t brightness, int32_t contrast = 0);
  569. float Mean();
  570. bool Filter(int32_t* kernel, int32_t Ksize, int32_t Kfactor, int32_t Koffset);
  571. bool Erode(int32_t Ksize=2);
  572. bool Dilate(int32_t Ksize=2);
  573. bool Edge(int32_t Ksize=2);
  574. void HuePalette(float correction=1);
  575. enum ImageOpType { OpAdd, OpAnd, OpXor, OpOr, OpMask, OpSrcCopy, OpDstCopy, OpSub, OpSrcBlend, OpScreen, OpAvg, OpBlendAlpha };
  576. void Mix(CxImage & imgsrc2, ImageOpType op, int32_t lXOffset = 0, int32_t lYOffset = 0, bool bMixAlpha = false);
  577. void MixFrom(CxImage & imagesrc2, int32_t lXOffset, int32_t lYOffset);
  578. bool UnsharpMask(float radius = 5.0f, float amount = 0.5f, int32_t threshold = 0);
  579. bool Lut(uint8_t* pLut);
  580. bool Lut(uint8_t* pLutR, uint8_t* pLutG, uint8_t* pLutB, uint8_t* pLutA = 0);
  581. bool GaussianBlur(float radius = 1.0f, CxImage* iDst = 0);
  582. bool TextBlur(uint8_t threshold = 100, uint8_t decay = 2, uint8_t max_depth = 5, bool bBlurHorizontal = true, bool bBlurVertical = true, CxImage* iDst = 0);
  583. bool SelectiveBlur(float radius = 1.0f, uint8_t threshold = 25, CxImage* iDst = 0);
  584. bool Solarize(uint8_t level = 128, bool bLinkedChannels = true);
  585. bool FloodFill(const int32_t xStart, const int32_t yStart, const RGBQUAD cFillColor, const uint8_t tolerance = 0,
  586. uint8_t nOpacity = 255, const bool bSelectFilledArea = false, const uint8_t nSelectionLevel = 255);
  587. bool Saturate(const int32_t saturation, const int32_t colorspace = 1);
  588. bool ConvertColorSpace(const int32_t dstColorSpace, const int32_t srcColorSpace);
  589. int32_t OptimalThreshold(int32_t method = 0, RECT * pBox = 0, CxImage* pContrastMask = 0);
  590. bool AdaptiveThreshold(int32_t method = 0, int32_t nBoxSize = 64, CxImage* pContrastMask = 0, int32_t nBias = 0, float fGlobalLocalBalance = 0.5f);
  591. bool RedEyeRemove(float strength = 0.8f);
  592. bool Trace(RGBQUAD color_target, RGBQUAD color_trace);
  593. //@}
  594. protected:
  595. /** \addtogroup Protected */ //@{
  596. bool IsPowerof2(int32_t x);
  597. bool FFT(int32_t dir,int32_t m,double *x,double *y);
  598. bool DFT(int32_t dir,int32_t m,double *x1,double *y1,double *x2,double *y2);
  599. bool RepairChannel(CxImage *ch, float radius);
  600. // <nipper>
  601. int32_t gen_convolve_matrix (float radius, float **cmatrix_p);
  602. float* gen_lookup_table (float *cmatrix, int32_t cmatrix_length);
  603. void blur_line (float *ctable, float *cmatrix, int32_t cmatrix_length, uint8_t* cur_col, uint8_t* dest_col, int32_t y, int32_t bytes);
  604. void blur_text (uint8_t threshold, uint8_t decay, uint8_t max_depth, CxImage* iSrc, CxImage* iDst, uint8_t bytes);
  605. //@}
  606. public:
  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. /** \addtogroup Selection */ //@{
  628. bool SelectionIsValid();
  629. #if CXIMAGE_SUPPORT_SELECTION
  630. bool SelectionClear(uint8_t level = 0);
  631. bool SelectionCreate();
  632. bool SelectionDelete();
  633. bool SelectionInvert();
  634. bool SelectionMirror();
  635. bool SelectionFlip();
  636. bool SelectionAddRect(RECT r, uint8_t level = 255);
  637. bool SelectionAddEllipse(RECT r, uint8_t level = 255);
  638. bool SelectionAddPolygon(POINT *points, int32_t npoints, uint8_t level = 255);
  639. bool SelectionAddColor(RGBQUAD c, uint8_t level = 255);
  640. bool SelectionAddPixel(int32_t x, int32_t y, uint8_t level = 255);
  641. bool SelectionCopy(CxImage &from);
  642. bool SelectionIsInside(int32_t x, int32_t y);
  643. void SelectionGetBox(RECT& r);
  644. bool SelectionToHRGN(HRGN& region);
  645. bool SelectionSplit(CxImage *dest);
  646. uint8_t SelectionGet(const int32_t x,const int32_t y);
  647. bool SelectionSet(CxImage &from);
  648. void SelectionRebuildBox();
  649. uint8_t* SelectionGetPointer(const int32_t x = 0,const int32_t y = 0);
  650. //@}
  651. protected:
  652. /** \addtogroup Protected */ //@{
  653. bool BlindSelectionIsInside(int32_t x, int32_t y);
  654. uint8_t BlindSelectionGet(const int32_t x,const int32_t y);
  655. void SelectionSet(const int32_t x,const int32_t y,const uint8_t level);
  656. public:
  657. #endif //CXIMAGE_SUPPORT_SELECTION
  658. //@}
  659. #if CXIMAGE_SUPPORT_ALPHA
  660. /** \addtogroup Alpha */ //@{
  661. void AlphaClear();
  662. bool AlphaCreate();
  663. void AlphaDelete();
  664. void AlphaInvert();
  665. bool AlphaMirror();
  666. bool AlphaFlip();
  667. bool AlphaCopy(CxImage &from);
  668. bool AlphaSplit(CxImage *dest);
  669. void AlphaStrip();
  670. void AlphaSet(uint8_t level);
  671. bool AlphaSet(CxImage &from);
  672. void AlphaSet(const int32_t x,const int32_t y,const uint8_t level);
  673. uint8_t AlphaGet(const int32_t x,const int32_t y);
  674. uint8_t AlphaGetMax() const;
  675. void AlphaSetMax(uint8_t nAlphaMax);
  676. bool AlphaIsValid();
  677. uint8_t* AlphaGetPointer(const int32_t x = 0,const int32_t y = 0);
  678. bool AlphaFromTransparency();
  679. void AlphaPaletteClear();
  680. void AlphaPaletteEnable(bool enable=true);
  681. bool AlphaPaletteIsEnabled();
  682. bool AlphaPaletteIsValid();
  683. bool AlphaPaletteSplit(CxImage *dest);
  684. //@}
  685. protected:
  686. /** \addtogroup Protected */ //@{
  687. uint8_t BlindAlphaGet(const int32_t x,const int32_t y);
  688. //@}
  689. #endif //CXIMAGE_SUPPORT_ALPHA
  690. public:
  691. #if CXIMAGE_SUPPORT_LAYERS
  692. /** \addtogroup Layers */ //@{
  693. bool LayerCreate(int32_t position = -1);
  694. bool LayerDelete(int32_t position = -1);
  695. void LayerDeleteAll();
  696. CxImage* GetLayer(int32_t position);
  697. CxImage* GetParent() const;
  698. int32_t GetNumLayers() const;
  699. int32_t LayerDrawAll(HDC hdc, int32_t x=0, int32_t y=0, int32_t cx = -1, int32_t cy = -1, RECT* pClipRect = 0, bool bSmooth = false);
  700. int32_t LayerDrawAll(HDC hdc, const RECT& rect, RECT* pClipRect=NULL, bool bSmooth = false);
  701. //@}
  702. #endif //CXIMAGE_SUPPORT_LAYERS
  703. protected:
  704. /** \addtogroup Protected */ //@{
  705. void Startup(uint32_t imagetype = 0);
  706. void CopyInfo(const CxImage &src);
  707. void Ghost(const CxImage *src);
  708. void RGBtoBGR(uint8_t *buffer, int32_t length);
  709. static float HueToRGB(float n1,float n2, float hue);
  710. void Bitfield2RGB(uint8_t *src, uint32_t redmask, uint32_t greenmask, uint32_t bluemask, uint8_t bpp);
  711. static int32_t CompareColors(const void *elem1, const void *elem2);
  712. int16_t m_ntohs(const int16_t word);
  713. int32_t m_ntohl(const int32_t dword);
  714. void bihtoh(BITMAPINFOHEADER* bih);
  715. void* pDib; //contains the header, the palette, the pixels
  716. BITMAPINFOHEADER head; //standard header
  717. CXIMAGEINFO info; //extended information
  718. uint8_t* pSelection; //selected region
  719. uint8_t* pAlpha; //alpha channel
  720. CxImage** ppLayers; //generic layers
  721. CxImage** ppFrames;
  722. //@}
  723. };
  724. ////////////////////////////////////////////////////////////////////////////
  725. #endif // !defined(__CXIMAGE_H)