FreeImagePlus - FreeImage 3.17.0
|
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, unsigned width = 0, unsigned height = 0, unsigned bpp = 0); 00126 virtual ~fipImage(); 00131 BOOL setSize(FREE_IMAGE_TYPE image_type, unsigned width, unsigned height, unsigned 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 unsigned getWidth() const; 00328 00333 unsigned getHeight() const; 00334 00339 unsigned 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 unsigned getImageSize() const; 00378 00383 unsigned getImageMemorySize() const; 00384 00390 unsigned getBitsPerPixel() const; 00391 00397 unsigned getLine() const; 00398 00403 double getHorizontalResolution() const; 00404 00409 double getVerticalResolution() const; 00410 00415 void setHorizontalResolution(double value); 00416 00421 void setVerticalResolution(double value); 00422 00424 00431 RGBQUAD* getPalette() const; 00432 00437 unsigned getPaletteSize() const; 00438 00443 unsigned getColorsUsed() const; 00444 00449 FREE_IMAGE_COLOR_TYPE getColorType() const; 00450 00455 BOOL isGrayscale() const; 00457 00460 00466 BOOL getThumbnail(fipImage& image) const; 00467 00473 BOOL setThumbnail(const fipImage& image); 00474 00480 BOOL hasThumbnail() const; 00481 00487 BOOL clearThumbnail(); 00488 00490 00493 00502 BYTE* accessPixels() const; 00503 00509 BYTE* getScanLine(unsigned scanline) const; 00510 00519 BOOL getPixelIndex(unsigned x, unsigned y, BYTE *value) const; 00520 00529 BOOL getPixelColor(unsigned x, unsigned y, RGBQUAD *value) const; 00530 00539 BOOL setPixelIndex(unsigned x, unsigned y, BYTE *value); 00540 00549 BOOL setPixelColor(unsigned x, unsigned y, RGBQUAD *value); 00550 00552 00564 BOOL convertToType(FREE_IMAGE_TYPE image_type, BOOL scale_linear = TRUE); 00565 00572 BOOL threshold(BYTE T); 00573 00580 BOOL dither(FREE_IMAGE_DITHER algorithm); 00581 00587 BOOL convertTo4Bits(); 00588 00594 BOOL convertTo8Bits(); 00595 00602 BOOL convertToGrayscale(); 00603 00611 BOOL colorQuantize(FREE_IMAGE_QUANTIZE algorithm); 00612 00618 BOOL convertTo16Bits555(); 00619 00625 BOOL convertTo16Bits565(); 00626 00632 BOOL convertTo24Bits(); 00633 00639 BOOL convertTo32Bits(); 00640 00646 BOOL convertToFloat(); 00647 00653 BOOL convertToRGBF(); 00654 00660 BOOL convertToRGBAF(); 00661 00667 BOOL convertToUINT16(); 00668 00674 BOOL convertToRGB16(); 00675 00681 BOOL convertToRGBA16(); 00682 00693 BOOL toneMapping(FREE_IMAGE_TMO tmo, double first_param = 0, double second_param = 0, double third_param = 1, double fourth_param = 0); 00694 00696 00699 00704 BOOL isTransparent() const; 00705 00711 unsigned getTransparencyCount() const; 00712 00718 BYTE* getTransparencyTable() const; 00719 00724 void setTransparencyTable(BYTE *table, int count); 00725 00730 BOOL hasFileBkColor() const; 00731 00740 BOOL getFileBkColor(RGBQUAD *bkcolor) const; 00741 00750 BOOL setFileBkColor(RGBQUAD *bkcolor); 00752 00761 BOOL getChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel) const; 00762 00770 BOOL setChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel); 00771 00780 BOOL splitChannels(fipImage& RedChannel, fipImage& GreenChannel, fipImage& BlueChannel); 00781 00789 BOOL combineChannels(fipImage& red, fipImage& green, fipImage& blue); 00791 00805 BOOL rotateEx(double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask); 00806 00814 BOOL rotate(double angle, const void *bkcolor = NULL); 00815 00820 BOOL flipHorizontal(); 00821 00826 BOOL flipVertical(); 00828 00836 BOOL invert(); 00837 00851 BOOL adjustCurve(BYTE *LUT, FREE_IMAGE_COLOR_CHANNEL channel); 00852 00859 BOOL adjustGamma(double gamma); 00860 00868 BOOL adjustBrightness(double percentage); 00869 00877 BOOL adjustContrast(double percentage); 00878 00889 BOOL adjustBrightnessContrastGamma(double brightness, double contrast, double gamma); 00890 00901 BOOL getHistogram(DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel = FICC_BLACK) const; 00903 00906 00915 BOOL rescale(unsigned new_width, unsigned new_height, FREE_IMAGE_FILTER filter); 00916 00924 BOOL makeThumbnail(unsigned max_size, BOOL convert = TRUE); 00926 00936 void setModified(BOOL bStatus = TRUE) { 00937 _bHasChanged = bStatus; 00938 } 00939 00945 BOOL isModified() { 00946 return _bHasChanged; 00947 } 00949 00957 unsigned getMetadataCount(FREE_IMAGE_MDMODEL model) const; 00966 BOOL getMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag) const; 00986 BOOL setMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag); 00988 00989 00990 protected: 00993 BOOL replace(FIBITMAP *new_dib); 00995 00996 }; 00997 00998 // ---------------------------------------------------------- 00999 01011 #ifdef _WIN32 01012 01013 class FIP_API fipWinImage : public fipImage 01014 { 01015 public: 01018 01019 fipWinImage(FREE_IMAGE_TYPE image_type = FIT_BITMAP, unsigned width = 0, unsigned height = 0, unsigned bpp = 0); 01020 01022 virtual ~fipWinImage(); 01023 01025 virtual void clear(); 01026 01028 BOOL isValid() const; 01030 01033 01040 fipWinImage& operator=(const fipImage& src); 01041 01048 fipWinImage& operator=(const fipWinImage& src); 01049 01056 HANDLE copyToHandle() const; 01057 01064 BOOL copyFromHandle(HANDLE hMem); 01065 01070 BOOL copyFromBitmap(HBITMAP hbmp); 01072 01081 BOOL copyToClipboard(HWND hWndNewOwner) const; 01082 01087 BOOL pasteFromClipboard(); 01089 01097 BOOL captureWindow(HWND hWndApplicationWindow, HWND hWndSelectedWindow); 01099 01100 01103 01112 void draw(HDC hDC, RECT& rcDest) const { 01113 drawEx(hDC, rcDest, FALSE, NULL, NULL); 01114 } 01115 01133 void drawEx(HDC hDC, RECT& rcDest, BOOL useFileBkg = FALSE, RGBQUAD *appBkColor = NULL, FIBITMAP *bg = NULL) const; 01134 01145 void setToneMappingOperator(FREE_IMAGE_TMO tmo, double first_param = 0, double second_param = 0, double third_param = 1, double fourth_param = 0); 01146 01156 void getToneMappingOperator(FREE_IMAGE_TMO *tmo, double *first_param, double *second_param, double *third_param, double *fourth_param) const; 01157 01159 01160 protected: 01162 mutable FIBITMAP *_display_dib; 01164 mutable BOOL _bDeleteMe; 01166 FREE_IMAGE_TMO _tmo; 01168 double _tmo_param_1; 01170 double _tmo_param_2; 01172 double _tmo_param_3; 01174 double _tmo_param_4; 01175 }; 01176 01177 #endif // _WIN32 01178 01179 // ---------------------------------------------------------- 01180 01187 class FIP_API fipMemoryIO : public fipObject 01188 { 01189 protected: 01191 FIMEMORY *_hmem; 01192 01193 public : 01203 fipMemoryIO(BYTE *data = NULL, DWORD size_in_bytes = 0); 01204 01209 virtual ~fipMemoryIO(); 01210 01215 void close(); 01216 01219 BOOL isValid() const; 01220 01224 FREE_IMAGE_FORMAT getFileType() const; 01225 01230 operator FIMEMORY*() { 01231 return _hmem; 01232 } 01233 01243 FIBITMAP* load(FREE_IMAGE_FORMAT fif, int flags = 0) const; 01251 FIMULTIBITMAP* loadMultiPage(FREE_IMAGE_FORMAT fif, int flags = 0) const; 01260 BOOL save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, int flags = 0); 01269 BOOL saveMultiPage(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, int flags = 0); 01278 unsigned read(void *buffer, unsigned size, unsigned count) const; 01287 unsigned write(const void *buffer, unsigned size, unsigned count); 01292 long tell() const; 01297 BOOL seek(long offset, int origin); 01304 BOOL acquire(BYTE **data, DWORD *size_in_bytes); 01306 01307 private: 01309 fipMemoryIO(const fipMemoryIO& src); 01311 fipMemoryIO& operator=(const fipMemoryIO& src); 01312 01313 }; 01314 01315 // ---------------------------------------------------------- 01316 01322 class FIP_API fipMultiPage : public fipObject 01323 { 01324 protected: 01326 FIMULTIBITMAP *_mpage; 01328 BOOL _bMemoryCache; 01329 01330 public: 01335 fipMultiPage(BOOL keep_cache_in_memory = FALSE); 01336 01341 virtual ~fipMultiPage(); 01342 01344 BOOL isValid() const; 01345 01350 operator FIMULTIBITMAP*() { 01351 return _mpage; 01352 } 01353 01363 BOOL open(const char* lpszPathName, BOOL create_new, BOOL read_only, int flags = 0); 01364 01372 BOOL open(fipMemoryIO& memIO, int flags = 0); 01373 01382 BOOL open(FreeImageIO *io, fi_handle handle, int flags = 0); 01383 01390 BOOL close(int flags = 0); 01391 01401 BOOL saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags = 0) const; 01402 01411 BOOL saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flags = 0) const; 01412 01417 int getPageCount() const; 01418 01424 void appendPage(fipImage& image); 01425 01432 void insertPage(int page, fipImage& image); 01433 01439 void deletePage(int page); 01440 01448 BOOL movePage(int target, int source); 01449 01467 FIBITMAP* lockPage(int page); 01468 01475 void unlockPage(fipImage& image, BOOL changed); 01476 01485 BOOL getLockedPageNumbers(int *pages, int *count) const; 01486 }; 01487 01488 // ---------------------------------------------------------- 01489 01495 class FIP_API fipTag : public fipObject 01496 { 01497 protected: 01499 FITAG *_tag; 01500 01501 public: 01508 fipTag(); 01513 virtual ~fipTag(); 01522 BOOL setKeyValue(const char *key, const char *value); 01523 01525 01532 fipTag(const fipTag& tag); 01537 fipTag& operator=(const fipTag& tag); 01543 fipTag& operator=(FITAG *tag); 01545 01551 operator FITAG*() { 01552 return _tag; 01553 } 01554 01556 BOOL isValid() const; 01557 01564 const char *getKey() const; 01569 const char *getDescription() const; 01574 WORD getID() const; 01579 FREE_IMAGE_MDTYPE getType() const; 01584 DWORD getCount() const; 01589 DWORD getLength() const; 01594 const void *getValue() const; 01600 BOOL setKey(const char *key); 01606 BOOL setDescription(const char *description); 01612 BOOL setID(WORD id); 01618 BOOL setType(FREE_IMAGE_MDTYPE type); 01624 BOOL setCount(DWORD count); 01630 BOOL setLength(DWORD length); 01636 BOOL setValue(const void *value); 01637 01639 01645 const char* toString(FREE_IMAGE_MDMODEL model, char *Make = NULL) const; 01646 01647 }; 01648 01675 class FIP_API fipMetadataFind : public fipObject 01676 { 01677 protected: 01679 FIMETADATA *_mdhandle; 01680 01681 public: 01683 BOOL isValid() const; 01684 01686 fipMetadataFind(); 01691 virtual ~fipMetadataFind(); 01701 BOOL findFirstMetadata(FREE_IMAGE_MDMODEL model, fipImage& image, fipTag& tag); 01709 BOOL findNextMetadata(fipTag& tag); 01710 01711 }; 01712 01713 #endif // FREEIMAGEPLUS_H