# FreeImagePlus

# FreeImagePlus.h

    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         LONG getImageSize() const;
    00378
    00384         unsigned getBitsPerPixel() const;
    00385
    00391         unsigned 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         unsigned getPaletteSize() const;
    00432
    00437         unsigned 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(unsigned 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(unsigned new_width, unsigned new_height, FREE_IMAGE_FILTER filter);
    00842
    00850         BOOL makeThumbnail(unsigned 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, unsigned width = 0, unsigned height = 0, unsigned 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
    01141         void close();
    01142
    01145         BOOL isValid() const;
    01146
    01150         FREE_IMAGE_FORMAT getFileType() const;
    01151
    01156         operator FIMEMORY*() {
    01157                 return _hmem;
    01158         }
    01159
    01169         FIBITMAP* load(FREE_IMAGE_FORMAT fif, int flags = 0) const;
    01177         FIMULTIBITMAP* loadMultiPage(FREE_IMAGE_FORMAT fif, int flags = 0) const;
    01186         BOOL save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, int flags = 0);
    01195         BOOL saveMultiPage(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, int flags = 0);
    01204         unsigned read(void *buffer, unsigned size, unsigned count) const;
    01213         unsigned write(const void *buffer, unsigned size, unsigned count);
    01218         long tell() const;
    01223         BOOL seek(long offset, int origin);
    01230         BOOL acquire(BYTE **data, DWORD *size_in_bytes);
    01232
    01233 private:
    01235         fipMemoryIO(const fipMemoryIO& src);
    01237         fipMemoryIO& operator=(const fipMemoryIO& src);
    01238
    01239 };
    01240
    01241 // ----------------------------------------------------------
    01242
    01248 class FIP_API fipMultiPage : public fipObject
    01249 {
    01250 protected:
    01252         FIMULTIBITMAP *_mpage;
    01254         BOOL _bMemoryCache;
    01255
    01256 public:
    01261         fipMultiPage(BOOL keep_cache_in_memory = FALSE);
    01262
    01267         virtual ~fipMultiPage();
    01268
    01270         BOOL isValid() const;
    01271
    01276         operator FIMULTIBITMAP*() {
    01277                 return _mpage;
    01278         }
    01279
    01289         BOOL open(const char* lpszPathName, BOOL create_new, BOOL read_only, int flags = 0);
    01290
    01298         BOOL open(fipMemoryIO& memIO, int flags = 0);
    01299
    01308         BOOL open(FreeImageIO *io, fi_handle handle, int flags = 0);
    01309
    01316         BOOL close(int flags = 0);
    01317
    01327         BOOL saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags = 0) const;
    01328
    01337         BOOL saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flags = 0) const;
    01338
    01343         int getPageCount() const;
    01344
    01350         void appendPage(fipImage& image);
    01351
    01358         void insertPage(int page, fipImage& image);
    01359
    01365         void deletePage(int page);
    01366
    01374         BOOL movePage(int target, int source);
    01375
    01393         FIBITMAP* lockPage(int page);
    01394
    01401         void unlockPage(fipImage& image, BOOL changed);
    01402
    01411         BOOL getLockedPageNumbers(int *pages, int *count) const;
    01412 };
    01413
    01414 // ----------------------------------------------------------
    01415
    01421 class FIP_API fipTag : public fipObject
    01422 {
    01423 protected:
    01425         FITAG *_tag;
    01426
    01427 public:
    01434         fipTag();
    01439         virtual ~fipTag();
    01448         BOOL setKeyValue(const char *key, const char *value);
    01449
    01451
    01458         fipTag(const fipTag& tag);
    01463         fipTag& operator=(const fipTag& tag);
    01469         fipTag& operator=(FITAG *tag);
    01471
    01477         operator FITAG*() {
    01478                 return _tag;
    01479         }
    01480
    01482         BOOL isValid() const;
    01483
    01490         const char *getKey() const;
    01495         const char *getDescription() const;
    01500         WORD getID() const;
    01505         FREE_IMAGE_MDTYPE getType() const;
    01510         DWORD getCount() const;
    01515         DWORD getLength() const;
    01520         const void *getValue() const;
    01526         BOOL setKey(const char *key);
    01532         BOOL setDescription(const char *description);
    01538         BOOL setID(WORD id);
    01544         BOOL setType(FREE_IMAGE_MDTYPE type);
    01550         BOOL setCount(DWORD count);
    01556         BOOL setLength(DWORD length);
    01562         BOOL setValue(const void *value);
    01563
    01565
    01571         const char* toString(FREE_IMAGE_MDMODEL model, char *Make = NULL) const;
    01572
    01573 };
    01574
    01601 class FIP_API fipMetadataFind : public fipObject
    01602 {
    01603 protected:
    01605         FIMETADATA *_mdhandle;
    01606
    01607 public:
    01609         BOOL isValid() const;
    01610
    01612         fipMetadataFind();
    01617         virtual ~fipMetadataFind();
    01627         BOOL findFirstMetadata(FREE_IMAGE_MDMODEL model, fipImage& image, fipTag& tag);
    01635         BOOL findNextMetadata(fipTag& tag);
    01636
    01637 };
    01638
    01639 #endif  // FREEIMAGEPLUS_H