view release on metacpan or search on metacpan
Revision history for Perl module Alien::FreeImage
1.001 2017-07-11
- upgrade to FreeImage-3.17.0
0.011 2014-12-09
- flag -fPIC strikes again
0.010 2014-12-08
- x64 linux requires -fPIC and -lstdc++
0.009 2014-11-30
- first working release
src/Makefile.mingw view on Meta::CPAN
# Define some additional symboles needed for WIN32 based builds.
WIN32_CFLAGS = -DWINVER=0x0500 $(LIB_TYPE_FLAGS) -DOPJ_STATIC
WIN32_CXXFLAGS = $(WIN32_CFLAGS) -DLIBRAW_NODLL
# Workaround for LibRawLite, which does not include C++ header
# file stdexcept, which is casually included with MSVC but not
# with MinGW. This can be removed after LibRawLite got control
# over its includes again.
WIN32_CXXFLAGS += -include stdexcept
# Define DLL image header information flags for the linker.
WIN32_LDFLAGS = -Wl,--subsystem,windows:5.0,--major-os-version,5
WIN32_STATIC_FLAGS = -DFREEIMAGE_LIB
WIN32_SHARED_FLAGS = -DFREEIMAGE_EXPORTS
MODULES = $(SRCS:.c=.o)
MODULES := $(MODULES:.cpp=.o)
RESOURCE = $(RCFILE:.rc=.coff)
CFLAGS ?= -O3 -fexceptions -DNDEBUG -DDISABLE_PERF_MEASUREMENT $(WIN32_CFLAGS)
CFLAGS += $(INCLUDE)
src/Source/FreeImage.h view on Meta::CPAN
#define FI16_565_RED_SHIFT 11
#define FI16_565_GREEN_SHIFT 5
#define FI16_565_BLUE_SHIFT 0
// ICC profile support ------------------------------------------------------
#define FIICC_DEFAULT 0x00
#define FIICC_COLOR_IS_CMYK 0x01
FI_STRUCT (FIICCPROFILE) {
WORD flags; //! info flag
DWORD size; //! profile's size measured in bytes
void *data; //! points to a block of contiguous memory containing the profile
};
// Important enums ----------------------------------------------------------
/** I/O image format identifiers.
*/
FI_ENUM(FREE_IMAGE_FORMAT) {
FIF_UNKNOWN = -1,
src/Source/FreeImage.h view on Meta::CPAN
#define PLUGINS
typedef const char *(DLL_CALLCONV *FI_FormatProc)(void);
typedef const char *(DLL_CALLCONV *FI_DescriptionProc)(void);
typedef const char *(DLL_CALLCONV *FI_ExtensionListProc)(void);
typedef const char *(DLL_CALLCONV *FI_RegExprProc)(void);
typedef void *(DLL_CALLCONV *FI_OpenProc)(FreeImageIO *io, fi_handle handle, BOOL read);
typedef void (DLL_CALLCONV *FI_CloseProc)(FreeImageIO *io, fi_handle handle, void *data);
typedef int (DLL_CALLCONV *FI_PageCountProc)(FreeImageIO *io, fi_handle handle, void *data);
typedef int (DLL_CALLCONV *FI_PageCapabilityProc)(FreeImageIO *io, fi_handle handle, void *data);
typedef FIBITMAP *(DLL_CALLCONV *FI_LoadProc)(FreeImageIO *io, fi_handle handle, int page, int flags, void *data);
typedef BOOL (DLL_CALLCONV *FI_SaveProc)(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data);
typedef BOOL (DLL_CALLCONV *FI_ValidateProc)(FreeImageIO *io, fi_handle handle);
typedef const char *(DLL_CALLCONV *FI_MimeProc)(void);
typedef BOOL (DLL_CALLCONV *FI_SupportsExportBPPProc)(int bpp);
typedef BOOL (DLL_CALLCONV *FI_SupportsExportTypeProc)(FREE_IMAGE_TYPE type);
typedef BOOL (DLL_CALLCONV *FI_SupportsICCProfilesProc)(void);
typedef BOOL (DLL_CALLCONV *FI_SupportsNoPixelsProc)(void);
FI_STRUCT (Plugin) {
FI_FormatProc format_proc;
FI_DescriptionProc description_proc;
src/Source/FreeImage.h view on Meta::CPAN
FI_SupportsExportTypeProc supports_export_type_proc;
FI_SupportsICCProfilesProc supports_icc_profiles_proc;
FI_SupportsNoPixelsProc supports_no_pixels_proc;
};
typedef void (DLL_CALLCONV *FI_InitProc)(Plugin *plugin, int format_id);
#endif // PLUGINS
// Load / Save flag constants -----------------------------------------------
#define FIF_LOAD_NOPIXELS 0x8000 //! loading: load the image header only (not supported by all plugins, default to full loading)
#define BMP_DEFAULT 0
#define BMP_SAVE_RLE 1
#define CUT_DEFAULT 0
#define DDS_DEFAULT 0
#define EXR_DEFAULT 0 //! save data as half with piz-based wavelet compression
#define EXR_FLOAT 0x0001 //! save data as float instead of as half (not recommended)
#define EXR_NONE 0x0002 //! save with no compression
src/Source/FreeImage.h view on Meta::CPAN
#define GIF_PLAYBACK 2 //! 'Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading
#define HDR_DEFAULT 0
#define ICO_DEFAULT 0
#define ICO_MAKEALPHA 1 //! convert to 32bpp and create an alpha channel from the AND-mask when loading
#define IFF_DEFAULT 0
#define J2K_DEFAULT 0 //! save with a 16:1 rate
#define JP2_DEFAULT 0 //! save with a 16:1 rate
#define JPEG_DEFAULT 0 //! loading (see JPEG_FAST); saving (see JPEG_QUALITYGOOD|JPEG_SUBSAMPLING_420)
#define JPEG_FAST 0x0001 //! load the file as fast as possible, sacrificing some quality
#define JPEG_ACCURATE 0x0002 //! load the file with the best quality, sacrificing some speed
#define JPEG_CMYK 0x0004 //! load separated CMYK "as is" (use | to combine with other load flags)
#define JPEG_EXIFROTATE 0x0008 //! load and rotate according to Exif 'Orientation' tag if available
#define JPEG_GREYSCALE 0x0010 //! load and convert to a 8-bit greyscale image
#define JPEG_QUALITYSUPERB 0x80 //! save with superb quality (100:1)
#define JPEG_QUALITYGOOD 0x0100 //! save with good quality (75:1)
#define JPEG_QUALITYNORMAL 0x0200 //! save with normal quality (50:1)
#define JPEG_QUALITYAVERAGE 0x0400 //! save with average quality (25:1)
#define JPEG_QUALITYBAD 0x0800 //! save with bad quality (10:1)
#define JPEG_PROGRESSIVE 0x2000 //! save as a progressive-JPEG (use | to combine with other save flags)
#define JPEG_SUBSAMPLING_411 0x1000 //! save with high 4x1 chroma subsampling (4:1:1)
#define JPEG_SUBSAMPLING_420 0x4000 //! save with medium 2x2 medium chroma subsampling (4:2:0) - default value
#define JPEG_SUBSAMPLING_422 0x8000 //! save with low 2x1 chroma subsampling (4:2:2)
#define JPEG_SUBSAMPLING_444 0x10000 //! save with no chroma subsampling (4:4:4)
#define JPEG_OPTIMIZE 0x20000 //! on saving, compute optimal Huffman coding tables (can reduce a few percent of file size)
#define JPEG_BASELINE 0x40000 //! save basic JPEG, without metadata or any markers
#define KOALA_DEFAULT 0
#define LBM_DEFAULT 0
#define MNG_DEFAULT 0
#define PCD_DEFAULT 0
#define PCD_BASE 1 //! load the bitmap sized 768 x 512
#define PCD_BASEDIV4 2 //! load the bitmap sized 384 x 256
#define PCD_BASEDIV16 3 //! load the bitmap sized 192 x 128
#define PCX_DEFAULT 0
#define PFM_DEFAULT 0
#define PICT_DEFAULT 0
#define PNG_DEFAULT 0
#define PNG_IGNOREGAMMA 1 //! loading: avoid gamma correction
#define PNG_Z_BEST_SPEED 0x0001 //! save using ZLib level 1 compression flag (default value is 6)
#define PNG_Z_DEFAULT_COMPRESSION 0x0006 //! save using ZLib level 6 compression flag (default recommended value)
#define PNG_Z_BEST_COMPRESSION 0x0009 //! save using ZLib level 9 compression flag (default value is 6)
#define PNG_Z_NO_COMPRESSION 0x0100 //! save without ZLib compression
#define PNG_INTERLACED 0x0200 //! save using Adam7 interlacing (use | to combine with other save flags)
#define PNM_DEFAULT 0
#define PNM_SAVE_RAW 0 //! if set the writer saves in RAW format (i.e. P4, P5 or P6)
#define PNM_SAVE_ASCII 1 //! if set the writer saves in ASCII format (i.e. P1, P2 or P3)
#define PSD_DEFAULT 0
#define PSD_CMYK 1 //! reads tags for separated CMYK (default is conversion to RGB)
#define PSD_LAB 2 //! reads tags for CIELab (default is conversion to RGB)
#define RAS_DEFAULT 0
#define RAW_DEFAULT 0 //! load the file as linear RGB 48-bit
#define RAW_PREVIEW 1 //! try to load the embedded JPEG preview with included Exif Data or default to RGB 24-bit
#define RAW_DISPLAY 2 //! load the file as RGB 24-bit
#define RAW_HALFSIZE 4 //! output a half-size color image
#define RAW_UNPROCESSED 8 //! output a FIT_UINT16 raw Bayer image
#define SGI_DEFAULT 0
#define TARGA_DEFAULT 0
#define TARGA_LOAD_RGB888 1 //! if set the loader converts RGB555 and ARGB8888 -> RGB888.
#define TARGA_SAVE_RLE 2 //! if set, the writer saves with RLE compression
#define TIFF_DEFAULT 0
#define TIFF_CMYK 0x0001 //! reads/stores tags for separated CMYK (use | to combine with compression flags)
#define TIFF_PACKBITS 0x0100 //! save using PACKBITS compression
#define TIFF_DEFLATE 0x0200 //! save using DEFLATE compression (a.k.a. ZLIB compression)
#define TIFF_ADOBE_DEFLATE 0x0400 //! save using ADOBE DEFLATE compression
#define TIFF_NONE 0x0800 //! save without any compression
#define TIFF_CCITTFAX3 0x1000 //! save using CCITT Group 3 fax encoding
#define TIFF_CCITTFAX4 0x2000 //! save using CCITT Group 4 fax encoding
#define TIFF_LZW 0x4000 //! save using LZW compression
#define TIFF_JPEG 0x8000 //! save using JPEG compression
#define TIFF_LOGLUV 0x10000 //! save using LogLuv compression
#define WBMP_DEFAULT 0
#define XBM_DEFAULT 0
#define XPM_DEFAULT 0
#define WEBP_DEFAULT 0 //! save with good quality (75:1)
#define WEBP_LOSSLESS 0x100 //! save in lossless mode
#define JXR_DEFAULT 0 //! save with quality 80 and no chroma subsampling (4:4:4)
#define JXR_LOSSLESS 0x0064 //! save lossless
#define JXR_PROGRESSIVE 0x2000 //! save as a progressive-JXR (use | to combine with other save flags)
// Background filling options ---------------------------------------------------------
// Constants used in FreeImage_FillBackground and FreeImage_EnlargeCanvas
#define FI_COLOR_IS_RGB_COLOR 0x00 //! RGBQUAD color is a RGB color (contains no valid alpha channel)
#define FI_COLOR_IS_RGBA_COLOR 0x01 //! RGBQUAD color is a RGBA color (contains a valid alpha channel)
#define FI_COLOR_FIND_EQUAL_COLOR 0x02 //! For palettized images: lookup equal RGB color from palette
#define FI_COLOR_ALPHA_IS_INDEX 0x04 //! The color's rgbReserved member (alpha) contains the palette index to be used
#define FI_COLOR_PALETTE_SEARCH_MASK (FI_COLOR_FIND_EQUAL_COLOR | FI_COLOR_ALPHA_IS_INDEX) // No color lookup is performed
src/Source/FreeImage.h view on Meta::CPAN
DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Allocate(int width, int height, int bpp, unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0));
DLL_API FIBITMAP *DLL_CALLCONV FreeImage_AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp FI_DEFAULT(8), unsigned red_mask FI_DEFAULT(0), unsigned green_mask FI_DEFAULT(0), unsigned blue_mask FI_DEFAULT(0));
DLL_API FIBITMAP * DLL_CALLCONV FreeImage_Clone(FIBITMAP *dib);
DLL_API void DLL_CALLCONV FreeImage_Unload(FIBITMAP *dib);
// Header loading routines
DLL_API BOOL DLL_CALLCONV FreeImage_HasPixels(FIBITMAP *dib);
// Load / Save routines -----------------------------------------------------
DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Load(FREE_IMAGE_FORMAT fif, const char *filename, int flags FI_DEFAULT(0));
DLL_API FIBITMAP *DLL_CALLCONV FreeImage_LoadU(FREE_IMAGE_FORMAT fif, const wchar_t *filename, int flags FI_DEFAULT(0));
DLL_API FIBITMAP *DLL_CALLCONV FreeImage_LoadFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags FI_DEFAULT(0));
DLL_API BOOL DLL_CALLCONV FreeImage_Save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, const char *filename, int flags FI_DEFAULT(0));
DLL_API BOOL DLL_CALLCONV FreeImage_SaveU(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, const wchar_t *filename, int flags FI_DEFAULT(0));
DLL_API BOOL DLL_CALLCONV FreeImage_SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FreeImageIO *io, fi_handle handle, int flags FI_DEFAULT(0));
// Memory I/O stream routines -----------------------------------------------
DLL_API FIMEMORY *DLL_CALLCONV FreeImage_OpenMemory(BYTE *data FI_DEFAULT(0), DWORD size_in_bytes FI_DEFAULT(0));
DLL_API void DLL_CALLCONV FreeImage_CloseMemory(FIMEMORY *stream);
DLL_API FIBITMAP *DLL_CALLCONV FreeImage_LoadFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY *stream, int flags FI_DEFAULT(0));
DLL_API BOOL DLL_CALLCONV FreeImage_SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FIMEMORY *stream, int flags FI_DEFAULT(0));
DLL_API long DLL_CALLCONV FreeImage_TellMemory(FIMEMORY *stream);
DLL_API BOOL DLL_CALLCONV FreeImage_SeekMemory(FIMEMORY *stream, long offset, int origin);
DLL_API BOOL DLL_CALLCONV FreeImage_AcquireMemory(FIMEMORY *stream, BYTE **data, DWORD *size_in_bytes);
DLL_API unsigned DLL_CALLCONV FreeImage_ReadMemory(void *buffer, unsigned size, unsigned count, FIMEMORY *stream);
DLL_API unsigned DLL_CALLCONV FreeImage_WriteMemory(const void *buffer, unsigned size, unsigned count, FIMEMORY *stream);
DLL_API FIMULTIBITMAP *DLL_CALLCONV FreeImage_LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY *stream, int flags FI_DEFAULT(0));
DLL_API BOOL DLL_CALLCONV FreeImage_SaveMultiBitmapToMemory(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, FIMEMORY *stream, int flags);
// Plugin Interface ---------------------------------------------------------
DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_RegisterLocalPlugin(FI_InitProc proc_address, const char *format FI_DEFAULT(0), const char *description FI_DEFAULT(0), const char *extension FI_DEFAULT(0), const char *regexpr FI_DEFAULT(0));
DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_RegisterExternalPlugin(const char *path, const char *format FI_DEFAULT(0), const char *description FI_DEFAULT(0), const char *extension FI_DEFAULT(0), const char *regexpr FI_DEFAULT(0));
DLL_API int DLL_CALLCONV FreeImage_GetFIFCount(void);
DLL_API int DLL_CALLCONV FreeImage_SetPluginEnabled(FREE_IMAGE_FORMAT fif, BOOL enable);
DLL_API int DLL_CALLCONV FreeImage_IsPluginEnabled(FREE_IMAGE_FORMAT fif);
DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFIFFromFormat(const char *format);
DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFIFFromMime(const char *mime);
src/Source/FreeImage.h view on Meta::CPAN
DLL_API FREE_IMAGE_FORMAT DLL_CALLCONV FreeImage_GetFIFFromFilenameU(const wchar_t *filename);
DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsReading(FREE_IMAGE_FORMAT fif);
DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsWriting(FREE_IMAGE_FORMAT fif);
DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsExportBPP(FREE_IMAGE_FORMAT fif, int bpp);
DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsExportType(FREE_IMAGE_FORMAT fif, FREE_IMAGE_TYPE type);
DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsICCProfiles(FREE_IMAGE_FORMAT fif);
DLL_API BOOL DLL_CALLCONV FreeImage_FIFSupportsNoPixels(FREE_IMAGE_FORMAT fif);
// Multipaging interface ----------------------------------------------------
DLL_API FIMULTIBITMAP * DLL_CALLCONV FreeImage_OpenMultiBitmap(FREE_IMAGE_FORMAT fif, const char *filename, BOOL create_new, BOOL read_only, BOOL keep_cache_in_memory FI_DEFAULT(FALSE), int flags FI_DEFAULT(0));
DLL_API FIMULTIBITMAP * DLL_CALLCONV FreeImage_OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags FI_DEFAULT(0));
DLL_API BOOL DLL_CALLCONV FreeImage_SaveMultiBitmapToHandle(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, FreeImageIO *io, fi_handle handle, int flags FI_DEFAULT(0));
DLL_API BOOL DLL_CALLCONV FreeImage_CloseMultiBitmap(FIMULTIBITMAP *bitmap, int flags FI_DEFAULT(0));
DLL_API int DLL_CALLCONV FreeImage_GetPageCount(FIMULTIBITMAP *bitmap);
DLL_API void DLL_CALLCONV FreeImage_AppendPage(FIMULTIBITMAP *bitmap, FIBITMAP *data);
DLL_API void DLL_CALLCONV FreeImage_InsertPage(FIMULTIBITMAP *bitmap, int page, FIBITMAP *data);
DLL_API void DLL_CALLCONV FreeImage_DeletePage(FIMULTIBITMAP *bitmap, int page);
DLL_API FIBITMAP * DLL_CALLCONV FreeImage_LockPage(FIMULTIBITMAP *bitmap, int page);
DLL_API void DLL_CALLCONV FreeImage_UnlockPage(FIMULTIBITMAP *bitmap, FIBITMAP *data, BOOL changed);
DLL_API BOOL DLL_CALLCONV FreeImage_MovePage(FIMULTIBITMAP *bitmap, int target, int source);
DLL_API BOOL DLL_CALLCONV FreeImage_GetLockedPageNumbers(FIMULTIBITMAP *bitmap, int *pages, int *count);
// Filetype request routines ------------------------------------------------
src/Source/FreeImage.h view on Meta::CPAN
/// @deprecated see FreeImage_Rotate
DLL_API FIBITMAP *DLL_CALLCONV FreeImage_RotateClassic(FIBITMAP *dib, double angle);
DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Rotate(FIBITMAP *dib, double angle, const void *bkcolor FI_DEFAULT(NULL));
DLL_API FIBITMAP *DLL_CALLCONV FreeImage_RotateEx(FIBITMAP *dib, double angle, double x_shift, double y_shift, double x_origin, double y_origin, BOOL use_mask);
DLL_API BOOL DLL_CALLCONV FreeImage_FlipHorizontal(FIBITMAP *dib);
DLL_API BOOL DLL_CALLCONV FreeImage_FlipVertical(FIBITMAP *dib);
// upsampling / downsampling
DLL_API FIBITMAP *DLL_CALLCONV FreeImage_Rescale(FIBITMAP *dib, int dst_width, int dst_height, FREE_IMAGE_FILTER filter FI_DEFAULT(FILTER_CATMULLROM));
DLL_API FIBITMAP *DLL_CALLCONV FreeImage_MakeThumbnail(FIBITMAP *dib, int max_pixel_size, BOOL convert FI_DEFAULT(TRUE));
DLL_API FIBITMAP *DLL_CALLCONV FreeImage_RescaleRect(FIBITMAP *dib, int dst_width, int dst_height, int left, int top, int right, int bottom, FREE_IMAGE_FILTER filter FI_DEFAULT(FILTER_CATMULLROM), unsigned flags FI_DEFAULT(0));
// color manipulation routines (point operations)
DLL_API BOOL DLL_CALLCONV FreeImage_AdjustCurve(FIBITMAP *dib, BYTE *LUT, FREE_IMAGE_COLOR_CHANNEL channel);
DLL_API BOOL DLL_CALLCONV FreeImage_AdjustGamma(FIBITMAP *dib, double gamma);
DLL_API BOOL DLL_CALLCONV FreeImage_AdjustBrightness(FIBITMAP *dib, double percentage);
DLL_API BOOL DLL_CALLCONV FreeImage_AdjustContrast(FIBITMAP *dib, double percentage);
DLL_API BOOL DLL_CALLCONV FreeImage_Invert(FIBITMAP *dib);
DLL_API BOOL DLL_CALLCONV FreeImage_GetHistogram(FIBITMAP *dib, DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel FI_DEFAULT(FICC_BLACK));
DLL_API int DLL_CALLCONV FreeImage_GetAdjustColorsLookupTable(BYTE *LUT, double brightness, double contrast, double gamma, BOOL invert);
DLL_API BOOL DLL_CALLCONV FreeImage_AdjustColors(FIBITMAP *dib, double brightness, double contrast, double gamma, BOOL invert FI_DEFAULT(FALSE));
src/Source/FreeImage/BitmapAccess.cpp view on Meta::CPAN
fih->transparency_count = 0;
memset(fih->transparent_table, 0xff, 256);
fih->has_pixels = header_only ? FALSE : TRUE;
// initialize FIICCPROFILE link
FIICCPROFILE *iccProfile = FreeImage_GetICCProfile(bitmap);
iccProfile->size = 0;
iccProfile->data = 0;
iccProfile->flags = 0;
// initialize metadata models list
fih->metadata = new(std::nothrow) METADATAMAP;
// initialize attached thumbnail
fih->thumbnail = NULL;
// store a pointer to user provided pixel buffer (if any)
src/Source/FreeImage/BitmapAccess.cpp view on Meta::CPAN
memset(dst_iccProfile, 0, sizeof(FIICCPROFILE));
// restore metadata link for new_dib
((FREEIMAGEHEADER *)new_dib->data)->metadata = dst_metadata;
// reset thumbnail link for new_dib
((FREEIMAGEHEADER *)new_dib->data)->thumbnail = NULL;
// copy possible ICC profile
FreeImage_CreateICCProfile(new_dib, src_iccProfile->data, src_iccProfile->size);
dst_iccProfile->flags = src_iccProfile->flags;
// copy metadata models
for(METADATAMAP::iterator i = (*src_metadata).begin(); i != (*src_metadata).end(); i++) {
int model = (*i).first;
TAGMAP *src_tagmap = (*i).second;
if(src_tagmap) {
// create a metadata model
TAGMAP *dst_tagmap = new(std::nothrow) TAGMAP();
src/Source/FreeImage/BitmapAccess.cpp view on Meta::CPAN
return minisblack ? FIC_MINISBLACK : FIC_MINISWHITE;
}
case 16:
case 24:
return FIC_RGB;
case 32:
{
if (FreeImage_GetICCProfile(dib)->flags & FIICC_COLOR_IS_CMYK) {
return FIC_CMYK;
}
if( FreeImage_HasPixels(dib) ) {
// check for fully opaque alpha layer
for (unsigned y = 0; y < FreeImage_GetHeight(dib); y++) {
rgb = (RGBQUAD *)FreeImage_GetScanLine(dib, y);
for (unsigned x = 0; x < FreeImage_GetWidth(dib); x++) {
if (rgb[x].rgbReserved != 0xFF) {
src/Source/FreeImage/BitmapAccess.cpp view on Meta::CPAN
// ----------------------------------------------------------
FIICCPROFILE * DLL_CALLCONV
FreeImage_GetICCProfile(FIBITMAP *dib) {
FIICCPROFILE *profile = (dib) ? (FIICCPROFILE *)&((FREEIMAGEHEADER *)dib->data)->iccProfile : NULL;
return profile;
}
FIICCPROFILE * DLL_CALLCONV
FreeImage_CreateICCProfile(FIBITMAP *dib, void *data, long size) {
// clear the profile but preserve profile->flags
FreeImage_DestroyICCProfile(dib);
// create the new profile
FIICCPROFILE *profile = FreeImage_GetICCProfile(dib);
if(size && profile) {
profile->data = malloc(size);
if(profile->data) {
memcpy(profile->data, data, profile->size = size);
}
}
return profile;
}
void DLL_CALLCONV
FreeImage_DestroyICCProfile(FIBITMAP *dib) {
FIICCPROFILE *profile = FreeImage_GetICCProfile(dib);
if(profile) {
if (profile->data) {
free (profile->data);
}
// clear the profile but preserve profile->flags
profile->data = NULL;
profile->size = 0;
}
}
// ----------------------------------------------------------
unsigned DLL_CALLCONV
FreeImage_GetWidth(FIBITMAP *dib) {
return dib ? FreeImage_GetInfoHeader(dib)->biWidth : 0;
src/Source/FreeImage/MNGHelper.cpp view on Meta::CPAN
bResult = mng_CopyInsertChunks(hPngMemory, inNextChunkName, inInsertChunk, chunk_length, start_pos, next_pos);
if(!bResult) {
return FALSE;
}
return TRUE;
}
static FIBITMAP*
mng_LoadFromMemoryHandle(FIMEMORY *hmem, int flags = 0) {
long offset = 0;
FIBITMAP *dib = NULL;
if(hmem) {
// seek to the start of the stream
FreeImage_SeekMemory(hmem, offset, SEEK_SET);
// check the file signature and deduce its format
// (the second argument is currently not used by FreeImage)
FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(hmem, 0);
if(fif != FIF_UNKNOWN) {
dib = FreeImage_LoadFromMemory(fif, hmem, flags);
}
}
return dib;
}
/**
Write a chunk in a PNG stream from the current position.
@param chunk_name Name of the chunk
@param chunk_data Chunk array
src/Source/FreeImage/MNGHelper.cpp view on Meta::CPAN
}
// --------------------------------------------------------------------------
/**
Load a FIBITMAP from a MNG or a JNG stream
@param format_id ID of the caller
@param io Stream i/o functions
@param handle Stream handle
@param Offset Start of the first chunk
@param flags Loading flags
@return Returns a dib if successful, returns NULL otherwise
*/
FIBITMAP*
mng_ReadChunks(int format_id, FreeImageIO *io, fi_handle handle, long Offset, int flags = 0) {
DWORD mLength = 0;
BYTE mChunkName[5];
BYTE *mChunk = NULL;
DWORD crc_file;
long LastOffset;
long mOrigPos;
BYTE *PLTE_file_chunk = NULL; // whole PLTE chunk (lentgh, name, array, crc)
DWORD PLTE_file_size = 0; // size of PLTE chunk
BOOL m_HasGlobalPalette = FALSE; // may turn to TRUE in PLTE chunk
src/Source/FreeImage/MNGHelper.cpp view on Meta::CPAN
DWORD res_y = 2835; // 72 dpi
RGBQUAD rgbBkColor = {0, 0, 0, 0};
WORD bk_red, bk_green, bk_blue;
BOOL hasBkColor = FALSE;
BOOL mHasIDAT = FALSE;
tEXtMAP key_value_pair;
// ---
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
// get the file size
const long mLOF = mng_LOF(io, handle);
// go to the first chunk
io->seek_proc(handle, Offset, SEEK_SET);
try {
BOOL mEnd = FALSE;
while(mEnd == FALSE) {
src/Source/FreeImage/MNGHelper.cpp view on Meta::CPAN
// ensure we remove some local chunks, so that global
// "PLTE" can be inserted right before "IDAT".
mng_RemoveChunk(hPngMemory, mng_PLTE);
mng_RemoveChunk(hPngMemory, mng_tRNS);
mng_RemoveChunk(hPngMemory, mng_bKGD);
// insert global "PLTE" chunk in its entirety before "IDAT"
mng_InsertChunk(hPngMemory, mng_IDAT, PLTE_file_chunk, PLTE_file_size);
}
if(dib) FreeImage_Unload(dib);
dib = mng_LoadFromMemoryHandle(hPngMemory, flags);
// stop after the first image
mEnd = TRUE;
break;
case JHDR:
if(mLength == 16) {
memcpy(&jng_width, &mChunk[0], 4);
memcpy(&jng_height, &mChunk[4], 4);
mng_SwapLong(&jng_width);
src/Source/FreeImage/MNGHelper.cpp view on Meta::CPAN
case IEND:
if(!hJpegMemory) {
mEnd = TRUE;
break;
}
// load the JPEG
if(dib) {
FreeImage_Unload(dib);
}
dib = mng_LoadFromMemoryHandle(hJpegMemory, flags);
// load the PNG alpha layer
if(mHasIDAT) {
BYTE *data = NULL;
DWORD size_in_bytes = 0;
// get a pointer to the IDAT buffer
FreeImage_AcquireMemory(hIDATMemory, &data, &size_in_bytes);
if(data && size_in_bytes) {
// wrap the IDAT chunk as a PNG stream
if(hPngMemory == NULL) {
hPngMemory = FreeImage_OpenMemory();
}
mng_WritePNGStream(jng_width, jng_height, jng_alpha_sample_depth, data, size_in_bytes, hPngMemory);
// load the PNG
if(dib_alpha) {
FreeImage_Unload(dib_alpha);
}
dib_alpha = mng_LoadFromMemoryHandle(hPngMemory, flags);
}
}
// stop the parsing
mEnd = TRUE;
break;
case JDAA:
break;
case gAMA:
src/Source/FreeImage/MNGHelper.cpp view on Meta::CPAN
}
// --------------------------------------------------------------------------
/**
Write a FIBITMAP to a JNG stream
@param format_id ID of the caller
@param io Stream i/o functions
@param dib Image to be saved
@param handle Stream handle
@param flags Saving flags
@return Returns TRUE if successful, returns FALSE otherwise
*/
BOOL
mng_WriteJNG(int format_id, FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int flags) {
DWORD jng_width = 0;
DWORD jng_height = 0;
BYTE jng_color_type = 0;
BYTE jng_image_sample_depth = 8;
BYTE jng_image_compression_method = 8; // 8: ISO-10918-1 Huffman-coded baseline JPEG.
BYTE jng_image_interlace_method = 0;
BYTE jng_alpha_sample_depth = 0;
BYTE jng_alpha_compression_method = 0;
BYTE jng_alpha_filter_method = 0;
src/Source/FreeImage/MNGHelper.cpp view on Meta::CPAN
buffer[10] = jng_image_compression_method;
buffer[11] = jng_image_interlace_method;
buffer[12] = jng_alpha_sample_depth;
buffer[13] = jng_alpha_compression_method;
buffer[14] = jng_alpha_filter_method;
buffer[15] = jng_alpha_interlace_method;
mng_WriteChunk(mng_JHDR, &buffer[0], 16, hJngMemory);
// --- write a sequence of JDAT chunks ---
hJpegMemory = FreeImage_OpenMemory();
flags |= JPEG_BASELINE;
if(!FreeImage_SaveToMemory(FIF_JPEG, dib_rgb, hJpegMemory, flags)) {
throw (const char*)NULL;
}
if(dib_rgb != dib) {
FreeImage_Unload(dib_rgb);
dib_rgb = NULL;
}
{
BYTE *jpeg_data = NULL;
DWORD size_in_bytes = 0;
src/Source/FreeImage/MemoryIO.cpp view on Meta::CPAN
free(mem_header);
free(stream);
}
}
// =====================================================================
// Memory stream load/save functions
// =====================================================================
FIBITMAP * DLL_CALLCONV
FreeImage_LoadFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY *stream, int flags) {
if (stream && stream->data) {
FreeImageIO io;
SetMemoryIO(&io);
return FreeImage_LoadFromHandle(fif, &io, (fi_handle)stream, flags);
}
return NULL;
}
BOOL DLL_CALLCONV
FreeImage_SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FIMEMORY *stream, int flags) {
if (stream) {
FreeImageIO io;
SetMemoryIO(&io);
FIMEMORYHEADER *mem_header = (FIMEMORYHEADER*)(stream->data);
if(mem_header->delete_me == TRUE) {
return FreeImage_SaveToHandle(fif, dib, &io, (fi_handle)stream, flags);
} else {
// do not save in a user buffer
FreeImage_OutputMessageProc(fif, "Memory buffer is read only");
}
}
return FALSE;
}
// =====================================================================
src/Source/FreeImage/MultiPage.cpp view on Meta::CPAN
FreeImageIO *io;
fi_handle handle;
CacheFile *m_cachefile;
std::map<FIBITMAP *, int> locked_pages;
BOOL changed;
int page_count;
BlockList m_blocks;
char *m_filename;
BOOL read_only;
FREE_IMAGE_FORMAT cache_fif;
int load_flags;
};
// =====================================================================
// Helper functions
// =====================================================================
inline void
ReplaceExtension(std::string& dst_filename, const std::string& src_filename, const std::string& dst_extension) {
size_t lastDot = src_filename.find_last_of('.');
if (lastDot == std::string::npos) {
src/Source/FreeImage/MultiPage.cpp view on Meta::CPAN
}
return 0;
}
// =====================================================================
// Multipage functions
// =====================================================================
FIMULTIBITMAP * DLL_CALLCONV
FreeImage_OpenMultiBitmap(FREE_IMAGE_FORMAT fif, const char *filename, BOOL create_new, BOOL read_only, BOOL keep_cache_in_memory, int flags) {
FILE *handle = NULL;
try {
// sanity check on the parameters
if (create_new) {
read_only = FALSE;
}
// retrieve the plugin list to find the node belonging to this plugin
src/Source/FreeImage/MultiPage.cpp view on Meta::CPAN
header->m_filename = new char[strlen(filename) + 1];
strcpy(header->m_filename, filename);
header->node = node;
header->fif = fif;
header->io = io.get ();
header->handle = handle;
header->changed = FALSE;
header->read_only = read_only;
header->m_cachefile = NULL;
header->cache_fif = fif;
header->load_flags = flags;
// store the MULTIBITMAPHEADER in the surrounding FIMULTIBITMAP structure
bitmap->data = header.get();
// cache the page count
header->page_count = FreeImage_InternalGetPageCount(bitmap.get());
// allocate a continueus block to describe the bitmap
src/Source/FreeImage/MultiPage.cpp view on Meta::CPAN
}
} catch (std::bad_alloc &) {
/** @todo report error */
}
if (handle)
fclose(handle);
return NULL;
}
FIMULTIBITMAP * DLL_CALLCONV
FreeImage_OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags) {
try {
BOOL read_only = FALSE; // modifications (if any) will be stored into the memory cache
if (io && handle) {
// retrieve the plugin list to find the node belonging to this plugin
PluginList *list = FreeImage_GetPluginList();
if (list) {
PluginNode *node = list->FindNodeFromFIF(fif);
src/Source/FreeImage/MultiPage.cpp view on Meta::CPAN
std::auto_ptr<FreeImageIO> tmp_io (new FreeImageIO (*io));
header->io = tmp_io.get();
header->m_filename = NULL;
header->node = node;
header->fif = fif;
header->handle = handle;
header->changed = FALSE;
header->read_only = read_only;
header->m_cachefile = NULL;
header->cache_fif = fif;
header->load_flags = flags;
// store the MULTIBITMAPHEADER in the surrounding FIMULTIBITMAP structure
bitmap->data = header.get();
// cache the page count
header->page_count = FreeImage_InternalGetPageCount(bitmap.get());
// allocate a continueus block to describe the bitmap
src/Source/FreeImage/MultiPage.cpp view on Meta::CPAN
}
}
}
} catch (std::bad_alloc &) {
/** @todo report error */
}
return NULL;
}
BOOL DLL_CALLCONV
FreeImage_SaveMultiBitmapToHandle(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, FreeImageIO *io, fi_handle handle, int flags) {
if(!bitmap || !bitmap->data || !io || !handle) {
return FALSE;
}
BOOL success = TRUE;
// retrieve the plugin list to find the node belonging to this plugin
PluginList *list = FreeImage_GetPluginList();
if (list) {
src/Source/FreeImage/MultiPage.cpp view on Meta::CPAN
for (BlockListIterator i = header->m_blocks.begin(); i != header->m_blocks.end(); i++) {
if (success) {
switch((*i)->m_type) {
case BLOCK_CONTINUEUS:
{
BlockContinueus *block = (BlockContinueus *)(*i);
for (int j = block->m_start; j <= block->m_end; j++) {
// load the original source data
FIBITMAP *dib = header->node->m_plugin->load_proc(header->io, header->handle, j, header->load_flags, data_read);
// save the data
success = node->m_plugin->save_proc(io, dib, handle, count, flags, data);
count++;
FreeImage_Unload(dib);
}
break;
}
case BLOCK_REFERENCE:
{
src/Source/FreeImage/MultiPage.cpp view on Meta::CPAN
FIMEMORY *hmem = FreeImage_OpenMemory(compressed_data, ref->m_size);
FIBITMAP *dib = FreeImage_LoadFromMemory(header->cache_fif, hmem, 0);
FreeImage_CloseMemory(hmem);
// get rid of the buffer
free(compressed_data);
// save the data
success = node->m_plugin->save_proc(io, dib, handle, count, flags, data);
count++;
// unload the dib
FreeImage_Unload(dib);
break;
}
}
} else {
src/Source/FreeImage/MultiPage.cpp view on Meta::CPAN
return success;
}
}
return FALSE;
}
BOOL DLL_CALLCONV
FreeImage_CloseMultiBitmap(FIMULTIBITMAP *bitmap, int flags) {
if (bitmap) {
BOOL success = TRUE;
if (bitmap->data) {
MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap);
// saves changes only of images loaded directly from a file
if (header->changed && header->m_filename) {
try {
// open a temp file
src/Source/FreeImage/MultiPage.cpp view on Meta::CPAN
// open the spool file and the source file
FILE *f = fopen(spool_name.c_str(), "w+b");
// saves changes
if (f == NULL) {
FreeImage_OutputMessageProc(header->fif, "Failed to open %s, %s", spool_name.c_str(), strerror(errno));
success = FALSE;
} else {
success = FreeImage_SaveMultiBitmapToHandle(header->fif, bitmap, header->io, (fi_handle)f, flags);
// close the files
if (fclose(f) != 0) {
success = FALSE;
FreeImage_OutputMessageProc(header->fif, "Failed to close %s, %s", spool_name.c_str(), strerror(errno));
}
}
if (header->handle) {
fclose((FILE *)header->handle);
src/Source/FreeImage/MultiPage.cpp view on Meta::CPAN
// open the bitmap
header->io->seek_proc(header->handle, 0, SEEK_SET);
void *data = FreeImage_Open(header->node, header->io, header->handle, TRUE);
// load the bitmap data
if (data != NULL) {
FIBITMAP *dib = (header->node->m_plugin->load_proc != NULL) ? header->node->m_plugin->load_proc(header->io, header->handle, page, header->load_flags, data) : NULL;
// close the file
FreeImage_Close(header->node, header->io, header->handle, data);
// if there was still another bitmap open, get rid of it
if (dib) {
header->locked_pages[dib] = page;
src/Source/FreeImage/MultiPage.cpp view on Meta::CPAN
}
return FALSE;
}
// =====================================================================
// Memory IO Multipage functions
// =====================================================================
FIMULTIBITMAP * DLL_CALLCONV
FreeImage_LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY *stream, int flags) {
BOOL read_only = FALSE; // modifications (if any) will be stored into the memory cache
// retrieve the plugin list to find the node belonging to this plugin
PluginList *list = FreeImage_GetPluginList();
if (list) {
PluginNode *node = list->FindNodeFromFIF(fif);
if (node) {
src/Source/FreeImage/MultiPage.cpp view on Meta::CPAN
if (header) {
header->m_filename = NULL;
header->node = node;
header->fif = fif;
header->io = io;
header->handle = (fi_handle)stream;
header->changed = FALSE;
header->read_only = read_only;
header->m_cachefile = NULL;
header->cache_fif = fif;
header->load_flags = flags;
// store the MULTIBITMAPHEADER in the surrounding FIMULTIBITMAP structure
bitmap->data = header;
// cache the page count
header->page_count = FreeImage_InternalGetPageCount(bitmap);
// allocate a continueus block to describe the bitmap
src/Source/FreeImage/MultiPage.cpp view on Meta::CPAN
delete io;
}
}
}
return NULL;
}
BOOL DLL_CALLCONV
FreeImage_SaveMultiBitmapToMemory(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, FIMEMORY *stream, int flags) {
if (stream && stream->data) {
FreeImageIO io;
SetMemoryIO(&io);
return FreeImage_SaveMultiBitmapToHandle(fif, bitmap, &io, (fi_handle)stream, flags);
}
return FALSE;
}
src/Source/FreeImage/PSDParser.cpp view on Meta::CPAN
psdParser::psdParser() {
_bThumbnailFilled = false;
_bDisplayInfoFilled = false;
_bResolutionInfoFilled = false;
_bResolutionInfoFilled_v2 = false;
_bCopyright = false;
_GlobalAngle = 30;
_ColourCount = -1;
_TransparentIndex = -1;
_fi_flags = 0;
_fi_format_id = FIF_UNKNOWN;
}
psdParser::~psdParser() {
}
bool psdParser::ReadLayerAndMaskInfoSection(FreeImageIO *io, fi_handle handle) {
bool bSuccess = false;
BYTE DataLength[4];
src/Source/FreeImage/PSDParser.cpp view on Meta::CPAN
_bResolutionInfoFilled = true;
nBytes += _resolutionInfo.Read(io, handle);
break;
// DisplayInfo structure
case 1007:
_bDisplayInfoFilled = true;
nBytes += _displayInfo.Read(io, handle);
break;
// (Photoshop 4.0) Copyright flag
// Boolean indicating whether image is copyrighted. Can be set via Property suite or by user in File Info...
case 1034:
n = (int)io->read_proc(&ShortValue, sizeof(ShortValue), 1, handle);
nBytes += n * sizeof(ShortValue);
_bCopyright = (1 == psdGetValue(ShortValue, sizeof(ShortValue)));
break;
// (Photoshop 4.0) Thumbnail resource for Photoshop 4.0 only
case 1033:
// (Photoshop 5.0) Thumbnail resource (supersedes resource 1033)
src/Source/FreeImage/PSDParser.cpp view on Meta::CPAN
}
return bSuccess;
}
FIBITMAP* psdParser::ReadImageData(FreeImageIO *io, fi_handle handle) {
if(handle == NULL)
return NULL;
bool header_only = (_fi_flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
WORD nCompression = 0;
io->read_proc(&nCompression, sizeof(nCompression), 1, handle);
#ifndef FREEIMAGE_BIGENDIAN
SwapShort(&nCompression);
#endif
if((nCompression != PSDP_COMPRESSION_NONE && nCompression != PSDP_COMPRESSION_RLE)) {
FreeImage_OutputMessageProc(_fi_format_id, "Unsupported compression %d", nCompression);
src/Source/FreeImage/PSDParser.cpp view on Meta::CPAN
if((mode == PSDP_CMYK || mode == PSDP_MULTICHANNEL)) {
// CMYK values are "inverted", invert them back
if(mode == PSDP_MULTICHANNEL) {
invertColor(bitmap);
} else {
FreeImage_Invert(bitmap);
}
if((_fi_flags & PSD_CMYK) == PSD_CMYK) {
// keep as CMYK
if(mode == PSDP_MULTICHANNEL) {
//### we force CMY to be CMYK, but CMY has no ICC.
// Create empty profile and add the flag.
FreeImage_CreateICCProfile(bitmap, NULL, 0);
FreeImage_GetICCProfile(bitmap)->flags |= FIICC_COLOR_IS_CMYK;
}
}
else {
// convert to RGB
ConvertCMYKtoRGBA(bitmap);
// The ICC Profile is no longer valid
_iccProfile.clear();
// remove the pending A if not present in source
if(nChannels == 4 || nChannels == 3 ) {
FIBITMAP* t = RemoveAlphaChannel(bitmap);
if(t) {
FreeImage_Unload(bitmap);
bitmap = t;
} // else: silently fail
}
}
}
else if ( mode == PSDP_LAB && !((_fi_flags & PSD_LAB) == PSD_LAB)) {
ConvertLABtoRGB(bitmap);
}
else {
if (needPalette && FreeImage_GetPalette(bitmap)) {
if(mode == PSDP_BITMAP) {
CREATE_GREYSCALE_PALETTE_REVERSE(FreeImage_GetPalette(bitmap), 2);
}
else if(mode == PSDP_INDEXED) {
if(!_colourModeData._plColourData || _colourModeData._Length != 768 || _ColourCount < 0) {
src/Source/FreeImage/PSDParser.cpp view on Meta::CPAN
#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR
if(FreeImage_GetImageType(bitmap) == FIT_BITMAP) {
SwapRedBlue32(bitmap);
}
#endif
}
return bitmap;
}
FIBITMAP* psdParser::Load(FreeImageIO *io, fi_handle handle, int s_format_id, int flags) {
FIBITMAP *Bitmap = NULL;
_fi_flags = flags;
_fi_format_id = s_format_id;
try {
if (NULL == handle) {
throw("Cannot open file");
}
if (!_headerInfo.Read(io, handle)) {
throw("Error in header");
}
src/Source/FreeImage/PSDParser.cpp view on Meta::CPAN
unsigned res_y = 2835; // 72 dpi
if (_bResolutionInfoFilled) {
_resolutionInfo.GetResolutionInfo(res_x, res_y);
}
FreeImage_SetDotsPerMeterX(Bitmap, res_x);
FreeImage_SetDotsPerMeterY(Bitmap, res_y);
}
// set ICC profile
FreeImage_CreateICCProfile(Bitmap, _iccProfile._ProfileData, _iccProfile._ProfileSize);
if ((flags & PSD_CMYK) == PSD_CMYK) {
short mode = _headerInfo._ColourMode;
if((mode == PSDP_CMYK) || (mode == PSDP_MULTICHANNEL)) {
FreeImage_GetICCProfile(Bitmap)->flags |= FIICC_COLOR_IS_CMYK;
}
}
} catch(const char *text) {
FreeImage_OutputMessageProc(s_format_id, text);
}
catch(const std::exception& e) {
FreeImage_OutputMessageProc(s_format_id, "%s", e.what());
}
src/Source/FreeImage/PSDParser.h view on Meta::CPAN
short _ColourCount;
short _TransparentIndex;
int _GlobalAngle;
bool _bResolutionInfoFilled;
bool _bResolutionInfoFilled_v2;
bool _bDisplayInfoFilled;
bool _bThumbnailFilled;
bool _bCopyright;
int _fi_flags;
int _fi_format_id;
private:
/** Actually ignore it */
bool ReadLayerAndMaskInfoSection(FreeImageIO *io, fi_handle handle);
FIBITMAP* ReadImageData(FreeImageIO *io, fi_handle handle);
public:
psdParser();
~psdParser();
FIBITMAP* Load(FreeImageIO *io, fi_handle handle, int s_format_id, int flags=0);
/** Also used by the TIFF plugin */
bool ReadImageResources(FreeImageIO *io, fi_handle handle, LONG length=0);
/** Used by the TIFF plugin */
FIBITMAP* GetThumbnail() {
return _thumbnail.getDib();
}
};
#endif // PSDPARSER_H
src/Source/FreeImage/Plugin.cpp view on Meta::CPAN
if (node->m_plugin->close_proc != NULL) {
node->m_plugin->close_proc(io, handle, data);
}
}
// =====================================================================
// Plugin System Load/Save Functions
// =====================================================================
FIBITMAP * DLL_CALLCONV
FreeImage_LoadFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags) {
if ((fif >= 0) && (fif < FreeImage_GetFIFCount())) {
PluginNode *node = s_plugins->FindNodeFromFIF(fif);
if (node != NULL) {
if(node->m_plugin->load_proc != NULL) {
void *data = FreeImage_Open(node, io, handle, TRUE);
FIBITMAP *bitmap = node->m_plugin->load_proc(io, handle, -1, flags, data);
FreeImage_Close(node, io, handle, data);
return bitmap;
}
}
}
return NULL;
}
FIBITMAP * DLL_CALLCONV
FreeImage_Load(FREE_IMAGE_FORMAT fif, const char *filename, int flags) {
FreeImageIO io;
SetDefaultIO(&io);
FILE *handle = fopen(filename, "rb");
if (handle) {
FIBITMAP *bitmap = FreeImage_LoadFromHandle(fif, &io, (fi_handle)handle, flags);
fclose(handle);
return bitmap;
} else {
FreeImage_OutputMessageProc((int)fif, "FreeImage_Load: failed to open file %s", filename);
}
return NULL;
}
FIBITMAP * DLL_CALLCONV
FreeImage_LoadU(FREE_IMAGE_FORMAT fif, const wchar_t *filename, int flags) {
FreeImageIO io;
SetDefaultIO(&io);
#ifdef _WIN32
FILE *handle = _wfopen(filename, L"rb");
if (handle) {
FIBITMAP *bitmap = FreeImage_LoadFromHandle(fif, &io, (fi_handle)handle, flags);
fclose(handle);
return bitmap;
} else {
FreeImage_OutputMessageProc((int)fif, "FreeImage_LoadU: failed to open input file");
}
#endif
return NULL;
}
BOOL DLL_CALLCONV
FreeImage_SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FreeImageIO *io, fi_handle handle, int flags) {
// cannot save "header only" formats
if(FreeImage_HasPixels(dib) == FALSE) {
FreeImage_OutputMessageProc((int)fif, "FreeImage_SaveToHandle: cannot save \"header only\" formats");
return FALSE;
}
if ((fif >= 0) && (fif < FreeImage_GetFIFCount())) {
PluginNode *node = s_plugins->FindNodeFromFIF(fif);
if (node) {
if(node->m_plugin->save_proc != NULL) {
void *data = FreeImage_Open(node, io, handle, FALSE);
BOOL result = node->m_plugin->save_proc(io, dib, handle, -1, flags, data);
FreeImage_Close(node, io, handle, data);
return result;
}
}
}
return FALSE;
}
BOOL DLL_CALLCONV
FreeImage_Save(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, const char *filename, int flags) {
FreeImageIO io;
SetDefaultIO(&io);
FILE *handle = fopen(filename, "w+b");
if (handle) {
BOOL success = FreeImage_SaveToHandle(fif, dib, &io, (fi_handle)handle, flags);
fclose(handle);
return success;
} else {
FreeImage_OutputMessageProc((int)fif, "FreeImage_Save: failed to open file %s", filename);
}
return FALSE;
}
BOOL DLL_CALLCONV
FreeImage_SaveU(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, const wchar_t *filename, int flags) {
FreeImageIO io;
SetDefaultIO(&io);
#ifdef _WIN32
FILE *handle = _wfopen(filename, L"w+b");
if (handle) {
BOOL success = FreeImage_SaveToHandle(fif, dib, &io, (fi_handle)handle, flags);
fclose(handle);
return success;
} else {
FreeImage_OutputMessageProc((int)fif, "FreeImage_SaveU: failed to open output file");
}
#endif
return FALSE;
}
src/Source/FreeImage/PluginBMP.cpp view on Meta::CPAN
break;
}
}
}
}
// --------------------------------------------------------------------------
static FIBITMAP *
LoadWindowsBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bits_offset, int type) {
FIBITMAP *dib = NULL;
try {
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
// load the info header
BITMAPINFOHEADER bih;
io->read_proc(&bih, sizeof(BITMAPINFOHEADER), 1, handle);
#ifdef FREEIMAGE_BIGENDIAN
SwapInfoHeader(&bih);
#endif
src/Source/FreeImage/PluginBMP.cpp view on Meta::CPAN
FreeImage_OutputMessageProc(s_format_id, message);
}
}
return NULL;
}
// --------------------------------------------------------------------------
static FIBITMAP *
LoadOS22XBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bits_offset) {
FIBITMAP *dib = NULL;
try {
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
// load the info header
BITMAPINFOHEADER bih;
io->read_proc(&bih, sizeof(BITMAPINFOHEADER), 1, handle);
#ifdef FREEIMAGE_BIGENDIAN
SwapInfoHeader(&bih);
#endif
src/Source/FreeImage/PluginBMP.cpp view on Meta::CPAN
FreeImage_OutputMessageProc(s_format_id, message);
}
return NULL;
}
// --------------------------------------------------------------------------
static FIBITMAP *
LoadOS21XBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bits_offset) {
FIBITMAP *dib = NULL;
try {
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
BITMAPINFOOS2_1X_HEADER bios2_1x;
io->read_proc(&bios2_1x, sizeof(BITMAPINFOOS2_1X_HEADER), 1, handle);
#ifdef FREEIMAGE_BIGENDIAN
SwapOS21XHeader(&bios2_1x);
#endif
// keep some general information about the bitmap
unsigned used_colors = 0;
src/Source/FreeImage/PluginBMP.cpp view on Meta::CPAN
}
static BOOL DLL_CALLCONV
SupportsNoPixels() {
return TRUE;
}
// ----------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
if (handle != NULL) {
BITMAPFILEHEADER bitmapfileheader;
DWORD type = 0;
// we use this offset value to make seemingly absolute seeks relative in the file
long offset_in_file = io->tell_proc(handle);
// read the fileheader
src/Source/FreeImage/PluginBMP.cpp view on Meta::CPAN
io->seek_proc(handle, 0 - (long)sizeof(DWORD), SEEK_CUR);
#ifdef FREEIMAGE_BIGENDIAN
SwapLong(&type);
#endif
// call the appropriate load function for the found bitmap type
switch(type) {
case 12:
// OS/2 and also all Windows versions since Windows 3.0
return LoadOS21XBMP(io, handle, flags, offset_in_file + bitmapfileheader.bfOffBits);
case 64:
// OS/2
return LoadOS22XBMP(io, handle, flags, offset_in_file + bitmapfileheader.bfOffBits);
case 40: // BITMAPINFOHEADER - all Windows versions since Windows 3.0
case 52: // BITMAPV2INFOHEADER (undocumented, partially supported)
case 56: // BITMAPV3INFOHEADER (undocumented, partially supported)
case 108: // BITMAPV4HEADER - all Windows versions since Windows 95/NT4 (partially supported)
case 124: // BITMAPV5HEADER - Windows 98/2000 and newer (partially supported)
return LoadWindowsBMP(io, handle, flags, offset_in_file + bitmapfileheader.bfOffBits, type);
default:
break;
}
FreeImage_OutputMessageProc(s_format_id, "unknown bmp subtype with id %d", type);
}
return NULL;
}
src/Source/FreeImage/PluginBMP.cpp view on Meta::CPAN
target[target_pos++] = RLE_COMMAND;
target[target_pos++] = RLE_ENDOFLINE;
// return the written size
return target_pos;
}
static BOOL DLL_CALLCONV
Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
if ((dib != NULL) && (handle != NULL)) {
// write the file header
BITMAPFILEHEADER bitmapfileheader;
bitmapfileheader.bfType = 0x4D42;
bitmapfileheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + FreeImage_GetColorsUsed(dib) * sizeof(RGBQUAD);
bitmapfileheader.bfSize = bitmapfileheader.bfOffBits + FreeImage_GetHeight(dib) * FreeImage_GetPitch(dib);
bitmapfileheader.bfReserved1 = 0;
bitmapfileheader.bfReserved2 = 0;
src/Source/FreeImage/PluginBMP.cpp view on Meta::CPAN
if (io->write_proc(&bitmapfileheader, sizeof(BITMAPFILEHEADER), 1, handle) != 1)
return FALSE;
// update the bitmap info header
BITMAPINFOHEADER bih;
memcpy(&bih, FreeImage_GetInfoHeader(dib), sizeof(BITMAPINFOHEADER));
if (bit_fields)
bih.biCompression = BI_BITFIELDS;
else if ((bih.biBitCount == 8) && (flags & BMP_SAVE_RLE))
bih.biCompression = BI_RLE8;
else
bih.biCompression = BI_RGB;
// write the bitmap info header
#ifdef FREEIMAGE_BIGENDIAN
SwapInfoHeader(&bih);
#endif
if (io->write_proc(&bih, sizeof(BITMAPINFOHEADER), 1, handle) != 1)
src/Source/FreeImage/PluginBMP.cpp view on Meta::CPAN
bgra.r = pal[i].rgbRed;
bgra.a = pal[i].rgbReserved;
if (io->write_proc(&bgra, sizeof(FILE_BGRA), 1, handle) != 1)
return FALSE;
}
}
// write the bitmap data... if RLE compression is enable, use it
unsigned bpp = FreeImage_GetBPP(dib);
if ((bpp == 8) && (flags & BMP_SAVE_RLE)) {
BYTE *buffer = (BYTE*)malloc(FreeImage_GetPitch(dib) * 2 * sizeof(BYTE));
for (DWORD i = 0; i < FreeImage_GetHeight(dib); ++i) {
int size = RLEEncodeLine(buffer, FreeImage_GetScanLine(dib, i), FreeImage_GetLine(dib));
if (io->write_proc(buffer, size, 1, handle) != 1) {
free(buffer);
return FALSE;
}
}
src/Source/FreeImage/PluginCUT.cpp view on Meta::CPAN
}
static BOOL DLL_CALLCONV
SupportsNoPixels() {
return TRUE;
}
// ----------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
FIBITMAP *dib = NULL;
if(!handle) {
return NULL;
}
try {
CUTHEADER header;
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
// read the cut header
if(io->read_proc(&header, 1, sizeof(CUTHEADER), handle) != sizeof(CUTHEADER)) {
throw FI_MSG_ERROR_PARSING;
}
#ifdef FREEIMAGE_BIGENDIAN
SwapShort((WORD *)&header.width);
SwapShort((WORD *)&header.height);
src/Source/FreeImage/PluginDDS.cpp view on Meta::CPAN
DDSCAPS2_CUBEMAP_NEGATIVEX = 0x00000800L,
DDSCAPS2_CUBEMAP_POSITIVEY = 0x00001000L,
DDSCAPS2_CUBEMAP_NEGATIVEY = 0x00002000L,
DDSCAPS2_CUBEMAP_POSITIVEZ = 0x00004000L,
DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x00008000L,
DDSCAPS2_VOLUME = 0x00200000L
};
typedef struct tagDDSURFACEDESC2 {
DWORD dwSize; // size of this structure (must be 124)
DWORD dwFlags; // combination of the DDSS_* flags
DWORD dwHeight;
DWORD dwWidth;
DWORD dwPitchOrLinearSize;
DWORD dwDepth; // Depth of a volume texture
DWORD dwMipMapCount;
DWORD dwReserved1[11];
DDPIXELFORMAT ddpfPixelFormat;
DDCAPS2 ddsCaps;
DWORD dwReserved2;
} DDSURFACEDESC2;
src/Source/FreeImage/PluginDDS.cpp view on Meta::CPAN
// Plugin Interface
// ==========================================================
static int s_format_id;
// ==========================================================
// Internal functions
// ==========================================================
static FIBITMAP *
LoadRGB (DDSURFACEDESC2 &desc, FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
int width = (int)desc.dwWidth & ~3;
int height = (int)desc.dwHeight & ~3;
int bpp = (int)desc.ddpfPixelFormat.dwRGBBitCount;
// allocate a new dib
FIBITMAP *dib = FreeImage_Allocate (width, height, bpp, desc.ddpfPixelFormat.dwRBitMask,
desc.ddpfPixelFormat.dwGBitMask, desc.ddpfPixelFormat.dwBBitMask);
if (dib == NULL)
return NULL;
src/Source/FreeImage/PluginDDS.cpp view on Meta::CPAN
if (!(desc.ddpfPixelFormat.dwFlags & DDPF_ALPHAPIXELS) && bpp == 32) {
// no transparency: convert to 24-bit
FIBITMAP *old = dib;
dib = FreeImage_ConvertTo24Bits (old);
FreeImage_Unload (old);
}
return dib;
}
template <class DECODER> static void
LoadDXT_Helper (FreeImageIO *io, fi_handle handle, int page, int flags, void *data, FIBITMAP *dib, int width, int height, int line) {
typedef typename DECODER::INFO INFO;
typedef typename INFO::Block Block;
Block *input_buffer = new(std::nothrow) Block[(width + 3) / 4];
if(!input_buffer) return;
int widthRest = (int) width & 3;
int heightRest = (int) height & 3;
int inputLine = (width + 3) / 4;
int y = 0;
src/Source/FreeImage/PluginDDS.cpp view on Meta::CPAN
if (widthRest) {
DecodeDXTBlock <DECODER> (pbDst, pbSrc, line, widthRest, heightRest);
}
}
delete [] input_buffer;
}
static FIBITMAP *
LoadDXT (int type, DDSURFACEDESC2 &desc, FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
int width = (int)desc.dwWidth & ~3;
int height = (int)desc.dwHeight & ~3;
// allocate a 32-bit dib
FIBITMAP *dib = FreeImage_Allocate (width, height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
if (dib == NULL)
return NULL;
int bpp = FreeImage_GetBPP (dib);
int line = CalculateLine (width, bpp);
BYTE *bits = FreeImage_GetBits (dib);
// select the right decoder
switch (type) {
case 1:
LoadDXT_Helper <DXT_BLOCKDECODER_1> (io, handle, page, flags, data, dib, width, height, line);
break;
case 3:
LoadDXT_Helper <DXT_BLOCKDECODER_3> (io, handle, page, flags, data, dib, width, height, line);
break;
case 5:
LoadDXT_Helper <DXT_BLOCKDECODER_5> (io, handle, page, flags, data, dib, width, height, line);
break;
}
return dib;
}
// ==========================================================
// Plugin Implementation
// ==========================================================
static const char * DLL_CALLCONV
src/Source/FreeImage/PluginDDS.cpp view on Meta::CPAN
return NULL;
}
static void DLL_CALLCONV
Close(FreeImageIO *io, fi_handle handle, void *data) {
}
// ----------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
DDSHEADER header;
FIBITMAP *dib = NULL;
memset(&header, 0, sizeof(header));
io->read_proc(&header, 1, sizeof(header), handle);
#ifdef FREEIMAGE_BIGENDIAN
SwapHeader(&header);
#endif
if (header.surfaceDesc.ddpfPixelFormat.dwFlags & DDPF_RGB) {
dib = LoadRGB (header.surfaceDesc, io, handle, page, flags, data);
}
else if (header.surfaceDesc.ddpfPixelFormat.dwFlags & DDPF_FOURCC) {
switch (header.surfaceDesc.ddpfPixelFormat.dwFourCC) {
case FOURCC_DXT1:
dib = LoadDXT (1, header.surfaceDesc, io, handle, page, flags, data);
break;
case FOURCC_DXT3:
dib = LoadDXT (3, header.surfaceDesc, io, handle, page, flags, data);
break;
case FOURCC_DXT5:
dib = LoadDXT (5, header.surfaceDesc, io, handle, page, flags, data);
break;
}
}
return dib;
}
/*
static BOOL DLL_CALLCONV
Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
return FALSE;
}
*/
// ==========================================================
// Init
// ==========================================================
void DLL_CALLCONV
InitDDS(Plugin *plugin, int format_id) {
src/Source/FreeImage/PluginEXR.cpp view on Meta::CPAN
}
static BOOL DLL_CALLCONV
SupportsNoPixels() {
return TRUE;
}
// --------------------------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
bool bUseRgbaInterface = false;
FIBITMAP *dib = NULL;
if(!handle) {
return NULL;
}
try {
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
// save the stream starting point
const long stream_start = io->tell_proc(handle);
// wrap the FreeImage IO stream
C_IStream istream(io, handle);
// open the file
Imf::InputFile file(istream);
src/Source/FreeImage/PluginEXR.cpp view on Meta::CPAN
} catch(Iex::BaseExc & e) {
FreeImage_OutputMessageProc(s_format_id, e.what());
return FALSE;
}
}
static BOOL DLL_CALLCONV
Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
const char *channel_name[4] = { "R", "G", "B", "A" };
BOOL bIsFlipped = FALSE;
half *halfData = NULL;
if(!dib || !handle) return FALSE;
try {
// check for EXR_LC compression and verify that the format is RGB
if((flags & EXR_LC) == EXR_LC) {
FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
if(((image_type != FIT_RGBF) && (image_type != FIT_RGBAF)) || ((flags & EXR_FLOAT) == EXR_FLOAT)) {
THROW (Iex::IoExc, "EXR_LC compression is only available with RGB[A]F images");
}
if((FreeImage_GetWidth(dib) % 2) || (FreeImage_GetHeight(dib) % 2)) {
THROW (Iex::IoExc, "EXR_LC compression only works when the width and height are a multiple of 2");
}
}
// wrap the FreeImage IO stream
C_OStream ostream(io, handle);
// compression
Imf::Compression compress;
if((flags & EXR_NONE) == EXR_NONE) {
// no compression
compress = Imf::NO_COMPRESSION;
} else if((flags & EXR_ZIP) == EXR_ZIP) {
// zlib compression, in blocks of 16 scan lines
compress = Imf::ZIP_COMPRESSION;
} else if((flags & EXR_PIZ) == EXR_PIZ) {
// piz-based wavelet compression
compress = Imf::PIZ_COMPRESSION;
} else if((flags & EXR_PXR24) == EXR_PXR24) {
// lossy 24-bit float compression
compress = Imf::PXR24_COMPRESSION;
} else if((flags & EXR_B44) == EXR_B44) {
// lossy 44% float compression
compress = Imf::B44_COMPRESSION;
} else {
// default value
compress = Imf::PIZ_COMPRESSION;
}
// create the header
int width = FreeImage_GetWidth(dib);
int height = FreeImage_GetHeight(dib);
src/Source/FreeImage/PluginEXR.cpp view on Meta::CPAN
Imath::Box2i displayWindow (Imath::V2i (-dx, -dy), Imath::V2i (width - dx - 1, height - dy - 1));
Imf::Header header = Imf::Header(displayWindow, dataWindow, 1,
Imath::V2f(0,0), 1,
Imf::INCREASING_Y, compress);
// handle thumbnail
SetPreviewImage(dib, header);
// check for EXR_LC compression
if((flags & EXR_LC) == EXR_LC) {
return SaveAsEXR_LC(ostream, dib, header, width, height);
}
// output pixel type
Imf::PixelType pixelType;
if((flags & EXR_FLOAT) == EXR_FLOAT) {
pixelType = Imf::FLOAT; // save as float data type
} else {
// default value
pixelType = Imf::HALF; // save as half data type
}
// check the data type and number of channels
int components = 0;
FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
switch(image_type) {
src/Source/FreeImage/PluginG3.cpp view on Meta::CPAN
}
static BOOL DLL_CALLCONV
SupportsExportDepth(int depth) {
return FALSE;
}
// ----------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
TIFF *faxTIFF = NULL;
FIBITMAP *dib = NULL;
FIMEMORY *memory = NULL;
//int verbose = 0;
int stretch = 0;
int rows;
float resX = 204.0;
float resY = 196.0;
src/Source/FreeImage/PluginGIF.cpp view on Meta::CPAN
int m_minCodeSize, m_clearCode, m_endCode, m_nextCode;
int m_bpp, m_slack; //Compressor information
int m_prefix; //Compressor state variable
int m_codeSize, m_codeMask; //Compressor/Decompressor state variables
int m_oldCode; //Decompressor state variable
int m_partial, m_partialSize; //Compressor/Decompressor bit buffer
int firstPixelPassed; // A specific flag that indicates if the first pixel
// of the whole image had already been read
std::string m_strings[MAX_LZW_CODE]; //This is what is really the "string table" data for the Decompressor
int* m_strmap;
//input buffer
BYTE *m_buffer;
int m_bufferSize, m_bufferRealSize, m_bufferPos, m_bufferShift;
void ClearCompressorTable(void);
src/Source/FreeImage/PluginGIF.cpp view on Meta::CPAN
PageCount(FreeImageIO *io, fi_handle handle, void *data) {
if( data == NULL ) {
return 0;
}
GIFinfo *info = (GIFinfo *)data;
return (int) info->image_descriptor_offsets.size();
}
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
if( data == NULL ) {
return NULL;
}
GIFinfo *info = (GIFinfo *)data;
if( page == -1 ) {
page = 0;
}
if( page < 0 || page >= (int)info->image_descriptor_offsets.size() ) {
return NULL;
src/Source/FreeImage/PluginGIF.cpp view on Meta::CPAN
FIBITMAP *dib = NULL;
try {
bool have_transparent = false, no_local_palette = false, interlaced = false;
int disposal_method = GIF_DISPOSAL_LEAVE, delay_time = 0, transparent_color = 0;
WORD left, top, width, height;
BYTE packed, b;
WORD w;
//playback pages to generate what the user would see for this frame
if( (flags & GIF_PLAYBACK) == GIF_PLAYBACK ) {
//Logical Screen Descriptor
io->seek_proc(handle, 6, SEEK_SET);
WORD logicalwidth, logicalheight;
io->read_proc(&logicalwidth, 2, 1, handle);
io->read_proc(&logicalheight, 2, 1, handle);
#ifdef FREEIMAGE_BIGENDIAN
SwapShort(&logicalwidth);
SwapShort(&logicalheight);
#endif
//set the background color with 0 alpha
src/Source/FreeImage/PluginGIF.cpp view on Meta::CPAN
SwapShort(&left);
SwapShort(&top);
SwapShort(&width);
SwapShort(&height);
#endif
io->read_proc(&packed, 1, 1, handle);
interlaced = (packed & GIF_PACKED_ID_INTERLACED) ? true : false;
no_local_palette = (packed & GIF_PACKED_ID_HAVELCT) ? false : true;
int bpp = 8;
if( (flags & GIF_LOAD256) == 0 ) {
if( !no_local_palette ) {
int size = 2 << (packed & GIF_PACKED_ID_LCTSIZE);
if( size <= 2 ) bpp = 1;
else if( size <= 16 ) bpp = 4;
} else if( info->global_color_table_offset != 0 ) {
if( info->global_color_table_size <= 2 ) bpp = 1;
else if( info->global_color_table_size <= 16 ) bpp = 4;
}
}
dib = FreeImage_Allocate(width, height, bpp);
src/Source/FreeImage/PluginGIF.cpp view on Meta::CPAN
FreeImage_Unload(dib);
}
FreeImage_OutputMessageProc(s_format_id, msg);
return NULL;
}
return dib;
}
static BOOL DLL_CALLCONV
Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
if( data == NULL ) {
return FALSE;
}
//GIFinfo *info = (GIFinfo *)data;
if( page == -1 ) {
page = 0;
}
try {
src/Source/FreeImage/PluginHDR.cpp view on Meta::CPAN
// ==========================================================
// RGBE library
// ==========================================================
// ----------------------------------------------------------
// maximum size of a line in the header
#define HDR_MAXLINE 256
// flags indicating which fields in an rgbeHeaderInfo are valid
#define RGBE_VALID_PROGRAMTYPE 0x01
#define RGBE_VALID_COMMENT 0x02
#define RGBE_VALID_GAMMA 0x04
#define RGBE_VALID_EXPOSURE 0x08
// offsets to red, green, and blue components in a data (float) pixel
#define RGBE_DATA_RED 0
#define RGBE_DATA_GREEN 1
#define RGBE_DATA_BLUE 2
src/Source/FreeImage/PluginHDR.cpp view on Meta::CPAN
}
static BOOL DLL_CALLCONV
SupportsNoPixels() {
return TRUE;
}
// --------------------------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
FIBITMAP *dib = NULL;
if(!handle) {
return NULL;
}
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
try {
rgbeHeaderInfo header_info;
unsigned width, height;
// Read the header
if(rgbe_ReadHeader(io, handle, &width, &height, &header_info) == FALSE) {
return NULL;
}
src/Source/FreeImage/PluginHDR.cpp view on Meta::CPAN
if(dib != NULL) {
FreeImage_Unload(dib);
}
FreeImage_OutputMessageProc(s_format_id, text);
}
return dib;
}
static BOOL DLL_CALLCONV
Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
if(!dib) return FALSE;
FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib);
if(src_type != FIT_RGBF) {
FreeImage_OutputMessageProc(s_format_id, "FREE_IMAGE_TYPE: Unable to convert from type %d to type %d.\n No such conversion exists.", src_type, FIT_RGBF);
return FALSE;
}
unsigned width = FreeImage_GetWidth(dib);
unsigned height = FreeImage_GetHeight(dib);
src/Source/FreeImage/PluginICO.cpp view on Meta::CPAN
if(lpIH) {
return lpIH->idCount;
}
return 1;
}
// ----------------------------------------------------------
static FIBITMAP*
LoadStandardIcon(FreeImageIO *io, fi_handle handle, int flags, BOOL header_only) {
FIBITMAP *dib = NULL;
// load the BITMAPINFOHEADER
BITMAPINFOHEADER bmih;
io->read_proc(&bmih, sizeof(BITMAPINFOHEADER), 1, handle);
#ifdef FREEIMAGE_BIGENDIAN
SwapInfoHeader(&bmih);
#endif
// allocate the bitmap
src/Source/FreeImage/PluginICO.cpp view on Meta::CPAN
INPLACESWAP(pixel[0], pixel[2]);
pixel += (bit_count>>3);
}
}
}
#endif
// bitmap has been loaded successfully!
// convert to 32bpp and generate an alpha channel
// apply the AND mask only if the image is not 32 bpp
if(((flags & ICO_MAKEALPHA) == ICO_MAKEALPHA) && (bit_count < 32)) {
FIBITMAP *dib32 = FreeImage_ConvertTo32Bits(dib);
FreeImage_Unload(dib);
if (dib32 == NULL) {
return NULL;
}
int width_and = WidthBytes(width);
BYTE *line_and = (BYTE *)malloc(width_and);
src/Source/FreeImage/PluginICO.cpp view on Meta::CPAN
}
free(line_and);
return dib32;
}
return dib;
}
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
if (page == -1) {
page = 0;
}
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
if (handle != NULL) {
FIBITMAP *dib = NULL;
// get the icon header
ICONHEADER *icon_header = (ICONHEADER*)data;
if (icon_header) {
// load the icon descriptions
ICONDIRENTRY *icon_list = (ICONDIRENTRY*)malloc(icon_header->idCount * sizeof(ICONDIRENTRY));
src/Source/FreeImage/PluginICO.cpp view on Meta::CPAN
if( IsPNG(io, handle) ) {
// Vista icon support
// see http://blogs.msdn.com/b/oldnewthing/archive/2010/10/22/10079192.aspx
dib = FreeImage_LoadFromHandle(FIF_PNG, io, handle, header_only ? FIF_LOAD_NOPIXELS : PNG_DEFAULT);
}
else {
// standard icon support
// see http://msdn.microsoft.com/en-us/library/ms997538.aspx
// see http://blogs.msdn.com/b/oldnewthing/archive/2010/10/18/10077133.aspx
dib = LoadStandardIcon(io, handle, flags, header_only);
}
free(icon_list);
return dib;
} else {
free(icon_list);
FreeImage_OutputMessageProc(s_format_id, "Page doesn't exist");
}
src/Source/FreeImage/PluginICO.cpp view on Meta::CPAN
memset(and_mask, 0, size_and);
}
io->write_proc(and_mask, size_and, 1, handle);
free(and_mask);
return TRUE;
}
static BOOL DLL_CALLCONV
Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
ICONHEADER *icon_header = NULL;
std::vector<FIBITMAP*> vPages;
int k;
if(!dib || !handle || !data) {
return FALSE;
}
// check format limits
unsigned w = FreeImage_GetWidth(dib);
src/Source/FreeImage/PluginICO.cpp view on Meta::CPAN
}
// get the icon header
icon_header = (ICONHEADER*)data;
try {
FIBITMAP *icon_dib = NULL;
// load all icons
for(k = 0; k < icon_header->idCount; k++) {
icon_dib = Load(io, handle, k, flags, data);
if(!icon_dib) {
throw FI_MSG_ERROR_DIB_MEMORY;
}
vPages.push_back(icon_dib);
}
// add the page
icon_dib = FreeImage_Clone(dib);
vPages.push_back(icon_dib);
icon_header->idCount++;
src/Source/FreeImage/PluginIFF.cpp view on Meta::CPAN
}
static BOOL DLL_CALLCONV
SupportsExportType(FREE_IMAGE_TYPE type) {
return FALSE;
}
// ----------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
if (handle != NULL) {
FIBITMAP *dib = NULL;
DWORD type, size;
io->read_proc(&type, 4, 1, handle);
#ifndef FREEIMAGE_BIGENDIAN
SwapLong(&type);
#endif
src/Source/FreeImage/PluginJ2K.cpp view on Meta::CPAN
static void DLL_CALLCONV
Close(FreeImageIO *io, fi_handle handle, void *data) {
// destroy the stream wrapper
J2KFIO_t *fio = (J2KFIO_t*)data;
opj_freeimage_stream_destroy(fio);
}
// ----------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
J2KFIO_t *fio = (J2KFIO_t*)data;
if (handle && fio) {
opj_codec_t *d_codec = NULL; // handle to a decompressor
opj_dparameters_t parameters; // decompression parameters
opj_image_t *image = NULL; // decoded image
FIBITMAP *dib = NULL;
// check the file format
if(!Validate(io, handle)) {
return NULL;
}
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
// get the OpenJPEG stream
opj_stream_t *d_stream = fio->stream;
// set decoding parameters to default values
opj_set_default_decoder_parameters(¶meters);
try {
// decode the JPEG-2000 codestream
src/Source/FreeImage/PluginJ2K.cpp view on Meta::CPAN
FreeImage_OutputMessageProc(s_format_id, text);
return NULL;
}
}
return NULL;
}
static BOOL DLL_CALLCONV
Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
J2KFIO_t *fio = (J2KFIO_t*)data;
if (dib && handle && fio) {
BOOL bSuccess;
opj_codec_t *c_codec = NULL; // handle to a compressor
opj_cparameters_t parameters; // compression parameters
opj_image_t *image = NULL; // image to encode
// get the OpenJPEG stream
opj_stream_t *c_stream = fio->stream;
// set encoding parameters to default values
opj_set_default_encoder_parameters(¶meters);
try {
parameters.tcp_numlayers = 0;
// if no rate entered, apply a 16:1 rate by default
if(flags == J2K_DEFAULT) {
parameters.tcp_rates[0] = (float)16;
} else {
// for now, the flags parameter is only used to specify the rate
parameters.tcp_rates[0] = (float)(flags & 0x3FF);
}
parameters.tcp_numlayers++;
parameters.cp_disto_alloc = 1;
// convert the dib to a OpenJPEG image
image = FIBITMAPToJ2KImage(s_format_id, dib, ¶meters);
if(!image) {
return FALSE;
}
src/Source/FreeImage/PluginJNG.cpp view on Meta::CPAN
// ----------------------------------------------------------
#define JNG_SIGNATURE_SIZE 8 // size of the signature
// ----------------------------------------------------------
// ----------------------------------------------------------
// mng interface (see MNGHelper.cpp)
// ----------------------------------------------------------
FIBITMAP* mng_ReadChunks(int format_id, FreeImageIO *io, fi_handle handle, long Offset, int flags = 0);
BOOL mng_WriteJNG(int format_id, FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int flags);
// ==========================================================
// Plugin Implementation
// ==========================================================
static const char * DLL_CALLCONV
Format() {
return "JNG";
}
src/Source/FreeImage/PluginJNG.cpp view on Meta::CPAN
static void * DLL_CALLCONV
Open(FreeImageIO *io, fi_handle handle, BOOL read) {
return NULL;
}
static void DLL_CALLCONV
Close(FreeImageIO *io, fi_handle handle, void *data) {
}
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
long offset = JNG_SIGNATURE_SIZE; // move to skip first 8 bytes of signature
// check the signature (8 bytes)
if(Validate(io, handle) == FALSE) {
return NULL;
}
// parse chunks and decode a jng or mng bitmap
return mng_ReadChunks(s_format_id, io, handle, offset, flags);
}
static BOOL DLL_CALLCONV
Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
return mng_WriteJNG(s_format_id, io, dib, handle, flags);
}
// ==========================================================
// Init
// ==========================================================
void DLL_CALLCONV
InitJNG(Plugin *plugin, int format_id) {
s_format_id = format_id;
src/Source/FreeImage/PluginJP2.cpp view on Meta::CPAN
static void DLL_CALLCONV
Close(FreeImageIO *io, fi_handle handle, void *data) {
// destroy the stream wrapper
J2KFIO_t *fio = (J2KFIO_t*)data;
opj_freeimage_stream_destroy(fio);
}
// ----------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
J2KFIO_t *fio = (J2KFIO_t*)data;
if (handle && fio) {
opj_codec_t *d_codec = NULL; // handle to a decompressor
opj_dparameters_t parameters; // decompression parameters
opj_image_t *image = NULL; // decoded image
FIBITMAP *dib = NULL;
// check the file format
if(!Validate(io, handle)) {
return NULL;
}
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
// get the OpenJPEG stream
opj_stream_t *d_stream = fio->stream;
// set decoding parameters to default values
opj_set_default_decoder_parameters(¶meters);
try {
// decode the JPEG-2000 file
src/Source/FreeImage/PluginJP2.cpp view on Meta::CPAN
FreeImage_OutputMessageProc(s_format_id, text);
return NULL;
}
}
return NULL;
}
static BOOL DLL_CALLCONV
Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
J2KFIO_t *fio = (J2KFIO_t*)data;
if (dib && handle && fio) {
BOOL bSuccess;
opj_codec_t *c_codec = NULL; // handle to a compressor
opj_cparameters_t parameters; // compression parameters
opj_image_t *image = NULL; // image to encode
// get the OpenJPEG stream
opj_stream_t *c_stream = fio->stream;
// set encoding parameters to default values
opj_set_default_encoder_parameters(¶meters);
try {
parameters.tcp_numlayers = 0;
// if no rate entered, apply a 16:1 rate by default
if(flags == JP2_DEFAULT) {
parameters.tcp_rates[0] = (float)16;
} else {
// for now, the flags parameter is only used to specify the rate
parameters.tcp_rates[0] = (float)(flags & 0x3FF);
}
parameters.tcp_numlayers++;
parameters.cp_disto_alloc = 1;
// convert the dib to a OpenJPEG image
image = FIBITMAPToJ2KImage(s_format_id, dib, ¶meters);
if(!image) {
return FALSE;
}
src/Source/FreeImage/PluginJPEG.cpp view on Meta::CPAN
/**
Initialize source. This is called by jpeg_read_header() before any
data is actually read. Unlike init_destination(), it may leave
bytes_in_buffer set to 0 (in which case a fill_input_buffer() call
will occur immediately).
*/
METHODDEF(void)
init_source (j_decompress_ptr cinfo) {
freeimage_src_ptr src = (freeimage_src_ptr) cinfo->src;
/* We reset the empty-input-file flag for each image,
* but we don't clear the input buffer.
* This is correct behavior for reading a series of images from one source.
*/
src->start_of_file = TRUE;
}
/**
This is called whenever bytes_in_buffer has reached zero and more
data is wanted. In typical applications, it should read fresh data
src/Source/FreeImage/PluginJPEG.cpp view on Meta::CPAN
}
static BOOL DLL_CALLCONV
SupportsNoPixels() {
return TRUE;
}
// ----------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
if (handle) {
FIBITMAP *dib = NULL;
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
// set up the jpeglib structures
struct jpeg_decompress_struct cinfo;
ErrorManager fi_error_mgr;
try {
// step 1: allocate and initialize JPEG decompression object
src/Source/FreeImage/PluginJPEG.cpp view on Meta::CPAN
jpeg_save_markers(&cinfo, JPEG_APP0 + m, 0xFFFF);
}
// step 3: read handle parameters with jpeg_read_header()
jpeg_read_header(&cinfo, TRUE);
// step 4: set parameters for decompression
unsigned int scale_denom = 1; // fraction by which to scale image
int requested_size = flags >> 16; // requested user size in pixels
if(requested_size > 0) {
// the JPEG codec can perform x2, x4 or x8 scaling on loading
// try to find the more appropriate scaling according to user's need
double scale = MAX((double)cinfo.image_width, (double)cinfo.image_height) / (double)requested_size;
if(scale >= 8) {
scale_denom = 8;
} else if(scale >= 4) {
scale_denom = 4;
} else if(scale >= 2) {
scale_denom = 2;
}
}
cinfo.scale_num = 1;
cinfo.scale_denom = scale_denom;
if ((flags & JPEG_ACCURATE) != JPEG_ACCURATE) {
cinfo.dct_method = JDCT_IFAST;
cinfo.do_fancy_upsampling = FALSE;
}
if ((flags & JPEG_GREYSCALE) == JPEG_GREYSCALE) {
// force loading as a 8-bit greyscale image
cinfo.out_color_space = JCS_GRAYSCALE;
}
// step 5a: start decompressor and calculate output width and height
jpeg_start_decompress(&cinfo);
// step 5b: allocate dib and init header
if((cinfo.output_components == 4) && (cinfo.out_color_space == JCS_CMYK)) {
// CMYK image
if((flags & JPEG_CMYK) == JPEG_CMYK) {
// load as CMYK
dib = FreeImage_AllocateHeader(header_only, cinfo.output_width, cinfo.output_height, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
if(!dib) throw FI_MSG_ERROR_DIB_MEMORY;
FreeImage_GetICCProfile(dib)->flags |= FIICC_COLOR_IS_CMYK;
} else {
// load as CMYK and convert to RGB
dib = FreeImage_AllocateHeader(header_only, cinfo.output_width, cinfo.output_height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
if(!dib) throw FI_MSG_ERROR_DIB_MEMORY;
}
} else {
// RGB or greyscale image
dib = FreeImage_AllocateHeader(header_only, cinfo.output_width, cinfo.output_height, 8 * cinfo.output_components, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
if(!dib) throw FI_MSG_ERROR_DIB_MEMORY;
src/Source/FreeImage/PluginJPEG.cpp view on Meta::CPAN
if (header_only) {
// release JPEG decompression object
jpeg_destroy_decompress(&cinfo);
// return header data
return dib;
}
// step 7a: while (scan lines remain to be read) jpeg_read_scanlines(...);
if((cinfo.out_color_space == JCS_CMYK) && ((flags & JPEG_CMYK) != JPEG_CMYK)) {
// convert from CMYK to RGB
JSAMPARRAY buffer; // output row buffer
unsigned row_stride; // physical row width in output buffer
// JSAMPLEs per row in output buffer
row_stride = cinfo.output_width * cinfo.output_components;
// make a one-row-high sample array that will go away when done with image
buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
src/Source/FreeImage/PluginJPEG.cpp view on Meta::CPAN
for(unsigned x = 0; x < cinfo.output_width; x++) {
WORD K = (WORD)src[3];
dst[FI_RGBA_RED] = (BYTE)((K * src[0]) / 255); // C -> R
dst[FI_RGBA_GREEN] = (BYTE)((K * src[1]) / 255); // M -> G
dst[FI_RGBA_BLUE] = (BYTE)((K * src[2]) / 255); // Y -> B
src += 4;
dst += 3;
}
}
} else if((cinfo.out_color_space == JCS_CMYK) && ((flags & JPEG_CMYK) == JPEG_CMYK)) {
// convert from LibJPEG CMYK to standard CMYK
JSAMPARRAY buffer; // output row buffer
unsigned row_stride; // physical row width in output buffer
// JSAMPLEs per row in output buffer
row_stride = cinfo.output_width * cinfo.output_components;
// make a one-row-high sample array that will go away when done with image
buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
src/Source/FreeImage/PluginJPEG.cpp view on Meta::CPAN
// step 8: finish decompression
jpeg_finish_decompress(&cinfo);
// step 9: release JPEG decompression object
jpeg_destroy_decompress(&cinfo);
// check for automatic Exif rotation
if(!header_only && ((flags & JPEG_EXIFROTATE) == JPEG_EXIFROTATE)) {
RotateExif(&dib);
}
// everything went well. return the loaded dib
return dib;
} catch (const char *text) {
jpeg_destroy_decompress(&cinfo);
if(NULL != dib) {
src/Source/FreeImage/PluginJPEG.cpp view on Meta::CPAN
}
}
}
return NULL;
}
// ----------------------------------------------------------
static BOOL DLL_CALLCONV
Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
if ((dib) && (handle)) {
try {
// Check dib format
const char *sError = "only 24-bit highcolor or 8-bit greyscale/palette bitmaps can be saved as JPEG";
FREE_IMAGE_COLOR_TYPE color_type = FreeImage_GetColorType(dib);
WORD bpp = (WORD)FreeImage_GetBPP(dib);
if ((bpp != 24) && (bpp != 8)) {
src/Source/FreeImage/PluginJPEG.cpp view on Meta::CPAN
default :
cinfo.in_color_space = JCS_RGB;
cinfo.input_components = 3;
break;
}
jpeg_set_defaults(&cinfo);
// progressive-JPEG support
if((flags & JPEG_PROGRESSIVE) == JPEG_PROGRESSIVE) {
jpeg_simple_progression(&cinfo);
}
// compute optimal Huffman coding tables for the image
if((flags & JPEG_OPTIMIZE) == JPEG_OPTIMIZE) {
cinfo.optimize_coding = TRUE;
}
// Set JFIF density parameters from the DIB data
cinfo.X_density = (UINT16) (0.5 + 0.0254 * FreeImage_GetDotsPerMeterX(dib));
cinfo.Y_density = (UINT16) (0.5 + 0.0254 * FreeImage_GetDotsPerMeterY(dib));
cinfo.density_unit = 1; // dots / inch
// thumbnail support (JFIF 1.02 extension markers)
if(FreeImage_GetThumbnail(dib) != NULL) {
cinfo.write_JFIF_header = 1; //<### force it, though when color is CMYK it will be incorrect
cinfo.JFIF_minor_version = 2;
}
// baseline JPEG support
if ((flags & JPEG_BASELINE) == JPEG_BASELINE) {
cinfo.write_JFIF_header = 0; // No marker for non-JFIF colorspaces
cinfo.write_Adobe_marker = 0; // write no Adobe marker by default
}
// set subsampling options if required
if(cinfo.in_color_space == JCS_RGB) {
if((flags & JPEG_SUBSAMPLING_411) == JPEG_SUBSAMPLING_411) {
// 4:1:1 (4x1 1x1 1x1) - CrH 25% - CbH 25% - CrV 100% - CbV 100%
// the horizontal color resolution is quartered
cinfo.comp_info[0].h_samp_factor = 4; // Y
cinfo.comp_info[0].v_samp_factor = 1;
cinfo.comp_info[1].h_samp_factor = 1; // Cb
cinfo.comp_info[1].v_samp_factor = 1;
cinfo.comp_info[2].h_samp_factor = 1; // Cr
cinfo.comp_info[2].v_samp_factor = 1;
} else if((flags & JPEG_SUBSAMPLING_420) == JPEG_SUBSAMPLING_420) {
// 4:2:0 (2x2 1x1 1x1) - CrH 50% - CbH 50% - CrV 50% - CbV 50%
// the chrominance resolution in both the horizontal and vertical directions is cut in half
cinfo.comp_info[0].h_samp_factor = 2; // Y
cinfo.comp_info[0].v_samp_factor = 2;
cinfo.comp_info[1].h_samp_factor = 1; // Cb
cinfo.comp_info[1].v_samp_factor = 1;
cinfo.comp_info[2].h_samp_factor = 1; // Cr
cinfo.comp_info[2].v_samp_factor = 1;
} else if((flags & JPEG_SUBSAMPLING_422) == JPEG_SUBSAMPLING_422){ //2x1 (low)
// 4:2:2 (2x1 1x1 1x1) - CrH 50% - CbH 50% - CrV 100% - CbV 100%
// half of the horizontal resolution in the chrominance is dropped (Cb & Cr),
// while the full resolution is retained in the vertical direction, with respect to the luminance
cinfo.comp_info[0].h_samp_factor = 2; // Y
cinfo.comp_info[0].v_samp_factor = 1;
cinfo.comp_info[1].h_samp_factor = 1; // Cb
cinfo.comp_info[1].v_samp_factor = 1;
cinfo.comp_info[2].h_samp_factor = 1; // Cr
cinfo.comp_info[2].v_samp_factor = 1;
}
else if((flags & JPEG_SUBSAMPLING_444) == JPEG_SUBSAMPLING_444){ //1x1 (no subsampling)
// 4:4:4 (1x1 1x1 1x1) - CrH 100% - CbH 100% - CrV 100% - CbV 100%
// the resolution of chrominance information (Cb & Cr) is preserved
// at the same rate as the luminance (Y) information
cinfo.comp_info[0].h_samp_factor = 1; // Y
cinfo.comp_info[0].v_samp_factor = 1;
cinfo.comp_info[1].h_samp_factor = 1; // Cb
cinfo.comp_info[1].v_samp_factor = 1;
cinfo.comp_info[2].h_samp_factor = 1; // Cr
cinfo.comp_info[2].v_samp_factor = 1;
}
}
// Step 4: set quality
// the first 7 bits are reserved for low level quality settings
// the other bits are high level (i.e. enum-ish)
int quality;
if ((flags & JPEG_QUALITYBAD) == JPEG_QUALITYBAD) {
quality = 10;
} else if ((flags & JPEG_QUALITYAVERAGE) == JPEG_QUALITYAVERAGE) {
quality = 25;
} else if ((flags & JPEG_QUALITYNORMAL) == JPEG_QUALITYNORMAL) {
quality = 50;
} else if ((flags & JPEG_QUALITYGOOD) == JPEG_QUALITYGOOD) {
quality = 75;
} else if ((flags & JPEG_QUALITYSUPERB) == JPEG_QUALITYSUPERB) {
quality = 100;
} else {
if ((flags & 0x7F) == 0) {
quality = 75;
} else {
quality = flags & 0x7F;
}
}
jpeg_set_quality(&cinfo, quality, TRUE); /* limit to baseline-JPEG values */
// Step 5: Start compressor
jpeg_start_compress(&cinfo, TRUE);
// Step 6: Write special markers
if ((flags & JPEG_BASELINE) != JPEG_BASELINE) {
write_markers(&cinfo, dib);
}
// Step 7: while (scan lines remain to be written)
if(color_type == FIC_RGB) {
// 24-bit RGB image : need to swap red and blue channels
unsigned pitch = FreeImage_GetPitch(dib);
BYTE *target = (BYTE*)malloc(pitch * sizeof(BYTE));
if (target == NULL) {
src/Source/FreeImage/PluginJXR.cpp view on Meta::CPAN
}
}
// ==========================================================
// Load
// ==========================================================
/**
Set decoder parameters
@param pDecoder Decoder handle
@param flags FreeImage load flags
*/
static void
SetDecoderParameters(PKImageDecode *pDecoder, int flags) {
// load image & alpha for formats with alpha
pDecoder->WMP.wmiSCP.uAlphaMode = 2;
// more options to come ...
}
/**
Copy or convert & copy decoded pixels into the dib
@param pDecoder Decoder handle
@param out_guid_format Target guid format
@param dib Output dib
src/Source/FreeImage/PluginJXR.cpp view on Meta::CPAN
// free the pixel format converter
PKFormatConverter_Release(&pConverter);
return error_code;
}
}
// --------------------------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
PKImageDecode *pDecoder = NULL; // decoder interface
ERR error_code = 0; // error code as returned by the interface
PKPixelFormatGUID guid_format; // loaded pixel format (== input file pixel format if no conversion needed)
FREE_IMAGE_TYPE image_type = FIT_UNKNOWN; // input image type
unsigned bpp = 0; // input image bit depth
FIBITMAP *dib = NULL;
// get the I/O stream wrapper
WMPStream *pDecodeStream = (WMPStream*)data;
if(!handle || !pDecodeStream) {
return NULL;
}
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
try {
int width, height; // image dimensions (in pixels)
// create a JXR decoder interface and initialize function pointers with *_WMP functions
error_code = PKImageDecode_Create_WMP(&pDecoder);
JXR_CHECK(error_code);
// attach the stream to the decoder ...
// ... then read the image container and the metadata
error_code = pDecoder->Initialize(pDecoder, pDecodeStream);
JXR_CHECK(error_code);
// set decoder parameters
SetDecoderParameters(pDecoder, flags);
// get dst image format specifications
unsigned red_mask = 0, green_mask = 0, blue_mask = 0;
error_code = GetInputPixelFormat(pDecoder, &guid_format, &image_type, &bpp, &red_mask, &green_mask, &blue_mask);
JXR_CHECK(error_code);
// get image dimensions
pDecoder->GetSize(pDecoder, &width, &height);
// allocate dst image
src/Source/FreeImage/PluginJXR.cpp view on Meta::CPAN
else {
// lossless mode
wmiSCP->uiDefaultQPIndex = 1;
}
}
/**
Set encoder parameters
@param wmiSCP Encoder parameters
@param pixelInfo Image specifications
@param flags FreeImage save flags
@param bHasAlpha TRUE if an alpha layer is present
*/
static void
SetEncoderParameters(CWMIStrCodecParam *wmiSCP, const PKPixelInfo *pixelInfo, int flags, BOOL bHasAlpha) {
float fltImageQuality = 1.0F;
// all values have been set to zero by the API
// update default values for some attributes
wmiSCP->cfColorFormat = YUV_444; // color format
wmiSCP->bdBitDepth = BD_LONG; // internal bit depth
wmiSCP->bfBitstreamFormat = SPATIAL; // compressed image data in spatial order
wmiSCP->bProgressiveMode = FALSE; // sequential mode
wmiSCP->olOverlap = OL_ONE; // single level overlap processing
wmiSCP->cNumOfSliceMinus1H = 0; // # of horizontal slices
wmiSCP->cNumOfSliceMinus1V = 0; // # of vertical slices
wmiSCP->sbSubband = SB_ALL; // keep all subbands
wmiSCP->uAlphaMode = 0; // 0:no alpha 1: alpha only else: something + alpha
wmiSCP->uiDefaultQPIndex = 1; // quantization for grey or rgb layer(s), 1: lossless
wmiSCP->uiDefaultQPIndexAlpha = 1; // quantization for alpha layer, 1: lossless
// process the flags
// -----------------
// progressive mode
if((flags & JXR_PROGRESSIVE) == JXR_PROGRESSIVE) {
// turn on progressive mode (instead of sequential mode)
wmiSCP->bProgressiveMode = TRUE;
}
// quality in [0.01 - 1.0), 1.0 means lossless - default is 0.80
int quality = flags & 0x7F;
if(quality == 0) {
// defaut to 0.80
fltImageQuality = 0.8F;
} else if((flags & JXR_LOSSLESS) == JXR_LOSSLESS) {
fltImageQuality = 1.0F;
} else {
quality = (quality >= 100) ? 100 : quality;
fltImageQuality = quality / 100.0F;
}
SetCompression(wmiSCP, pixelInfo, fltImageQuality);
// alpha compression
if(bHasAlpha) {
wmiSCP->uAlphaMode = 2; // encode with a planar alpha channel
}
}
// --------------------------------------------------------------------------
static BOOL DLL_CALLCONV
Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
BOOL bIsFlipped = FALSE; // FreeImage DIB are upside-down relative to usual graphic conventions
PKPixelFormatGUID guid_format; // image format
PKPixelInfo pixelInfo; // image specifications
BOOL bHasAlpha = FALSE; // is alpha layer present ?
PKImageEncode *pEncoder = NULL; // encoder interface
ERR error_code = 0; // error code as returned by the interface
// get the I/O stream wrapper
WMPStream *pEncodeStream = (WMPStream*)data;
src/Source/FreeImage/PluginJXR.cpp view on Meta::CPAN
// create a JXR encoder interface and initialize function pointers with *_WMP functions
error_code = PKImageEncode_Create_WMP(&pEncoder);
JXR_CHECK(error_code);
// attach the stream to the encoder and set all encoder parameters to zero ...
error_code = pEncoder->Initialize(pEncoder, pEncodeStream, &pEncoder->WMP.wmiSCP, sizeof(CWMIStrCodecParam));
JXR_CHECK(error_code);
// ... then configure the encoder
SetEncoderParameters(&pEncoder->WMP.wmiSCP, &pixelInfo, flags, bHasAlpha);
// set pixel format
pEncoder->SetPixelFormat(pEncoder, guid_format);
// set image size
pEncoder->SetSize(pEncoder, width, height);
// set resolution (convert from universal units to English units)
float resX = (float)(unsigned)(0.5F + 0.0254F * FreeImage_GetDotsPerMeterX(dib));
float resY = (float)(unsigned)(0.5F + 0.0254F * FreeImage_GetDotsPerMeterY(dib));
src/Source/FreeImage/PluginKOALA.cpp view on Meta::CPAN
}
static BOOL DLL_CALLCONV
SupportsExportType(FREE_IMAGE_TYPE type) {
return FALSE;
}
// ----------------------------------------------------------
FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
if (handle) {
koala_t image;
// read the load address
unsigned char load_address[2]; // highbit, lowbit
io->read_proc(&load_address, 1, 2, handle);
// if the load address is correct, skip it. otherwise ignore the load address
src/Source/FreeImage/PluginMNG.cpp view on Meta::CPAN
// ----------------------------------------------------------
#define MNG_SIGNATURE_SIZE 8 // size of the signature
// ----------------------------------------------------------
// ----------------------------------------------------------
// mng interface (see MNGHelper.cpp)
// ----------------------------------------------------------
FIBITMAP* mng_ReadChunks(int format_id, FreeImageIO *io, fi_handle handle, long Offset, int flags = 0);
// ==========================================================
// Plugin Implementation
// ==========================================================
static const char * DLL_CALLCONV
Format() {
return "MNG";
}
src/Source/FreeImage/PluginMNG.cpp view on Meta::CPAN
static void * DLL_CALLCONV
Open(FreeImageIO *io, fi_handle handle, BOOL read) {
return NULL;
}
static void DLL_CALLCONV
Close(FreeImageIO *io, fi_handle handle, void *data) {
}
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
long offset = MNG_SIGNATURE_SIZE; // move to skip first 8 bytes of signature
// check the signature (8 bytes)
if(Validate(io, handle) == FALSE) {
return NULL;
}
// parse chunks and decode a jng or mng bitmap
return mng_ReadChunks(s_format_id, io, handle, offset, flags);
}
// ==========================================================
// Init
// ==========================================================
void DLL_CALLCONV
InitMNG(Plugin *plugin, int format_id) {
s_format_id = format_id;
src/Source/FreeImage/PluginPCD.cpp view on Meta::CPAN
}
static BOOL DLL_CALLCONV
SupportsNoPixels() {
return TRUE;
}
// ----------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
FIBITMAP *dib = NULL;
unsigned width;
unsigned height;
const unsigned bpp = 24;
int scan_line_add = 1;
int start_scan_line = 0;
BYTE *y1 = NULL, *y2 = NULL, *cbcr = NULL;
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
// to make absolute seeks possible we store the current position in the file
long offset_in_file = io->tell_proc(handle);
long seek = 0;
// decide which bitmap in the cabinet to load
switch (flags) {
case PCD_BASEDIV4 :
seek = 0x2000;
width = 192;
height = 128;
break;
case PCD_BASEDIV16 :
seek = 0xB800;
width = 384;
height = 256;
src/Source/FreeImage/PluginPCX.cpp view on Meta::CPAN
in a generalized form.
The third parameter (int page) indicates wether we will be loading a certain page
in the bitmap or if we will load the default one. This parameter is only used if
the plugin supports multi-paged bitmaps, e.g. cabinet bitmaps that contain a series
of images or pages. If the plugin does support multi-paging, the page parameter
can contain either a number higher or equal to 0 to load a certain page, or -1 to
load the default page. If the plugin does not support multi-paging,
the page parameter is always -1.
The fourth parameter (int flags) manipulates the load function to load a bitmap
in a certain way. Every plugin has a different flag parameter with different meanings.
The last parameter (void *data) can contain a special data block used when
the file is read multi-paged. Because not every plugin supports multi-paging
not every plugin will use the data parameter and it will be set to NULL.However,
when the plugin does support multi-paging the parameter contains a pointer to a
block of data allocated by the Open function.
*/
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
FIBITMAP *dib = NULL;
BYTE *bits; // Pointer to dib data
RGBQUAD *pal; // Pointer to dib palette
BYTE *line = NULL; // PCX raster line
BYTE *ReadBuf = NULL; // buffer;
BOOL bIsRLE; // True if the file is run-length encoded
if(!handle) {
return NULL;
}
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
try {
// check PCX identifier
long start_pos = io->tell_proc(handle);
BOOL validated = pcx_validate(io, handle);
io->seek_proc(handle, start_pos, SEEK_SET);
if(!validated) {
throw FI_MSG_ERROR_MAGIC_NUMBER;
}
src/Source/FreeImage/PluginPFM.cpp view on Meta::CPAN
}
static BOOL DLL_CALLCONV
SupportsNoPixels() {
return TRUE;
}
// ----------------------------------------------------------
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
char line_buffer[PFM_MAXLINE];
char id_one = 0, id_two = 0;
FIBITMAP *dib = NULL;
float *lineBuffer = NULL;
if (!handle) {
return NULL;
}
BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
try {
FREE_IMAGE_TYPE image_type = FIT_UNKNOWN;
// Read the first two bytes of the file to determine the file format
// "PF" = color image
// "Pf" = greyscale image
io->read_proc(&id_one, 1, 1, handle);
io->read_proc(&id_two, 1, 1, handle);
src/Source/FreeImage/PluginPFM.cpp view on Meta::CPAN
if(NULL != text) {
FreeImage_OutputMessageProc(s_format_id, text);
}
return NULL;
}
}
static BOOL DLL_CALLCONV
Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
if(!dib || !handle) return FALSE;
FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
if((image_type != FIT_RGBF) && (image_type != FIT_FLOAT)) {
return FALSE;
}
unsigned width = FreeImage_GetWidth(dib);
unsigned height = FreeImage_GetHeight(dib);
unsigned lineWidth = FreeImage_GetLine(dib);
src/Source/FreeImage/PluginPICT.cpp view on Meta::CPAN
/* 0x12 */ { "BkPixPat", NA, "color background pattern" },
/* 0x13 */ { "PnPixPat", NA, "color pen pattern" },
/* 0x14 */ { "FillPixPat", NA, "color fill pattern" },
/* 0x15 */ { "PnLocHFrac", 2, "fractional pen position" },
/* 0x16 */ { "ChExtra", 2, "extra for each character" },
/* 0x17 */ res(0),
/* 0x18 */ res(0),
/* 0x19 */ res(0),
/* 0x1a */ { "RGBFgCol", RGB_LEN, "RGB foreColor" },
/* 0x1b */ { "RGBBkCol", RGB_LEN, "RGB backColor" },
/* 0x1c */ { "HiliteMode", 0, "hilite mode flag" },
/* 0x1d */ { "HiliteColor", RGB_LEN, "RGB hilite color" },
/* 0x1e */ { "DefHilite", 0, "Use default hilite color" },
/* 0x1f */ { "OpColor", 6, "RGB OpColor for arithmetic modes" },
/* 0x20 */ { "Line", 8, "pnLoc (point), newPt (point)" },
/* 0x21 */ { "LineFrom", 4, "newPt (point)" },
/* 0x22 */ { "ShortLine", 6, "pnLoc (point, dh, dv (-128 .. 127))" },
/* 0x23 */ { "ShortLineFrom", 2, "dh, dv (-128 .. 127)" },
/* 0x24 */ res(WORD_LEN),
/* 0x25 */ res(WORD_LEN),
/* 0x26 */ res(WORD_LEN),
src/Source/FreeImage/PluginPICT.cpp view on Meta::CPAN
pixelSize == Source bits per pixel.
*/
static void
SkipBits( FreeImageIO *io, fi_handle handle, MacRect* bounds, WORD rowBytes, int pixelSize ) {
int i;
WORD pixwidth; // bytes per row when uncompressed.
int height = bounds->bottom - bounds->top;
int width = bounds->right - bounds->left;
// High bit of rowBytes is flag.
if (pixelSize <= 8) {
rowBytes &= 0x7fff;
}
pixwidth = (WORD)width;
if (pixelSize == 16) {
pixwidth *= 2;
}
if (rowBytes == 0) {
rowBytes = pixwidth;
src/Source/FreeImage/PluginPICT.cpp view on Meta::CPAN
Decompression routine for 8 bpp.
rowBytes is the number of bytes each source row would take if it were uncompressed.
This _isn't_ equal to the number of pixels in the row - it seems apple pads the data to a word boundary and then compresses it.
Of course, we have to decompress the excess data and then throw it away.
*/
static void
Unpack8Bits( FreeImageIO *io, fi_handle handle, FIBITMAP* dib, MacRect* bounds, WORD rowBytes ) {
int height = bounds->bottom - bounds->top;
int width = bounds->right - bounds->left;
// High bit of rowBytes is flag.
rowBytes &= 0x7fff;
if (rowBytes == 0) {
rowBytes = (WORD)width;
}
for ( int i = 0; i < height; i++ ) {
int linelen; // length of source line in bytes.
if (rowBytes > 250) {
linelen = Read16( io, handle );
src/Source/FreeImage/PluginPICT.cpp view on Meta::CPAN
UnpackBits( FreeImageIO *io, fi_handle handle, FIBITMAP* dib, MacRect* bounds, WORD rowBytes, int pixelSize ) {
WORD pixwidth; // bytes per row when uncompressed.
int pkpixsize;
int PixelPerRLEUnit;
char outputMessage[ outputMessageSize ] = "";
int height = bounds->bottom - bounds->top;
int width = bounds->right - bounds->left;
// High bit of rowBytes is flag.
if (pixelSize <= 8) {
rowBytes &= 0x7fff;
}
pixwidth = (WORD)width;
pkpixsize = 1; // RLE unit: one byte for everything...
if (pixelSize == 16) { // ...except 16 bpp.
pkpixsize = 2;
pixwidth *= 2;
}
src/Source/FreeImage/PluginPICT.cpp view on Meta::CPAN
return FALSE;
}
/**
This plugin decodes macintosh PICT files with 1,2,4,8,16 and 32 bits per pixel as well as PICT/JPEG.
If an alpha channel is present in a 32-bit-PICT, it is decoded as well.
The PICT format is a general picture file format and can contain a lot of other elements besides bitmaps.
These elements are ignored.
*/
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
char outputMessage[ outputMessageSize ] = "";
FIBITMAP* dib = NULL;
try {
// Skip empty 512 byte header.
if ( !io->seek_proc(handle, 512, SEEK_CUR) == 0 )
return NULL;
// Read PICT header
Read16( io, handle ); // Skip version 1 picture size