FreeImagePlus  - FreeImage 3.15.3
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  LONG getImageSize() const;
378 
384  unsigned getBitsPerPixel() const;
385 
391  unsigned getLine() const;
392 
397  double getHorizontalResolution() const;
398 
403  double getVerticalResolution() const;
404 
409  void setHorizontalResolution(double value);
410 
415  void setVerticalResolution(double value);
416 
418 
425  RGBQUAD* getPalette() const;
426 
431  unsigned getPaletteSize() const;
432 
437  unsigned getColorsUsed() const;
438 
443  FREE_IMAGE_COLOR_TYPE getColorType() const;
444 
449  BOOL isGrayscale() const;
451 
454 
460  BOOL getThumbnail(fipImage& image) const;
461 
467  BOOL setThumbnail(const fipImage& image);
468 
474  BOOL hasThumbnail() const;
475 
481  BOOL clearThumbnail();
482 
484 
487 
496  BYTE* accessPixels() const;
497 
503  BYTE* getScanLine(unsigned scanline) const;
504 
513  BOOL getPixelIndex(unsigned x, unsigned y, BYTE *value) const;
514 
523  BOOL getPixelColor(unsigned x, unsigned y, RGBQUAD *value) const;
524 
533  BOOL setPixelIndex(unsigned x, unsigned y, BYTE *value);
534 
543  BOOL setPixelColor(unsigned x, unsigned y, RGBQUAD *value);
544 
546 
558  BOOL convertToType(FREE_IMAGE_TYPE image_type, BOOL scale_linear = TRUE);
559 
566  BOOL threshold(BYTE T);
567 
574  BOOL dither(FREE_IMAGE_DITHER algorithm);
575 
581  BOOL convertTo4Bits();
582 
588  BOOL convertTo8Bits();
589 
596  BOOL convertToGrayscale();
597 
605  BOOL colorQuantize(FREE_IMAGE_QUANTIZE algorithm);
606 
612  BOOL convertTo16Bits555();
613 
619  BOOL convertTo16Bits565();
620 
626  BOOL convertTo24Bits();
627 
633  BOOL convertTo32Bits();
634 
640  BOOL convertToFloat();
641 
647  BOOL convertToRGBF();
648 
654  BOOL convertToUINT16();
655 
661  BOOL convertToRGB16();
662 
673  BOOL toneMapping(FREE_IMAGE_TMO tmo, double first_param = 0, double second_param = 0, double third_param = 1, double fourth_param = 0);
674 
676 
679 
684  BOOL isTransparent() const;
685 
691  unsigned getTransparencyCount() const;
692 
698  BYTE* getTransparencyTable() const;
699 
704  void setTransparencyTable(BYTE *table, int count);
705 
710  BOOL hasFileBkColor() const;
711 
720  BOOL getFileBkColor(RGBQUAD *bkcolor) const;
721 
730  BOOL setFileBkColor(RGBQUAD *bkcolor);
732 
741  BOOL getChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel) const;
742 
750  BOOL setChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel);
751 
760  BOOL splitChannels(fipImage& RedChannel, fipImage& GreenChannel, fipImage& BlueChannel);
761 
769  BOOL combineChannels(fipImage& red, fipImage& green, fipImage& blue);
771 
785  BOOL rotateEx(double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask);
786 
794  BOOL rotate(double angle, const void *bkcolor = NULL);
795 
800  BOOL flipHorizontal();
801 
806  BOOL flipVertical();
808 
816  BOOL invert();
817 
831  BOOL adjustCurve(BYTE *LUT, FREE_IMAGE_COLOR_CHANNEL channel);
832 
839  BOOL adjustGamma(double gamma);
840 
848  BOOL adjustBrightness(double percentage);
849 
857  BOOL adjustContrast(double percentage);
858 
869  BOOL adjustBrightnessContrastGamma(double brightness, double contrast, double gamma);
870 
881  BOOL getHistogram(DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel = FICC_BLACK) const;
883 
886 
895  BOOL rescale(unsigned new_width, unsigned new_height, FREE_IMAGE_FILTER filter);
896 
904  BOOL makeThumbnail(unsigned max_size, BOOL convert = TRUE);
906 
916  void setModified(BOOL bStatus = TRUE) {
917  _bHasChanged = bStatus;
918  }
919 
925  BOOL isModified() {
926  return _bHasChanged;
927  }
929 
937  unsigned getMetadataCount(FREE_IMAGE_MDMODEL model) const;
946  BOOL getMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag) const;
966  BOOL setMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag);
968 
969 
970  protected:
973  BOOL replace(FIBITMAP *new_dib);
975 
976 };
977 
978 // ----------------------------------------------------------
979 
991 #ifdef _WIN32
992 
993 class FIP_API fipWinImage : public fipImage
994 {
995 public:
998  fipWinImage(FREE_IMAGE_TYPE image_type = FIT_BITMAP, unsigned width = 0, unsigned height = 0, unsigned bpp = 0);
1000 
1002  virtual ~fipWinImage();
1003 
1005  virtual void clear();
1006 
1008  BOOL isValid() const;
1010 
1013 
1020  fipWinImage& operator=(const fipImage& src);
1021 
1028  fipWinImage& operator=(const fipWinImage& src);
1029 
1036  HANDLE copyToHandle() const;
1037 
1044  BOOL copyFromHandle(HANDLE hMem);
1045 
1050  BOOL copyFromBitmap(HBITMAP hbmp);
1052 
1061  BOOL copyToClipboard(HWND hWndNewOwner) const;
1062 
1067  BOOL pasteFromClipboard();
1069 
1077  BOOL captureWindow(HWND hWndApplicationWindow, HWND hWndSelectedWindow);
1079 
1080 
1083 
1092  void draw(HDC hDC, RECT& rcDest) const {
1093  drawEx(hDC, rcDest, FALSE, NULL, NULL);
1094  }
1095 
1113  void drawEx(HDC hDC, RECT& rcDest, BOOL useFileBkg = FALSE, RGBQUAD *appBkColor = NULL, FIBITMAP *bg = NULL) const;
1114 
1125  void setToneMappingOperator(FREE_IMAGE_TMO tmo, double first_param = 0, double second_param = 0, double third_param = 1, double fourth_param = 0);
1126 
1136  void getToneMappingOperator(FREE_IMAGE_TMO *tmo, double *first_param, double *second_param, double *third_param, double *fourth_param) const;
1137 
1139 
1140 protected:
1142  mutable FIBITMAP *_display_dib;
1144  mutable BOOL _bDeleteMe;
1146  FREE_IMAGE_TMO _tmo;
1155 };
1156 
1157 #endif // _WIN32
1158 
1159 // ----------------------------------------------------------
1160 
1167 class FIP_API fipMemoryIO : public fipObject
1168 {
1169 protected:
1171  FIMEMORY *_hmem;
1172 
1173 public :
1183  fipMemoryIO(BYTE *data = NULL, DWORD size_in_bytes = 0);
1184 
1189  virtual ~fipMemoryIO();
1190 
1195  void close();
1196 
1199  BOOL isValid() const;
1200 
1204  FREE_IMAGE_FORMAT getFileType() const;
1205 
1210  operator FIMEMORY*() {
1211  return _hmem;
1212  }
1213 
1223  FIBITMAP* load(FREE_IMAGE_FORMAT fif, int flags = 0) const;
1231  FIMULTIBITMAP* loadMultiPage(FREE_IMAGE_FORMAT fif, int flags = 0) const;
1240  BOOL save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, int flags = 0);
1249  BOOL saveMultiPage(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, int flags = 0);
1258  unsigned read(void *buffer, unsigned size, unsigned count) const;
1267  unsigned write(const void *buffer, unsigned size, unsigned count);
1272  long tell() const;
1277  BOOL seek(long offset, int origin);
1284  BOOL acquire(BYTE **data, DWORD *size_in_bytes);
1286 
1287 private:
1289  fipMemoryIO(const fipMemoryIO& src);
1291  fipMemoryIO& operator=(const fipMemoryIO& src);
1292 
1293 };
1294 
1295 // ----------------------------------------------------------
1296 
1302 class FIP_API fipMultiPage : public fipObject
1303 {
1304 protected:
1306  FIMULTIBITMAP *_mpage;
1309 
1310 public:
1315  fipMultiPage(BOOL keep_cache_in_memory = FALSE);
1316 
1321  virtual ~fipMultiPage();
1322 
1324  BOOL isValid() const;
1325 
1330  operator FIMULTIBITMAP*() {
1331  return _mpage;
1332  }
1333 
1343  BOOL open(const char* lpszPathName, BOOL create_new, BOOL read_only, int flags = 0);
1344 
1352  BOOL open(fipMemoryIO& memIO, int flags = 0);
1353 
1362  BOOL open(FreeImageIO *io, fi_handle handle, int flags = 0);
1363 
1370  BOOL close(int flags = 0);
1371 
1381  BOOL saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags = 0) const;
1382 
1391  BOOL saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flags = 0) const;
1392 
1397  int getPageCount() const;
1398 
1404  void appendPage(fipImage& image);
1405 
1412  void insertPage(int page, fipImage& image);
1413 
1419  void deletePage(int page);
1420 
1428  BOOL movePage(int target, int source);
1429 
1447  FIBITMAP* lockPage(int page);
1448 
1455  void unlockPage(fipImage& image, BOOL changed);
1456 
1465  BOOL getLockedPageNumbers(int *pages, int *count) const;
1466 };
1467 
1468 // ----------------------------------------------------------
1469 
1475 class FIP_API fipTag : public fipObject
1476 {
1477 protected:
1479  FITAG *_tag;
1480 
1481 public:
1488  fipTag();
1493  virtual ~fipTag();
1502  BOOL setKeyValue(const char *key, const char *value);
1503 
1505 
1512  fipTag(const fipTag& tag);
1517  fipTag& operator=(const fipTag& tag);
1523  fipTag& operator=(FITAG *tag);
1525 
1531  operator FITAG*() {
1532  return _tag;
1533  }
1534 
1536  BOOL isValid() const;
1537 
1544  const char *getKey() const;
1549  const char *getDescription() const;
1554  WORD getID() const;
1559  FREE_IMAGE_MDTYPE getType() const;
1564  DWORD getCount() const;
1569  DWORD getLength() const;
1574  const void *getValue() const;
1580  BOOL setKey(const char *key);
1586  BOOL setDescription(const char *description);
1592  BOOL setID(WORD id);
1598  BOOL setType(FREE_IMAGE_MDTYPE type);
1604  BOOL setCount(DWORD count);
1610  BOOL setLength(DWORD length);
1616  BOOL setValue(const void *value);
1617 
1619 
1625  const char* toString(FREE_IMAGE_MDMODEL model, char *Make = NULL) const;
1626 
1627 };
1628 
1655 class FIP_API fipMetadataFind : public fipObject
1656 {
1657 protected:
1659  FIMETADATA *_mdhandle;
1660 
1661 public:
1663  BOOL isValid() const;
1664 
1666  fipMetadataFind();
1671  virtual ~fipMetadataFind();
1681  BOOL findFirstMetadata(FREE_IMAGE_MDMODEL model, fipImage& image, fipTag& tag);
1689  BOOL findNextMetadata(fipTag& tag);
1690 
1691 };
1692 
1693 #endif // FREEIMAGEPLUS_H
Multi-page file stream.
Definition: FreeImagePlus.h:1302
FREE_IMAGE_FORMAT _fif
Original (or last saved) fif format if available, FIF_UNKNOWN otherwise.
Definition: FreeImagePlus.h:109
Definition: FreeImage.h:165
Memory handle.
Definition: FreeImagePlus.h:1167
double _tmo_param_4
fourth tone mapping algorithm parameter
Definition: FreeImagePlus.h:1154
fipImage & operator=(const fipImage &src)
Copy constructor.
BOOL _bMemoryCache
TRUE when using a memory cache, FALSE otherwise.
Definition: FreeImagePlus.h:1308
Abstract base class for all objects used by the library.
Definition: FreeImagePlus.h:76
FREE_IMAGE_TMO _tmo
tone mapping operator
Definition: FreeImagePlus.h:1146
Definition: FreeImage.h:196
double _tmo_param_1
first tone mapping algorithm parameter
Definition: FreeImagePlus.h:1148
BOOL _bHasChanged
TRUE whenever the display need to be refreshed.
Definition: FreeImagePlus.h:111
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.
FIBITMAP * _display_dib
DIB used for display (this allow to display non-standard bitmaps)
Definition: FreeImagePlus.h:1142
BOOL _bDeleteMe
remember to delete _display_dib
Definition: FreeImagePlus.h:1144
FIMULTIBITMAP * _mpage
Pointer to a multi-page file stream.
Definition: FreeImagePlus.h:1306
FIMETADATA * _mdhandle
Pointer to a search handle.
Definition: FreeImagePlus.h:1659
A class designed for MS Windows (TM) platforms.
Definition: FreeImagePlus.h:993
virtual void clear()
Destroy image data.
BOOL isModified()
Get the image status.
Definition: FreeImagePlus.h:925
virtual ~fipObject()
Destructor.
Definition: FreeImagePlus.h:80
double _tmo_param_2
second tone mapping algorithm parameter
Definition: FreeImagePlus.h:1150
void draw(HDC hDC, RECT &rcDest) const
Draw (stretch) the image on a HDC, using StretchDIBits.
Definition: FreeImagePlus.h:1092
A class used to manage all photo related images and all image types used by the library.
Definition: FreeImagePlus.h:103
FITAG * _tag
Pointer to a FreeImage tag.
Definition: FreeImagePlus.h:1479
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:1152
void setModified(BOOL bStatus=TRUE)
Set the image status as 'modified'.
Definition: FreeImagePlus.h:916
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...
FIMEMORY * _hmem
Pointer to a memory stream.
Definition: FreeImagePlus.h:1171
FreeImage Tag.
Definition: FreeImagePlus.h:1475
BOOL isValid() const
Returns TRUE if the image is allocated, FALSE otherwise.
Definition: FreeImage.h:210
Metadata iterator.
Definition: FreeImagePlus.h:1655