00001 // ========================================================== 00002 // FreeImagePlus 3 00003 // 00004 // Design and implementation by 00005 // - Hervé Drolon (drolon@infonie.fr) 00006 // 00007 // This file is part of FreeImage 3 00008 // 00009 // COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY 00010 // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES 00011 // THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE 00012 // OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED 00013 // CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT 00014 // THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY 00015 // SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL 00016 // PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER 00017 // THIS DISCLAIMER. 00018 // 00019 // Use at your own risk! 00020 // ========================================================== 00021 00022 #ifndef FREEIMAGEPLUS_H 00023 #define FREEIMAGEPLUS_H 00024 00025 #ifdef WIN32 00026 #include <windows.h> 00027 #endif // WIN32 00028 #include "FreeImage.h" 00029 00030 00031 // Compiler options --------------------------------------------------------- 00032 00033 #if defined(FREEIMAGE_LIB) || !defined(WIN32) 00034 #define FIP_API 00035 #else 00036 // The following ifdef block is the standard way of creating macros which make exporting 00037 // from a DLL simpler. All files within this DLL are compiled with the FIP_EXPORTS 00038 // symbol defined on the command line. this symbol should not be defined on any project 00039 // that uses this DLL. This way any other project whose source files include this file see 00040 // FIP_API functions as being imported from a DLL, wheras this DLL sees symbols 00041 // defined with this macro as being exported. 00042 #ifdef FIP_EXPORTS 00043 #define FIP_API __declspec(dllexport) 00044 #else 00045 #define FIP_API __declspec(dllimport) 00046 #endif // FIP_EXPORTS 00047 #endif // FREEIMAGE_LIB || !WIN32 00048 00050 00053 00054 const BYTE WHITE = 255; 00056 const BYTE BLACK = 0; 00058 00059 // ---------------------------------------------------------- 00060 00066 class FIP_API fipGenericImage 00067 { 00068 protected: 00070 WORD m_Width; 00072 WORD m_Height; 00074 WORD m_ScanWidth; 00075 00076 public: 00077 00080 00081 WORD getWidth() { return m_Width; } 00083 WORD getHeight() { return m_Height; } 00085 WORD getScanWidth() { return m_ScanWidth; } 00087 00090 00091 virtual BOOL isValid() = 0; 00093 }; 00094 00095 // ---------------------------------------------------------- 00096 00105 class FIP_API fipImage : public fipGenericImage 00106 { 00107 protected: 00109 FIBITMAP *m_dib; 00111 BYTE *m_bits; 00112 00113 public: 00114 00117 00118 fipImage(WORD width = 0, WORD height = 0, WORD bpp = 0); 00120 ~fipImage(); 00122 BOOL setSize(WORD width, WORD height, WORD bpp); 00124 00127 00128 fipImage(const fipImage& src); 00130 fipImage(const FIBITMAP *dib); 00132 fipImage& operator=(const fipImage& src); 00134 fipImage& operator=(FIBITMAP *dib); 00135 00136 00138 00147 BOOL copySubImage(fipImage& dst, int left, int top, int right, int bottom); 00148 00161 BOOL pasteSubImage(fipImage& src, int left, int top, int alpha = 256); 00162 00164 00169 00170 00176 BOOL load(const char* lpszPathName, int flag = 0); 00177 00179 00186 BOOL loadFromHandle(FreeImageIO *io, fi_handle handle, int flag = 0); 00187 00189 00195 BOOL save(const char* lpszPathName, int flag = 0); 00196 00198 00206 BOOL saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flag = 0); 00208 00213 00214 FIBITMAP* getFIBITMAP(); 00215 00217 BOOL isValid(); 00218 00220 BITMAPINFO* getInfo(); 00221 00223 BITMAPINFOHEADER* getInfoHeader(); 00224 00226 LONG getImageSize(); 00227 00232 WORD getBitsPerPixel(); 00233 00235 WORD getLine(); 00236 00238 WORD getHorizontalResolution(); 00239 00241 WORD getVerticalResolution(); 00242 00244 void setHorizontalResolution(LONG value); 00245 00247 void setVerticalResolution(LONG value); 00249 00252 00253 RGBQUAD* getPalette(); 00254 00256 WORD getPaletteSize(); 00257 00259 WORD getColorsUsed(); 00260 00264 FREE_IMAGE_COLOR_TYPE getColorType(); 00265 00267 BOOL isGrayscale(); 00269 00272 00280 BYTE* accessPixels(); 00281 00285 BYTE *getScanLine(int scanline); 00286 00288 00297 BOOL threshold(BYTE T); 00298 00302 BOOL convertTo8Bits(); 00303 00307 BOOL convertTo16Bits555(); 00308 00312 BOOL convertTo16Bits565(); 00313 00317 BOOL convertTo24Bits(); 00318 00322 BOOL convertTo32Bits(); 00323 00330 BOOL convertToGrayscale(); 00331 00339 BOOL colorQuantize(FREE_IMAGE_QUANTIZE algorithm); 00340 00347 BOOL dither(FREE_IMAGE_DITHER algorithm); 00349 00358 BOOL getChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel); 00359 00367 BOOL splitChannels(fipImage& RedChannel, fipImage& GreenChannel, fipImage& BlueChannel); 00368 00373 BOOL getRedChannel(fipImage& red); 00374 00379 BOOL getGreenChannel(fipImage& green); 00380 00385 BOOL getBlueChannel(fipImage& blue); 00386 00391 BOOL getAlphaChannel(fipImage& alpha); 00392 00397 BOOL setAlphaChannel(fipImage& alpha); 00398 00405 BOOL combineChannels(fipImage& red, fipImage& green, fipImage& blue); 00407 00421 BOOL rotateEx(double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask); 00422 00428 BOOL rotate(double angle); 00429 00431 BOOL flipHorizontal(); 00432 00434 BOOL flipVertical(); 00436 00442 BOOL invert(); 00443 00457 BOOL adjustCurve(BYTE *LUT, FREE_IMAGE_COLOR_CHANNEL channel); 00458 00465 BOOL adjustGamma(double gamma); 00466 00474 BOOL adjustBrightness(double percentage); 00475 00483 BOOL adjustContrast(double percentage); 00484 00494 BOOL getHistogram(DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel = FICC_BLACK); 00496 00499 00508 BOOL rescale(WORD new_width, WORD new_height, FREE_IMAGE_FILTER filter); 00510 00511 00512 protected: 00515 void updateInfo(); 00516 BOOL replace(FIBITMAP *new_dib); 00517 BOOL replace(fipImage& img) { 00518 return replace(img.getFIBITMAP()); 00519 } 00521 00522 }; 00523 00524 // ---------------------------------------------------------- 00525 00536 #ifdef WIN32 00537 00538 class FIP_API fipWinImage : public fipImage 00539 { 00540 public: 00543 00544 fipWinImage(WORD width = 0, WORD height = 0, WORD bpp = 0) : fipImage(width, height, bpp) { } 00545 00547 ~fipWinImage() { } 00549 00552 00553 fipWinImage(const fipImage& Img) : fipImage(Img) { } 00554 00556 fipWinImage(const FIBITMAP *dib) : fipImage(dib) { } 00557 00563 HANDLE copyToHandle(); 00564 00569 void copyFromHandle(HANDLE hMem); 00570 00575 void copyFromBitmap(HBITMAP hbmp); 00576 00578 00581 00587 void draw(HDC hDC, RECT& rcDest); 00588 00590 }; 00591 00592 #endif // WIN32 00593 00594 #endif // FREEIMAGEPLUS_H