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) 00034 #define FIP_API 00035 #define FIP_CALLCONV 00036 #else 00037 #if defined(_WIN32) || defined(__WIN32__) 00038 #define WIN32_LEAN_AND_MEAN 00039 #define FIP_CALLCONV __stdcall 00040 // The following ifdef block is the standard way of creating macros which make exporting 00041 // from a DLL simpler. All files within this DLL are compiled with the FIP_EXPORTS 00042 // symbol defined on the command line. this symbol should not be defined on any project 00043 // that uses this DLL. This way any other project whose source files include this file see 00044 // FIP_API functions as being imported from a DLL, wheras this DLL sees symbols 00045 // defined with this macro as being exported. 00046 #ifdef FIP_EXPORTS 00047 #define FIP_API __declspec(dllexport) 00048 #else 00049 #define FIP_API __declspec(dllimport) 00050 #endif // FIP_EXPORTS 00051 #else 00052 // try the gcc visibility support (see http://gcc.gnu.org/wiki/Visibility) 00053 #if defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) 00054 #ifndef GCC_HASCLASSVISIBILITY 00055 #define GCC_HASCLASSVISIBILITY 00056 #endif 00057 #endif 00058 #define FIP_CALLCONV 00059 #if defined(GCC_HASCLASSVISIBILITY) 00060 #define FIP_API __attribute__ ((visibility("default"))) 00061 #else 00062 #define FIP_API 00063 #endif 00064 #endif // WIN32 / !WIN32 00065 #endif // FREEIMAGE_LIB 00066 00068 00069 // ---------------------------------------------------------- 00070 00076 class FIP_API fipObject 00077 { 00078 public: 00080 virtual ~fipObject(){}; 00081 00084 00085 virtual BOOL isValid() const = 0; 00087 }; 00088 00089 // ---------------------------------------------------------- 00090 00091 class fipMemoryIO; 00092 class fipMultiPage; 00093 class fipTag; 00094 00103 class FIP_API fipImage : public fipObject 00104 { 00105 protected: 00107 FIBITMAP *_dib; 00109 FREE_IMAGE_FORMAT _fif; 00111 mutable BOOL _bHasChanged; 00112 00113 public: 00114 friend class fipMultiPage; 00115 00116 public: 00117 00124 fipImage(FREE_IMAGE_TYPE image_type = FIT_BITMAP, WORD width = 0, WORD height = 0, WORD bpp = 0); 00126 virtual ~fipImage(); 00131 BOOL setSize(FREE_IMAGE_TYPE image_type, WORD width, WORD height, WORD bpp, unsigned red_mask = 0, unsigned green_mask = 0, unsigned blue_mask = 0); 00133 virtual void clear(); 00135 00142 fipImage(const fipImage& src); 00147 fipImage& operator=(const fipImage& src); 00153 fipImage& operator=(FIBITMAP *dib); 00154 00155 00168 BOOL copySubImage(fipImage& dst, int left, int top, int right, int bottom) const; 00169 00183 BOOL pasteSubImage(fipImage& src, int left, int top, int alpha = 256); 00184 00195 BOOL crop(int left, int top, int right, int bottom); 00196 00198 00208 static FREE_IMAGE_FORMAT identifyFIF(const char* lpszPathName); 00209 00214 static FREE_IMAGE_FORMAT identifyFIFU(const wchar_t* lpszPathName); 00215 00223 static FREE_IMAGE_FORMAT identifyFIFFromHandle(FreeImageIO *io, fi_handle handle); 00224 00231 static FREE_IMAGE_FORMAT identifyFIFFromMemory(FIMEMORY *hmem); 00232 00234 00235 00247 BOOL load(const char* lpszPathName, int flag = 0); 00248 00253 BOOL loadU(const wchar_t* lpszPathName, int flag = 0); 00254 00263 BOOL loadFromHandle(FreeImageIO *io, fi_handle handle, int flag = 0); 00264 00272 BOOL loadFromMemory(fipMemoryIO& memIO, int flag = 0); 00273 00281 BOOL save(const char* lpszPathName, int flag = 0) const; 00282 00287 BOOL saveU(const wchar_t* lpszPathName, int flag = 0) const; 00288 00298 BOOL saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flag = 0) const; 00299 00308 BOOL saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flag = 0) const; 00309 00311 00316 00321 FREE_IMAGE_TYPE getImageType() const; 00322 00327 WORD getWidth() const; 00328 00333 WORD getHeight() const; 00334 00339 WORD getScanWidth() const; 00340 00353 operator FIBITMAP*() { 00354 return _dib; 00355 } 00356 00358 BOOL isValid() const; 00359 00364 BITMAPINFO* getInfo() const; 00365 00370 BITMAPINFOHEADER* getInfoHeader() const; 00371 00377 LONG getImageSize() const; 00378 00384 WORD getBitsPerPixel() const; 00385 00391 WORD getLine() const; 00392 00397 double getHorizontalResolution() const; 00398 00403 double getVerticalResolution() const; 00404 00409 void setHorizontalResolution(double value); 00410 00415 void setVerticalResolution(double value); 00416 00418 00425 RGBQUAD* getPalette() const; 00426 00431 WORD getPaletteSize() const; 00432 00437 WORD getColorsUsed() const; 00438 00443 FREE_IMAGE_COLOR_TYPE getColorType() const; 00444 00449 BOOL isGrayscale() const; 00451 00454 00463 BYTE* accessPixels() const; 00464 00470 BYTE* getScanLine(WORD scanline) const; 00471 00480 BOOL getPixelIndex(unsigned x, unsigned y, BYTE *value) const; 00481 00490 BOOL getPixelColor(unsigned x, unsigned y, RGBQUAD *value) const; 00491 00500 BOOL setPixelIndex(unsigned x, unsigned y, BYTE *value); 00501 00510 BOOL setPixelColor(unsigned x, unsigned y, RGBQUAD *value); 00511 00513 00525 BOOL convertToType(FREE_IMAGE_TYPE image_type, BOOL scale_linear = TRUE); 00526 00533 BOOL threshold(BYTE T); 00534 00541 BOOL dither(FREE_IMAGE_DITHER algorithm); 00542 00548 BOOL convertTo4Bits(); 00549 00555 BOOL convertTo8Bits(); 00556 00563 BOOL convertToGrayscale(); 00564 00572 BOOL colorQuantize(FREE_IMAGE_QUANTIZE algorithm); 00573 00579 BOOL convertTo16Bits555(); 00580 00586 BOOL convertTo16Bits565(); 00587 00593 BOOL convertTo24Bits(); 00594 00600 BOOL convertTo32Bits(); 00601 00607 BOOL convertToRGBF(); 00608 00619 BOOL toneMapping(FREE_IMAGE_TMO tmo, double first_param = 0, double second_param = 0, double third_param = 1, double fourth_param = 0); 00620 00622 00625 00630 BOOL isTransparent() const; 00631 00637 unsigned getTransparencyCount() const; 00638 00644 BYTE* getTransparencyTable() const; 00645 00650 void setTransparencyTable(BYTE *table, int count); 00651 00656 BOOL hasFileBkColor() const; 00657 00666 BOOL getFileBkColor(RGBQUAD *bkcolor) const; 00667 00676 BOOL setFileBkColor(RGBQUAD *bkcolor); 00678 00687 BOOL getChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel) const; 00688 00696 BOOL setChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel); 00697 00706 BOOL splitChannels(fipImage& RedChannel, fipImage& GreenChannel, fipImage& BlueChannel); 00707 00715 BOOL combineChannels(fipImage& red, fipImage& green, fipImage& blue); 00717 00731 BOOL rotateEx(double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask); 00732 00740 BOOL rotate(double angle, const void *bkcolor = NULL); 00741 00746 BOOL flipHorizontal(); 00747 00752 BOOL flipVertical(); 00754 00762 BOOL invert(); 00763 00777 BOOL adjustCurve(BYTE *LUT, FREE_IMAGE_COLOR_CHANNEL channel); 00778 00785 BOOL adjustGamma(double gamma); 00786 00794 BOOL adjustBrightness(double percentage); 00795 00803 BOOL adjustContrast(double percentage); 00804 00815 BOOL adjustBrightnessContrastGamma(double brightness, double contrast, double gamma); 00816 00827 BOOL getHistogram(DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel = FICC_BLACK) const; 00829 00832 00841 BOOL rescale(WORD new_width, WORD new_height, FREE_IMAGE_FILTER filter); 00842 00850 BOOL makeThumbnail(WORD max_size, BOOL convert = TRUE); 00852 00862 void setModified(BOOL bStatus = TRUE) { 00863 _bHasChanged = bStatus; 00864 } 00865 00871 BOOL isModified() { 00872 return _bHasChanged; 00873 } 00875 00883 unsigned getMetadataCount(FREE_IMAGE_MDMODEL model) const; 00892 BOOL getMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag) const; 00912 BOOL setMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag); 00914 00915 00916 protected: 00919 BOOL replace(FIBITMAP *new_dib); 00921 00922 }; 00923 00924 // ---------------------------------------------------------- 00925 00937 #ifdef _WIN32 00938 00939 class FIP_API fipWinImage : public fipImage 00940 { 00941 public: 00944 00945 fipWinImage(FREE_IMAGE_TYPE image_type = FIT_BITMAP, WORD width = 0, WORD height = 0, WORD bpp = 0); 00946 00948 virtual ~fipWinImage(); 00949 00951 virtual void clear(); 00952 00954 BOOL isValid() const; 00956 00959 00966 fipWinImage& operator=(const fipImage& src); 00967 00974 fipWinImage& operator=(const fipWinImage& src); 00975 00982 HANDLE copyToHandle() const; 00983 00990 BOOL copyFromHandle(HANDLE hMem); 00991 00996 BOOL copyFromBitmap(HBITMAP hbmp); 00998 01007 BOOL copyToClipboard(HWND hWndNewOwner) const; 01008 01013 BOOL pasteFromClipboard(); 01015 01023 BOOL captureWindow(HWND hWndApplicationWindow, HWND hWndSelectedWindow); 01025 01026 01029 01038 void draw(HDC hDC, RECT& rcDest) const { 01039 drawEx(hDC, rcDest, FALSE, NULL, NULL); 01040 } 01041 01059 void drawEx(HDC hDC, RECT& rcDest, BOOL useFileBkg = FALSE, RGBQUAD *appBkColor = NULL, FIBITMAP *bg = NULL) const; 01060 01071 void setToneMappingOperator(FREE_IMAGE_TMO tmo, double first_param = 0, double second_param = 0, double third_param = 1, double fourth_param = 0); 01072 01082 void getToneMappingOperator(FREE_IMAGE_TMO *tmo, double *first_param, double *second_param, double *third_param, double *fourth_param) const; 01083 01085 01086 protected: 01088 mutable FIBITMAP *_display_dib; 01090 mutable BOOL _bDeleteMe; 01092 FREE_IMAGE_TMO _tmo; 01094 double _tmo_param_1; 01096 double _tmo_param_2; 01098 double _tmo_param_3; 01100 double _tmo_param_4; 01101 }; 01102 01103 #endif // _WIN32 01104 01105 // ---------------------------------------------------------- 01106 01113 class FIP_API fipMemoryIO : public fipObject 01114 { 01115 protected: 01117 FIMEMORY *_hmem; 01118 01119 public : 01129 fipMemoryIO(BYTE *data = NULL, DWORD size_in_bytes = 0); 01130 01135 virtual ~fipMemoryIO(); 01136 01139 BOOL isValid() const; 01140 01144 FREE_IMAGE_FORMAT getFileType() const; 01145 01150 operator FIMEMORY*() { 01151 return _hmem; 01152 } 01153 01163 FIBITMAP* load(FREE_IMAGE_FORMAT fif, int flags = 0) const; 01172 BOOL save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, int flags = 0); 01181 unsigned read(void *buffer, unsigned size, unsigned count) const; 01190 unsigned write(const void *buffer, unsigned size, unsigned count); 01195 long tell() const; 01200 BOOL seek(long offset, int origin); 01207 BOOL acquire(BYTE **data, DWORD *size_in_bytes); 01209 01210 private: 01212 fipMemoryIO(const fipMemoryIO& src); 01214 fipMemoryIO& operator=(const fipMemoryIO& src); 01215 01216 }; 01217 01218 // ---------------------------------------------------------- 01219 01225 class FIP_API fipMultiPage : public fipObject 01226 { 01227 protected: 01229 FIMULTIBITMAP *_mpage; 01231 BOOL _bMemoryCache; 01232 01233 public: 01238 fipMultiPage(BOOL keep_cache_in_memory = FALSE); 01239 01244 virtual ~fipMultiPage(); 01245 01247 BOOL isValid() const; 01248 01258 BOOL open(const char* lpszPathName, BOOL create_new, BOOL read_only, int flags = 0); 01259 01267 BOOL open(fipMemoryIO& memIO, int flags = 0); 01268 01275 BOOL close(int flags = 0); 01276 01281 int getPageCount() const; 01282 01288 void appendPage(fipImage& image); 01289 01296 void insertPage(int page, fipImage& image); 01297 01303 void deletePage(int page); 01304 01312 BOOL movePage(int target, int source); 01313 01331 FIBITMAP* lockPage(int page); 01332 01339 void unlockPage(fipImage& image, BOOL changed); 01340 01349 BOOL getLockedPageNumbers(int *pages, int *count) const; 01350 }; 01351 01352 // ---------------------------------------------------------- 01353 01359 class FIP_API fipTag : public fipObject 01360 { 01361 protected: 01363 FITAG *_tag; 01364 01365 public: 01372 fipTag(); 01377 virtual ~fipTag(); 01386 BOOL setKeyValue(const char *key, const char *value); 01387 01389 01396 fipTag(const fipTag& tag); 01401 fipTag& operator=(const fipTag& tag); 01407 fipTag& operator=(FITAG *tag); 01409 01415 operator FITAG*() { 01416 return _tag; 01417 } 01418 01420 BOOL isValid() const; 01421 01428 const char *getKey() const; 01433 const char *getDescription() const; 01438 WORD getID() const; 01443 FREE_IMAGE_MDTYPE getType() const; 01448 DWORD getCount() const; 01453 DWORD getLength() const; 01458 const void *getValue() const; 01464 BOOL setKey(const char *key); 01470 BOOL setDescription(const char *description); 01476 BOOL setID(WORD id); 01482 BOOL setType(FREE_IMAGE_MDTYPE type); 01488 BOOL setCount(DWORD count); 01494 BOOL setLength(DWORD length); 01500 BOOL setValue(const void *value); 01501 01503 01509 const char* toString(FREE_IMAGE_MDMODEL model, char *Make = NULL) const; 01510 01511 }; 01512 01539 class FIP_API fipMetadataFind : public fipObject 01540 { 01541 protected: 01543 FIMETADATA *_mdhandle; 01544 01545 public: 01547 BOOL isValid() const; 01548 01550 fipMetadataFind(); 01555 virtual ~fipMetadataFind(); 01565 BOOL findFirstMetadata(FREE_IMAGE_MDMODEL model, fipImage& image, fipTag& tag); 01573 BOOL findNextMetadata(fipTag& tag); 01574 01575 }; 01576 01577 #endif // FREEIMAGEPLUS_H