FreeImagePlus  FreeImage 3.18.0
FreeImagePlus.h
1 // ==========================================================
2 // FreeImagePlus 3
3 //
4 // Design and implementation by
5 // - Hervé Drolon (drolon@infonie.fr)
6 //
7 // This file is part of FreeImage 3
8 //
9 // COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
10 // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
11 // THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
12 // OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
13 // CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
14 // THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
15 // SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
16 // PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
17 // THIS DISCLAIMER.
18 //
19 // Use at your own risk!
20 // ==========================================================
21 
22 #ifndef FREEIMAGEPLUS_H
23 #define FREEIMAGEPLUS_H
24 
25 #ifdef _WIN32
26 #include <windows.h>
27 #endif // _WIN32
28 #include "FreeImage.h"
29 
30 
31 // Compiler options ---------------------------------------------------------
32 
33 #if defined(FREEIMAGE_LIB)
34  #define FIP_API
35  #define FIP_CALLCONV
36 #else
37  #if defined(_WIN32) || defined(__WIN32__)
38  #define WIN32_LEAN_AND_MEAN
39  #define FIP_CALLCONV __stdcall
40  // The following ifdef block is the standard way of creating macros which make exporting
41  // from a DLL simpler. All files within this DLL are compiled with the FIP_EXPORTS
42  // symbol defined on the command line. this symbol should not be defined on any project
43  // that uses this DLL. This way any other project whose source files include this file see
44  // FIP_API functions as being imported from a DLL, wheras this DLL sees symbols
45  // defined with this macro as being exported.
46  #ifdef FIP_EXPORTS
47  #define FIP_API __declspec(dllexport)
48  #else
49  #define FIP_API __declspec(dllimport)
50  #endif // FIP_EXPORTS
51  #else
52  // try the gcc visibility support (see http://gcc.gnu.org/wiki/Visibility)
53  #if defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
54  #ifndef GCC_HASCLASSVISIBILITY
55  #define GCC_HASCLASSVISIBILITY
56  #endif
57  #endif
58  #define FIP_CALLCONV
59  #if defined(GCC_HASCLASSVISIBILITY)
60  #define FIP_API __attribute__ ((visibility("default")))
61  #else
62  #define FIP_API
63  #endif
64  #endif // WIN32 / !WIN32
65 #endif // FREEIMAGE_LIB
66 
68 
69 // ----------------------------------------------------------
70 
76 class FIP_API fipObject
77 {
78 public:
80  virtual ~fipObject(){};
81 
84  virtual BOOL isValid() const = 0;
87 };
88 
89 // ----------------------------------------------------------
90 
91 class fipMemoryIO;
92 class fipMultiPage;
93 class fipTag;
94 
103 class FIP_API fipImage : public fipObject
104 {
105 protected:
107  FIBITMAP *_dib;
109  FREE_IMAGE_FORMAT _fif;
111  mutable BOOL _bHasChanged;
112 
113 public:
114  friend class fipMultiPage;
115 
116 public:
117 
124  fipImage(FREE_IMAGE_TYPE image_type = FIT_BITMAP, unsigned width = 0, unsigned height = 0, unsigned bpp = 0);
126  virtual ~fipImage();
131  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);
133  virtual void clear();
135 
142  fipImage(const fipImage& src);
147  fipImage& operator=(const fipImage& src);
153  fipImage& operator=(FIBITMAP *dib);
154 
155 
168  BOOL copySubImage(fipImage& dst, int left, int top, int right, int bottom) const;
169 
183  BOOL pasteSubImage(fipImage& src, int left, int top, int alpha = 256);
184 
195  BOOL crop(int left, int top, int right, int bottom);
196 
215  BOOL createView(fipImage& dynamicView, unsigned left, unsigned top, unsigned right, unsigned bottom);
216 
218 
228  static FREE_IMAGE_FORMAT identifyFIF(const char* lpszPathName);
229 
234  static FREE_IMAGE_FORMAT identifyFIFU(const wchar_t* lpszPathName);
235 
243  static FREE_IMAGE_FORMAT identifyFIFFromHandle(FreeImageIO *io, fi_handle handle);
244 
251  static FREE_IMAGE_FORMAT identifyFIFFromMemory(FIMEMORY *hmem);
252 
254 
255 
268  BOOL load(const char* lpszPathName, int flag = 0);
269 
278  BOOL load(FREE_IMAGE_FORMAT fif, const char* lpszPathName, int flag = 0);
279 
284  BOOL loadU(const wchar_t* lpszPathName, int flag = 0);
285 
290  BOOL loadU(FREE_IMAGE_FORMAT fif, const wchar_t* lpszPathName, int flag = 0);
291 
300  BOOL loadFromHandle(FreeImageIO *io, fi_handle handle, int flag = 0);
301 
309  BOOL loadFromMemory(fipMemoryIO& memIO, int flag = 0);
310 
319  BOOL loadFromMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flag = 0);
320 
329  BOOL save(const char* lpszPathName, int flag = 0);
330 
339  BOOL save(FREE_IMAGE_FORMAT fif, const char* lpszPathName, int flag = 0);
340 
345  BOOL saveU(const wchar_t* lpszPathName, int flag = 0);
346 
351  BOOL saveU(FREE_IMAGE_FORMAT fif, const wchar_t* lpszPathName, int flag = 0);
352 
362  BOOL saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flag = 0);
363 
372  BOOL saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flag = 0);
373 
375 
380 
385  FREE_IMAGE_TYPE getImageType() const;
386 
390  FREE_IMAGE_FORMAT getFIF() const;
391 
396  unsigned getWidth() const;
397 
402  unsigned getHeight() const;
403 
408  unsigned getScanWidth() const;
409 
422  operator FIBITMAP*() {
423  return _dib;
424  }
425 
427  BOOL isValid() const;
428 
433  const BITMAPINFO* getInfo() const;
434 
439  const BITMAPINFOHEADER* getInfoHeader() const;
440 
446  unsigned getImageSize() const;
447 
452  unsigned getImageMemorySize() const;
453 
459  unsigned getBitsPerPixel() const;
460 
466  unsigned getLine() const;
467 
472  double getHorizontalResolution() const;
473 
478  double getVerticalResolution() const;
479 
484  void setHorizontalResolution(double value);
485 
490  void setVerticalResolution(double value);
491 
493 
500  RGBQUAD* getPalette() const;
501 
506  unsigned getPaletteSize() const;
507 
512  unsigned getColorsUsed() const;
513 
518  FREE_IMAGE_COLOR_TYPE getColorType() const;
519 
524  BOOL isGrayscale() const;
526 
529 
535  BOOL getThumbnail(fipImage& image) const;
536 
542  BOOL setThumbnail(const fipImage& image);
543 
549  BOOL hasThumbnail() const;
550 
556  BOOL clearThumbnail();
557 
559 
562 
571  BYTE* accessPixels() const;
572 
578  BYTE* getScanLine(unsigned scanline) const;
579 
588  BOOL getPixelIndex(unsigned x, unsigned y, BYTE *value) const;
589 
598  BOOL getPixelColor(unsigned x, unsigned y, RGBQUAD *value) const;
599 
608  BOOL setPixelIndex(unsigned x, unsigned y, BYTE *value);
609 
618  BOOL setPixelColor(unsigned x, unsigned y, RGBQUAD *value);
619 
621 
633  BOOL convertToType(FREE_IMAGE_TYPE image_type, BOOL scale_linear = TRUE);
634 
641  BOOL threshold(BYTE T);
642 
649  BOOL dither(FREE_IMAGE_DITHER algorithm);
650 
656  BOOL convertTo4Bits();
657 
663  BOOL convertTo8Bits();
664 
671  BOOL convertToGrayscale();
672 
680  BOOL colorQuantize(FREE_IMAGE_QUANTIZE algorithm);
681 
687  BOOL convertTo16Bits555();
688 
694  BOOL convertTo16Bits565();
695 
701  BOOL convertTo24Bits();
702 
708  BOOL convertTo32Bits();
709 
715  BOOL convertToFloat();
716 
722  BOOL convertToRGBF();
723 
729  BOOL convertToRGBAF();
730 
736  BOOL convertToUINT16();
737 
743  BOOL convertToRGB16();
744 
750  BOOL convertToRGBA16();
751 
762  BOOL toneMapping(FREE_IMAGE_TMO tmo, double first_param = 0, double second_param = 0, double third_param = 1, double fourth_param = 0);
763 
765 
768 
773  BOOL isTransparent() const;
774 
780  unsigned getTransparencyCount() const;
781 
787  BYTE* getTransparencyTable() const;
788 
793  void setTransparencyTable(BYTE *table, int count);
794 
799  BOOL hasFileBkColor() const;
800 
809  BOOL getFileBkColor(RGBQUAD *bkcolor) const;
810 
819  BOOL setFileBkColor(RGBQUAD *bkcolor);
821 
830  BOOL getChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel) const;
831 
839  BOOL setChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel);
840 
849  BOOL splitChannels(fipImage& RedChannel, fipImage& GreenChannel, fipImage& BlueChannel);
850 
858  BOOL combineChannels(fipImage& red, fipImage& green, fipImage& blue);
860 
874  BOOL rotateEx(double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask);
875 
883  BOOL rotate(double angle, const void *bkcolor = NULL);
884 
889  BOOL flipHorizontal();
890 
895  BOOL flipVertical();
897 
905  BOOL invert();
906 
920  BOOL adjustCurve(BYTE *LUT, FREE_IMAGE_COLOR_CHANNEL channel);
921 
928  BOOL adjustGamma(double gamma);
929 
937  BOOL adjustBrightness(double percentage);
938 
946  BOOL adjustContrast(double percentage);
947 
958  BOOL adjustBrightnessContrastGamma(double brightness, double contrast, double gamma);
959 
970  BOOL getHistogram(DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel = FICC_BLACK) const;
972 
975 
984  BOOL rescale(unsigned new_width, unsigned new_height, FREE_IMAGE_FILTER filter);
985 
993  BOOL makeThumbnail(unsigned max_size, BOOL convert = TRUE);
995 
1005  void setModified(BOOL bStatus = TRUE) {
1006  _bHasChanged = bStatus;
1007  }
1008 
1014  BOOL isModified() {
1015  return _bHasChanged;
1016  }
1018 
1026  unsigned getMetadataCount(FREE_IMAGE_MDMODEL model) const;
1035  BOOL getMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag) const;
1055  BOOL setMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag);
1056 
1060  void clearMetadata();
1062 
1063  protected:
1066  BOOL replace(FIBITMAP *new_dib);
1068 
1069 };
1070 
1071 // ----------------------------------------------------------
1072 
1084 #ifdef _WIN32
1085 
1086 class FIP_API fipWinImage : public fipImage
1087 {
1088 public:
1091  fipWinImage(FREE_IMAGE_TYPE image_type = FIT_BITMAP, unsigned width = 0, unsigned height = 0, unsigned bpp = 0);
1093 
1095  virtual ~fipWinImage();
1096 
1098  virtual void clear();
1099 
1101  BOOL isValid() const;
1103 
1106 
1113  fipWinImage& operator=(const fipImage& src);
1114 
1121  fipWinImage& operator=(const fipWinImage& src);
1122 
1129  HANDLE copyToHandle() const;
1130 
1137  BOOL copyFromHandle(HANDLE hMem);
1138 
1143  BOOL copyFromBitmap(HBITMAP hbmp);
1145 
1154  BOOL copyToClipboard(HWND hWndNewOwner) const;
1155 
1160  BOOL pasteFromClipboard();
1162 
1170  BOOL captureWindow(HWND hWndApplicationWindow, HWND hWndSelectedWindow);
1172 
1173 
1176 
1185  void draw(HDC hDC, RECT& rcDest) const {
1186  drawEx(hDC, rcDest, FALSE, NULL, NULL);
1187  }
1188 
1206  void drawEx(HDC hDC, RECT& rcDest, BOOL useFileBkg = FALSE, RGBQUAD *appBkColor = NULL, FIBITMAP *bg = NULL) const;
1207 
1218  void setToneMappingOperator(FREE_IMAGE_TMO tmo, double first_param = 0, double second_param = 0, double third_param = 1, double fourth_param = 0);
1219 
1229  void getToneMappingOperator(FREE_IMAGE_TMO *tmo, double *first_param, double *second_param, double *third_param, double *fourth_param) const;
1230 
1232 
1233 protected:
1235  mutable FIBITMAP *_display_dib;
1237  mutable BOOL _bDeleteMe;
1239  FREE_IMAGE_TMO _tmo;
1248 };
1249 
1250 #endif // _WIN32
1251 
1252 // ----------------------------------------------------------
1253 
1260 class FIP_API fipMemoryIO : public fipObject
1261 {
1262 protected:
1264  FIMEMORY *_hmem;
1265 
1266 public :
1276  fipMemoryIO(BYTE *data = NULL, DWORD size_in_bytes = 0);
1277 
1282  virtual ~fipMemoryIO();
1283 
1288  void close();
1289 
1292  BOOL isValid() const;
1293 
1297  FREE_IMAGE_FORMAT getFileType() const;
1298 
1303  operator FIMEMORY*() {
1304  return _hmem;
1305  }
1306 
1316  FIBITMAP* load(FREE_IMAGE_FORMAT fif, int flags = 0) const;
1324  FIMULTIBITMAP* loadMultiPage(FREE_IMAGE_FORMAT fif, int flags = 0) const;
1333  BOOL save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, int flags = 0);
1342  BOOL saveMultiPage(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, int flags = 0);
1351  unsigned read(void *buffer, unsigned size, unsigned count) const;
1360  unsigned write(const void *buffer, unsigned size, unsigned count);
1365  long tell() const;
1370  BOOL seek(long offset, int origin);
1377  BOOL acquire(BYTE **data, DWORD *size_in_bytes);
1379 
1380 private:
1382  fipMemoryIO(const fipMemoryIO& src);
1384  fipMemoryIO& operator=(const fipMemoryIO& src);
1385 
1386 };
1387 
1388 // ----------------------------------------------------------
1389 
1395 class FIP_API fipMultiPage : public fipObject
1396 {
1397 protected:
1399  FIMULTIBITMAP *_mpage;
1402 
1403 public:
1408  fipMultiPage(BOOL keep_cache_in_memory = FALSE);
1409 
1414  virtual ~fipMultiPage();
1415 
1417  BOOL isValid() const;
1418 
1423  operator FIMULTIBITMAP*() {
1424  return _mpage;
1425  }
1426 
1436  BOOL open(const char* lpszPathName, BOOL create_new, BOOL read_only, int flags = 0);
1437 
1445  BOOL open(fipMemoryIO& memIO, int flags = 0);
1446 
1455  BOOL open(FreeImageIO *io, fi_handle handle, int flags = 0);
1456 
1463  BOOL close(int flags = 0);
1464 
1474  BOOL saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags = 0) const;
1475 
1484  BOOL saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flags = 0) const;
1485 
1490  int getPageCount() const;
1491 
1497  void appendPage(fipImage& image);
1498 
1505  void insertPage(int page, fipImage& image);
1506 
1512  void deletePage(int page);
1513 
1521  BOOL movePage(int target, int source);
1522 
1540  FIBITMAP* lockPage(int page);
1541 
1548  void unlockPage(fipImage& image, BOOL changed);
1549 
1558  BOOL getLockedPageNumbers(int *pages, int *count) const;
1559 };
1560 
1561 // ----------------------------------------------------------
1562 
1568 class FIP_API fipTag : public fipObject
1569 {
1570 protected:
1572  FITAG *_tag;
1573 
1574 public:
1581  fipTag();
1586  virtual ~fipTag();
1595  BOOL setKeyValue(const char *key, const char *value);
1596 
1598 
1605  fipTag(const fipTag& tag);
1610  fipTag& operator=(const fipTag& tag);
1616  fipTag& operator=(FITAG *tag);
1618 
1624  operator FITAG*() {
1625  return _tag;
1626  }
1627 
1629  BOOL isValid() const;
1630 
1637  const char *getKey() const;
1642  const char *getDescription() const;
1647  WORD getID() const;
1652  FREE_IMAGE_MDTYPE getType() const;
1657  DWORD getCount() const;
1662  DWORD getLength() const;
1667  const void *getValue() const;
1673  BOOL setKey(const char *key);
1679  BOOL setDescription(const char *description);
1685  BOOL setID(WORD id);
1691  BOOL setType(FREE_IMAGE_MDTYPE type);
1697  BOOL setCount(DWORD count);
1703  BOOL setLength(DWORD length);
1709  BOOL setValue(const void *value);
1710 
1712 
1718  const char* toString(FREE_IMAGE_MDMODEL model, char *Make = NULL) const;
1719 
1720 };
1721 
1748 class FIP_API fipMetadataFind : public fipObject
1749 {
1750 protected:
1752  FIMETADATA *_mdhandle;
1753 
1754 public:
1756  BOOL isValid() const;
1757 
1759  fipMetadataFind();
1764  virtual ~fipMetadataFind();
1774  BOOL findFirstMetadata(FREE_IMAGE_MDMODEL model, fipImage& image, fipTag& tag);
1782  BOOL findNextMetadata(fipTag& tag);
1783 
1784 };
1785 
1786 #endif // FREEIMAGEPLUS_H
Multi-page file stream.
Definition: FreeImagePlus.h:1395
FREE_IMAGE_FORMAT _fif
Original (or last saved) fif format if available, FIF_UNKNOWN otherwise.
Definition: FreeImagePlus.h:109
Definition: FreeImage.h:179
Memory handle.
Definition: FreeImagePlus.h:1260
double _tmo_param_4
fourth tone mapping algorithm parameter
Definition: FreeImagePlus.h:1247
fipImage & operator=(const fipImage &src)
Copy constructor.
BOOL _bMemoryCache
TRUE when using a memory cache, FALSE otherwise.
Definition: FreeImagePlus.h:1401
BOOL saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags=0) const
Saves a multi-page image using the specified FreeImageIO struct and fi_handle, and an optional flag...
Abstract base class for all objects used by the library.
Definition: FreeImagePlus.h:76
FREE_IMAGE_TMO _tmo
tone mapping operator
Definition: FreeImagePlus.h:1239
Definition: FreeImage.h:210
double _tmo_param_1
first tone mapping algorithm parameter
Definition: FreeImagePlus.h:1241
BOOL _bHasChanged
TRUE whenever the display need to be refreshed.
Definition: FreeImagePlus.h:111
FIBITMAP * _display_dib
DIB used for display (this allow to display non-standard bitmaps)
Definition: FreeImagePlus.h:1235
BOOL saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO &memIO, int flags=0) const
Saves a multi-page image using the specified memory stream and an optional flag.
BOOL _bDeleteMe
remember to delete _display_dib
Definition: FreeImagePlus.h:1237
FIMULTIBITMAP * _mpage
Pointer to a multi-page file stream.
Definition: FreeImagePlus.h:1399
FIMETADATA * _mdhandle
Pointer to a search handle.
Definition: FreeImagePlus.h:1752
A class designed for MS Windows (TM) platforms.
Definition: FreeImagePlus.h:1086
virtual void clear()
Destroy image data.
BOOL isModified()
Get the image status.
Definition: FreeImagePlus.h:1014
virtual ~fipObject()
Destructor.
Definition: FreeImagePlus.h:80
double _tmo_param_2
second tone mapping algorithm parameter
Definition: FreeImagePlus.h:1243
A class used to manage all photo related images and all image types used by the library.
Definition: FreeImagePlus.h:103
void draw(HDC hDC, RECT &rcDest) const
Draw (stretch) the image on a HDC, using StretchDIBits.
Definition: FreeImagePlus.h:1185
FITAG * _tag
Pointer to a FreeImage tag.
Definition: FreeImagePlus.h:1572
FIBITMAP * _dib
DIB data.
Definition: FreeImagePlus.h:107
virtual BOOL isValid() const =0
Returns TRUE if the object is allocated, FALSE otherwise.
double _tmo_param_3
third tone mapping algorithm parameter
Definition: FreeImagePlus.h:1245
BOOL isValid() const
Returns TRUE if the image is allocated, FALSE otherwise.
void setModified(BOOL bStatus=TRUE)
Set the image status as &#39;modified&#39;.
Definition: FreeImagePlus.h:1005
FIMEMORY * _hmem
Pointer to a memory stream.
Definition: FreeImagePlus.h:1264
FreeImage Tag.
Definition: FreeImagePlus.h:1568
Definition: FreeImage.h:224
Metadata iterator.
Definition: FreeImagePlus.h:1748