// ==========================================================
// FreeImagePlus 3
//
// Design and implementation by
// - Herv?Drolon (drolon@infonie.fr)
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================
#ifndef FREEIMAGEPLUS_H
#define FREEIMAGEPLUS_H
#ifdef _WIN32
#include <windows.h>
#endif // _WIN32
#include "FreeImage.h"
// Compiler options ---------------------------------------------------------
#if defined(FREEIMAGE_LIB) || !defined(_WIN32)
#define FIP_API
#define FIP_CALLCONV
#else
#define WIN32_LEAN_AND_MEAN
#define FIP_CALLCONV __stdcall
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the FIP_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// FIP_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef FIP_EXPORTS
#define FIP_API __declspec(dllexport)
#else
#define FIP_API __declspec(dllimport)
#endif // FIP_EXPORTS
#endif // FREEIMAGE_LIB || !_WIN32
///////////////////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------
/** Abstract base class for all objects used by the library.
@version FreeImage 3
@author Herv?Drolon
*/
class FIP_API fipObject
{
public:
/**@name Information functions */
//@{
/// Returns TRUE if the object is allocated, FALSE otherwise
virtual BOOL isValid() const = 0;
//@}
};
// ----------------------------------------------------------
class fipMemoryIO;
class fipMultiPage;
class fipTag;
/** A class used to manage all photo related images and all image types used by the library.
fipImage encapsulates the FIBITMAP format. It relies on the FreeImage library, especially for
loading / saving images and for bit depth conversion.
@version FreeImage 3
@author Herv?Drolon
*/
class FIP_API fipImage : public fipObject
{
protected:
/// DIB data
FIBITMAP *_dib;
/// TRUE whenever the display need to be refreshed
mutable BOOL _bHasChanged;
public:
friend class fipMultiPage;
public:
/**@name Creation & Destruction */
//@{
/**
Constructor
@see FreeImage_AllocateT
*/
fipImage(FREE_IMAGE_TYPE image_type = FIT_BITMAP, WORD width = 0, WORD height = 0, WORD bpp = 0);
/// Destructor
~fipImage();
/**
Image allocator
@see FreeImage_AllocateT
*/
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);
/// Destroy image data
virtual void clear();
//@}
/**@name Copying */
//@{
/**
Copy constructor
@see FreeImage_Clone
*/
fipImage(const fipImage& src);
/**
Copy constructor
@see FreeImage_Clone
*/
fipImage& operator=(const fipImage& src);
/**
<b>Assignement operator</b><br>
Copy the input pointer and manage its destruction
@see operator FIBITMAP*()
*/
fipImage& operator=(FIBITMAP *dib);
/**
@brief Copy a sub part of the current image and returns it as a fipImage object.
This method works with any bitmap type.
@param dst Output subimage
@param left Specifies the left position of the cropped rectangle.
@param top Specifies the top position of the cropped rectangle.
@param right Specifies the right position of the cropped rectangle.
@param bottom Specifies the bottom position of the cropped rectangle.
@return Returns TRUE if successful, FALSE otherwise.
@see FreeImage_Copy
*/
BOOL copySubImage(fipImage& dst, int left, int top, int right, int bottom) const;
/**
@brief Alpha blend or combine a sub part image with the current image.
The bit depth of dst bitmap must be greater than or equal to the bit depth of src.
Upper promotion of src is done internally. Supported bit depth equals to 4, 8, 16, 24 or 32.
@param src Source subimage
@param left Specifies the left position of the sub image.
@param top Specifies the top position of the sub image.
@param alpha Alpha blend factor. The source and destination images are alpha blended if
alpha = 0..255. If alpha > 255, then the source image is combined to the destination image.
@return Returns TRUE if successful, FALSE otherwise.
@see FreeImage_Paste
*/
BOOL pasteSubImage(fipImage& src, int left, int top, int alpha = 256);
/**
@brief Crop a sub part of the current image and update it accordingly.
This method works with any bitmap type.
@param left Specifies the left position of the cropped rectangle.
@param top Specifies the top position of the cropped rectangle.
@param right Specifies the right position of the cropped rectangle.
@param bottom Specifies the bottom position of the cropped rectangle.
@return Returns TRUE if successful, FALSE otherwise.
*/
BOOL crop(int left, int top, int right, int bottom);
//@}
/** @name Loading & Saving
* Loading and saving is handled by the FreeImage library.
*/
//@{
/**
@brief Loads an image from disk, given its file name and an optional flag.
@param lpszPathName Path and file name of the image to load.
@param flag The signification of this flag depends on the image to be read.
@return Returns TRUE if successful, FALSE otherwise.
@see FreeImage_Load, FreeImage documentation
*/
BOOL load(const char* lpszPathName, int flag = 0);
/**
UNICODE version of load (this function only works under WIN32 and does nothing on other OS)
@see load
*/
BOOL loadU(const wchar_t* lpszPathName, int flag = 0);
/**
@brief Loads an image using the specified FreeImageIO struct and fi_handle, and an optional flag.
@param io FreeImageIO structure
@param handle FreeImage fi_handle
@param flag The signification of this flag depends on the image to be read.
@return Returns TRUE if successful, FALSE otherwise.
@see FreeImage_LoadFromHandle, FreeImage documentation
*/
BOOL loadFromHandle(FreeImageIO *io, fi_handle handle, int flag = 0);
/**
@brief Loads an image using the specified memory stream and an optional flag.
@param memIO FreeImage memory stream
@param flag The signification of this flag depends on the image to be read.
@return Returns TRUE if successful, FALSE otherwise.
@see FreeImage_LoadFromMemory, FreeImage documentation
*/
BOOL loadFromMemory(fipMemoryIO& memIO, int flag = 0);
/**
@brief Saves an image to disk, given its file name and an optional flag.
@param lpszPathName Path and file name of the image to save.
@param flag The signification of this flag depends on the image to be saved.
@return Returns TRUE if successful, FALSE otherwise.
@see FreeImage_Save, FreeImage documentation
*/
BOOL save(const char* lpszPathName, int flag = 0) const;
/**
UNICODE version of save (this function only works under WIN32 and does nothing on other OS)
@see save
*/
BOOL saveU(const wchar_t* lpszPathName, int flag = 0) const;
/**