FreeImagePlus  - FreeImage 3.17.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 
198 
208  static FREE_IMAGE_FORMAT identifyFIF(const char* lpszPathName);
209 
214  static FREE_IMAGE_FORMAT identifyFIFU(const wchar_t* lpszPathName);
215 
223  static FREE_IMAGE_FORMAT identifyFIFFromHandle(FreeImageIO *io, fi_handle handle);
224 
231  static FREE_IMAGE_FORMAT identifyFIFFromMemory(FIMEMORY *hmem);
232 
234 
235 
247  BOOL load(const char* lpszPathName, int flag = 0);
248 
253  BOOL loadU(const wchar_t* lpszPathName, int flag = 0);
254 
263  BOOL loadFromHandle(FreeImageIO *io, fi_handle handle, int flag = 0);
264 
272  BOOL loadFromMemory(fipMemoryIO& memIO, int flag = 0);
273 
281  BOOL save(const char* lpszPathName, int flag = 0) const;
282 
287  BOOL saveU(const wchar_t* lpszPathName, int flag = 0) const;
288 
298  BOOL saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flag = 0) const;
299 
308  BOOL saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flag = 0) const;
309 
311 
316 
321  FREE_IMAGE_TYPE getImageType() const;
322 
327  unsigned getWidth() const;
328 
333  unsigned getHeight() const;
334 
339  unsigned getScanWidth() const;
340 
353  operator FIBITMAP*() {
354  return _dib;
355  }
356 
358  BOOL isValid() const;
359 
364  BITMAPINFO* getInfo() const;
365 
370  BITMAPINFOHEADER* getInfoHeader() const;
371 
377  unsigned getImageSize() const;
378 
383  unsigned getImageMemorySize() const;
384 
390  unsigned getBitsPerPixel() const;
391 
397  unsigned getLine() const;
398 
403  double getHorizontalResolution() const;
404 
409  double getVerticalResolution() const;
410 
415  void setHorizontalResolution(double value);
416 
421  void setVerticalResolution(double value);
422 
424 
431  RGBQUAD* getPalette() const;
432 
437  unsigned getPaletteSize() const;
438 
443  unsigned getColorsUsed() const;
444 
449  FREE_IMAGE_COLOR_TYPE getColorType() const;
450 
455  BOOL isGrayscale() const;
457 
460 
466  BOOL getThumbnail(fipImage& image) const;
467 
473  BOOL setThumbnail(const fipImage& image);
474 
480  BOOL hasThumbnail() const;
481 
487  BOOL clearThumbnail();
488 
490 
493 
502  BYTE* accessPixels() const;
503 
509  BYTE* getScanLine(unsigned scanline) const;
510 
519  BOOL getPixelIndex(unsigned x, unsigned y, BYTE *value) const;
520 
529  BOOL getPixelColor(unsigned x, unsigned y, RGBQUAD *value) const;
530 
539  BOOL setPixelIndex(unsigned x, unsigned y, BYTE *value);
540 
549  BOOL setPixelColor(unsigned x, unsigned y, RGBQUAD *value);
550 
552 
564  BOOL convertToType(FREE_IMAGE_TYPE image_type, BOOL scale_linear = TRUE);
565 
572  BOOL threshold(BYTE T);
573 
580  BOOL dither(FREE_IMAGE_DITHER algorithm);
581 
587  BOOL convertTo4Bits();
588 
594  BOOL convertTo8Bits();
595 
602  BOOL convertToGrayscale();
603 
611  BOOL colorQuantize(FREE_IMAGE_QUANTIZE algorithm);
612 
618  BOOL convertTo16Bits555();
619 
625  BOOL convertTo16Bits565();
626 
632  BOOL convertTo24Bits();
633 
639  BOOL convertTo32Bits();
640 
646  BOOL convertToFloat();
647 
653  BOOL convertToRGBF();
654 
660  BOOL convertToRGBAF();
661 
667  BOOL convertToUINT16();
668 
674  BOOL convertToRGB16();
675 
681  BOOL convertToRGBA16();
682 
693  BOOL toneMapping(FREE_IMAGE_TMO tmo, double first_param = 0, double second_param = 0, double third_param = 1, double fourth_param = 0);
694 
696 
699 
704  BOOL isTransparent() const;
705 
711  unsigned getTransparencyCount() const;
712 
718  BYTE* getTransparencyTable() const;
719 
724  void setTransparencyTable(BYTE *table, int count);
725 
730  BOOL hasFileBkColor() const;
731 
740  BOOL getFileBkColor(RGBQUAD *bkcolor) const;
741 
750  BOOL setFileBkColor(RGBQUAD *bkcolor);
752 
761  BOOL getChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel) const;
762 
770  BOOL setChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel);
771 
780  BOOL splitChannels(fipImage& RedChannel, fipImage& GreenChannel, fipImage& BlueChannel);
781 
789  BOOL combineChannels(fipImage& red, fipImage& green, fipImage& blue);
791 
805  BOOL rotateEx(double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask);
806 
814  BOOL rotate(double angle, const void *bkcolor = NULL);
815 
820  BOOL flipHorizontal();
821 
826  BOOL flipVertical();
828 
836  BOOL invert();
837 
851  BOOL adjustCurve(BYTE *LUT, FREE_IMAGE_COLOR_CHANNEL channel);
852 
859  BOOL adjustGamma(double gamma);
860 
868  BOOL adjustBrightness(double percentage);
869 
877  BOOL adjustContrast(double percentage);
878 
889  BOOL adjustBrightnessContrastGamma(double brightness, double contrast, double gamma);
890 
901  BOOL getHistogram(DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel = FICC_BLACK) const;
903 
906 
915  BOOL rescale(unsigned new_width, unsigned new_height, FREE_IMAGE_FILTER filter);
916 
924  BOOL makeThumbnail(unsigned max_size, BOOL convert = TRUE);
926 
936  void setModified(BOOL bStatus = TRUE) {
937  _bHasChanged = bStatus;
938  }
939 
945  BOOL isModified() {
946  return _bHasChanged;
947  }
949 
957  unsigned getMetadataCount(FREE_IMAGE_MDMODEL model) const;
966  BOOL getMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag) const;
986  BOOL setMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag);
988 
989 
990  protected:
993  BOOL replace(FIBITMAP *new_dib);
995 
996 };
997 
998 // ----------------------------------------------------------
999 
1011 #ifdef _WIN32
1012 
1013 class FIP_API fipWinImage : public fipImage
1014 {
1015 public:
1018  fipWinImage(FREE_IMAGE_TYPE image_type = FIT_BITMAP, unsigned width = 0, unsigned height = 0, unsigned bpp = 0);
1020 
1022  virtual ~fipWinImage();
1023 
1025  virtual void clear();
1026 
1028  BOOL isValid() const;
1030 
1033 
1040  fipWinImage& operator=(const fipImage& src);
1041 
1048  fipWinImage& operator=(const fipWinImage& src);
1049 
1056  HANDLE copyToHandle() const;
1057 
1064  BOOL copyFromHandle(HANDLE hMem);
1065 
1070  BOOL copyFromBitmap(HBITMAP hbmp);
1072 
1081  BOOL copyToClipboard(HWND hWndNewOwner) const;
1082 
1087  BOOL pasteFromClipboard();
1089 
1097  BOOL captureWindow(HWND hWndApplicationWindow, HWND hWndSelectedWindow);
1099 
1100 
1103 
1112  void draw(HDC hDC, RECT& rcDest) const {
1113  drawEx(hDC, rcDest, FALSE, NULL, NULL);
1114  }
1115 
1133  void drawEx(HDC hDC, RECT& rcDest, BOOL useFileBkg = FALSE, RGBQUAD *appBkColor = NULL, FIBITMAP *bg = NULL) const;
1134 
1145  void setToneMappingOperator(FREE_IMAGE_TMO tmo, double first_param = 0, double second_param = 0, double third_param = 1, double fourth_param = 0);
1146 
1156  void getToneMappingOperator(FREE_IMAGE_TMO *tmo, double *first_param, double *second_param, double *third_param, double *fourth_param) const;
1157 
1159 
1160 protected:
1162  mutable FIBITMAP *_display_dib;
1164  mutable BOOL _bDeleteMe;
1166  FREE_IMAGE_TMO _tmo;
1175 };
1176 
1177 #endif // _WIN32
1178 
1179 // ----------------------------------------------------------
1180 
1187 class FIP_API fipMemoryIO : public fipObject
1188 {
1189 protected:
1191  FIMEMORY *_hmem;
1192 
1193 public :
1203  fipMemoryIO(BYTE *data = NULL, DWORD size_in_bytes = 0);
1204 
1209  virtual ~fipMemoryIO();
1210 
1215  void close();
1216 
1219  BOOL isValid() const;
1220 
1224  FREE_IMAGE_FORMAT getFileType() const;
1225 
1230  operator FIMEMORY*() {
1231  return _hmem;
1232  }
1233 
1243  FIBITMAP* load(FREE_IMAGE_FORMAT fif, int flags = 0) const;
1251  FIMULTIBITMAP* loadMultiPage(FREE_IMAGE_FORMAT fif, int flags = 0) const;
1260  BOOL save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, int flags = 0);
1269  BOOL saveMultiPage(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, int flags = 0);
1278  unsigned read(void *buffer, unsigned size, unsigned count) const;
1287  unsigned write(const void *buffer, unsigned size, unsigned count);
1292  long tell() const;
1297  BOOL seek(long offset, int origin);
1304  BOOL acquire(BYTE **data, DWORD *size_in_bytes);
1306 
1307 private:
1309  fipMemoryIO(const fipMemoryIO& src);
1311  fipMemoryIO& operator=(const fipMemoryIO& src);
1312 
1313 };
1314 
1315 // ----------------------------------------------------------
1316 
1322 class FIP_API fipMultiPage : public fipObject
1323 {
1324 protected:
1326  FIMULTIBITMAP *_mpage;
1329 
1330 public:
1335  fipMultiPage(BOOL keep_cache_in_memory = FALSE);
1336 
1341  virtual ~fipMultiPage();
1342 
1344  BOOL isValid() const;
1345 
1350  operator FIMULTIBITMAP*() {
1351  return _mpage;
1352  }
1353 
1363  BOOL open(const char* lpszPathName, BOOL create_new, BOOL read_only, int flags = 0);
1364 
1372  BOOL open(fipMemoryIO& memIO, int flags = 0);
1373 
1382  BOOL open(FreeImageIO *io, fi_handle handle, int flags = 0);
1383 
1390  BOOL close(int flags = 0);
1391 
1401  BOOL saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags = 0) const;
1402 
1411  BOOL saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flags = 0) const;
1412 
1417  int getPageCount() const;
1418 
1424  void appendPage(fipImage& image);
1425 
1432  void insertPage(int page, fipImage& image);
1433 
1439  void deletePage(int page);
1440 
1448  BOOL movePage(int target, int source);
1449 
1467  FIBITMAP* lockPage(int page);
1468 
1475  void unlockPage(fipImage& image, BOOL changed);
1476 
1485  BOOL getLockedPageNumbers(int *pages, int *count) const;
1486 };
1487 
1488 // ----------------------------------------------------------
1489 
1495 class FIP_API fipTag : public fipObject
1496 {
1497 protected:
1499  FITAG *_tag;
1500 
1501 public:
1508  fipTag();
1513  virtual ~fipTag();
1522  BOOL setKeyValue(const char *key, const char *value);
1523 
1525 
1532  fipTag(const fipTag& tag);
1537  fipTag& operator=(const fipTag& tag);
1543  fipTag& operator=(FITAG *tag);
1545 
1551  operator FITAG*() {
1552  return _tag;
1553  }
1554 
1556  BOOL isValid() const;
1557 
1564  const char *getKey() const;
1569  const char *getDescription() const;
1574  WORD getID() const;
1579  FREE_IMAGE_MDTYPE getType() const;
1584  DWORD getCount() const;
1589  DWORD getLength() const;
1594  const void *getValue() const;
1600  BOOL setKey(const char *key);
1606  BOOL setDescription(const char *description);
1612  BOOL setID(WORD id);
1618  BOOL setType(FREE_IMAGE_MDTYPE type);
1624  BOOL setCount(DWORD count);
1630  BOOL setLength(DWORD length);
1636  BOOL setValue(const void *value);
1637 
1639 
1645  const char* toString(FREE_IMAGE_MDMODEL model, char *Make = NULL) const;
1646 
1647 };
1648 
1675 class FIP_API fipMetadataFind : public fipObject
1676 {
1677 protected:
1679  FIMETADATA *_mdhandle;
1680 
1681 public:
1683  BOOL isValid() const;
1684 
1686  fipMetadataFind();
1691  virtual ~fipMetadataFind();
1701  BOOL findFirstMetadata(FREE_IMAGE_MDMODEL model, fipImage& image, fipTag& tag);
1709  BOOL findNextMetadata(fipTag& tag);
1710 
1711 };
1712 
1713 #endif // FREEIMAGEPLUS_H
Multi-page file stream.
Definition: FreeImagePlus.h:1322
FREE_IMAGE_FORMAT _fif
Original (or last saved) fif format if available, FIF_UNKNOWN otherwise.
Definition: FreeImagePlus.h:109
Definition: FreeImage.h:180
Memory handle.
Definition: FreeImagePlus.h:1187
double _tmo_param_4
fourth tone mapping algorithm parameter
Definition: FreeImagePlus.h:1174
fipImage & operator=(const fipImage &src)
Copy constructor
BOOL _bMemoryCache
TRUE when using a memory cache, FALSE otherwise.
Definition: FreeImagePlus.h:1328
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:1166
Definition: FreeImage.h:211
double _tmo_param_1
first tone mapping algorithm parameter
Definition: FreeImagePlus.h:1168
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:1162
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:1164
FIMULTIBITMAP * _mpage
Pointer to a multi-page file stream.
Definition: FreeImagePlus.h:1326
FIMETADATA * _mdhandle
Pointer to a search handle.
Definition: FreeImagePlus.h:1679
A class designed for MS Windows (TM) platforms.
Definition: FreeImagePlus.h:1013
virtual void clear()
Destroy image data.
BOOL isModified()
Get the image status
Definition: FreeImagePlus.h:945
virtual ~fipObject()
Destructor.
Definition: FreeImagePlus.h:80
double _tmo_param_2
second tone mapping algorithm parameter
Definition: FreeImagePlus.h:1170
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:1112
FITAG * _tag
Pointer to a FreeImage tag.
Definition: FreeImagePlus.h:1499
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:1172
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:936
FIMEMORY * _hmem
Pointer to a memory stream.
Definition: FreeImagePlus.h:1191
FreeImage Tag
Definition: FreeImagePlus.h:1495
Definition: FreeImage.h:225
Metadata iterator
Definition: FreeImagePlus.h:1675