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:
81  virtual BOOL isValid() const = 0;
84 };
85 
86 // ----------------------------------------------------------
87 
88 class fipMemoryIO;
89 class fipMultiPage;
90 class fipTag;
91 
100 class FIP_API fipImage : public fipObject
101 {
102 protected:
104  FIBITMAP *_dib;
106  mutable BOOL _bHasChanged;
107 
108 public:
109  friend class fipMultiPage;
110 
111 public:
112 
119  fipImage(FREE_IMAGE_TYPE image_type = FIT_BITMAP, WORD width = 0, WORD height = 0, WORD bpp = 0);
121  ~fipImage();
126  BOOL setSize(FREE_IMAGE_TYPE image_type, WORD width, WORD height, WORD bpp, unsigned red_mask = 0, unsigned green_mask = 0, unsigned blue_mask = 0);
128  virtual void clear();
130 
137  fipImage(const fipImage& src);
142  fipImage& operator=(const fipImage& src);
148  fipImage& operator=(FIBITMAP *dib);
149 
150 
163  BOOL copySubImage(fipImage& dst, int left, int top, int right, int bottom) const;
164 
178  BOOL pasteSubImage(fipImage& src, int left, int top, int alpha = 256);
179 
190  BOOL crop(int left, int top, int right, int bottom);
191 
192 
194 
206  BOOL load(const char* lpszPathName, int flag = 0);
207 
212  BOOL loadU(const wchar_t* lpszPathName, int flag = 0);
213 
222  BOOL loadFromHandle(FreeImageIO *io, fi_handle handle, int flag = 0);
223 
231  BOOL loadFromMemory(fipMemoryIO& memIO, int flag = 0);
232 
240  BOOL save(const char* lpszPathName, int flag = 0) const;
241 
246  BOOL saveU(const wchar_t* lpszPathName, int flag = 0) const;
247 
257  BOOL saveToHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flag = 0) const;
258 
267  BOOL saveToMemory(FREE_IMAGE_FORMAT fif, fipMemoryIO& memIO, int flag = 0) const;
268 
270 
275 
280  FREE_IMAGE_TYPE getImageType() const;
281 
286  WORD getWidth() const;
287 
292  WORD getHeight() const;
293 
298  WORD getScanWidth() const;
299 
312  operator FIBITMAP*() {
313  return _dib;
314  }
315 
317  BOOL isValid() const;
318 
323  BITMAPINFO* getInfo() const;
324 
329  BITMAPINFOHEADER* getInfoHeader() const;
330 
336  LONG getImageSize() const;
337 
343  WORD getBitsPerPixel() const;
344 
350  WORD getLine() const;
351 
356  double getHorizontalResolution() const;
357 
362  double getVerticalResolution() const;
363 
368  void setHorizontalResolution(double value);
369 
374  void setVerticalResolution(double value);
375 
377 
384  RGBQUAD* getPalette() const;
385 
390  WORD getPaletteSize() const;
391 
396  WORD getColorsUsed() const;
397 
402  FREE_IMAGE_COLOR_TYPE getColorType() const;
403 
408  BOOL isGrayscale() const;
410 
413 
422  BYTE* accessPixels() const;
423 
429  BYTE* getScanLine(WORD scanline) const;
430 
439  BOOL getPixelIndex(unsigned x, unsigned y, BYTE *value) const;
440 
449  BOOL getPixelColor(unsigned x, unsigned y, RGBQUAD *value) const;
450 
459  BOOL setPixelIndex(unsigned x, unsigned y, BYTE *value);
460 
469  BOOL setPixelColor(unsigned x, unsigned y, RGBQUAD *value);
470 
472 
484  BOOL convertToType(FREE_IMAGE_TYPE image_type, BOOL scale_linear = TRUE);
485 
492  BOOL threshold(BYTE T);
493 
500  BOOL dither(FREE_IMAGE_DITHER algorithm);
501 
507  BOOL convertTo4Bits();
508 
514  BOOL convertTo8Bits();
515 
522  BOOL convertToGrayscale();
523 
531  BOOL colorQuantize(FREE_IMAGE_QUANTIZE algorithm);
532 
538  BOOL convertTo16Bits555();
539 
545  BOOL convertTo16Bits565();
546 
552  BOOL convertTo24Bits();
553 
559  BOOL convertTo32Bits();
560 
566  BOOL convertToRGBF();
567 
576  BOOL toneMapping(FREE_IMAGE_TMO tmo, double first_param = 0, double second_param = 0);
577 
579 
582 
587  BOOL isTransparent() const;
588 
594  unsigned getTransparencyCount() const;
595 
601  BYTE* getTransparencyTable() const;
602 
607  void setTransparencyTable(BYTE *table, int count);
608 
613  BOOL hasFileBkColor() const;
614 
623  BOOL getFileBkColor(RGBQUAD *bkcolor) const;
624 
633  BOOL setFileBkColor(RGBQUAD *bkcolor);
635 
644  BOOL getChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel) const;
645 
653  BOOL setChannel(fipImage& image, FREE_IMAGE_COLOR_CHANNEL channel);
654 
663  BOOL splitChannels(fipImage& RedChannel, fipImage& GreenChannel, fipImage& BlueChannel);
664 
672  BOOL combineChannels(fipImage& red, fipImage& green, fipImage& blue);
674 
688  BOOL rotateEx(double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask);
689 
696  BOOL rotate(double angle);
697 
702  BOOL flipHorizontal();
703 
708  BOOL flipVertical();
710 
718  BOOL invert();
719 
733  BOOL adjustCurve(BYTE *LUT, FREE_IMAGE_COLOR_CHANNEL channel);
734 
741  BOOL adjustGamma(double gamma);
742 
750  BOOL adjustBrightness(double percentage);
751 
759  BOOL adjustContrast(double percentage);
760 
771  BOOL getHistogram(DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel = FICC_BLACK) const;
773 
776 
785  BOOL rescale(WORD new_width, WORD new_height, FREE_IMAGE_FILTER filter);
786 
794  BOOL makeThumbnail(WORD max_size, BOOL convert = TRUE);
796 
806  void setModified(BOOL bStatus = TRUE) {
807  _bHasChanged = bStatus;
808  }
809 
815  BOOL isModified() {
816  return _bHasChanged;
817  }
819 
827  unsigned getMetadataCount(FREE_IMAGE_MDMODEL model) const;
836  BOOL getMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag) const;
856  BOOL setMetadata(FREE_IMAGE_MDMODEL model, const char *key, fipTag& tag);
858 
859 
860  protected:
863  BOOL replace(FIBITMAP *new_dib);
865 
866 };
867 
868 // ----------------------------------------------------------
869 
881 #ifdef _WIN32
882 
883 class FIP_API fipWinImage : public fipImage
884 {
885 public:
888  fipWinImage(FREE_IMAGE_TYPE image_type = FIT_BITMAP, WORD width = 0, WORD height = 0, WORD bpp = 0);
890 
892  ~fipWinImage();
893 
895  virtual void clear();
896 
898  BOOL isValid() const;
900 
903 
910  fipWinImage& operator=(const fipImage& src);
911 
918  fipWinImage& operator=(const fipWinImage& src);
919 
926  HANDLE copyToHandle() const;
927 
934  BOOL copyFromHandle(HANDLE hMem);
935 
940  BOOL copyFromBitmap(HBITMAP hbmp);
942 
951  BOOL copyToClipboard(HWND hWndNewOwner) const;
952 
957  BOOL pasteFromClipboard();
959 
967  BOOL captureWindow(HWND hWndApplicationWindow, HWND hWndSelectedWindow);
969 
970 
973 
982  void draw(HDC hDC, RECT& rcDest) const {
983  drawEx(hDC, rcDest, FALSE, NULL, NULL);
984  }
985 
1003  void drawEx(HDC hDC, RECT& rcDest, BOOL useFileBkg = FALSE, RGBQUAD *appBkColor = NULL, FIBITMAP *bg = NULL) const;
1004 
1013  void setToneMappingOperator(FREE_IMAGE_TMO tmo, double first_param = 0, double second_param = 0);
1014 
1022  void getToneMappingOperator(FREE_IMAGE_TMO *tmo, double *first_param, double *second_param) const;
1023 
1025 
1026 protected:
1028  mutable FIBITMAP *_display_dib;
1030  mutable BOOL _bDeleteMe;
1032  FREE_IMAGE_TMO _tmo;
1037 };
1038 
1039 #endif // _WIN32
1040 
1041 // ----------------------------------------------------------
1042 
1049 class FIP_API fipMemoryIO : public fipObject
1050 {
1051 protected:
1053  FIMEMORY *_hmem;
1054 
1055 public :
1065  fipMemoryIO(BYTE *data = NULL, DWORD size_in_bytes = 0);
1066 
1071  ~fipMemoryIO();
1072 
1075  BOOL isValid() const;
1076 
1080  FREE_IMAGE_FORMAT getFileType() const;
1081 
1086  operator FIMEMORY*() {
1087  return _hmem;
1088  }
1089 
1099  FIBITMAP* load(FREE_IMAGE_FORMAT fif, int flags = 0) const;
1108  BOOL save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, int flags = 0);
1117  unsigned read(void *buffer, unsigned size, unsigned count) const;
1126  unsigned write(const void *buffer, unsigned size, unsigned count);
1131  long tell() const;
1136  BOOL seek(long offset, int origin);
1143  BOOL acquire(BYTE **data, DWORD *size_in_bytes);
1145 
1146 private:
1148  fipMemoryIO(const fipMemoryIO& src);
1150  fipMemoryIO& operator=(const fipMemoryIO& src);
1151 
1152 };
1153 
1154 // ----------------------------------------------------------
1155 
1161 class FIP_API fipMultiPage : public fipObject
1162 {
1163 protected:
1165  FIMULTIBITMAP *_mpage;
1168 
1169 public:
1174  fipMultiPage(BOOL keep_cache_in_memory = FALSE);
1175 
1180  ~fipMultiPage();
1181 
1183  BOOL isValid() const;
1184 
1194  BOOL open(const char* lpszPathName, BOOL create_new, BOOL read_only, int flags = 0);
1195 
1203  BOOL open(fipMemoryIO& memIO, int flags = 0);
1204 
1211  BOOL close(int flags = 0);
1212 
1217  int getPageCount() const;
1218 
1224  void appendPage(fipImage& image);
1225 
1232  void insertPage(int page, fipImage& image);
1233 
1239  void deletePage(int page);
1240 
1248  BOOL movePage(int target, int source);
1249 
1267  FIBITMAP* lockPage(int page);
1268 
1275  void unlockPage(fipImage& image, BOOL changed);
1276 
1285  BOOL getLockedPageNumbers(int *pages, int *count) const;
1286 };
1287 
1288 // ----------------------------------------------------------
1289 
1295 class FIP_API fipTag : public fipObject
1296 {
1297 protected:
1299  FITAG *_tag;
1300 
1301 public:
1308  fipTag();
1313  ~fipTag();
1322  BOOL setKeyValue(const char *key, const char *value);
1323 
1325 
1332  fipTag(const fipTag& tag);
1337  fipTag& operator=(const fipTag& tag);
1343  fipTag& operator=(FITAG *tag);
1345 
1351  operator FITAG*() {
1352  return _tag;
1353  }
1354 
1356  BOOL isValid() const;
1357 
1364  const char *getKey() const;
1369  const char *getDescription() const;
1374  WORD getID() const;
1379  FREE_IMAGE_MDTYPE getType() const;
1384  DWORD getCount() const;
1389  DWORD getLength() const;
1394  const void *getValue() const;
1400  BOOL setKey(const char *key);
1406  BOOL setDescription(const char *description);
1412  BOOL setID(WORD id);
1418  BOOL setType(FREE_IMAGE_MDTYPE type);
1424  BOOL setCount(DWORD count);
1430  BOOL setLength(DWORD length);
1436  BOOL setValue(const void *value);
1437 
1439 
1445  const char* toString(FREE_IMAGE_MDMODEL model, char *Make = NULL) const;
1446 
1447 };
1448 
1475 class FIP_API fipMetadataFind : public fipObject
1476 {
1477 protected:
1479  FIMETADATA *_mdhandle;
1480 
1481 public:
1483  BOOL isValid() const;
1484 
1486  fipMetadataFind();
1491  ~fipMetadataFind();
1501  BOOL findFirstMetadata(FREE_IMAGE_MDMODEL model, fipImage& image, fipTag& tag);
1509  BOOL findNextMetadata(fipTag& tag);
1510 
1511 };
1512 
1513 #endif // FREEIMAGEPLUS_H
Multi-page file stream.
Definition: FreeImagePlus.h:1161
Definition: FreeImage.h:173
Memory handle.
Definition: FreeImagePlus.h:1049
fipImage & operator=(const fipImage &src)
Copy constructor.
BOOL _bMemoryCache
TRUE when using a memory cache, FALSE otherwise.
Definition: FreeImagePlus.h:1167
Abstract base class for all objects used by the library.
Definition: FreeImagePlus.h:76
FREE_IMAGE_TMO _tmo
tone mapping operator
Definition: FreeImagePlus.h:1032
Definition: FreeImage.h:204
double _tmo_param_1
first tone mapping algorithm parameter
Definition: FreeImagePlus.h:1034
BOOL _bHasChanged
TRUE whenever the display need to be refreshed.
Definition: FreeImagePlus.h:106
FIBITMAP * _display_dib
DIB used for display (this allow to display non-standard bitmaps)
Definition: FreeImagePlus.h:1028
BOOL _bDeleteMe
remember to delete _display_dib
Definition: FreeImagePlus.h:1030
FIMULTIBITMAP * _mpage
Pointer to a multi-page file stream.
Definition: FreeImagePlus.h:1165
FIMETADATA * _mdhandle
Pointer to a search handle.
Definition: FreeImagePlus.h:1479
A class designed for MS Windows (TM) platforms.
Definition: FreeImagePlus.h:883
virtual void clear()
Destroy image data.
BOOL isModified()
Get the image status.
Definition: FreeImagePlus.h:815
double _tmo_param_2
second tone mapping algorithm parameter
Definition: FreeImagePlus.h:1036
void draw(HDC hDC, RECT &rcDest) const
Draw (stretch) the image on a HDC, using StretchDIBits.
Definition: FreeImagePlus.h:982
A class used to manage all photo related images and all image types used by the library.
Definition: FreeImagePlus.h:100
FITAG * _tag
Pointer to a FreeImage tag.
Definition: FreeImagePlus.h:1299
FIBITMAP * _dib
DIB data.
Definition: FreeImagePlus.h:104
virtual BOOL isValid() const =0
Returns TRUE if the object is allocated, FALSE otherwise.
void setModified(BOOL bStatus=TRUE)
Set the image status as 'modified'.
Definition: FreeImagePlus.h:806
FIMEMORY * _hmem
Pointer to a memory stream.
Definition: FreeImagePlus.h:1053
FreeImage Tag.
Definition: FreeImagePlus.h:1295
BOOL isValid() const
Returns TRUE if the image is allocated, FALSE otherwise.
Definition: FreeImage.h:218
Metadata iterator.
Definition: FreeImagePlus.h:1475