diff options
Diffstat (limited to 'plugins/AdvaImg/src/FreeImage')
56 files changed, 2450 insertions, 2083 deletions
diff --git a/plugins/AdvaImg/src/FreeImage/BitmapAccess.cpp b/plugins/AdvaImg/src/FreeImage/BitmapAccess.cpp index 584870f359..5b90ed8607 100644 --- a/plugins/AdvaImg/src/FreeImage/BitmapAccess.cpp +++ b/plugins/AdvaImg/src/FreeImage/BitmapAccess.cpp @@ -39,6 +39,12 @@ #include "../Metadata/FreeImageTag.h"
+/** Constants for the BITMAPINFOHEADER::biCompression field */
+#ifndef _WINGDI_
+#define BI_RGB 0L
+#define BI_BITFIELDS 3L
+#endif // _WINGDI_
+
// ----------------------------------------------------------
// Metadata definitions
// ----------------------------------------------------------
@@ -62,10 +68,6 @@ FI_STRUCT (METADATAHEADER) { FI_STRUCT (FREEIMAGEHEADER) {
FREE_IMAGE_TYPE type; // data type - bitmap, array of long, double, complex, etc
- unsigned red_mask; // bit layout of the red components
- unsigned green_mask; // bit layout of the green components
- unsigned blue_mask; // bit layout of the blue components
-
RGBQUAD bkgnd_color; // background color used for RGB transparency
BOOL transparent; // why another table? for easy transparency table retrieval!
@@ -84,10 +86,20 @@ FI_STRUCT (FREEIMAGEHEADER) { };
// ----------------------------------------------------------
+// FREEIMAGERGBMASKS definition
+// ----------------------------------------------------------
+
+FI_STRUCT (FREEIMAGERGBMASKS) {
+ unsigned red_mask; // bit layout of the red components
+ unsigned green_mask; // bit layout of the green components
+ unsigned blue_mask; // bit layout of the blue components
+};
+
+// ----------------------------------------------------------
// Memory allocation on a specified alignment boundary
// ----------------------------------------------------------
-#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER >= 1300)
+#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
void* FreeImage_Aligned_Malloc(size_t amount, size_t alignment) {
assert(alignment == FIBITMAP_ALIGNMENT);
@@ -130,7 +142,7 @@ void* FreeImage_Aligned_Malloc(size_t amount, size_t alignment) { That's why the code below allocates *two* alignments instead of one.
*/
void* mem_real = malloc(amount + 2 * alignment);
- if (!mem_real) return NULL;
+ if(!mem_real) return NULL;
char* mem_align = (char*)((unsigned long)(2 * alignment - (unsigned long)mem_real % (unsigned long)alignment) + (unsigned long)mem_real);
*((long*)mem_align - 1) = (long)mem_real;
return mem_align;
@@ -154,18 +166,22 @@ Align the palette and the pixels on a FIBITMAP_ALIGNMENT bytes alignment boundar @param width
@param height
@param bpp
+@param need_masks
@see FreeImage_AllocateHeaderT
*/
static size_t
-FreeImage_GetImageSizeHeader(BOOL header_only, unsigned width, unsigned height, unsigned bpp) {
+FreeImage_GetImageSizeHeader(BOOL header_only, unsigned width, unsigned height, unsigned bpp, BOOL need_masks) {
size_t dib_size = sizeof(FREEIMAGEHEADER);
dib_size += (dib_size % FIBITMAP_ALIGNMENT ? FIBITMAP_ALIGNMENT - dib_size % FIBITMAP_ALIGNMENT : 0);
dib_size += FIBITMAP_ALIGNMENT - sizeof(BITMAPINFOHEADER) % FIBITMAP_ALIGNMENT;
dib_size += sizeof(BITMAPINFOHEADER);
// palette is aligned on a 16 bytes boundary
- dib_size += sizeof(RGBQUAD) * CalculateUsedPaletteEntries(bpp);
+ dib_size += sizeof(RGBQUAD) * CalculateUsedPaletteEntries(bpp);
+ // we both add palette size and masks size if need_masks is true, since CalculateUsedPaletteEntries
+ // always returns 0 if need_masks is true (which is only true for 16 bit images).
+ dib_size += need_masks ? sizeof(DWORD) * 3 : 0;
dib_size += (dib_size % FIBITMAP_ALIGNMENT ? FIBITMAP_ALIGNMENT - dib_size % FIBITMAP_ALIGNMENT : 0);
- if (!header_only) {
+ if(!header_only) {
const size_t header_size = dib_size;
// pixels are aligned on a 16 bytes boundary
@@ -196,74 +212,98 @@ FreeImage_GetImageSizeHeader(BOOL header_only, unsigned width, unsigned height, return dib_size;
}
+/**
+Helper for 16-bit FIT_BITMAP +Returns a pointer to the bitmap's red-, green- and blue masks.
+@param dib The bitmap to obtain masks from.
+@return Returns a pointer to the bitmap's red-, green- and blue masks
+or NULL, if no masks are present (e.g. for 24 bit images).
+*/
+static FREEIMAGERGBMASKS *
+FreeImage_GetRGBMasks(FIBITMAP *dib) {
+ return FreeImage_HasRGBMasks(dib) ? (FREEIMAGERGBMASKS *)(((BYTE *)FreeImage_GetInfoHeader(dib)) + sizeof(BITMAPINFOHEADER)) : NULL;
+}
+
FIBITMAP * DLL_CALLCONV
FreeImage_AllocateHeaderT(BOOL header_only, FREE_IMAGE_TYPE type, int width, int height, int bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask) {
+
+ // check input variables
+ width = abs(width);
+ height = abs(height);
+ if(!((width > 0) && (height > 0))) {
+ return NULL;
+ }
+
+ // we only store the masks (and allocate memory for
+ // them) for 16 images of type FIT_BITMAP
+ BOOL need_masks = FALSE;
+
+ // check pixel bit depth
+ switch(type) {
+ case FIT_BITMAP:
+ switch(bpp) {
+ case 1:
+ case 4:
+ case 8:
+ break;
+ case 16:
+ need_masks = TRUE;
+ break;
+ case 24:
+ case 32:
+ break;
+ default:
+ bpp = 8;
+ break;
+ }
+ break;
+ case FIT_UINT16:
+ bpp = 8 * sizeof(unsigned short);
+ break;
+ case FIT_INT16:
+ bpp = 8 * sizeof(short);
+ break;
+ case FIT_UINT32:
+ bpp = 8 * sizeof(DWORD);
+ break;
+ case FIT_INT32:
+ bpp = 8 * sizeof(LONG);
+ break;
+ case FIT_FLOAT:
+ bpp = 8 * sizeof(float);
+ break;
+ case FIT_DOUBLE:
+ bpp = 8 * sizeof(double);
+ break;
+ case FIT_COMPLEX:
+ bpp = 8 * sizeof(FICOMPLEX);
+ break;
+ case FIT_RGB16:
+ bpp = 8 * sizeof(FIRGB16);
+ break;
+ case FIT_RGBA16:
+ bpp = 8 * sizeof(FIRGBA16);
+ break;
+ case FIT_RGBF:
+ bpp = 8 * sizeof(FIRGBF);
+ break;
+ case FIT_RGBAF:
+ bpp = 8 * sizeof(FIRGBAF);
+ break;
+ default:
+ return NULL;
+ }
+
FIBITMAP *bitmap = (FIBITMAP *)malloc(sizeof(FIBITMAP));
if (bitmap != NULL) {
- width = abs(width);
- height = abs(height);
-
- // check pixel bit depth
- switch(type) {
- case FIT_BITMAP:
- switch(bpp) {
- case 1:
- case 4:
- case 8:
- case 16:
- case 24:
- case 32:
- break;
- default:
- bpp = 8;
- break;
- }
- break;
- case FIT_UINT16:
- bpp = 8 * sizeof(unsigned short);
- break;
- case FIT_INT16:
- bpp = 8 * sizeof(short);
- break;
- case FIT_UINT32:
- bpp = 8 * sizeof(DWORD);
- break;
- case FIT_INT32:
- bpp = 8 * sizeof(LONG);
- break;
- case FIT_FLOAT:
- bpp = 8 * sizeof(float);
- break;
- case FIT_DOUBLE:
- bpp = 8 * sizeof(double);
- break;
- case FIT_COMPLEX:
- bpp = 8 * sizeof(FICOMPLEX);
- break;
- case FIT_RGB16:
- bpp = 8 * sizeof(FIRGB16);
- break;
- case FIT_RGBA16:
- bpp = 8 * sizeof(FIRGBA16);
- break;
- case FIT_RGBF:
- bpp = 8 * sizeof(FIRGBF);
- break;
- case FIT_RGBAF:
- bpp = 8 * sizeof(FIRGBAF);
- break;
- default:
- free(bitmap);
- return NULL;
- }
// calculate the size of a FreeImage image
// align the palette and the pixels on a FIBITMAP_ALIGNMENT bytes alignment boundary
// palette is aligned on a 16 bytes boundary
// pixels are aligned on a 16 bytes boundary
- size_t dib_size = FreeImage_GetImageSizeHeader(header_only, width, height, bpp);
+ size_t dib_size = FreeImage_GetImageSizeHeader(header_only, width, height, bpp, need_masks);
if(dib_size == 0) {
// memory allocation will fail (probably a malloc overflow)
@@ -281,10 +321,6 @@ FreeImage_AllocateHeaderT(BOOL header_only, FREE_IMAGE_TYPE type, int width, int FREEIMAGEHEADER *fih = (FREEIMAGEHEADER *)bitmap->data;
fih->type = type;
- fih->red_mask = red_mask;
- fih->green_mask = green_mask;
- fih->blue_mask = blue_mask;
-
memset(&fih->bkgnd_color, 0, sizeof(RGBQUAD));
fih->transparent = FALSE;
@@ -315,7 +351,7 @@ FreeImage_AllocateHeaderT(BOOL header_only, FREE_IMAGE_TYPE type, int width, int bih->biWidth = width;
bih->biHeight = height;
bih->biPlanes = 1;
- bih->biCompression = 0;
+ bih->biCompression = need_masks ? BI_BITFIELDS : BI_RGB;
bih->biBitCount = (WORD)bpp;
bih->biClrUsed = CalculateUsedPaletteEntries(bpp);
bih->biClrImportant = bih->biClrUsed;
@@ -332,6 +368,14 @@ FreeImage_AllocateHeaderT(BOOL header_only, FREE_IMAGE_TYPE type, int width, int }
}
+ // just setting the masks (only if needed) just like the palette.
+ if (need_masks) {
+ FREEIMAGERGBMASKS *masks = FreeImage_GetRGBMasks(bitmap);
+ masks->red_mask = red_mask;
+ masks->green_mask = green_mask;
+ masks->blue_mask = blue_mask;
+ }
+
return bitmap;
}
@@ -396,17 +440,20 @@ FreeImage_Unload(FIBITMAP *dib) { FIBITMAP * DLL_CALLCONV
FreeImage_Clone(FIBITMAP *dib) {
- if (!dib) return NULL;
+ if(!dib) return NULL;
- unsigned width = FreeImage_GetWidth(dib);
- unsigned height = FreeImage_GetHeight(dib);
- unsigned bpp = FreeImage_GetBPP(dib);
+ FREE_IMAGE_TYPE type = FreeImage_GetImageType(dib);
+ unsigned width = FreeImage_GetWidth(dib);
+ unsigned height = FreeImage_GetHeight(dib);
+ unsigned bpp = FreeImage_GetBPP(dib);
// check for pixel availability ...
BOOL header_only = FreeImage_HasPixels(dib) ? FALSE : TRUE;
+ // check whether this image has masks defined ...
+ BOOL need_masks = (bpp == 16 && type == FIT_BITMAP) ? TRUE : FALSE;
// allocate a new dib
- FIBITMAP *new_dib = FreeImage_AllocateHeaderT(header_only, FreeImage_GetImageType(dib), width, height, bpp,
+ FIBITMAP *new_dib = FreeImage_AllocateHeaderT(header_only, type, width, height, bpp,
FreeImage_GetRedMask(dib), FreeImage_GetGreenMask(dib), FreeImage_GetBlueMask(dib));
if (new_dib) {
@@ -423,7 +470,7 @@ FreeImage_Clone(FIBITMAP *dib) { // palette is aligned on a 16 bytes boundary
// pixels are aligned on a 16 bytes boundary
- size_t dib_size = FreeImage_GetImageSizeHeader(header_only, width, height, bpp);
+ size_t dib_size = FreeImage_GetImageSizeHeader(header_only, width, height, bpp, need_masks);
// copy the bitmap + internal pointers (remember to restore new_dib internal pointers later)
memcpy(new_dib->data, dib->data, dib_size);
@@ -578,15 +625,19 @@ FreeImage_GetColorType(FIBITMAP *dib) { if (FreeImage_GetICCProfile(dib)->flags & FIICC_COLOR_IS_CMYK)
return FIC_CMYK;
- for (unsigned y = 0; y < FreeImage_GetHeight(dib); y++) {
- rgb = (RGBQUAD *)FreeImage_GetScanLine(dib, y);
+ 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)
- return FIC_RGBALPHA;
+ for (unsigned x = 0; x < FreeImage_GetWidth(dib); x++)
+ if (rgb[x].rgbReserved != 0xFF)
+ return FIC_RGBALPHA;
+ }
+ return FIC_RGB;
}
- return FIC_RGB;
+ return FIC_RGBALPHA;
}
default :
@@ -610,19 +661,27 @@ FreeImage_HasPixels(FIBITMAP *dib) { // ----------------------------------------------------------
+BOOL DLL_CALLCONV
+FreeImage_HasRGBMasks(FIBITMAP *dib) {
+ return dib && FreeImage_GetInfoHeader(dib)->biCompression == BI_BITFIELDS;
+}
+
unsigned DLL_CALLCONV
FreeImage_GetRedMask(FIBITMAP *dib) {
- return dib ? ((FREEIMAGEHEADER *)dib->data)->red_mask : 0;
+ FREEIMAGERGBMASKS *masks = FreeImage_GetRGBMasks(dib);
+ return masks ? masks->red_mask : 0;
}
unsigned DLL_CALLCONV
FreeImage_GetGreenMask(FIBITMAP *dib) {
- return dib ? ((FREEIMAGEHEADER *)dib->data)->green_mask : 0;
+ FREEIMAGERGBMASKS *masks = FreeImage_GetRGBMasks(dib);
+ return masks ? masks->green_mask : 0;
}
unsigned DLL_CALLCONV
FreeImage_GetBlueMask(FIBITMAP *dib) {
- return dib ? ((FREEIMAGEHEADER *)dib->data)->blue_mask : 0;
+ FREEIMAGERGBMASKS *masks = FreeImage_GetRGBMasks(dib);
+ return masks ? masks->blue_mask : 0;
}
// ----------------------------------------------------------
@@ -736,9 +795,9 @@ FreeImage_GetTransparencyCount(FIBITMAP *dib) { void DLL_CALLCONV
FreeImage_SetTransparencyTable(FIBITMAP *dib, BYTE *table, int count) {
if (dib) {
- count = MIN(count, 256);
+ count = MAX(0, MIN(count, 256));
if (FreeImage_GetBPP(dib) <= 8) {
- ((FREEIMAGEHEADER *)dib->data)->transparent = TRUE;
+ ((FREEIMAGEHEADER *)dib->data)->transparent = (count > 0) ? TRUE : FALSE;
((FREEIMAGEHEADER *)dib->data)->transparency_count = count;
if (table) {
@@ -915,7 +974,7 @@ FreeImage_SetDotsPerMeterY(FIBITMAP *dib, unsigned res) { BITMAPINFOHEADER * DLL_CALLCONV
FreeImage_GetInfoHeader(FIBITMAP *dib) {
- if (!dib) return NULL;
+ if(!dib) return NULL;
size_t lp = (size_t)dib->data + sizeof(FREEIMAGEHEADER);
lp += (lp % FIBITMAP_ALIGNMENT ? FIBITMAP_ALIGNMENT - lp % FIBITMAP_ALIGNMENT : 0);
lp += FIBITMAP_ALIGNMENT - sizeof(BITMAPINFOHEADER) % FIBITMAP_ALIGNMENT;
@@ -933,13 +992,13 @@ FreeImage_GetInfo(FIBITMAP *dib) { FIMETADATA * DLL_CALLCONV
FreeImage_FindFirstMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, FITAG **tag) {
- if (!dib)
+ if(!dib)
return NULL;
// get the metadata model
METADATAMAP *metadata = ((FREEIMAGEHEADER *)dib->data)->metadata;
TAGMAP *tagmap = NULL;
- if ( (*metadata).find(model) != (*metadata).end()) {
+ if( (*metadata).find(model) != (*metadata).end() ) {
tagmap = (*metadata)[model];
}
if(tagmap) {
@@ -976,7 +1035,7 @@ FreeImage_FindFirstMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, FITAG **tag BOOL DLL_CALLCONV
FreeImage_FindNextMetadata(FIMETADATA *mdhandle, FITAG **tag) {
- if (!mdhandle)
+ if(!mdhandle)
return FALSE;
METADATAHEADER *mdh = (METADATAHEADER *)mdhandle->data;
@@ -1019,7 +1078,7 @@ FreeImage_FindCloseMetadata(FIMETADATA *mdhandle) { BOOL DLL_CALLCONV
FreeImage_CloneMetadata(FIBITMAP *dst, FIBITMAP *src) {
- if (!src || !dst) return FALSE;
+ if(!src || !dst) return FALSE;
// get metadata links
METADATAMAP *src_metadata = ((FREEIMAGEHEADER *)src->data)->metadata;
@@ -1034,7 +1093,7 @@ FreeImage_CloneMetadata(FIBITMAP *dst, FIBITMAP *src) { TAGMAP *src_tagmap = (*i).second;
if(src_tagmap) {
- if ( dst_metadata->find(model) != dst_metadata->end()) {
+ if( dst_metadata->find(model) != dst_metadata->end() ) {
// destroy dst model
FreeImage_SetMetadata((FREE_IMAGE_MDMODEL)model, dst, NULL, NULL);
}
@@ -1069,7 +1128,7 @@ FreeImage_CloneMetadata(FIBITMAP *dst, FIBITMAP *src) { BOOL DLL_CALLCONV
FreeImage_SetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, FITAG *tag) {
- if (!dib)
+ if(!dib)
return FALSE;
TAGMAP *tagmap = NULL;
@@ -1083,7 +1142,7 @@ FreeImage_SetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, if(key != NULL) {
- if (!tagmap) {
+ if(!tagmap) {
// this model, doesn't exist: create it
tagmap = new(std::nothrow) TAGMAP();
(*metadata)[model] = tagmap;
@@ -1158,7 +1217,7 @@ FreeImage_SetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, BOOL DLL_CALLCONV
FreeImage_GetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, FITAG **tag) {
- if (!dib || !key || !tag)
+ if(!dib || !key || !tag)
return FALSE;
TAGMAP *tagmap = NULL;
@@ -1166,13 +1225,13 @@ FreeImage_GetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, // get the metadata model
METADATAMAP *metadata = ((FREEIMAGEHEADER *)dib->data)->metadata;
- if (!(*metadata).empty()) {
+ if(!(*metadata).empty()) {
METADATAMAP::iterator model_iterator = metadata->find(model);
- if (model_iterator != metadata->end()) {
+ if (model_iterator != metadata->end() ) {
// this model exists : try to get the requested tag
tagmap = model_iterator->second;
TAGMAP::iterator tag_iterator = tagmap->find(key);
- if (tag_iterator != tagmap->end()) {
+ if (tag_iterator != tagmap->end() ) {
// get the requested tag
*tag = tag_iterator->second;
}
@@ -1186,17 +1245,17 @@ FreeImage_GetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, unsigned DLL_CALLCONV
FreeImage_GetMetadataCount(FREE_IMAGE_MDMODEL model, FIBITMAP *dib) {
- if (!dib)
+ if(!dib)
return FALSE;
TAGMAP *tagmap = NULL;
// get the metadata model
METADATAMAP *metadata = ((FREEIMAGEHEADER *)dib->data)->metadata;
- if ( (*metadata).find(model) != (*metadata).end()) {
+ if( (*metadata).find(model) != (*metadata).end() ) {
tagmap = (*metadata)[model];
}
- if (!tagmap) {
+ if(!tagmap) {
// this model, doesn't exist: return
return 0;
}
diff --git a/plugins/AdvaImg/src/FreeImage/ColorLookup.cpp b/plugins/AdvaImg/src/FreeImage/ColorLookup.cpp index 3e81abdb95..5f677eee5c 100644 --- a/plugins/AdvaImg/src/FreeImage/ColorLookup.cpp +++ b/plugins/AdvaImg/src/FreeImage/ColorLookup.cpp @@ -568,7 +568,7 @@ FreeImage_LookupX11Color(const char *szColor, BYTE *nRed, BYTE *nGreen, BYTE *nB if ( (szColor[0] == 'g' || szColor[0] == 'G') && (szColor[1] == 'r' || szColor[1] == 'R') && (szColor[2] == 'e' || szColor[2] == 'E' || szColor[2] == 'a' || szColor[2] == 'A' ) && - (szColor[3] == 'y' || szColor[3] == 'Y' )) { + (szColor[3] == 'y' || szColor[3] == 'Y' ) ) { // grey<num>, or gray<num>, num 1...100 i = strtol(szColor+4, NULL, 10); @@ -762,7 +762,7 @@ FreeImage_LookupSVGColor(const char *szColor, BYTE *nRed, BYTE *nGreen, BYTE *nB if ( (szColor[0] == 'g' || szColor[0] == 'G') && (szColor[1] == 'r' || szColor[1] == 'R') && (szColor[2] == 'e' || szColor[2] == 'E' || szColor[2] == 'a' || szColor[2] == 'A' ) && - (szColor[3] == 'y' || szColor[3] == 'Y' )) { + (szColor[3] == 'y' || szColor[3] == 'Y' ) ) { // grey<num>, or gray<num>, num 1...100 i = strtol(szColor+4, NULL, 10); diff --git a/plugins/AdvaImg/src/FreeImage/Conversion.cpp b/plugins/AdvaImg/src/FreeImage/Conversion.cpp index 3c14bab9dd..04cec65ab5 100644 --- a/plugins/AdvaImg/src/FreeImage/Conversion.cpp +++ b/plugins/AdvaImg/src/FreeImage/Conversion.cpp @@ -145,7 +145,7 @@ _convertCMYKtoRGBA(unsigned width, unsigned height, BYTE* line_start, unsigned p BOOL ConvertCMYKtoRGBA(FIBITMAP* dib) { - if (!FreeImage_HasPixels(dib)) { + if(!FreeImage_HasPixels(dib)) { return FALSE; } @@ -294,7 +294,7 @@ _convertLABtoRGB(unsigned width, unsigned height, BYTE* line_start, unsigned pit BOOL ConvertLABtoRGB(FIBITMAP* dib) { - if (!FreeImage_HasPixels(dib)) { + if(!FreeImage_HasPixels(dib)) { return FALSE; } @@ -330,7 +330,7 @@ ConvertLABtoRGB(FIBITMAP* dib) { FIBITMAP* RemoveAlphaChannel(FIBITMAP* src) { - if (!FreeImage_HasPixels(src)) { + if(!FreeImage_HasPixels(src)) { return NULL; } @@ -367,10 +367,10 @@ FreeImage_ColorQuantize(FIBITMAP *dib, FREE_IMAGE_QUANTIZE quantize) { FIBITMAP * DLL_CALLCONV FreeImage_ColorQuantizeEx(FIBITMAP *dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, int ReserveSize, RGBQUAD *ReservePalette) { - if ( PaletteSize < 2 ) PaletteSize = 2; - if ( PaletteSize > 256 ) PaletteSize = 256; - if ( ReserveSize < 0 ) ReserveSize = 0; - if ( ReserveSize > PaletteSize ) ReserveSize = PaletteSize; + if( PaletteSize < 2 ) PaletteSize = 2; + if( PaletteSize > 256 ) PaletteSize = 256; + if( ReserveSize < 0 ) ReserveSize = 0; + if( ReserveSize > PaletteSize ) ReserveSize = PaletteSize; if (FreeImage_HasPixels(dib)) { if (FreeImage_GetBPP(dib) == 24) { switch(quantize) { diff --git a/plugins/AdvaImg/src/FreeImage/Conversion16_555.cpp b/plugins/AdvaImg/src/FreeImage/Conversion16_555.cpp index c0c4785704..abaf2f1824 100644 --- a/plugins/AdvaImg/src/FreeImage/Conversion16_555.cpp +++ b/plugins/AdvaImg/src/FreeImage/Conversion16_555.cpp @@ -115,7 +115,7 @@ FreeImage_ConvertLine32To16_555(BYTE *target, BYTE *source, int width_in_pixels) FIBITMAP * DLL_CALLCONV FreeImage_ConvertTo16Bits555(FIBITMAP *dib) { - if (!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP)) return NULL; + if(!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP)) return NULL; const int width = FreeImage_GetWidth(dib); const int height = FreeImage_GetHeight(dib); diff --git a/plugins/AdvaImg/src/FreeImage/Conversion16_565.cpp b/plugins/AdvaImg/src/FreeImage/Conversion16_565.cpp index 28e8255b4e..eb3dd9de3f 100644 --- a/plugins/AdvaImg/src/FreeImage/Conversion16_565.cpp +++ b/plugins/AdvaImg/src/FreeImage/Conversion16_565.cpp @@ -111,7 +111,7 @@ FreeImage_ConvertLine32To16_565(BYTE *target, BYTE *source, int width_in_pixels) FIBITMAP * DLL_CALLCONV FreeImage_ConvertTo16Bits565(FIBITMAP *dib) { - if (!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP)) return NULL; + if(!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP)) return NULL; const int width = FreeImage_GetWidth(dib); const int height = FreeImage_GetHeight(dib); diff --git a/plugins/AdvaImg/src/FreeImage/Conversion24.cpp b/plugins/AdvaImg/src/FreeImage/Conversion24.cpp index f04b946ef0..1d5bba7f02 100644 --- a/plugins/AdvaImg/src/FreeImage/Conversion24.cpp +++ b/plugins/AdvaImg/src/FreeImage/Conversion24.cpp @@ -121,20 +121,24 @@ FreeImage_ConvertLine32To24(BYTE *target, BYTE *source, int width_in_pixels) { FIBITMAP * DLL_CALLCONV
FreeImage_ConvertTo24Bits(FIBITMAP *dib) {
- if (!FreeImage_HasPixels(dib)) return NULL;
+ if(!FreeImage_HasPixels(dib)) return NULL;
const unsigned bpp = FreeImage_GetBPP(dib);
-
const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
- if ((image_type != FIT_BITMAP) && (image_type != FIT_RGB16)) {
+
+ if((image_type != FIT_BITMAP) && (image_type != FIT_RGB16) && (image_type != FIT_RGBA16)) {
return NULL;
}
+
+ const int width = FreeImage_GetWidth(dib);
+ const int height = FreeImage_GetHeight(dib);
- if (bpp != 24) {
- const int width = FreeImage_GetWidth(dib);
- const int height = FreeImage_GetHeight(dib);
- FIBITMAP *new_dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
+ if(image_type == FIT_BITMAP) {
+ if(bpp == 24) {
+ return FreeImage_Clone(dib);
+ }
+ FIBITMAP *new_dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
if(new_dib == NULL) {
return NULL;
}
@@ -187,28 +191,62 @@ FreeImage_ConvertTo24Bits(FIBITMAP *dib) { }
return new_dib;
}
+ }
+
+ } else if(image_type == FIT_RGB16) {
+ FIBITMAP *new_dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
+ if(new_dib == NULL) {
+ return NULL;
+ }
- case 48:
- {
- const unsigned src_pitch = FreeImage_GetPitch(dib);
- const unsigned dst_pitch = FreeImage_GetPitch(new_dib);
- const BYTE *src_bits = FreeImage_GetBits(dib);
- BYTE *dst_bits = FreeImage_GetBits(new_dib);
- for (int rows = 0; rows < height; rows++) {
- const FIRGB16 *src_pixel = (FIRGB16*)src_bits;
- RGBTRIPLE *dst_pixel = (RGBTRIPLE*)dst_bits;
- for(int cols = 0; cols < width; cols++) {
- dst_pixel[cols].rgbtRed = (BYTE)(src_pixel[cols].red >> 8);
- dst_pixel[cols].rgbtGreen = (BYTE)(src_pixel[cols].green >> 8);
- dst_pixel[cols].rgbtBlue = (BYTE)(src_pixel[cols].blue >> 8);
- }
- src_bits += src_pitch;
- dst_bits += dst_pitch;
- }
- return new_dib;
+ // copy metadata from src to dst
+ FreeImage_CloneMetadata(new_dib, dib);
+
+ const unsigned src_pitch = FreeImage_GetPitch(dib);
+ const unsigned dst_pitch = FreeImage_GetPitch(new_dib);
+ const BYTE *src_bits = FreeImage_GetBits(dib);
+ BYTE *dst_bits = FreeImage_GetBits(new_dib);
+ for (int rows = 0; rows < height; rows++) {
+ const FIRGB16 *src_pixel = (FIRGB16*)src_bits;
+ RGBTRIPLE *dst_pixel = (RGBTRIPLE*)dst_bits;
+ for(int cols = 0; cols < width; cols++) {
+ dst_pixel[cols].rgbtRed = (BYTE)(src_pixel[cols].red >> 8);
+ dst_pixel[cols].rgbtGreen = (BYTE)(src_pixel[cols].green >> 8);
+ dst_pixel[cols].rgbtBlue = (BYTE)(src_pixel[cols].blue >> 8);
}
+ src_bits += src_pitch;
+ dst_bits += dst_pitch;
}
+
+ return new_dib;
+
+ } else if(image_type == FIT_RGBA16) {
+ FIBITMAP *new_dib = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
+ if(new_dib == NULL) {
+ return NULL;
+ }
+
+ // copy metadata from src to dst
+ FreeImage_CloneMetadata(new_dib, dib);
+
+ const unsigned src_pitch = FreeImage_GetPitch(dib);
+ const unsigned dst_pitch = FreeImage_GetPitch(new_dib);
+ const BYTE *src_bits = FreeImage_GetBits(dib);
+ BYTE *dst_bits = FreeImage_GetBits(new_dib);
+ for (int rows = 0; rows < height; rows++) {
+ const FIRGBA16 *src_pixel = (FIRGBA16*)src_bits;
+ RGBTRIPLE *dst_pixel = (RGBTRIPLE*)dst_bits;
+ for(int cols = 0; cols < width; cols++) {
+ dst_pixel[cols].rgbtRed = (BYTE)(src_pixel[cols].red >> 8);
+ dst_pixel[cols].rgbtGreen = (BYTE)(src_pixel[cols].green >> 8);
+ dst_pixel[cols].rgbtBlue = (BYTE)(src_pixel[cols].blue >> 8);
+ }
+ src_bits += src_pitch;
+ dst_bits += dst_pitch;
+ }
+
+ return new_dib;
}
- return FreeImage_Clone(dib);
+ return NULL;
}
diff --git a/plugins/AdvaImg/src/FreeImage/Conversion32.cpp b/plugins/AdvaImg/src/FreeImage/Conversion32.cpp index fad74671cd..b8bd518471 100644 --- a/plugins/AdvaImg/src/FreeImage/Conversion32.cpp +++ b/plugins/AdvaImg/src/FreeImage/Conversion32.cpp @@ -186,12 +186,12 @@ FreeImage_ConvertLine8To32MapTransparency(BYTE *target, BYTE *source, int width_ FIBITMAP * DLL_CALLCONV
FreeImage_ConvertTo32Bits(FIBITMAP *dib) {
- if (!FreeImage_HasPixels(dib)) return NULL;
+ if(!FreeImage_HasPixels(dib)) return NULL;
const int bpp = FreeImage_GetBPP(dib);
const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
- if ((image_type != FIT_BITMAP) && (image_type != FIT_RGB16) && (image_type != FIT_RGBA16)) {
+ if((image_type != FIT_BITMAP) && (image_type != FIT_RGB16) && (image_type != FIT_RGBA16)) {
return NULL;
}
diff --git a/plugins/AdvaImg/src/FreeImage/Conversion4.cpp b/plugins/AdvaImg/src/FreeImage/Conversion4.cpp index 7c09ac824a..13048b6d3f 100644 --- a/plugins/AdvaImg/src/FreeImage/Conversion4.cpp +++ b/plugins/AdvaImg/src/FreeImage/Conversion4.cpp @@ -29,7 +29,7 @@ void DLL_CALLCONV FreeImage_ConvertLine1To4(BYTE *target, BYTE *source, int width_in_pixels) { BOOL hinibble = TRUE; - for (int cols = 0; cols < width_in_pixels; cols++) { + for (int cols = 0; cols < width_in_pixels; cols++){ if (hinibble == TRUE){ target[cols >> 1] = ((source[cols >> 3] & (0x80 >> (cols & 0x07))) != 0 ? 15 : 0) << 4; } @@ -46,7 +46,7 @@ FreeImage_ConvertLine8To4(BYTE *target, BYTE *source, int width_in_pixels, RGBQU BOOL hinibble = TRUE; BYTE index; - for (int cols = 0; cols < width_in_pixels; cols++) { + for (int cols = 0; cols < width_in_pixels; cols++){ index = GREY(palette[source[cols]].rgbRed, palette[source[cols]].rgbGreen, palette[source[cols]].rgbBlue); if (hinibble) { target[cols >> 1] = (index & 0xF0); @@ -140,7 +140,7 @@ FreeImage_ConvertLine32To4(BYTE *target, BYTE *source, int width_in_pixels) { FIBITMAP * DLL_CALLCONV FreeImage_ConvertTo4Bits(FIBITMAP *dib) { - if (!FreeImage_HasPixels(dib)) return NULL; + if(!FreeImage_HasPixels(dib)) return NULL; const int bpp = FreeImage_GetBPP(dib); diff --git a/plugins/AdvaImg/src/FreeImage/Conversion8.cpp b/plugins/AdvaImg/src/FreeImage/Conversion8.cpp index 867cf756ed..1c331a6552 100644 --- a/plugins/AdvaImg/src/FreeImage/Conversion8.cpp +++ b/plugins/AdvaImg/src/FreeImage/Conversion8.cpp @@ -6,6 +6,7 @@ // - Hervé Drolon (drolon@infonie.fr)
// - Jani Kajala (janik@remedy.fi)
// - Karl-Heinz Bussian (khbussian@moss.de)
+// - Carsten Klein (cklein05@users.sourceforge.net)
//
// This file is part of FreeImage 3
//
@@ -31,36 +32,32 @@ void DLL_CALLCONV
FreeImage_ConvertLine1To8(BYTE *target, BYTE *source, int width_in_pixels) {
- for (int cols = 0; cols < width_in_pixels; cols++)
+ for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++)
target[cols] = (source[cols >> 3] & (0x80 >> (cols & 0x07))) != 0 ? 255 : 0;
}
void DLL_CALLCONV
FreeImage_ConvertLine4To8(BYTE *target, BYTE *source, int width_in_pixels) {
- int count_new = 0;
- int count_org = 0;
+ unsigned count_new = 0;
+ unsigned count_org = 0;
BOOL hinibble = TRUE;
- while (count_new < width_in_pixels) {
+ while (count_new < (unsigned)width_in_pixels) {
if (hinibble) {
- target[count_new] = (source[count_org] & 0xF0) >> 4;
+ target[count_new] = (source[count_org] >> 4);
} else {
target[count_new] = (source[count_org] & 0x0F);
-
count_org++;
}
-
hinibble = !hinibble;
-
count_new++;
}
}
void DLL_CALLCONV
FreeImage_ConvertLine16To8_555(BYTE *target, BYTE *source, int width_in_pixels) {
- WORD *bits = (WORD *)source;
-
- for (int cols = 0; cols < width_in_pixels; cols++) {
+ const WORD *const bits = (WORD *)source;
+ for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) {
target[cols] = GREY((((bits[cols] & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT) * 0xFF) / 0x1F,
(((bits[cols] & FI16_555_GREEN_MASK) >> FI16_555_GREEN_SHIFT) * 0xFF) / 0x1F,
(((bits[cols] & FI16_555_BLUE_MASK) >> FI16_555_BLUE_SHIFT) * 0xFF) / 0x1F);
@@ -69,28 +66,26 @@ FreeImage_ConvertLine16To8_555(BYTE *target, BYTE *source, int width_in_pixels) void DLL_CALLCONV
FreeImage_ConvertLine16To8_565(BYTE *target, BYTE *source, int width_in_pixels) {
- WORD *bits = (WORD *)source;
-
- for (int cols = 0; cols < width_in_pixels; cols++)
+ const WORD *const bits = (WORD *)source;
+ for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) {
target[cols] = GREY((((bits[cols] & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT) * 0xFF) / 0x1F,
(((bits[cols] & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT) * 0xFF) / 0x3F,
- (((bits[cols] & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT) * 0xFF) / 0x1F);
+ (((bits[cols] & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT) * 0xFF) / 0x1F);
+ }
}
void DLL_CALLCONV
FreeImage_ConvertLine24To8(BYTE *target, BYTE *source, int width_in_pixels) {
- for (int cols = 0; cols < width_in_pixels; cols++) {
+ for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) {
target[cols] = GREY(source[FI_RGBA_RED], source[FI_RGBA_GREEN], source[FI_RGBA_BLUE]);
-
source += 3;
}
}
void DLL_CALLCONV
FreeImage_ConvertLine32To8(BYTE *target, BYTE *source, int width_in_pixels) {
- for (int cols = 0; cols < width_in_pixels; cols++) {
+ for (unsigned cols = 0; cols < (unsigned)width_in_pixels; cols++) {
target[cols] = GREY(source[FI_RGBA_RED], source[FI_RGBA_GREEN], source[FI_RGBA_BLUE]);
-
source += 4;
}
}
@@ -101,64 +96,54 @@ FreeImage_ConvertLine32To8(BYTE *target, BYTE *source, int width_in_pixels) { FIBITMAP * DLL_CALLCONV
FreeImage_ConvertTo8Bits(FIBITMAP *dib) {
- if (!FreeImage_HasPixels(dib)) return NULL;
-
- const int bpp = FreeImage_GetBPP(dib);
+ if (!FreeImage_HasPixels(dib)) {
+ return NULL;
+ }
const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
- if ((image_type != FIT_BITMAP) && (image_type != FIT_UINT16)) {
+ if (image_type != FIT_BITMAP && image_type != FIT_UINT16) {
return NULL;
}
- if(bpp != 8) {
- const int width = FreeImage_GetWidth(dib);
- const int height = FreeImage_GetHeight(dib);
- FIBITMAP *new_dib = FreeImage_Allocate(width, height, 8);
+ const unsigned bpp = FreeImage_GetBPP(dib);
+
+ if (bpp != 8) {
+
+ const unsigned width = FreeImage_GetWidth(dib);
+ const unsigned height = FreeImage_GetHeight(dib);
- if(new_dib == NULL) {
+ // Allocate a destination image
+ FIBITMAP *new_dib = FreeImage_Allocate(width, height, 8);
+ if (new_dib == NULL) {
return NULL;
}
- // copy metadata from src to dst
+ // Copy metadata from src to dst
FreeImage_CloneMetadata(new_dib, dib);
- // Build a greyscale palette (*always* needed for image processing)
-
+ // Palette of destination image has already been initialized
RGBQUAD *new_pal = FreeImage_GetPalette(new_dib);
- for(int i = 0; i < 256; i++) {
- new_pal[i].rgbRed = (BYTE)i;
- new_pal[i].rgbGreen = (BYTE)i;
- new_pal[i].rgbBlue = (BYTE)i;
- }
+ const FREE_IMAGE_COLOR_TYPE color_type = FreeImage_GetColorType(dib);
- if(image_type == FIT_BITMAP) {
+ if (image_type == FIT_BITMAP) {
switch(bpp) {
case 1:
{
- if(FreeImage_GetColorType(dib) == FIC_PALETTE) {
-
+ if (color_type == FIC_PALETTE) {
// Copy the palette
-
RGBQUAD *old_pal = FreeImage_GetPalette(dib);
- memcpy(&new_pal[0], &old_pal[0], sizeof(RGBQUAD));
- memcpy(&new_pal[255], &old_pal[1], sizeof(RGBQUAD));
+ new_pal[0] = old_pal[0];
+ new_pal[255] = old_pal[1];
+ } else if (color_type == FIC_MINISWHITE) {
+ // Create a reverse grayscale palette
+ CREATE_GREYSCALE_PALETTE_REVERSE(new_pal, 256);
}
- else if(FreeImage_GetColorType(dib) == FIC_MINISWHITE) {
-
- // Reverse the grayscale palette
-
- for(int i = 0; i < 256; i++) {
- new_pal[i].rgbRed = new_pal[i].rgbGreen = new_pal[i].rgbBlue = (BYTE)(255 - i);
- }
- }
-
// Expand and copy the bitmap data
-
- for (int rows = 0; rows < height; rows++) {
+ for (unsigned rows = 0; rows < height; rows++) {
FreeImage_ConvertLine1To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width);
}
return new_dib;
@@ -166,22 +151,13 @@ FreeImage_ConvertTo8Bits(FIBITMAP *dib) { case 4 :
{
- if(FreeImage_GetColorType(dib) == FIC_PALETTE) {
-
+ if (color_type == FIC_PALETTE) {
// Copy the palette
-
- RGBQUAD *old_pal = FreeImage_GetPalette(dib);
-
- for (int i = 0; i < 16; i++) {
- new_pal[i].rgbRed = old_pal[i].rgbRed;
- new_pal[i].rgbGreen = old_pal[i].rgbGreen;
- new_pal[i].rgbBlue = old_pal[i].rgbBlue;
- }
+ memcpy(new_pal, FreeImage_GetPalette(dib), 16 * sizeof(RGBQUAD));
}
// Expand and copy the bitmap data
-
- for (int rows = 0; rows < height; rows++) {
+ for (unsigned rows = 0; rows < height; rows++) {
FreeImage_ConvertLine4To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width);
}
return new_dib;
@@ -190,23 +166,22 @@ FreeImage_ConvertTo8Bits(FIBITMAP *dib) { case 16 :
{
// Expand and copy the bitmap data
-
- for (int rows = 0; rows < height; rows++) {
- if ((FreeImage_GetRedMask(dib) == FI16_565_RED_MASK) && (FreeImage_GetGreenMask(dib) == FI16_565_GREEN_MASK) && (FreeImage_GetBlueMask(dib) == FI16_565_BLUE_MASK)) {
+ if (IS_FORMAT_RGB565(dib)) {
+ for (unsigned rows = 0; rows < height; rows++) {
FreeImage_ConvertLine16To8_565(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width);
- } else {
+ }
+ } else {
+ for (unsigned rows = 0; rows < height; rows++) {
FreeImage_ConvertLine16To8_555(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width);
}
}
-
return new_dib;
}
case 24 :
{
// Expand and copy the bitmap data
-
- for (int rows = 0; rows < height; rows++) {
+ for (unsigned rows = 0; rows < height; rows++) {
FreeImage_ConvertLine24To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width);
}
return new_dib;
@@ -215,32 +190,30 @@ FreeImage_ConvertTo8Bits(FIBITMAP *dib) { case 32 :
{
// Expand and copy the bitmap data
-
- for (int rows = 0; rows < height; rows++) {
+ for (unsigned rows = 0; rows < height; rows++) {
FreeImage_ConvertLine32To8(FreeImage_GetScanLine(new_dib, rows), FreeImage_GetScanLine(dib, rows), width);
}
return new_dib;
}
}
- } else if(image_type == FIT_UINT16) {
+ } else if (image_type == FIT_UINT16) {
const unsigned src_pitch = FreeImage_GetPitch(dib);
const unsigned dst_pitch = FreeImage_GetPitch(new_dib);
const BYTE *src_bits = FreeImage_GetBits(dib);
BYTE *dst_bits = FreeImage_GetBits(new_dib);
- for (int rows = 0; rows < height; rows++) {
- const WORD *src_pixel = (WORD*)src_bits;
+
+ for (unsigned rows = 0; rows < height; rows++) {
+ const WORD *const src_pixel = (WORD*)src_bits;
BYTE *dst_pixel = (BYTE*)dst_bits;
- for(int cols = 0; cols < width; cols++) {
+ for(unsigned cols = 0; cols < width; cols++) {
dst_pixel[cols] = (BYTE)(src_pixel[cols] >> 8);
}
src_bits += src_pitch;
dst_bits += dst_pitch;
}
-
return new_dib;
-
}
} // bpp != 8
@@ -250,76 +223,81 @@ FreeImage_ConvertTo8Bits(FIBITMAP *dib) { FIBITMAP * DLL_CALLCONV
FreeImage_ConvertToGreyscale(FIBITMAP *dib) {
- if (!FreeImage_HasPixels(dib)) return NULL;
+ if (!FreeImage_HasPixels(dib)) {
+ return NULL;
+ }
const FREE_IMAGE_COLOR_TYPE color_type = FreeImage_GetColorType(dib);
- const int bpp = FreeImage_GetBPP(dib);
- if ((color_type == FIC_PALETTE) || (color_type == FIC_MINISWHITE)) {
- const int width = FreeImage_GetWidth(dib);
- const int height = FreeImage_GetHeight(dib);
- FIBITMAP *new_dib = FreeImage_Allocate(width, height, 8);
+ if (color_type == FIC_PALETTE || color_type == FIC_MINISWHITE) {
+
+ const unsigned bpp = FreeImage_GetBPP(dib);
+ const unsigned width = FreeImage_GetWidth(dib);
+ const unsigned height = FreeImage_GetHeight(dib);
- if(new_dib == NULL) {
+ FIBITMAP *new_dib = FreeImage_Allocate(width, height, 8);
+ if (new_dib == NULL) {
return NULL;
}
- // copy metadata from src to dst
+ // Copy metadata from src to dst
FreeImage_CloneMetadata(new_dib, dib);
- // Build a greyscale palette
-
- RGBQUAD *new_pal = FreeImage_GetPalette(new_dib);
-
- for(int i = 0; i < 256; i++) {
- new_pal[i].rgbRed = (BYTE)i;
- new_pal[i].rgbGreen = (BYTE)i;
- new_pal[i].rgbBlue = (BYTE)i;
+ // Create a greyscale palette
+ BYTE grey_pal[256];
+ const RGBQUAD *pal = FreeImage_GetPalette(dib);
+ const unsigned size = CalculateUsedPaletteEntries(bpp);
+ for (unsigned i = 0; i < size; i++) {
+ grey_pal[i] = GREY(pal->rgbRed, pal->rgbGreen, pal->rgbBlue);
+ pal++;
}
- // allocate a 24-bit buffer
-
- BYTE *buffer = (BYTE*)malloc( CalculatePitch(CalculateLine(width, 24)) * sizeof(BYTE));
- if(NULL == buffer) {
- FreeImage_Unload(new_dib);
- return NULL;
- }
+ const BYTE *src_bits = FreeImage_GetBits(dib);
+ BYTE *dst_bits = FreeImage_GetBits(new_dib);
- // Convert the palette to 24-bit, then to 8-bit
+ const unsigned src_pitch = FreeImage_GetPitch(dib);
+ const unsigned dst_pitch = FreeImage_GetPitch(new_dib);
switch(bpp) {
case 1:
{
- for (int rows = 0; rows < height; rows++) {
- FreeImage_ConvertLine1To24(buffer, FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib));
- FreeImage_ConvertLine24To8(FreeImage_GetScanLine(new_dib, rows), buffer, width);
+ for (unsigned y = 0; y < height; y++) {
+ for (unsigned x = 0; x < width; x++) {
+ const unsigned pixel = (src_bits[x >> 3] & (0x80 >> (x & 0x07))) != 0;
+ dst_bits[x] = grey_pal[pixel];
+ }
+ src_bits += src_pitch;
+ dst_bits += dst_pitch;
}
}
break;
case 4:
{
- for (int rows = 0; rows < height; rows++) {
- FreeImage_ConvertLine4To24(buffer, FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib));
- FreeImage_ConvertLine24To8(FreeImage_GetScanLine(new_dib, rows), buffer, width);
+ for (unsigned y = 0; y < height; y++) {
+ for (unsigned x = 0; x < width; x++) {
+ const unsigned pixel = x & 0x01 ? src_bits[x >> 1] & 0x0F : src_bits[x >> 1] >> 4;
+ dst_bits[x] = grey_pal[pixel];
+ }
+ src_bits += src_pitch;
+ dst_bits += dst_pitch;
}
}
break;
case 8:
{
- for (int rows = 0; rows < height; rows++) {
- FreeImage_ConvertLine8To24(buffer, FreeImage_GetScanLine(dib, rows), width, FreeImage_GetPalette(dib));
- FreeImage_ConvertLine24To8(FreeImage_GetScanLine(new_dib, rows), buffer, width);
+ for (unsigned y = 0; y < height; y++) {
+ for (unsigned x = 0; x < width; x++) {
+ dst_bits[x] = grey_pal[src_bits[x]];
+ }
+ src_bits += src_pitch;
+ dst_bits += dst_pitch;
}
}
break;
-
}
- free(buffer);
-
return new_dib;
-
}
// Convert the bitmap to 8-bit greyscale
diff --git a/plugins/AdvaImg/src/FreeImage/ConversionFloat.cpp b/plugins/AdvaImg/src/FreeImage/ConversionFloat.cpp index 181ff396e1..e72d14cb83 100644 --- a/plugins/AdvaImg/src/FreeImage/ConversionFloat.cpp +++ b/plugins/AdvaImg/src/FreeImage/ConversionFloat.cpp @@ -31,7 +31,7 @@ FreeImage_ConvertToFloat(FIBITMAP *dib) { FIBITMAP *src = NULL;
FIBITMAP *dst = NULL;
- if (!FreeImage_HasPixels(dib)) return NULL;
+ if(!FreeImage_HasPixels(dib)) return NULL;
FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib);
@@ -40,11 +40,11 @@ FreeImage_ConvertToFloat(FIBITMAP *dib) { case FIT_BITMAP:
{
// allow conversion from 8-bit
- if ((FreeImage_GetBPP(dib) == 8) && (FreeImage_GetColorType(dib) == FIC_MINISBLACK)) {
+ if((FreeImage_GetBPP(dib) == 8) && (FreeImage_GetColorType(dib) == FIC_MINISBLACK)) {
src = dib;
} else {
src = FreeImage_ConvertToGreyscale(dib);
- if (!src) return NULL;
+ if(!src) return NULL;
}
break;
}
@@ -68,7 +68,7 @@ FreeImage_ConvertToFloat(FIBITMAP *dib) { const unsigned height = FreeImage_GetHeight(src);
dst = FreeImage_AllocateT(FIT_FLOAT, width, height);
- if (!dst) {
+ if(!dst) {
if(src != dib) {
FreeImage_Unload(src);
}
diff --git a/plugins/AdvaImg/src/FreeImage/ConversionRGB16.cpp b/plugins/AdvaImg/src/FreeImage/ConversionRGB16.cpp index 6b9d17fbed..bd38504a1e 100644 --- a/plugins/AdvaImg/src/FreeImage/ConversionRGB16.cpp +++ b/plugins/AdvaImg/src/FreeImage/ConversionRGB16.cpp @@ -31,7 +31,7 @@ FreeImage_ConvertToRGB16(FIBITMAP *dib) { FIBITMAP *src = NULL;
FIBITMAP *dst = NULL;
- if (!FreeImage_HasPixels(dib)) return NULL;
+ if(!FreeImage_HasPixels(dib)) return NULL;
const FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib);
@@ -40,11 +40,11 @@ FreeImage_ConvertToRGB16(FIBITMAP *dib) { case FIT_BITMAP:
{
// convert to 24-bit if needed
- if ((FreeImage_GetBPP(dib) == 24) || (FreeImage_GetBPP(dib) == 32)) {
+ if((FreeImage_GetBPP(dib) == 24) || (FreeImage_GetBPP(dib) == 32)) {
src = dib;
} else {
src = FreeImage_ConvertTo24Bits(dib);
- if (!src) return NULL;
+ if(!src) return NULL;
}
break;
}
@@ -70,7 +70,7 @@ FreeImage_ConvertToRGB16(FIBITMAP *dib) { const unsigned height = FreeImage_GetHeight(src);
dst = FreeImage_AllocateT(FIT_RGB16, width, height);
- if (!dst) {
+ if(!dst) {
if(src != dib) {
FreeImage_Unload(src);
}
diff --git a/plugins/AdvaImg/src/FreeImage/ConversionRGBF.cpp b/plugins/AdvaImg/src/FreeImage/ConversionRGBF.cpp index 6b8739532f..b5161d566d 100644 --- a/plugins/AdvaImg/src/FreeImage/ConversionRGBF.cpp +++ b/plugins/AdvaImg/src/FreeImage/ConversionRGBF.cpp @@ -31,7 +31,7 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) { FIBITMAP *src = NULL;
FIBITMAP *dst = NULL;
- if (!FreeImage_HasPixels(dib)) return NULL;
+ if(!FreeImage_HasPixels(dib)) return NULL;
const FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib);
@@ -41,9 +41,9 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) { {
// allow conversion from 24- and 32-bit
const FREE_IMAGE_COLOR_TYPE color_type = FreeImage_GetColorType(dib);
- if ((color_type != FIC_RGB) && (color_type != FIC_RGBALPHA)) {
+ if((color_type != FIC_RGB) && (color_type != FIC_RGBALPHA)) {
src = FreeImage_ConvertTo24Bits(dib);
- if (!src) return NULL;
+ if(!src) return NULL;
} else {
src = dib;
}
@@ -83,7 +83,7 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) { const unsigned height = FreeImage_GetHeight(src);
dst = FreeImage_AllocateT(FIT_RGBF, width, height);
- if (!dst) {
+ if(!dst) {
if(src != dib) {
FreeImage_Unload(src);
}
diff --git a/plugins/AdvaImg/src/FreeImage/ConversionType.cpp b/plugins/AdvaImg/src/FreeImage/ConversionType.cpp index 23528b60fe..b537f72814 100644 --- a/plugins/AdvaImg/src/FreeImage/ConversionType.cpp +++ b/plugins/AdvaImg/src/FreeImage/ConversionType.cpp @@ -47,7 +47,7 @@ CONVERT_TYPE<Tdst, Tsrc>::convert(FIBITMAP *src, FREE_IMAGE_TYPE dst_type) { dst = FreeImage_AllocateT(dst_type, width, height, bpp, FreeImage_GetRedMask(src), FreeImage_GetGreenMask(src), FreeImage_GetBlueMask(src)); - if (!dst) return NULL; + if(!dst) return NULL; // convert from src_type to dst_type @@ -86,7 +86,7 @@ CONVERT_TO_BYTE<Tsrc>::convert(FIBITMAP *src, BOOL scale_linear) { // allocate a 8-bit dib dst = FreeImage_AllocateT(FIT_BITMAP, width, height, 8, 0, 0, 0); - if (!dst) return NULL; + if(!dst) return NULL; // build a greyscale palette RGBQUAD *pal = FreeImage_GetPalette(dst); @@ -160,7 +160,7 @@ CONVERT_TO_COMPLEX<Tsrc>::convert(FIBITMAP *src) { // allocate dst image dst = FreeImage_AllocateT(FIT_COMPLEX, width, height); - if (!dst) return NULL; + if(!dst) return NULL; // convert from src_type to FIT_COMPLEX @@ -236,7 +236,7 @@ FIBITMAP* DLL_CALLCONV FreeImage_ConvertToStandardType(FIBITMAP *src, BOOL scale_linear) { FIBITMAP *dst = NULL; - if (!src) return NULL; + if(!src) return NULL; // convert from src_type to FIT_BITMAP @@ -306,7 +306,7 @@ FIBITMAP* DLL_CALLCONV FreeImage_ConvertToType(FIBITMAP *src, FREE_IMAGE_TYPE dst_type, BOOL scale_linear) { FIBITMAP *dst = NULL; - if (!FreeImage_HasPixels(src)) return NULL; + if(!FreeImage_HasPixels(src)) return NULL; // convert from src_type to dst_type diff --git a/plugins/AdvaImg/src/FreeImage/ConversionUINT16.cpp b/plugins/AdvaImg/src/FreeImage/ConversionUINT16.cpp index 3744cfe3b4..ed4691f3a2 100644 --- a/plugins/AdvaImg/src/FreeImage/ConversionUINT16.cpp +++ b/plugins/AdvaImg/src/FreeImage/ConversionUINT16.cpp @@ -31,7 +31,7 @@ FreeImage_ConvertToUINT16(FIBITMAP *dib) { FIBITMAP *src = NULL;
FIBITMAP *dst = NULL;
- if (!FreeImage_HasPixels(dib)) return NULL;
+ if(!FreeImage_HasPixels(dib)) return NULL;
const FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(dib);
@@ -40,11 +40,11 @@ FreeImage_ConvertToUINT16(FIBITMAP *dib) { case FIT_BITMAP:
{
// convert to greyscale if needed
- if ((FreeImage_GetBPP(dib) == 8) && (FreeImage_GetColorType(dib) == FIC_MINISBLACK)) {
+ if((FreeImage_GetBPP(dib) == 8) && (FreeImage_GetColorType(dib) == FIC_MINISBLACK)) {
src = dib;
} else {
src = FreeImage_ConvertToGreyscale(dib);
- if (!src) return NULL;
+ if(!src) return NULL;
}
break;
}
@@ -70,7 +70,7 @@ FreeImage_ConvertToUINT16(FIBITMAP *dib) { const unsigned height = FreeImage_GetHeight(src);
dst = FreeImage_AllocateT(FIT_UINT16, width, height);
- if (!dst) {
+ if(!dst) {
if(src != dib) {
FreeImage_Unload(src);
}
diff --git a/plugins/AdvaImg/src/FreeImage/FreeImage.cpp b/plugins/AdvaImg/src/FreeImage/FreeImage.cpp index b36f10aca1..2de6077eed 100644 --- a/plugins/AdvaImg/src/FreeImage/FreeImage.cpp +++ b/plugins/AdvaImg/src/FreeImage/FreeImage.cpp @@ -132,7 +132,7 @@ FreeImage_OutputMessageProc(int fif, const char *fmt, ...) { // check the length of the format string - int str_length = (int)( (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt)); + int str_length = (int)( (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt) ); // parse the format string and put the result in 'message' diff --git a/plugins/AdvaImg/src/FreeImage/FreeImageIO.cpp b/plugins/AdvaImg/src/FreeImage/FreeImageIO.cpp index b289530be7..f8cf7604eb 100644 --- a/plugins/AdvaImg/src/FreeImage/FreeImageIO.cpp +++ b/plugins/AdvaImg/src/FreeImage/FreeImageIO.cpp @@ -69,7 +69,7 @@ _MemoryReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle) { for(x = 0; x < count; x++) { //if there isnt size bytes left to read, set pos to eof and return a short count - if ( (mem_header->filelen - mem_header->curpos) < (long)size ) { + if( (mem_header->filelen - mem_header->curpos) < (long)size ) { mem_header->curpos = mem_header->filelen; break; } @@ -91,13 +91,13 @@ _MemoryWriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) //double the data block size if we need to while( (mem_header->curpos + (long)(size*count)) >= mem_header->datalen ) { //if we are at or above 1G, we cant double without going negative - if ( mem_header->datalen & 0x40000000 ) { + if( mem_header->datalen & 0x40000000 ) { //max 2G - if ( mem_header->datalen == 0x7FFFFFFF ) { + if( mem_header->datalen == 0x7FFFFFFF ) { return 0; } newdatalen = 0x7FFFFFFF; - } else if ( mem_header->datalen == 0 ) { + } else if( mem_header->datalen == 0 ) { //default to 4K if nothing yet newdatalen = 4096; } else { @@ -105,7 +105,7 @@ _MemoryWriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) newdatalen = mem_header->datalen << 1; } newdata = realloc( mem_header->data, newdatalen ); - if ( !newdata ) { + if( !newdata ) { return 0; } mem_header->data = newdata; @@ -113,7 +113,7 @@ _MemoryWriteProc(void *buffer, unsigned size, unsigned count, fi_handle handle) } memcpy( (char *)mem_header->data + mem_header->curpos, buffer, size*count ); mem_header->curpos += size*count; - if ( mem_header->curpos > mem_header->filelen ) { + if( mem_header->curpos > mem_header->filelen ) { mem_header->filelen = mem_header->curpos; } return count; @@ -126,21 +126,21 @@ _MemorySeekProc(fi_handle handle, long offset, int origin) { switch(origin) { //0 to filelen-1 are 'inside' the file default: case SEEK_SET: //can fseek() to 0-7FFFFFFF always - if ( offset >= 0 ) { + if( offset >= 0 ) { mem_header->curpos = offset; return 0; } break; case SEEK_CUR: - if ( mem_header->curpos + offset >= 0 ) { + if( mem_header->curpos + offset >= 0 ) { mem_header->curpos += offset; return 0; } break; case SEEK_END: - if ( mem_header->filelen + offset >= 0 ) { + if( mem_header->filelen + offset >= 0 ) { mem_header->curpos = mem_header->filelen + offset; return 0; } diff --git a/plugins/AdvaImg/src/FreeImage/GetType.cpp b/plugins/AdvaImg/src/FreeImage/GetType.cpp index 76edc7f3f9..0ac15fc2e6 100644 --- a/plugins/AdvaImg/src/FreeImage/GetType.cpp +++ b/plugins/AdvaImg/src/FreeImage/GetType.cpp @@ -27,7 +27,6 @@ #include "Utilities.h" #include "FreeImageIO.h" #include "Plugin.h" -#include "../DeprecationManager/DeprecationMgr.h" // ---------------------------------------------------------- diff --git a/plugins/AdvaImg/src/FreeImage/Halftoning.cpp b/plugins/AdvaImg/src/FreeImage/Halftoning.cpp index 1542fc9268..313cc26e15 100644 --- a/plugins/AdvaImg/src/FreeImage/Halftoning.cpp +++ b/plugins/AdvaImg/src/FreeImage/Halftoning.cpp @@ -176,7 +176,7 @@ static FIBITMAP* OrderedDispersedDot(FIBITMAP *dib, int order) { BYTE *matrix = (BYTE*)malloc(l*l * sizeof(BYTE)); for(int i = 0; i < l*l; i++) { // according to "Purdue University: Digital Image Processing Laboratory: Image Halftoning, April 30th, 2006 - matrix[i] = (BYTE)( 255 * (((double)dithervalue(i / l, i % l, order) + 0.5) / (l*l))); + matrix[i] = (BYTE)( 255 * (((double)dithervalue(i / l, i % l, order) + 0.5) / (l*l)) ); } // perform the dithering @@ -312,7 +312,7 @@ FIBITMAP * DLL_CALLCONV FreeImage_Dither(FIBITMAP *dib, FREE_IMAGE_DITHER algorithm) { FIBITMAP *input = NULL, *dib8 = NULL; - if (!FreeImage_HasPixels(dib)) return NULL; + if(!FreeImage_HasPixels(dib)) return NULL; const unsigned bpp = FreeImage_GetBPP(dib); @@ -401,7 +401,7 @@ FIBITMAP * DLL_CALLCONV FreeImage_Threshold(FIBITMAP *dib, BYTE T) { FIBITMAP *dib8 = NULL; - if (!FreeImage_HasPixels(dib)) return NULL; + if(!FreeImage_HasPixels(dib)) return NULL; const unsigned bpp = FreeImage_GetBPP(dib); diff --git a/plugins/AdvaImg/src/FreeImage/J2KHelper.cpp b/plugins/AdvaImg/src/FreeImage/J2KHelper.cpp index 44b210aca0..c9f8fa57af 100644 --- a/plugins/AdvaImg/src/FreeImage/J2KHelper.cpp +++ b/plugins/AdvaImg/src/FreeImage/J2KHelper.cpp @@ -1,500 +1,500 @@ -// ========================================================== -// JPEG2000 helpers -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" -#include "../LibOpenJPEG/openjpeg.h" - -/** -Divide an integer by a power of 2 and round upwards -@return Returns a divided by 2^b -*/ -static int int_ceildivpow2(int a, int b) { - return (a + (1 << b) - 1) >> b; -} - -/** -Convert a OpenJPEG image to a FIBITMAP -@param format_id Plugin ID -@param image OpenJPEG image -@return Returns the converted image if successful, returns NULL otherwise -*/ -FIBITMAP* J2KImageToFIBITMAP(int format_id, const opj_image_t *image) { - FIBITMAP *dib = NULL; - - try { - // compute image width and height - - //int w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx); - int wr = image->comps[0].w; - int wrr = int_ceildivpow2(image->comps[0].w, image->comps[0].factor); - - //int h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy); - //int hr = image->comps[0].h; - int hrr = int_ceildivpow2(image->comps[0].h, image->comps[0].factor); - - // check the number of components - - int numcomps = image->numcomps; - - BOOL bIsValid = TRUE; - for(int c = 0; c < numcomps - 1; c++) { - if ( (image->comps[c].dx == image->comps[c+1].dx) && - (image->comps[c].dy == image->comps[c+1].dy) && - (image->comps[c].prec == image->comps[c+1].prec) ) { - continue; - } else { - bIsValid = FALSE; - break; - } - } - bIsValid &= ((numcomps == 1) || (numcomps == 3) || (numcomps == 4)); - if (!bIsValid) { - if(numcomps) { - FreeImage_OutputMessageProc(format_id, "Warning: image contains %d greyscale components. Only the first will be loaded.\n", numcomps); - numcomps = 1; - } else { - // unknown type - throw FI_MSG_ERROR_UNSUPPORTED_FORMAT; - } - } - - // create a new DIB - - if(image->comps[0].prec <= 8) { - switch(numcomps) { - case 1: - dib = FreeImage_Allocate(wrr, hrr, 8); - break; - case 3: - dib = FreeImage_Allocate(wrr, hrr, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - break; - case 4: - dib = FreeImage_Allocate(wrr, hrr, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - break; - } - } else if(image->comps[0].prec <= 16) { - switch(numcomps) { - case 1: - dib = FreeImage_AllocateT(FIT_UINT16, wrr, hrr); - break; - case 3: - dib = FreeImage_AllocateT(FIT_RGB16, wrr, hrr); - break; - case 4: - dib = FreeImage_AllocateT(FIT_RGBA16, wrr, hrr); - break; - } - } else { - throw FI_MSG_ERROR_UNSUPPORTED_FORMAT; - } - if (!dib) { - throw FI_MSG_ERROR_DIB_MEMORY; - } - - if(image->comps[0].prec <= 8) { - if(numcomps == 1) { - // 8-bit greyscale - // ---------------------------------------------------------- - - // build a greyscale palette - - RGBQUAD *pal = FreeImage_GetPalette(dib); - for (int i = 0; i < 256; i++) { - pal[i].rgbRed = (BYTE)i; - pal[i].rgbGreen = (BYTE)i; - pal[i].rgbBlue = (BYTE)i; - } - - // load pixel data - - unsigned pixel_count = 0; - - for(int y = 0; y < hrr; y++) { - BYTE *bits = FreeImage_GetScanLine(dib, hrr - 1 - y); - - for(int x = 0; x < wrr; x++) { - const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; - - int index = image->comps[0].data[pixel_pos]; - index += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - - bits[x] = (BYTE)index; - - pixel_count++; - } - } - } - else if(numcomps == 3) { - - // 24-bit RGB - // ---------------------------------------------------------- - - // load pixel data - - unsigned pixel_count = 0; - - for(int y = 0; y < hrr; y++) { - BYTE *bits = FreeImage_GetScanLine(dib, hrr - 1 - y); - - for(int x = 0; x < wrr; x++) { - const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; - - int r = image->comps[0].data[pixel_pos]; - r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - - int g = image->comps[1].data[pixel_pos]; - g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - - int b = image->comps[2].data[pixel_pos]; - b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - - bits[FI_RGBA_RED] = (BYTE)r; - bits[FI_RGBA_GREEN] = (BYTE)g; - bits[FI_RGBA_BLUE] = (BYTE)b; - bits += 3; - - pixel_count++; - } - } - } - else if(numcomps == 4) { - - // 32-bit RGBA - // ---------------------------------------------------------- - - // load pixel data - - unsigned pixel_count = 0; - - for(int y = 0; y < hrr; y++) { - BYTE *bits = FreeImage_GetScanLine(dib, hrr - 1 - y); - - for(int x = 0; x < wrr; x++) { - const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; - - int r = image->comps[0].data[pixel_pos]; - r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - - int g = image->comps[1].data[pixel_pos]; - g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - - int b = image->comps[2].data[pixel_pos]; - b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - - int a = image->comps[3].data[pixel_pos]; - a += (image->comps[3].sgnd ? 1 << (image->comps[3].prec - 1) : 0); - - bits[FI_RGBA_RED] = (BYTE)r; - bits[FI_RGBA_GREEN] = (BYTE)g; - bits[FI_RGBA_BLUE] = (BYTE)b; - bits[FI_RGBA_ALPHA] = (BYTE)a; - bits += 4; - - pixel_count++; - } - } - } - } - else if(image->comps[0].prec <= 16) { - if(numcomps == 1) { - // 16-bit greyscale - // ---------------------------------------------------------- - - // load pixel data - - unsigned pixel_count = 0; - - for(int y = 0; y < hrr; y++) { - unsigned short *bits = (unsigned short*)FreeImage_GetScanLine(dib, hrr - 1 - y); - - for(int x = 0; x < wrr; x++) { - const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; - - int index = image->comps[0].data[pixel_pos]; - index += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - - bits[x] = (unsigned short)index; - - pixel_count++; - } - } - } - else if(numcomps == 3) { - - // 48-bit RGB - // ---------------------------------------------------------- - - // load pixel data - - unsigned pixel_count = 0; - - for(int y = 0; y < hrr; y++) { - FIRGB16 *bits = (FIRGB16*)FreeImage_GetScanLine(dib, hrr - 1 - y); - - for(int x = 0; x < wrr; x++) { - const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; - - int r = image->comps[0].data[pixel_pos]; - r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - - int g = image->comps[1].data[pixel_pos]; - g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - - int b = image->comps[2].data[pixel_pos]; - b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - - bits[x].red = (WORD)r; - bits[x].green = (WORD)g; - bits[x].blue = (WORD)b; - - pixel_count++; - } - } - } - else if(numcomps == 4) { - - // 64-bit RGBA - // ---------------------------------------------------------- - - // load pixel data - - unsigned pixel_count = 0; - - for(int y = 0; y < hrr; y++) { - FIRGBA16 *bits = (FIRGBA16*)FreeImage_GetScanLine(dib, hrr - 1 - y); - - for(int x = 0; x < wrr; x++) { - const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr; - - int r = image->comps[0].data[pixel_pos]; - r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - - int g = image->comps[1].data[pixel_pos]; - g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - - int b = image->comps[2].data[pixel_pos]; - b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - - int a = image->comps[3].data[pixel_pos]; - a += (image->comps[3].sgnd ? 1 << (image->comps[3].prec - 1) : 0); - - bits[x].red = (WORD)r; - bits[x].green = (WORD)g; - bits[x].blue = (WORD)b; - bits[x].alpha = (WORD)a; - - pixel_count++; - } - } - } - } - - return dib; - - } catch(const char *text) { - if(dib) FreeImage_Unload(dib); - FreeImage_OutputMessageProc(format_id, text); - return NULL; - } - -} - -/** -Convert a FIBITMAP to a OpenJPEG image -@param format_id Plugin ID -@param dib FreeImage image -@param parameters Compression parameters -@return Returns the converted image if successful, returns NULL otherwise -*/ -opj_image_t* FIBITMAPToJ2KImage(int format_id, FIBITMAP *dib, const opj_cparameters_t *parameters) { - int prec, numcomps, x, y, index; - OPJ_COLOR_SPACE color_space; - opj_image_cmptparm_t cmptparm[4]; // maximum of 4 components - opj_image_t *image = NULL; // image to encode - - try { - int w = FreeImage_GetWidth(dib); - int h = FreeImage_GetHeight(dib); - - // get image characteristics - FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); - - if(image_type == FIT_BITMAP) { - // standard image ... - prec = 8; - switch(FreeImage_GetColorType(dib)) { - case FIC_MINISBLACK: - numcomps = 1; - color_space = CLRSPC_GRAY; - break; - case FIC_RGB: - if(FreeImage_GetBPP(dib) == 32) { - // 32-bit image with a fully opaque layer - numcomps = 4; - color_space = CLRSPC_SRGB; - } else { - // 24-bit image - numcomps = 3; - color_space = CLRSPC_SRGB; - } - break; - case FIC_RGBALPHA: - numcomps = 4; - color_space = CLRSPC_SRGB; - break; - default: - return NULL; - } - } else { - // HDR image ... - prec = 16; - switch(image_type) { - case FIT_UINT16: - numcomps = 1; - color_space = CLRSPC_GRAY; - break; - case FIT_RGB16: - numcomps = 3; - color_space = CLRSPC_SRGB; - break; - case FIT_RGBA16: - numcomps = 4; - color_space = CLRSPC_SRGB; - break; - default: - return NULL; - } - } - - // initialize image components - memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t)); - for(int i = 0; i < numcomps; i++) { - cmptparm[i].dx = parameters->subsampling_dx; - cmptparm[i].dy = parameters->subsampling_dy; - cmptparm[i].w = w; - cmptparm[i].h = h; - cmptparm[i].prec = prec; - cmptparm[i].bpp = prec; - cmptparm[i].sgnd = 0; - } - // create the image - image = opj_image_create(numcomps, &cmptparm[0], color_space); - if (!image) { - throw FI_MSG_ERROR_DIB_MEMORY; - } - - // set image offset and reference grid - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = parameters->image_offset_x0 + (w - 1) * parameters->subsampling_dx + 1; - image->y1 = parameters->image_offset_y0 + (h - 1) * parameters->subsampling_dy + 1; - - // set image data - if(prec == 8) { - switch(numcomps) { - case 1: - index = 0; - for(y = 0; y < h; y++) { - BYTE *bits = FreeImage_GetScanLine(dib, h - 1 - y); - for(x = 0; x < w; x++) { - image->comps[0].data[index] = bits[x]; - index++; - } - } - break; - case 3: - index = 0; - for(y = 0; y < h; y++) { - BYTE *bits = FreeImage_GetScanLine(dib, h - 1 - y); - for(x = 0; x < w; x++) { - image->comps[0].data[index] = bits[FI_RGBA_RED]; - image->comps[1].data[index] = bits[FI_RGBA_GREEN]; - image->comps[2].data[index] = bits[FI_RGBA_BLUE]; - bits += 3; - index++; - } - } - break; - case 4: - index = 0; - for(y = 0; y < h; y++) { - BYTE *bits = FreeImage_GetScanLine(dib, h - 1 - y); - for(x = 0; x < w; x++) { - image->comps[0].data[index] = bits[FI_RGBA_RED]; - image->comps[1].data[index] = bits[FI_RGBA_GREEN]; - image->comps[2].data[index] = bits[FI_RGBA_BLUE]; - image->comps[3].data[index] = bits[FI_RGBA_ALPHA]; - bits += 4; - index++; - } - } - break; - } - } - else if(prec == 16) { - switch(numcomps) { - case 1: - index = 0; - for(y = 0; y < h; y++) { - WORD *bits = (WORD*)FreeImage_GetScanLine(dib, h - 1 - y); - for(x = 0; x < w; x++) { - image->comps[0].data[index] = bits[x]; - index++; - } - } - break; - case 3: - index = 0; - for(y = 0; y < h; y++) { - FIRGB16 *bits = (FIRGB16*)FreeImage_GetScanLine(dib, h - 1 - y); - for(x = 0; x < w; x++) { - image->comps[0].data[index] = bits[x].red; - image->comps[1].data[index] = bits[x].green; - image->comps[2].data[index] = bits[x].blue; - index++; - } - } - break; - case 4: - index = 0; - for(y = 0; y < h; y++) { - FIRGBA16 *bits = (FIRGBA16*)FreeImage_GetScanLine(dib, h - 1 - y); - for(x = 0; x < w; x++) { - image->comps[0].data[index] = bits[x].red; - image->comps[1].data[index] = bits[x].green; - image->comps[2].data[index] = bits[x].blue; - image->comps[3].data[index] = bits[x].alpha; - index++; - } - } - break; - } - } - - return image; - - } catch (const char *text) { - if(image) opj_image_destroy(image); - FreeImage_OutputMessageProc(format_id, text); - return NULL; - } -} +// ==========================================================
+// JPEG2000 helpers
+//
+// Design and implementation by
+// - Hervé Drolon (drolon@infonie.fr)
+//
+// This file is part of FreeImage 3
+//
+// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
+// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
+// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
+// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
+// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
+// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
+// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
+// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+// THIS DISCLAIMER.
+//
+// Use at your own risk!
+// ==========================================================
+
+#include "FreeImage.h"
+#include "Utilities.h"
+#include "../LibOpenJPEG/openjpeg.h"
+
+/**
+Divide an integer by a power of 2 and round upwards
+@return Returns a divided by 2^b
+*/
+static int int_ceildivpow2(int a, int b) {
+ return (a + (1 << b) - 1) >> b;
+}
+
+/**
+Convert a OpenJPEG image to a FIBITMAP
+@param format_id Plugin ID
+@param image OpenJPEG image
+@return Returns the converted image if successful, returns NULL otherwise
+*/
+FIBITMAP* J2KImageToFIBITMAP(int format_id, const opj_image_t *image) {
+ FIBITMAP *dib = NULL;
+
+ try {
+ // compute image width and height
+
+ //int w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
+ int wr = image->comps[0].w;
+ int wrr = int_ceildivpow2(image->comps[0].w, image->comps[0].factor);
+
+ //int h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy);
+ //int hr = image->comps[0].h;
+ int hrr = int_ceildivpow2(image->comps[0].h, image->comps[0].factor);
+
+ // check the number of components
+
+ int numcomps = image->numcomps;
+
+ BOOL bIsValid = TRUE;
+ for(int c = 0; c < numcomps - 1; c++) {
+ if( (image->comps[c].dx == image->comps[c+1].dx) &&
+ (image->comps[c].dy == image->comps[c+1].dy) &&
+ (image->comps[c].prec == image->comps[c+1].prec) ) {
+ continue;
+ } else {
+ bIsValid = FALSE;
+ break;
+ }
+ }
+ bIsValid &= ((numcomps == 1) || (numcomps == 3) || (numcomps == 4));
+ if(!bIsValid) {
+ if(numcomps) {
+ FreeImage_OutputMessageProc(format_id, "Warning: image contains %d greyscale components. Only the first will be loaded.\n", numcomps);
+ numcomps = 1;
+ } else {
+ // unknown type
+ throw FI_MSG_ERROR_UNSUPPORTED_FORMAT;
+ }
+ }
+
+ // create a new DIB
+
+ if(image->comps[0].prec <= 8) {
+ switch(numcomps) {
+ case 1:
+ dib = FreeImage_Allocate(wrr, hrr, 8);
+ break;
+ case 3:
+ dib = FreeImage_Allocate(wrr, hrr, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
+ break;
+ case 4:
+ dib = FreeImage_Allocate(wrr, hrr, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
+ break;
+ }
+ } else if(image->comps[0].prec <= 16) {
+ switch(numcomps) {
+ case 1:
+ dib = FreeImage_AllocateT(FIT_UINT16, wrr, hrr);
+ break;
+ case 3:
+ dib = FreeImage_AllocateT(FIT_RGB16, wrr, hrr);
+ break;
+ case 4:
+ dib = FreeImage_AllocateT(FIT_RGBA16, wrr, hrr);
+ break;
+ }
+ } else {
+ throw FI_MSG_ERROR_UNSUPPORTED_FORMAT;
+ }
+ if(!dib) {
+ throw FI_MSG_ERROR_DIB_MEMORY;
+ }
+
+ if(image->comps[0].prec <= 8) {
+ if(numcomps == 1) {
+ // 8-bit greyscale
+ // ----------------------------------------------------------
+
+ // build a greyscale palette
+
+ RGBQUAD *pal = FreeImage_GetPalette(dib);
+ for (int i = 0; i < 256; i++) {
+ pal[i].rgbRed = (BYTE)i;
+ pal[i].rgbGreen = (BYTE)i;
+ pal[i].rgbBlue = (BYTE)i;
+ }
+
+ // load pixel data
+
+ unsigned pixel_count = 0;
+
+ for(int y = 0; y < hrr; y++) {
+ BYTE *bits = FreeImage_GetScanLine(dib, hrr - 1 - y);
+
+ for(int x = 0; x < wrr; x++) {
+ const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr;
+
+ int index = image->comps[0].data[pixel_pos];
+ index += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
+
+ bits[x] = (BYTE)index;
+
+ pixel_count++;
+ }
+ }
+ }
+ else if(numcomps == 3) {
+
+ // 24-bit RGB
+ // ----------------------------------------------------------
+
+ // load pixel data
+
+ unsigned pixel_count = 0;
+
+ for(int y = 0; y < hrr; y++) {
+ BYTE *bits = FreeImage_GetScanLine(dib, hrr - 1 - y);
+
+ for(int x = 0; x < wrr; x++) {
+ const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr;
+
+ int r = image->comps[0].data[pixel_pos];
+ r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
+
+ int g = image->comps[1].data[pixel_pos];
+ g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0);
+
+ int b = image->comps[2].data[pixel_pos];
+ b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0);
+
+ bits[FI_RGBA_RED] = (BYTE)r;
+ bits[FI_RGBA_GREEN] = (BYTE)g;
+ bits[FI_RGBA_BLUE] = (BYTE)b;
+ bits += 3;
+
+ pixel_count++;
+ }
+ }
+ }
+ else if(numcomps == 4) {
+
+ // 32-bit RGBA
+ // ----------------------------------------------------------
+
+ // load pixel data
+
+ unsigned pixel_count = 0;
+
+ for(int y = 0; y < hrr; y++) {
+ BYTE *bits = FreeImage_GetScanLine(dib, hrr - 1 - y);
+
+ for(int x = 0; x < wrr; x++) {
+ const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr;
+
+ int r = image->comps[0].data[pixel_pos];
+ r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
+
+ int g = image->comps[1].data[pixel_pos];
+ g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0);
+
+ int b = image->comps[2].data[pixel_pos];
+ b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0);
+
+ int a = image->comps[3].data[pixel_pos];
+ a += (image->comps[3].sgnd ? 1 << (image->comps[3].prec - 1) : 0);
+
+ bits[FI_RGBA_RED] = (BYTE)r;
+ bits[FI_RGBA_GREEN] = (BYTE)g;
+ bits[FI_RGBA_BLUE] = (BYTE)b;
+ bits[FI_RGBA_ALPHA] = (BYTE)a;
+ bits += 4;
+
+ pixel_count++;
+ }
+ }
+ }
+ }
+ else if(image->comps[0].prec <= 16) {
+ if(numcomps == 1) {
+ // 16-bit greyscale
+ // ----------------------------------------------------------
+
+ // load pixel data
+
+ unsigned pixel_count = 0;
+
+ for(int y = 0; y < hrr; y++) {
+ unsigned short *bits = (unsigned short*)FreeImage_GetScanLine(dib, hrr - 1 - y);
+
+ for(int x = 0; x < wrr; x++) {
+ const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr;
+
+ int index = image->comps[0].data[pixel_pos];
+ index += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
+
+ bits[x] = (unsigned short)index;
+
+ pixel_count++;
+ }
+ }
+ }
+ else if(numcomps == 3) {
+
+ // 48-bit RGB
+ // ----------------------------------------------------------
+
+ // load pixel data
+
+ unsigned pixel_count = 0;
+
+ for(int y = 0; y < hrr; y++) {
+ FIRGB16 *bits = (FIRGB16*)FreeImage_GetScanLine(dib, hrr - 1 - y);
+
+ for(int x = 0; x < wrr; x++) {
+ const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr;
+
+ int r = image->comps[0].data[pixel_pos];
+ r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
+
+ int g = image->comps[1].data[pixel_pos];
+ g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0);
+
+ int b = image->comps[2].data[pixel_pos];
+ b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0);
+
+ bits[x].red = (WORD)r;
+ bits[x].green = (WORD)g;
+ bits[x].blue = (WORD)b;
+
+ pixel_count++;
+ }
+ }
+ }
+ else if(numcomps == 4) {
+
+ // 64-bit RGBA
+ // ----------------------------------------------------------
+
+ // load pixel data
+
+ unsigned pixel_count = 0;
+
+ for(int y = 0; y < hrr; y++) {
+ FIRGBA16 *bits = (FIRGBA16*)FreeImage_GetScanLine(dib, hrr - 1 - y);
+
+ for(int x = 0; x < wrr; x++) {
+ const unsigned pixel_pos = pixel_count / wrr * wr + pixel_count % wrr;
+
+ int r = image->comps[0].data[pixel_pos];
+ r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
+
+ int g = image->comps[1].data[pixel_pos];
+ g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0);
+
+ int b = image->comps[2].data[pixel_pos];
+ b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0);
+
+ int a = image->comps[3].data[pixel_pos];
+ a += (image->comps[3].sgnd ? 1 << (image->comps[3].prec - 1) : 0);
+
+ bits[x].red = (WORD)r;
+ bits[x].green = (WORD)g;
+ bits[x].blue = (WORD)b;
+ bits[x].alpha = (WORD)a;
+
+ pixel_count++;
+ }
+ }
+ }
+ }
+
+ return dib;
+
+ } catch(const char *text) {
+ if(dib) FreeImage_Unload(dib);
+ FreeImage_OutputMessageProc(format_id, text);
+ return NULL;
+ }
+
+}
+
+/**
+Convert a FIBITMAP to a OpenJPEG image
+@param format_id Plugin ID
+@param dib FreeImage image
+@param parameters Compression parameters
+@return Returns the converted image if successful, returns NULL otherwise
+*/
+opj_image_t* FIBITMAPToJ2KImage(int format_id, FIBITMAP *dib, const opj_cparameters_t *parameters) {
+ int prec, numcomps, x, y, index;
+ OPJ_COLOR_SPACE color_space;
+ opj_image_cmptparm_t cmptparm[4]; // maximum of 4 components
+ opj_image_t *image = NULL; // image to encode
+
+ try {
+ int w = FreeImage_GetWidth(dib);
+ int h = FreeImage_GetHeight(dib);
+
+ // get image characteristics
+ FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
+
+ if(image_type == FIT_BITMAP) {
+ // standard image ...
+ prec = 8;
+ switch(FreeImage_GetColorType(dib)) {
+ case FIC_MINISBLACK:
+ numcomps = 1;
+ color_space = CLRSPC_GRAY;
+ break;
+ case FIC_RGB:
+ if(FreeImage_GetBPP(dib) == 32) {
+ // 32-bit image with a fully opaque layer
+ numcomps = 4;
+ color_space = CLRSPC_SRGB;
+ } else {
+ // 24-bit image
+ numcomps = 3;
+ color_space = CLRSPC_SRGB;
+ }
+ break;
+ case FIC_RGBALPHA:
+ numcomps = 4;
+ color_space = CLRSPC_SRGB;
+ break;
+ default:
+ return NULL;
+ }
+ } else {
+ // HDR image ...
+ prec = 16;
+ switch(image_type) {
+ case FIT_UINT16:
+ numcomps = 1;
+ color_space = CLRSPC_GRAY;
+ break;
+ case FIT_RGB16:
+ numcomps = 3;
+ color_space = CLRSPC_SRGB;
+ break;
+ case FIT_RGBA16:
+ numcomps = 4;
+ color_space = CLRSPC_SRGB;
+ break;
+ default:
+ return NULL;
+ }
+ }
+
+ // initialize image components
+ memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t));
+ for(int i = 0; i < numcomps; i++) {
+ cmptparm[i].dx = parameters->subsampling_dx;
+ cmptparm[i].dy = parameters->subsampling_dy;
+ cmptparm[i].w = w;
+ cmptparm[i].h = h;
+ cmptparm[i].prec = prec;
+ cmptparm[i].bpp = prec;
+ cmptparm[i].sgnd = 0;
+ }
+ // create the image
+ image = opj_image_create(numcomps, &cmptparm[0], color_space);
+ if(!image) {
+ throw FI_MSG_ERROR_DIB_MEMORY;
+ }
+
+ // set image offset and reference grid
+ image->x0 = parameters->image_offset_x0;
+ image->y0 = parameters->image_offset_y0;
+ image->x1 = parameters->image_offset_x0 + (w - 1) * parameters->subsampling_dx + 1;
+ image->y1 = parameters->image_offset_y0 + (h - 1) * parameters->subsampling_dy + 1;
+
+ // set image data
+ if(prec == 8) {
+ switch(numcomps) {
+ case 1:
+ index = 0;
+ for(y = 0; y < h; y++) {
+ BYTE *bits = FreeImage_GetScanLine(dib, h - 1 - y);
+ for(x = 0; x < w; x++) {
+ image->comps[0].data[index] = bits[x];
+ index++;
+ }
+ }
+ break;
+ case 3:
+ index = 0;
+ for(y = 0; y < h; y++) {
+ BYTE *bits = FreeImage_GetScanLine(dib, h - 1 - y);
+ for(x = 0; x < w; x++) {
+ image->comps[0].data[index] = bits[FI_RGBA_RED];
+ image->comps[1].data[index] = bits[FI_RGBA_GREEN];
+ image->comps[2].data[index] = bits[FI_RGBA_BLUE];
+ bits += 3;
+ index++;
+ }
+ }
+ break;
+ case 4:
+ index = 0;
+ for(y = 0; y < h; y++) {
+ BYTE *bits = FreeImage_GetScanLine(dib, h - 1 - y);
+ for(x = 0; x < w; x++) {
+ image->comps[0].data[index] = bits[FI_RGBA_RED];
+ image->comps[1].data[index] = bits[FI_RGBA_GREEN];
+ image->comps[2].data[index] = bits[FI_RGBA_BLUE];
+ image->comps[3].data[index] = bits[FI_RGBA_ALPHA];
+ bits += 4;
+ index++;
+ }
+ }
+ break;
+ }
+ }
+ else if(prec == 16) {
+ switch(numcomps) {
+ case 1:
+ index = 0;
+ for(y = 0; y < h; y++) {
+ WORD *bits = (WORD*)FreeImage_GetScanLine(dib, h - 1 - y);
+ for(x = 0; x < w; x++) {
+ image->comps[0].data[index] = bits[x];
+ index++;
+ }
+ }
+ break;
+ case 3:
+ index = 0;
+ for(y = 0; y < h; y++) {
+ FIRGB16 *bits = (FIRGB16*)FreeImage_GetScanLine(dib, h - 1 - y);
+ for(x = 0; x < w; x++) {
+ image->comps[0].data[index] = bits[x].red;
+ image->comps[1].data[index] = bits[x].green;
+ image->comps[2].data[index] = bits[x].blue;
+ index++;
+ }
+ }
+ break;
+ case 4:
+ index = 0;
+ for(y = 0; y < h; y++) {
+ FIRGBA16 *bits = (FIRGBA16*)FreeImage_GetScanLine(dib, h - 1 - y);
+ for(x = 0; x < w; x++) {
+ image->comps[0].data[index] = bits[x].red;
+ image->comps[1].data[index] = bits[x].green;
+ image->comps[2].data[index] = bits[x].blue;
+ image->comps[3].data[index] = bits[x].alpha;
+ index++;
+ }
+ }
+ break;
+ }
+ }
+
+ return image;
+
+ } catch (const char *text) {
+ if(image) opj_image_destroy(image);
+ FreeImage_OutputMessageProc(format_id, text);
+ return NULL;
+ }
+}
diff --git a/plugins/AdvaImg/src/FreeImage/MultiPage.cpp b/plugins/AdvaImg/src/FreeImage/MultiPage.cpp index e5bcee3ded..60ce85eb10 100644 --- a/plugins/AdvaImg/src/FreeImage/MultiPage.cpp +++ b/plugins/AdvaImg/src/FreeImage/MultiPage.cpp @@ -269,8 +269,8 @@ FreeImage_OpenMultiBitmap(FREE_IMAGE_FORMAT fif, const char *filename, BOOL crea header->node = node;
header->fif = fif;
header->io = io.get ();
- header->handle = handle;
- header->changed = FALSE;
+ header->handle = handle;
+ header->changed = FALSE;
header->read_only = read_only;
header->m_cachefile = NULL;
header->cache_fif = fif;
@@ -344,13 +344,13 @@ FreeImage_OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_h 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);
-
+
if (node) {
std::auto_ptr<FIMULTIBITMAP> bitmap (new FIMULTIBITMAP);
std::auto_ptr<MULTIBITMAPHEADER> header (new MULTIBITMAPHEADER);
@@ -359,13 +359,13 @@ FreeImage_OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_h header->m_filename = NULL;
header->node = node;
header->fif = fif;
- header->handle = handle;
- header->changed = FALSE;
+ 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();
@@ -400,7 +400,7 @@ FreeImage_OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_h BOOL DLL_CALLCONV
FreeImage_SaveMultiBitmapToHandle(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP *bitmap, FreeImageIO *io, fi_handle handle, int flags) {
- if (!bitmap || !bitmap->data || !io || !handle) {
+ if(!bitmap || !bitmap->data || !io || !handle) {
return FALSE;
}
@@ -546,7 +546,7 @@ FreeImage_CloseMultiBitmap(FIMULTIBITMAP *bitmap, int flags) { if (success) {
remove(header->m_filename);
success = (rename(spool_name.c_str(), header->m_filename) == 0) ? TRUE:FALSE;
- if (!success) {
+ if(!success) {
FreeImage_OutputMessageProc(header->fif, "Failed to rename %s to %s", spool_name.c_str(), header->m_filename);
}
} else {
@@ -647,12 +647,12 @@ FreeImage_SavePageToBlock(MULTIBITMAPHEADER *header, FIBITMAP *data) { FIMEMORY *hmem = FreeImage_OpenMemory();
if(hmem==NULL) return NULL;
// save the file to memory
- if (!FreeImage_SaveToMemory(header->cache_fif, data, hmem, 0)) {
+ if(!FreeImage_SaveToMemory(header->cache_fif, data, hmem, 0)) {
FreeImage_CloseMemory(hmem);
return NULL;
}
// get the buffer from the memory stream
- if (!FreeImage_AcquireMemory(hmem, &compressed_data, &compressed_size)) {
+ if(!FreeImage_AcquireMemory(hmem, &compressed_data, &compressed_size)) {
FreeImage_CloseMemory(hmem);
return NULL;
}
diff --git a/plugins/AdvaImg/src/FreeImage/NNQuantizer.cpp b/plugins/AdvaImg/src/FreeImage/NNQuantizer.cpp index 6eb9aeaf48..f907c41d55 100644 --- a/plugins/AdvaImg/src/FreeImage/NNQuantizer.cpp +++ b/plugins/AdvaImg/src/FreeImage/NNQuantizer.cpp @@ -60,7 +60,7 @@ NNQuantizer::NNQuantizer(int PaletteSize) freq = (int *)malloc(netsize * sizeof(int)); radpower = (int *)malloc(initrad * sizeof(int)); - if ( !network || !bias || !freq || !radpower ) { + if( !network || !bias || !freq || !radpower ) { if(network) free(network); if(bias) free(bias); if(freq) free(freq); @@ -455,7 +455,7 @@ FIBITMAP* NNQuantizer::Quantize(FIBITMAP *dib, int ReserveSize, RGBQUAD *Reserve // 3) Initialize the network and apply the learning algorithm - if ( netsize > ReserveSize ) { + if( netsize > ReserveSize ) { netsize -= ReserveSize; initnet(); learn(sampling); diff --git a/plugins/AdvaImg/src/FreeImage/PSDParser.cpp b/plugins/AdvaImg/src/FreeImage/PSDParser.cpp index 93573d01c0..57c703a06f 100644 --- a/plugins/AdvaImg/src/FreeImage/PSDParser.cpp +++ b/plugins/AdvaImg/src/FreeImage/PSDParser.cpp @@ -72,7 +72,7 @@ bool psdHeaderInfo::Read(FreeImageIO *io, fi_handle handle) { psdHeader header; const int n = (int)io->read_proc(&header, sizeof(header), 1, handle); - if (!n) { + if(!n) { return false; } @@ -282,7 +282,7 @@ int psdDisplayInfo::Read(FreeImageIO *io, fi_handle handle) { n = (int)io->read_proc(&ShortValue, sizeof(ShortValue), 1, handle); nBytes += n * sizeof(ShortValue); _Opacity = (short)psdGetValue(ShortValue, sizeof(_Opacity) ); - if ((_Opacity < 0) || (_Opacity > 100)) { + if((_Opacity < 0) || (_Opacity > 100)) { throw "Invalid DisplayInfo::Opacity value"; } @@ -418,7 +418,7 @@ BOOL invertColor(FIBITMAP* dib) { FREE_IMAGE_TYPE type = FreeImage_GetImageType(dib); const unsigned Bpp = FreeImage_GetBPP(dib)/8; - if ((type == FIT_BITMAP && Bpp == 4) || type == FIT_RGBA16) { + if((type == FIT_BITMAP && Bpp == 4) || type == FIT_RGBA16) { const unsigned width = FreeImage_GetWidth(dib); const unsigned height = FreeImage_GetHeight(dib); BYTE *line_start = FreeImage_GetScanLine(dib, 0); @@ -508,7 +508,7 @@ bool psdParser::ReadImageResources(FreeImageIO *io, fi_handle handle, LONG lengt n = (int)io->read_proc(&oResource._OSType, sizeof(oResource._OSType), 1, handle); nBytes += n * sizeof(oResource._OSType); - if ( (nBytes % 2) != 0 ) { + if( (nBytes % 2) != 0 ) { return false; } @@ -653,7 +653,7 @@ FIBITMAP* psdParser::ReadImageData(FreeImageIO *io, fi_handle handle) { SwapShort(&nCompression); #endif - if ((nCompression != PSDP_COMPRESSION_NONE && nCompression != PSDP_COMPRESSION_RLE)) { + if((nCompression != PSDP_COMPRESSION_NONE && nCompression != PSDP_COMPRESSION_RLE)) { FreeImage_OutputMessageProc(_fi_format_id, "Unsupported compression %d", nCompression); return NULL; } @@ -730,7 +730,7 @@ FIBITMAP* psdParser::ReadImageData(FreeImageIO *io, fi_handle handle) { throw "Unsupported color mode"; break; } - if (!bitmap) { + if(!bitmap) { throw FI_MSG_ERROR_DIB_MEMORY; } @@ -797,7 +797,7 @@ FIBITMAP* psdParser::ReadImageData(FreeImageIO *io, fi_handle handle) { // later use this array as WORD rleLineSizeList[nChannels][nHeight]; WORD *rleLineSizeList = new (std::nothrow) WORD[nChannels*nHeight]; - if (!rleLineSizeList) { + if(!rleLineSizeList) { FreeImage_Unload(bitmap); SAFE_DELETE_ARRAY(line_start); throw std::bad_alloc(); @@ -820,7 +820,7 @@ FIBITMAP* psdParser::ReadImageData(FreeImageIO *io, fi_handle handle) { } BYTE* rle_line_start = new (std::nothrow) BYTE[largestRLELine]; - if (!rle_line_start) { + if(!rle_line_start) { FreeImage_Unload(bitmap); SAFE_DELETE_ARRAY(line_start); SAFE_DELETE_ARRAY(rleLineSizeList); @@ -924,7 +924,7 @@ FIBITMAP* psdParser::ReadImageData(FreeImageIO *io, fi_handle handle) { // --- Further process the bitmap --- - if ((mode == PSDP_CMYK || mode == PSDP_MULTICHANNEL)) { + if((mode == PSDP_CMYK || mode == PSDP_MULTICHANNEL)) { // CMYK values are "inverted", invert them back if(mode == PSDP_MULTICHANNEL) { @@ -933,7 +933,7 @@ FIBITMAP* psdParser::ReadImageData(FreeImageIO *io, fi_handle handle) { FreeImage_Invert(bitmap); } - if ((_fi_flags & PSD_CMYK) == PSD_CMYK) { + if((_fi_flags & PSD_CMYK) == PSD_CMYK) { // keep as CMYK if(mode == PSDP_MULTICHANNEL) { @@ -971,7 +971,7 @@ FIBITMAP* psdParser::ReadImageData(FreeImageIO *io, fi_handle handle) { CREATE_GREYSCALE_PALETTE_REVERSE(FreeImage_GetPalette(bitmap), 2); } else if(mode == PSDP_INDEXED) { - if (!_colourModeData._plColourData || _colourModeData._Length != 768 || _ColourCount < 0) { + if(!_colourModeData._plColourData || _colourModeData._Length != 768 || _ColourCount < 0) { FreeImage_OutputMessageProc(_fi_format_id, "Indexed image has no palette. Using the default grayscale one."); } else { _colourModeData.FillPalette(bitmap); @@ -1037,7 +1037,7 @@ FIBITMAP* psdParser::Load(FreeImageIO *io, fi_handle handle, int s_format_id, in FreeImage_CreateICCProfile(Bitmap, _iccProfile._ProfileData, _iccProfile._ProfileSize); if ((flags & PSD_CMYK) == PSD_CMYK) { short mode = _headerInfo._ColourMode; - if ((mode == PSDP_CMYK) || (mode == PSDP_MULTICHANNEL)) { + if((mode == PSDP_CMYK) || (mode == PSDP_MULTICHANNEL)) { FreeImage_GetICCProfile(Bitmap)->flags |= FIICC_COLOR_IS_CMYK; } } diff --git a/plugins/AdvaImg/src/FreeImage/PixelAccess.cpp b/plugins/AdvaImg/src/FreeImage/PixelAccess.cpp index 158f9997b2..e3dccfe1c9 100644 --- a/plugins/AdvaImg/src/FreeImage/PixelAccess.cpp +++ b/plugins/AdvaImg/src/FreeImage/PixelAccess.cpp @@ -29,19 +29,20 @@ BYTE * DLL_CALLCONV
FreeImage_GetBits(FIBITMAP *dib) {
- if (!FreeImage_HasPixels(dib)) {
+ if(!FreeImage_HasPixels(dib)) {
return NULL;
}
// returns the pixels aligned on a FIBITMAP_ALIGNMENT bytes alignment boundary
size_t lp = (size_t)FreeImage_GetInfoHeader(dib);
lp += sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * FreeImage_GetColorsUsed(dib);
+ lp += FreeImage_HasRGBMasks(dib) ? sizeof(DWORD) * 3 : 0;
lp += (lp % FIBITMAP_ALIGNMENT ? FIBITMAP_ALIGNMENT - lp % FIBITMAP_ALIGNMENT : 0);
return (BYTE *)lp;
}
BYTE * DLL_CALLCONV
FreeImage_GetScanLine(FIBITMAP *dib, int scanline) {
- if (!FreeImage_HasPixels(dib)) {
+ if(!FreeImage_HasPixels(dib)) {
return NULL;
}
return CalculateScanLine(FreeImage_GetBits(dib), FreeImage_GetPitch(dib), scanline);
@@ -51,10 +52,10 @@ BOOL DLL_CALLCONV FreeImage_GetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value) {
BYTE shift;
- if (!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP))
+ if(!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP))
return FALSE;
- if ((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) {
+ if((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) {
BYTE *bits = FreeImage_GetScanLine(dib, y);
switch(FreeImage_GetBPP(dib)) {
@@ -80,10 +81,10 @@ FreeImage_GetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value) { BOOL DLL_CALLCONV
FreeImage_GetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value) {
- if (!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP))
+ if(!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP))
return FALSE;
- if ((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) {
+ if((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) {
BYTE *bits = FreeImage_GetScanLine(dib, y);
switch(FreeImage_GetBPP(dib)) {
@@ -91,7 +92,7 @@ FreeImage_GetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value) { {
bits += 2*x;
WORD *pixel = (WORD *)bits;
- if ((FreeImage_GetRedMask(dib) == FI16_565_RED_MASK) && (FreeImage_GetGreenMask(dib) == FI16_565_GREEN_MASK) && (FreeImage_GetBlueMask(dib) == FI16_565_BLUE_MASK)) {
+ if((FreeImage_GetRedMask(dib) == FI16_565_RED_MASK) && (FreeImage_GetGreenMask(dib) == FI16_565_GREEN_MASK) && (FreeImage_GetBlueMask(dib) == FI16_565_BLUE_MASK)) {
value->rgbBlue = (BYTE)((((*pixel & FI16_565_BLUE_MASK) >> FI16_565_BLUE_SHIFT) * 0xFF) / 0x1F);
value->rgbGreen = (BYTE)((((*pixel & FI16_565_GREEN_MASK) >> FI16_565_GREEN_SHIFT) * 0xFF) / 0x3F);
value->rgbRed = (BYTE)((((*pixel & FI16_565_RED_MASK) >> FI16_565_RED_SHIFT) * 0xFF) / 0x1F);
@@ -132,10 +133,10 @@ BOOL DLL_CALLCONV FreeImage_SetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value) {
BYTE shift;
- if (!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP))
+ if(!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP))
return FALSE;
- if ((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) {
+ if((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) {
BYTE *bits = FreeImage_GetScanLine(dib, y);
switch(FreeImage_GetBPP(dib)) {
@@ -162,10 +163,10 @@ FreeImage_SetPixelIndex(FIBITMAP *dib, unsigned x, unsigned y, BYTE *value) { BOOL DLL_CALLCONV
FreeImage_SetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value) {
- if (!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP))
+ if(!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP))
return FALSE;
- if ((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) {
+ if((x < FreeImage_GetWidth(dib)) && (y < FreeImage_GetHeight(dib))) {
BYTE *bits = FreeImage_GetScanLine(dib, y);
switch(FreeImage_GetBPP(dib)) {
@@ -173,7 +174,7 @@ FreeImage_SetPixelColor(FIBITMAP *dib, unsigned x, unsigned y, RGBQUAD *value) { {
bits += 2*x;
WORD *pixel = (WORD *)bits;
- if ((FreeImage_GetRedMask(dib) == FI16_565_RED_MASK) && (FreeImage_GetGreenMask(dib) == FI16_565_GREEN_MASK) && (FreeImage_GetBlueMask(dib) == FI16_565_BLUE_MASK)) {
+ if((FreeImage_GetRedMask(dib) == FI16_565_RED_MASK) && (FreeImage_GetGreenMask(dib) == FI16_565_GREEN_MASK) && (FreeImage_GetBlueMask(dib) == FI16_565_BLUE_MASK)) {
*pixel = ((value->rgbBlue >> 3) << FI16_565_BLUE_SHIFT) |
((value->rgbGreen >> 2) << FI16_565_GREEN_SHIFT) |
((value->rgbRed >> 3) << FI16_565_RED_SHIFT);
diff --git a/plugins/AdvaImg/src/FreeImage/Plugin.cpp b/plugins/AdvaImg/src/FreeImage/Plugin.cpp index ce2863a72e..7ded36ebc2 100644 --- a/plugins/AdvaImg/src/FreeImage/Plugin.cpp +++ b/plugins/AdvaImg/src/FreeImage/Plugin.cpp @@ -2,7 +2,7 @@ // FreeImage Plugin Interface // // Design and implementation by -// - Floris van den Berg (flvdberg@wxs.nl) +// - Floris van den Berg (floris@geekhq.nl) // - Rui Lopes (ruiglopes@yahoo.com) // - Detlev Vendt (detlev.vendt@brillit.de) // - Petr Pytelka (pyta@lightcomp.com) @@ -38,6 +38,8 @@ #include "FreeImageIO.h" #include "Plugin.h" +#include "../Metadata/FreeImageTag.h" + // ===================================================================== using namespace std; @@ -85,12 +87,18 @@ m_node_count(0) { FREE_IMAGE_FORMAT PluginList::AddNode(FI_InitProc init_proc, void *instance, const char *format, const char *description, const char *extension, const char *regexpr) { if (init_proc != NULL) { - PluginNode *node = new PluginNode; - Plugin *plugin = new Plugin; + PluginNode *node = new(std::nothrow) PluginNode; + Plugin *plugin = new(std::nothrow) Plugin; + if(!node || !plugin) { + if(node) delete node; + if(plugin) delete plugin; + FreeImage_OutputMessageProc(FIF_UNKNOWN, FI_MSG_ERROR_MEMORY); + return FIF_UNKNOWN; + } memset(plugin, 0, sizeof(Plugin)); - // fill-in the plugin structure + // fill-in the plugin structure // note we have memset to 0, so all unset pointers should be NULL) init_proc(plugin, (int)m_plugin_map.size()); @@ -99,28 +107,27 @@ PluginList::AddNode(FI_InitProc init_proc, void *instance, const char *format, c const char *the_format = NULL; - if (format != NULL) + if (format != NULL) { the_format = format; - else if (plugin->format_proc != NULL) + } else if (plugin->format_proc != NULL) { the_format = plugin->format_proc(); + } // add the node if it wasn't there already if (the_format != NULL) { - if (FindNodeFromFormat(the_format) == NULL) { - node->m_id = (int)m_plugin_map.size(); - node->m_instance = instance; - node->m_plugin = plugin; - node->m_format = format; - node->m_description = description; - node->m_extension = extension; - node->m_regexpr = regexpr; - node->m_enabled = TRUE; - - m_plugin_map[(const int)m_plugin_map.size()] = node; - - return (FREE_IMAGE_FORMAT)node->m_id; - } + node->m_id = (int)m_plugin_map.size(); + node->m_instance = instance; + node->m_plugin = plugin; + node->m_format = format; + node->m_description = description; + node->m_extension = extension; + node->m_regexpr = regexpr; + node->m_enabled = TRUE; + + m_plugin_map[(const int)m_plugin_map.size()] = node; + + return (FREE_IMAGE_FORMAT)node->m_id; } // something went wrong while allocating the plugin... cleanup @@ -134,15 +141,14 @@ PluginList::AddNode(FI_InitProc init_proc, void *instance, const char *format, c PluginNode * PluginList::FindNodeFromFormat(const char *format) { - int count = 0; - for (map<int, PluginNode *>::iterator i = m_plugin_map.begin(); i != m_plugin_map.end(); ++i) { const char *the_format = ((*i).second->m_format != NULL) ? (*i).second->m_format : (*i).second->m_plugin->format_proc(); - if (FreeImage_stricmp(the_format, format) == 0) - return (*i).second; - - count++; + if ((*i).second->m_enabled) { + if (FreeImage_stricmp(the_format, format) == 0) { + return (*i).second; + } + } } return NULL; @@ -150,15 +156,14 @@ PluginList::FindNodeFromFormat(const char *format) { PluginNode * PluginList::FindNodeFromMime(const char *mime) { - int count = 0; - for (map<int, PluginNode *>::iterator i = m_plugin_map.begin(); i != m_plugin_map.end(); ++i) { const char *the_mime = ((*i).second->m_plugin->mime_proc != NULL) ? (*i).second->m_plugin->mime_proc() : ""; - if ((the_mime != NULL) && (strcmp(the_mime, mime) == 0)) - return (*i).second; - - count++; + if ((*i).second->m_enabled) { + if ((the_mime != NULL) && (strcmp(the_mime, mime) == 0)) { + return (*i).second; + } + } } return NULL; @@ -168,8 +173,9 @@ PluginNode * PluginList::FindNodeFromFIF(int node_id) { map<int, PluginNode *>::iterator i = m_plugin_map.find(node_id); - if (i != m_plugin_map.end()) + if (i != m_plugin_map.end()) { return (*i).second; + } return NULL; } @@ -187,8 +193,9 @@ PluginList::IsEmpty() const { PluginList::~PluginList() { for (map<int, PluginNode *>::iterator i = m_plugin_map.begin(); i != m_plugin_map.end(); ++i) { #ifdef _WIN32 - if ((*i).second->m_instance != NULL) + if ((*i).second->m_instance != NULL) { FreeLibrary((HINSTANCE)(*i).second->m_instance); + } #endif delete (*i).second->m_plugin; delete ((*i).second); @@ -211,6 +218,9 @@ FreeImage_GetPluginList() { void DLL_CALLCONV FreeImage_Initialise(BOOL load_local_plugins_only) { if (s_plugin_reference_count++ == 0) { + + // initialise the TagLib singleton + TagLib& s = TagLib::instance(); // internal plugin initialization @@ -246,7 +256,7 @@ FreeImage_Initialise(BOOL load_local_plugins_only) { //s_plugins->AddNode(InitXBM); //s_plugins->AddNode(InitXPM); //s_plugins->AddNode(InitDDS); - s_plugins->AddNode(InitGIF); + s_plugins->AddNode(InitGIF); //s_plugins->AddNode(InitHDR); //s_plugins->AddNode(InitG3); //s_plugins->AddNode(InitSGI); @@ -299,18 +309,14 @@ FreeImage_LoadFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handl PluginNode *node = s_plugins->FindNodeFromFIF(fif); if (node != NULL) { - if (node->m_enabled) { - if(node->m_plugin->load_proc != NULL) { - FIBITMAP *bitmap = NULL; + if(node->m_plugin->load_proc != NULL) { + void *data = FreeImage_Open(node, io, handle, TRUE); - void *data = FreeImage_Open(node, io, handle, TRUE); + FIBITMAP *bitmap = node->m_plugin->load_proc(io, handle, -1, flags, data); - bitmap = node->m_plugin->load_proc(io, handle, -1, flags, data); + FreeImage_Close(node, io, handle, data); - FreeImage_Close(node, io, handle, data); - - return bitmap; - } + return bitmap; } } } @@ -370,18 +376,14 @@ FreeImage_SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP *dib, FreeImageIO *io, fi PluginNode *node = s_plugins->FindNodeFromFIF(fif); if (node) { - if (node->m_enabled) { - if(node->m_plugin->save_proc != NULL) { - BOOL result = FALSE; - - void *data = FreeImage_Open(node, io, handle, FALSE); + if(node->m_plugin->save_proc != NULL) { + void *data = FreeImage_Open(node, io, handle, FALSE); - result = node->m_plugin->save_proc(io, dib, handle, -1, flags, data); + BOOL result = node->m_plugin->save_proc(io, dib, handle, -1, flags, data); - FreeImage_Close(node, io, handle, data); + FreeImage_Close(node, io, handle, data); - return result; - } + return result; } } } @@ -503,7 +505,7 @@ FreeImage_GetFIFFromFormat(const char *format) { if (s_plugins != NULL) { PluginNode *node = s_plugins->FindNodeFromFormat(format); - return (node != NULL) ? (node->m_enabled) ? (FREE_IMAGE_FORMAT)node->m_id : FIF_UNKNOWN : FIF_UNKNOWN; + return (node != NULL) ? (FREE_IMAGE_FORMAT)node->m_id : FIF_UNKNOWN; } return FIF_UNKNOWN; @@ -514,7 +516,7 @@ FreeImage_GetFIFFromMime(const char *mime) { if (s_plugins != NULL) { PluginNode *node = s_plugins->FindNodeFromMime(mime); - return (node != NULL) ? (node->m_enabled) ? (FREE_IMAGE_FORMAT)node->m_id : FIF_UNKNOWN : FIF_UNKNOWN; + return (node != NULL) ? (FREE_IMAGE_FORMAT)node->m_id : FIF_UNKNOWN; } return FIF_UNKNOWN; @@ -712,7 +714,7 @@ FreeImage_GetFIFFromFilenameU(const wchar_t *filename) { // convert to single character - no national chars in extensions char *extension = (char *)malloc(wcslen(place)+1); unsigned int i=0; - for (; i < wcslen(place); i++) // convert 16-bit to 8-bit + for(; i < wcslen(place); i++) // convert 16-bit to 8-bit extension[i] = (char)(place[i] & 0x00FF); // set terminating 0 extension[i]=0; diff --git a/plugins/AdvaImg/src/FreeImage/PluginBMP.cpp b/plugins/AdvaImg/src/FreeImage/PluginBMP.cpp index d69336f3f5..4041d859fa 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginBMP.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginBMP.cpp @@ -213,7 +213,7 @@ LoadPixelDataRLE4(FreeImageIO *io, fi_handle handle, int width, int height, FIBI height = abs(height); pixels = (BYTE*)malloc(width * height * sizeof(BYTE)); - if (!pixels) throw(1); + if(!pixels) throw(1); memset(pixels, 0, width * height * sizeof(BYTE)); BYTE *q = pixels; @@ -313,7 +313,7 @@ LoadPixelDataRLE4(FreeImageIO *io, fi_handle handle, int width, int height, FIBI BOOL hinibble = TRUE; - for (int cols = 0; cols < width; cols++) { + for (int cols = 0; cols < width; cols++){ if (hinibble) { dst[cols >> 1] = (src[cols] << 4); } else { @@ -352,7 +352,7 @@ LoadPixelDataRLE8(FreeImageIO *io, fi_handle handle, int width, int height, FIBI int bits = 0; for (;;) { - if ( io->read_proc(&status_byte, sizeof(BYTE), 1, handle) != 1) { + if( io->read_proc(&status_byte, sizeof(BYTE), 1, handle) != 1) { return FALSE; } @@ -520,7 +520,7 @@ LoadWindowsBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bit switch (compression) { case BI_RGB : - if ( LoadPixelData(io, handle, dib, height, pitch, bit_count)) { + if( LoadPixelData(io, handle, dib, height, pitch, bit_count) ) { return dib; } else { throw "Error encountered while decoding BMP data"; @@ -528,7 +528,7 @@ LoadWindowsBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bit break; case BI_RLE4 : - if ( LoadPixelDataRLE4(io, handle, width, height, dib)) { + if( LoadPixelDataRLE4(io, handle, width, height, dib) ) { return dib; } else { throw "Error encountered while decoding RLE4 BMP data"; @@ -536,7 +536,7 @@ LoadWindowsBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bit break; case BI_RLE8 : - if ( LoadPixelDataRLE8(io, handle, width, height, dib)) { + if( LoadPixelDataRLE8(io, handle, width, height, dib) ) { return dib; } else { throw "Error encountered while decoding RLE8 BMP data"; @@ -597,7 +597,7 @@ LoadWindowsBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bit dib = FreeImage_AllocateHeader(header_only, width, height, bit_count, bitfields[0], bitfields[1], bitfields[2]); } else { - if ( bit_count == 32 ) { + if( bit_count == 32 ) { dib = FreeImage_AllocateHeader(header_only, width, height, bit_count, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); } else { dib = FreeImage_AllocateHeader(header_only, width, height, bit_count, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); @@ -747,7 +747,7 @@ LoadOS22XBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bits_ return dib; case BI_RLE4 : - if ( LoadPixelDataRLE4(io, handle, width, height, dib)) { + if( LoadPixelDataRLE4(io, handle, width, height, dib) ) { return dib; } else { throw "Error encountered while decoding RLE4 BMP data"; @@ -755,7 +755,7 @@ LoadOS22XBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bits_ break; case BI_RLE8 : - if ( LoadPixelDataRLE8(io, handle, width, height, dib)) { + if( LoadPixelDataRLE8(io, handle, width, height, dib) ) { return dib; } else { throw "Error encountered while decoding RLE8 BMP data"; @@ -805,7 +805,7 @@ LoadOS22XBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bits_ case 24 : case 32 : { - if ( bit_count == 32 ) { + if( bit_count == 32 ) { dib = FreeImage_AllocateHeader(header_only, width, height, bit_count, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); } else { dib = FreeImage_AllocateHeader(header_only, width, height, bit_count, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); @@ -951,7 +951,7 @@ LoadOS21XBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bits_ case 24 : case 32 : { - if ( bit_count == 32 ) { + if( bit_count == 32 ) { dib = FreeImage_AllocateHeader(header_only, width, height, bit_count, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); } else { dib = FreeImage_AllocateHeader(header_only, width, height, bit_count, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); @@ -1082,7 +1082,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // check the signature - if ((bitmapfileheader.bfType != 0x4D42) && (bitmapfileheader.bfType != 0x4142)) { + if((bitmapfileheader.bfType != 0x4D42) && (bitmapfileheader.bfType != 0x4142)) { FreeImage_OutputMessageProc(s_format_id, FI_MSG_ERROR_MAGIC_NUMBER); return NULL; } diff --git a/plugins/AdvaImg/src/FreeImage/PluginCUT.cpp b/plugins/AdvaImg/src/FreeImage/PluginCUT.cpp index 746fa034a6..5dcd16b84f 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginCUT.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginCUT.cpp @@ -105,7 +105,7 @@ static FIBITMAP * DLL_CALLCONV Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { FIBITMAP *dib = NULL; - if (!handle) { + if(!handle) { return NULL; } diff --git a/plugins/AdvaImg/src/FreeImage/PluginDDS.cpp b/plugins/AdvaImg/src/FreeImage/PluginDDS.cpp index 0a1667d7f1..639942388f 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginDDS.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginDDS.cpp @@ -378,6 +378,10 @@ template <class DECODER> void DecodeDXTBlock (BYTE *dstData, const BYTE *srcBloc decoder.SetY (y); for (int x = 0; x < bw; x++) { decoder.GetColor (x, y, (Color8888 &)*dst); + +#if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB + INPLACESWAP(dst[FI_RGBA_RED], dst[FI_RGBA_BLUE]); +#endif dst += 4; } } @@ -444,7 +448,7 @@ LoadDXT_Helper (FreeImageIO *io, fi_handle handle, int page, int flags, void *da typedef typename INFO::Block Block; Block *input_buffer = new(std::nothrow) Block[(width + 3) / 4]; - if (!input_buffer) return; + if(!input_buffer) return; int widthRest = (int) width & 3; int heightRest = (int) height & 3; diff --git a/plugins/AdvaImg/src/FreeImage/PluginEXR.cpp b/plugins/AdvaImg/src/FreeImage/PluginEXR.cpp index b9963a11b2..4a19b8b56f 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginEXR.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginEXR.cpp @@ -96,7 +96,7 @@ C_IStream::seekg (Imf::Int64 pos) { void C_OStream::write (const char c[/*n*/], int n) { - if ((unsigned)n != _io->write_proc((void*)&c[0], 1, n, _handle)) { + if((unsigned)n != _io->write_proc((void*)&c[0], 1, n, _handle)) { Iex::throwErrnoExc(); } } @@ -178,7 +178,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { bool bUseRgbaInterface = false; FIBITMAP *dib = NULL; - if (!handle) { + if(!handle) { return NULL; } @@ -242,7 +242,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { bHandled = true; } } - if (!bHandled) { + if(!bHandled) { THROW (Iex::InputExc, "Unable to handle mixed component types (color model = " << exr_color_model << ")"); } } @@ -260,9 +260,9 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // check for supported image color models // -------------------------------------------------------------- - if ((components == 1) || (components == 2)) { + if((components == 1) || (components == 2)) { // if the image is gray-alpha (YA), ignore the alpha channel - if ((components == 1) && channels.findChannel("Y")) { + if((components == 1) && channels.findChannel("Y")) { image_type = FIT_FLOAT; components = 1; } else { @@ -307,7 +307,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // allocate a new dib dib = FreeImage_AllocateHeaderT(header_only, image_type, width, height, 0); - if (!dib) THROW (Iex::NullExc, FI_MSG_ERROR_MEMORY); + if(!dib) THROW (Iex::NullExc, FI_MSG_ERROR_MEMORY); // try to load the preview image // -------------------------------------------------------------- @@ -410,7 +410,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { pitch, // yStride 1, 1, // x/y sampling 0.0)); // fillValue - } else if ((components == 3) || (components == 4)) { + } else if((components == 3) || (components == 4)) { const char *channel_name[4] = { "R", "G", "B", "A" }; for(int c = 0; c < components; c++) { @@ -450,12 +450,12 @@ Set the preview image using the dib embedded thumbnail */ static BOOL SetPreviewImage(FIBITMAP *dib, Imf::Header& header) { - if (!FreeImage_GetThumbnail(dib)) { + if(!FreeImage_GetThumbnail(dib)) { return FALSE; } FIBITMAP* thumbnail = FreeImage_GetThumbnail(dib); - if ((FreeImage_GetImageType(thumbnail) != FIT_BITMAP) || (FreeImage_GetBPP(thumbnail) != 32)) { + if((FreeImage_GetImageType(thumbnail) != FIT_BITMAP) || (FreeImage_GetBPP(thumbnail) != 32)) { // invalid thumbnail - ignore it FreeImage_OutputMessageProc(s_format_id, FI_MSG_WARNING_INVALID_THUMBNAIL); } else { @@ -560,16 +560,16 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void BOOL bIsFlipped = FALSE; half *halfData = NULL; - if (!dib || !handle) return FALSE; + if(!dib || !handle) return FALSE; try { // check for EXR_LC compression and verify that the format is RGB - if ((flags & EXR_LC) == EXR_LC) { + 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)) { + 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)) { + 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"); } } @@ -579,19 +579,19 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void // compression Imf::Compression compress; - if ((flags & EXR_NONE) == EXR_NONE) { + if((flags & EXR_NONE) == EXR_NONE) { // no compression compress = Imf::NO_COMPRESSION; - } else if ((flags & EXR_ZIP) == EXR_ZIP) { + } 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) { + } else if((flags & EXR_PIZ) == EXR_PIZ) { // piz-based wavelet compression compress = Imf::PIZ_COMPRESSION; - } else if ((flags & EXR_PXR24) == EXR_PXR24) { + } else if((flags & EXR_PXR24) == EXR_PXR24) { // lossy 24-bit float compression compress = Imf::PXR24_COMPRESSION; - } else if ((flags & EXR_B44) == EXR_B44) { + } else if((flags & EXR_B44) == EXR_B44) { // lossy 44% float compression compress = Imf::B44_COMPRESSION; } else { @@ -615,13 +615,13 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void SetPreviewImage(dib, header); // check for EXR_LC compression - if ((flags & EXR_LC) == EXR_LC) { + 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) { + if((flags & EXR_FLOAT) == EXR_FLOAT) { pixelType = Imf::FLOAT; // save as float data type } else { // default value @@ -667,7 +667,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void if(pixelType == Imf::HALF) { // convert from float to half halfData = new(std::nothrow) half[width * height * components]; - if (!halfData) THROW (Iex::NullExc, FI_MSG_ERROR_MEMORY); + if(!halfData) THROW (Iex::NullExc, FI_MSG_ERROR_MEMORY); for(int y = 0; y < height; y++) { float *src_bits = (float*)FreeImage_GetScanLine(dib, height - 1 - y); @@ -700,7 +700,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void (char*)(bits), // base bytespp, // xStride pitch)); // yStride - } else if ((image_type == FIT_RGBF) || (image_type == FIT_RGBAF)) { + } else if((image_type == FIT_RGBF) || (image_type == FIT_RGBAF)) { for(int c = 0; c < components; c++) { char *channel_base = (char*)(bits) + c*bytespc; frameBuffer.insert (channel_name[c],// name diff --git a/plugins/AdvaImg/src/FreeImage/PluginG3.cpp b/plugins/AdvaImg/src/FreeImage/PluginG3.cpp index c383a455b7..d5c08b36e6 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginG3.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginG3.cpp @@ -124,7 +124,7 @@ copyFaxFile(FreeImageIO *io, fi_handle handle, TIFF* tifin, uint32 xsize, int st throw FI_MSG_ERROR_MEMORY; } - if (!G3ReadFile(io, handle, tifin->tif_rawdata, tifin->tif_rawdatasize)) { + if(!G3ReadFile(io, handle, tifin->tif_rawdata, tifin->tif_rawdatasize)) { throw "Read error at scanline 0"; } tifin->tif_rawcp = tifin->tif_rawdata; @@ -319,7 +319,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // open a temporary memory buffer to save decoded scanlines memory = FreeImage_OpenMemory(); - if (!memory) throw FI_MSG_ERROR_MEMORY; + if(!memory) throw FI_MSG_ERROR_MEMORY; // wrap the raw fax file faxTIFF = TIFFClientOpen("(FakeInput)", "w", diff --git a/plugins/AdvaImg/src/FreeImage/PluginGIF.cpp b/plugins/AdvaImg/src/FreeImage/PluginGIF.cpp index 7af1d821d8..e8d84afac4 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginGIF.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginGIF.cpp @@ -167,8 +167,8 @@ FreeImage_SetMetadataEx(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key static BOOL FreeImage_GetMetadataEx(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, FREE_IMAGE_MDTYPE type, FITAG **tag) { - if ( FreeImage_GetMetadata(model, dib, key, tag)) { - if ( FreeImage_GetTagType(*tag) == type ) { + if( FreeImage_GetMetadata(model, dib, key, tag) ) { + if( FreeImage_GetTagType(*tag) == type ) { return TRUE; } } @@ -187,10 +187,10 @@ StringTable::StringTable() StringTable::~StringTable() { - if ( m_buffer != NULL ) { + if( m_buffer != NULL ) { delete [] m_buffer; } - if ( m_strmap != NULL ) { + if( m_strmap != NULL ) { delete [] m_strmap; m_strmap = NULL; } @@ -218,10 +218,10 @@ void StringTable::Initialize(int minCodeSize) BYTE *StringTable::FillInputBuffer(int len) { - if ( m_buffer == NULL ) { + if( m_buffer == NULL ) { m_buffer = new(std::nothrow) BYTE[len]; m_bufferRealSize = len; - } else if ( len > m_bufferRealSize ) { + } else if( len > m_bufferRealSize ) { delete [] m_buffer; m_buffer = new(std::nothrow) BYTE[len]; m_bufferRealSize = len; @@ -273,7 +273,7 @@ int StringTable::CompressEnd(BYTE *buf) bool StringTable::Compress(BYTE *buf, int *len) { - if ( m_bufferSize == 0 || m_done ) { + if( m_bufferSize == 0 || m_done ) { return false; } @@ -288,7 +288,7 @@ bool StringTable::Compress(BYTE *buf, int *len) int nextprefix = (((m_prefix)<<8)&0xFFF00) + (ch & 0x000FF); if(firstPixelPassed) { - if ( m_strmap[nextprefix] > 0) { + if( m_strmap[nextprefix] > 0) { m_prefix = m_strmap[nextprefix]; } else { m_partial |= m_prefix << m_partialSize; @@ -304,13 +304,13 @@ bool StringTable::Compress(BYTE *buf, int *len) m_strmap[nextprefix] = m_nextCode; //increment the next highest valid code, increase the code size - if ( m_nextCode == (1 << m_codeSize)) { + if( m_nextCode == (1 << m_codeSize) ) { m_codeSize++; } m_nextCode++; //if we're out of codes, restart the string table - if ( m_nextCode == MAX_LZW_CODE ) { + if( m_nextCode == MAX_LZW_CODE ) { m_partial |= m_clearCode << m_partialSize; m_partialSize += m_codeSize; ClearCompressorTable(); @@ -321,7 +321,7 @@ bool StringTable::Compress(BYTE *buf, int *len) } //increment to the next pixel - if ( m_bufferShift > 0 && !(m_bufferPos + 1 == m_bufferSize && m_bufferShift <= m_slack)) { + if( m_bufferShift > 0 && !(m_bufferPos + 1 == m_bufferSize && m_bufferShift <= m_slack) ) { m_bufferShift -= m_bpp; } else { m_bufferPos++; @@ -329,7 +329,7 @@ bool StringTable::Compress(BYTE *buf, int *len) } //jump out here if the output buffer is full - if ( bufpos - buf == *len ) { + if( bufpos - buf == *len ) { return true; } @@ -341,7 +341,7 @@ bool StringTable::Compress(BYTE *buf, int *len) m_prefix = ch & 0x000FF; //increment to the next pixel - if ( m_bufferShift > 0 && !(m_bufferPos + 1 == m_bufferSize && m_bufferShift <= m_slack)) { + if( m_bufferShift > 0 && !(m_bufferPos + 1 == m_bufferSize && m_bufferShift <= m_slack) ) { m_bufferShift -= m_bpp; } else { m_bufferPos++; @@ -349,7 +349,7 @@ bool StringTable::Compress(BYTE *buf, int *len) } //jump out here if the output buffer is full - if ( bufpos - buf == *len ) { + if( bufpos - buf == *len ) { return true; } } @@ -363,12 +363,12 @@ bool StringTable::Compress(BYTE *buf, int *len) bool StringTable::Decompress(BYTE *buf, int *len) { - if ( m_bufferSize == 0 || m_done ) { + if( m_bufferSize == 0 || m_done ) { return false; } BYTE *bufpos = buf; - for ( ; m_bufferPos < m_bufferSize; m_bufferPos++ ) { + for( ; m_bufferPos < m_bufferSize; m_bufferPos++ ) { m_partial |= (int)m_buffer[m_bufferPos] << m_partialSize; m_partialSize += 8; while( m_partialSize >= m_codeSize ) { @@ -376,22 +376,22 @@ bool StringTable::Decompress(BYTE *buf, int *len) m_partial >>= m_codeSize; m_partialSize -= m_codeSize; - if ( code > m_nextCode || (m_nextCode == MAX_LZW_CODE && code != m_clearCode) || code == m_endCode ) { + if( code > m_nextCode || (m_nextCode == MAX_LZW_CODE && code != m_clearCode) || code == m_endCode ) { m_done = true; *len = (int)(bufpos - buf); return true; } - if ( code == m_clearCode ) { + if( code == m_clearCode ) { ClearDecompressorTable(); continue; } //add new string to string table, if not the first pass since a clear code - if ( m_oldCode != MAX_LZW_CODE ) { + if( m_oldCode != MAX_LZW_CODE ) { m_strings[m_nextCode] = m_strings[m_oldCode] + m_strings[code == m_nextCode ? m_oldCode : code][0]; } - if ( (int)m_strings[code].size() > *len - (bufpos - buf)) { + if( (int)m_strings[code].size() > *len - (bufpos - buf) ) { //out of space, stuff the code back in for next time m_partial <<= m_codeSize; m_partialSize += m_codeSize; @@ -406,9 +406,9 @@ bool StringTable::Decompress(BYTE *buf, int *len) bufpos += m_strings[code].size(); //increment the next highest valid code, add a bit to the mask if we need to increase the code size - if ( m_oldCode != MAX_LZW_CODE && m_nextCode < MAX_LZW_CODE ) { - if ( ++m_nextCode < MAX_LZW_CODE ) { - if ( (m_nextCode & m_codeMask) == 0 ) { + if( m_oldCode != MAX_LZW_CODE && m_nextCode < MAX_LZW_CODE ) { + if( ++m_nextCode < MAX_LZW_CODE ) { + if( (m_nextCode & m_codeMask) == 0 ) { m_codeSize++; m_codeMask |= m_nextCode; } @@ -443,7 +443,7 @@ void StringTable::ClearCompressorTable(void) void StringTable::ClearDecompressorTable(void) { - for ( int i = 0; i < m_clearCode; i++ ) { + for( int i = 0; i < m_clearCode; i++ ) { m_strings[i].resize(1); m_strings[i][0] = (char)i; } @@ -492,13 +492,13 @@ MimeType() { static BOOL DLL_CALLCONV Validate(FreeImageIO *io, fi_handle handle) { char buf[6]; - if ( io->read_proc(buf, 6, 1, handle) < 1 ) { + if( io->read_proc(buf, 6, 1, handle) < 1 ) { return FALSE; } BOOL bResult = FALSE; - if ( !strncmp(buf, "GIF", 3)) { - if ( buf[3] >= '0' && buf[3] <= '9' && buf[4] >= '0' && buf[4] <= '9' && buf[5] >= 'a' && buf[5] <= 'z' ) { + if( !strncmp(buf, "GIF", 3) ) { + if( buf[3] >= '0' && buf[3] <= '9' && buf[4] >= '0' && buf[4] <= '9' && buf[5] >= 'a' && buf[5] <= 'z' ) { bResult = TRUE; } } @@ -525,7 +525,7 @@ SupportsExportType(FREE_IMAGE_TYPE type) { static void *DLL_CALLCONV Open(FreeImageIO *io, fi_handle handle, BOOL read) { GIFinfo *info = new(std::nothrow) GIFinfo; - if ( info == NULL ) { + if( info == NULL ) { return NULL; } @@ -534,10 +534,10 @@ Open(FreeImageIO *io, fi_handle handle, BOOL read) { // memset(info, 0, sizeof(GIFinfo)); info->read = read; - if ( read ) { + if( read ) { try { //Header - if ( !Validate(io, handle)) { + if( !Validate(io, handle) ) { throw FI_MSG_ERROR_MAGIC_NUMBER; } io->seek_proc(handle, 6, SEEK_CUR); @@ -545,16 +545,16 @@ Open(FreeImageIO *io, fi_handle handle, BOOL read) { //Logical Screen Descriptor io->seek_proc(handle, 4, SEEK_CUR); BYTE packed; - if ( io->read_proc(&packed, 1, 1, handle) < 1 ) { + if( io->read_proc(&packed, 1, 1, handle) < 1 ) { throw "EOF reading Logical Screen Descriptor"; } - if ( io->read_proc(&info->background_color, 1, 1, handle) < 1 ) { + if( io->read_proc(&info->background_color, 1, 1, handle) < 1 ) { throw "EOF reading Logical Screen Descriptor"; } io->seek_proc(handle, 1, SEEK_CUR); //Global Color Table - if ( packed & GIF_PACKED_LSD_HAVEGCT ) { + if( packed & GIF_PACKED_LSD_HAVEGCT ) { info->global_color_table_offset = io->tell_proc(handle); info->global_color_table_size = 2 << (packed & GIF_PACKED_LSD_GCTSIZE); io->seek_proc(handle, 3 * info->global_color_table_size, SEEK_CUR); @@ -564,42 +564,42 @@ Open(FreeImageIO *io, fi_handle handle, BOOL read) { size_t gce_offset = 0; BYTE block = 0; while( block != GIF_BLOCK_TRAILER ) { - if ( io->read_proc(&block, 1, 1, handle) < 1 ) { + if( io->read_proc(&block, 1, 1, handle) < 1 ) { throw "EOF reading blocks"; } - if ( block == GIF_BLOCK_IMAGE_DESCRIPTOR ) { + if( block == GIF_BLOCK_IMAGE_DESCRIPTOR ) { info->image_descriptor_offsets.push_back(io->tell_proc(handle)); //GCE may be 0, meaning no GCE preceded this ID info->graphic_control_extension_offsets.push_back(gce_offset); gce_offset = 0; io->seek_proc(handle, 8, SEEK_CUR); - if ( io->read_proc(&packed, 1, 1, handle) < 1 ) { + if( io->read_proc(&packed, 1, 1, handle) < 1 ) { throw "EOF reading Image Descriptor"; } //Local Color Table - if ( packed & GIF_PACKED_ID_HAVELCT ) { + if( packed & GIF_PACKED_ID_HAVELCT ) { io->seek_proc(handle, 3 * (2 << (packed & GIF_PACKED_ID_LCTSIZE)), SEEK_CUR); } //LZW Minimum Code Size io->seek_proc(handle, 1, SEEK_CUR); - } else if ( block == GIF_BLOCK_EXTENSION ) { + } else if( block == GIF_BLOCK_EXTENSION ) { BYTE ext; - if ( io->read_proc(&ext, 1, 1, handle) < 1 ) { + if( io->read_proc(&ext, 1, 1, handle) < 1 ) { throw "EOF reading extension"; } - if ( ext == GIF_EXT_GRAPHIC_CONTROL ) { + if( ext == GIF_EXT_GRAPHIC_CONTROL ) { //overwrite previous offset if more than one GCE found before an ID gce_offset = io->tell_proc(handle); - } else if ( ext == GIF_EXT_COMMENT ) { + } else if( ext == GIF_EXT_COMMENT ) { info->comment_extension_offsets.push_back(io->tell_proc(handle)); - } else if ( ext == GIF_EXT_APPLICATION ) { + } else if( ext == GIF_EXT_APPLICATION ) { info->application_extension_offsets.push_back(io->tell_proc(handle)); } - } else if ( block == GIF_BLOCK_TRAILER ) { + } else if( block == GIF_BLOCK_TRAILER ) { continue; } else { throw "Invalid GIF block found"; @@ -607,12 +607,12 @@ Open(FreeImageIO *io, fi_handle handle, BOOL read) { //Data Sub-blocks BYTE len; - if ( io->read_proc(&len, 1, 1, handle) < 1 ) { + if( io->read_proc(&len, 1, 1, handle) < 1 ) { throw "EOF reading sub-block"; } while( len != 0 ) { io->seek_proc(handle, len, SEEK_CUR); - if ( io->read_proc(&len, 1, 1, handle) < 1 ) { + if( io->read_proc(&len, 1, 1, handle) < 1 ) { throw "EOF reading sub-block"; } } @@ -632,12 +632,12 @@ Open(FreeImageIO *io, fi_handle handle, BOOL read) { static void DLL_CALLCONV Close(FreeImageIO *io, fi_handle handle, void *data) { - if ( data == NULL ) { + if( data == NULL ) { return; } GIFinfo *info = (GIFinfo *)data; - if ( !info->read ) { + if( !info->read ) { //Trailer BYTE b = GIF_BLOCK_TRAILER; io->write_proc(&b, 1, 1, handle); @@ -648,7 +648,7 @@ Close(FreeImageIO *io, fi_handle handle, void *data) { static int DLL_CALLCONV PageCount(FreeImageIO *io, fi_handle handle, void *data) { - if ( data == NULL ) { + if( data == NULL ) { return 0; } GIFinfo *info = (GIFinfo *)data; @@ -658,15 +658,15 @@ PageCount(FreeImageIO *io, fi_handle handle, void *data) { static FIBITMAP * DLL_CALLCONV Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { - if ( data == NULL ) { + if( data == NULL ) { return NULL; } GIFinfo *info = (GIFinfo *)data; - if ( page == -1 ) { + if( page == -1 ) { page = 0; } - if ( page < 0 || page >= (int)info->image_descriptor_offsets.size()) { + if( page < 0 || page >= (int)info->image_descriptor_offsets.size() ) { return NULL; } @@ -679,7 +679,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { WORD w; //playback pages to generate what the user would see for this frame - if ( (flags & GIF_PLAYBACK) == GIF_PLAYBACK ) { + if( (flags & GIF_PLAYBACK) == GIF_PLAYBACK ) { //Logical Screen Descriptor io->seek_proc(handle, 6, SEEK_SET); WORD logicalwidth, logicalheight; @@ -691,7 +691,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { #endif //set the background color with 0 alpha RGBQUAD background; - if ( info->global_color_table_offset != 0 && info->background_color < info->global_color_table_size ) { + if( info->global_color_table_offset != 0 && info->background_color < info->global_color_table_size ) { io->seek_proc(handle, (long)(info->global_color_table_offset + (info->background_color * 3)), SEEK_SET); io->read_proc(&background.rgbRed, 1, 1, handle); io->read_proc(&background.rgbGreen, 1, 1, handle); @@ -705,16 +705,16 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { //allocate entire logical area dib = FreeImage_Allocate(logicalwidth, logicalheight, 32); - if ( dib == NULL ) { + if( dib == NULL ) { throw FI_MSG_ERROR_DIB_MEMORY; } //fill with background color to start int x, y; RGBQUAD *scanline; - for ( y = 0; y < logicalheight; y++ ) { + for( y = 0; y < logicalheight; y++ ) { scanline = (RGBQUAD *)FreeImage_GetScanLine(dib, y); - for ( x = 0; x < logicalwidth; x++ ) { + for( x = 0; x < logicalwidth; x++ ) { *scanline++ = background; } } @@ -743,14 +743,14 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { pageinfo.push_back(PageInfo(disposal_method, left, top, width, height)); - if ( start != end ) { - if ( left == 0 && top == 0 && width == logicalwidth && height == logicalheight ) { - if ( disposal_method == GIF_DISPOSAL_BACKGROUND ) { + if( start != end ) { + if( left == 0 && top == 0 && width == logicalwidth && height == logicalheight ) { + if( disposal_method == GIF_DISPOSAL_BACKGROUND ) { pageinfo.pop_back(); start++; break; - } else if ( disposal_method != GIF_DISPOSAL_PREVIOUS ) { - if ( !have_transparent ) { + } else if( disposal_method != GIF_DISPOSAL_PREVIOUS ) { + if( !have_transparent ) { break; } } @@ -758,23 +758,23 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { } start--; } - if ( start < 0 ) { + if( start < 0 ) { start = 0; } //draw each page into the logical area delay_time = 0; - for ( page = start; page <= end; page++ ) { + for( page = start; page <= end; page++ ) { PageInfo &info = pageinfo[end - page]; //things we can skip having to decode - if ( page != end ) { - if ( info.disposal_method == GIF_DISPOSAL_PREVIOUS ) { + if( page != end ) { + if( info.disposal_method == GIF_DISPOSAL_PREVIOUS ) { continue; } - if ( info.disposal_method == GIF_DISPOSAL_BACKGROUND ) { - for ( y = 0; y < info.height; y++ ) { + if( info.disposal_method == GIF_DISPOSAL_BACKGROUND ) { + for( y = 0; y < info.height; y++ ) { scanline = (RGBQUAD *)FreeImage_GetScanLine(dib, logicalheight - (y + info.top) - 1) + info.left; - for ( x = 0; x < info.width; x++ ) { + for( x = 0; x < info.width; x++ ) { *scanline++ = background; } } @@ -784,14 +784,14 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { //decode page FIBITMAP *pagedib = Load(io, handle, page, GIF_LOAD256, data); - if ( pagedib != NULL ) { + if( pagedib != NULL ) { RGBQUAD *pal = FreeImage_GetPalette(pagedib); have_transparent = false; - if ( FreeImage_IsTransparent(pagedib)) { + if( FreeImage_IsTransparent(pagedib) ) { int count = FreeImage_GetTransparencyCount(pagedib); BYTE *table = FreeImage_GetTransparencyTable(pagedib); - for ( int i = 0; i < count; i++ ) { - if ( table[i] == 0 ) { + for( int i = 0; i < count; i++ ) { + if( table[i] == 0 ) { have_transparent = true; transparent_color = i; break; @@ -799,11 +799,11 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { } } //copy page data into logical buffer, with full alpha opaqueness - for ( y = 0; y < info.height; y++ ) { + for( y = 0; y < info.height; y++ ) { scanline = (RGBQUAD *)FreeImage_GetScanLine(dib, logicalheight - (y + info.top) - 1) + info.left; BYTE *pageline = FreeImage_GetScanLine(pagedib, info.height - y - 1); - for ( x = 0; x < info.width; x++ ) { - if ( !have_transparent || *pageline != transparent_color ) { + for( x = 0; x < info.width; x++ ) { + if( !have_transparent || *pageline != transparent_color ) { *scanline = pal[*pageline]; scanline->rgbReserved = 255; } @@ -812,9 +812,9 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { } } //copy frame time - if ( page == end ) { + if( page == end ) { FITAG *tag; - if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, pagedib, "FrameTime", FIDT_LONG, &tag)) { + if( FreeImage_GetMetadataEx(FIMD_ANIMATION, pagedib, "FrameTime", FIDT_LONG, &tag) ) { delay_time = *(LONG *)FreeImage_GetTagValue(tag); } } @@ -846,18 +846,18 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { no_local_palette = (packed & GIF_PACKED_ID_HAVELCT) ? false : true; int bpp = 8; - if ( (flags & GIF_LOAD256) == 0 ) { - if ( !no_local_palette ) { + 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; + 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); - if ( dib == NULL ) { + if( dib == NULL ) { throw FI_MSG_ERROR_DIB_MEMORY; } @@ -870,7 +870,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { //Palette RGBQUAD *pal = FreeImage_GetPalette(dib); - if ( !no_local_palette ) { + if( !no_local_palette ) { int size = 2 << (packed & GIF_PACKED_ID_LCTSIZE); int i = 0; @@ -880,7 +880,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { io->read_proc(&pal[i].rgbBlue, 1, 1, handle); i++; } - } else if ( info->global_color_table_offset != 0 ) { + } else if( info->global_color_table_offset != 0 ) { long pos = io->tell_proc(handle); io->seek_proc(handle, (long)info->global_color_table_offset, SEEK_SET); @@ -895,7 +895,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { io->seek_proc(handle, pos, SEEK_SET); } else { //its legal to have no palette, but we're going to generate *something* - for ( int i = 0; i < 256; i++ ) { + for( int i = 0; i < 256; i++ ) { pal[i].rgbRed = (BYTE)i; pal[i].rgbGreen = (BYTE)i; pal[i].rgbBlue = (BYTE)i; @@ -915,25 +915,25 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { while( b ) { io->read_proc(stringtable->FillInputBuffer(b), b, 1, handle); int size = sizeof(buf); - while( stringtable->Decompress(buf, &size)) { - for ( int i = 0; i < size; i++ ) { + while( stringtable->Decompress(buf, &size) ) { + for( int i = 0; i < size; i++ ) { scanline[xpos] |= (buf[i] & mask) << shift; - if ( shift > 0 ) { + if( shift > 0 ) { shift -= bpp; } else { xpos++; shift = 8 - bpp; } - if ( ++x >= width ) { - if ( interlaced ) { + if( ++x >= width ) { + if( interlaced ) { y += g_GifInterlaceIncrement[interlacepass]; - if ( y >= height && ++interlacepass < GIF_INTERLACE_PASSES ) { + if( y >= height && ++interlacepass < GIF_INTERLACE_PASSES ) { y = g_GifInterlaceOffset[interlacepass]; } } else { y++; } - if ( y >= height ) { + if( y >= height ) { stringtable->Done(); break; } @@ -947,7 +947,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { io->read_proc(&b, 1, 1, handle); } - if ( page == 0 ) { + if( page == 0 ) { size_t idx; //Logical Screen Descriptor @@ -963,7 +963,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { FreeImage_SetMetadataEx(FIMD_ANIMATION, dib, "LogicalHeight", ANIMTAG_LOGICALHEIGHT, FIDT_SHORT, 1, 2, &logicalheight); //Global Color Table - if ( info->global_color_table_offset != 0 ) { + if( info->global_color_table_offset != 0 ) { RGBQUAD globalpalette[256]; io->seek_proc(handle, (long)info->global_color_table_offset, SEEK_SET); int i = 0; @@ -976,29 +976,29 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { } FreeImage_SetMetadataEx(FIMD_ANIMATION, dib, "GlobalPalette", ANIMTAG_GLOBALPALETTE, FIDT_PALETTE, info->global_color_table_size, info->global_color_table_size * 4, globalpalette); //background color - if ( info->background_color < info->global_color_table_size ) { + if( info->background_color < info->global_color_table_size ) { FreeImage_SetBackgroundColor(dib, &globalpalette[info->background_color]); } } //Application Extension LONG loop = 1; //If no AE with a loop count is found, the default must be 1 - for ( idx = 0; idx < info->application_extension_offsets.size(); idx++ ) { + for( idx = 0; idx < info->application_extension_offsets.size(); idx++ ) { io->seek_proc(handle, (long)info->application_extension_offsets[idx], SEEK_SET); io->read_proc(&b, 1, 1, handle); - if ( b == 11 ) { //All AEs start with an 11 byte sub-block to determine what type of AE it is + if( b == 11 ) { //All AEs start with an 11 byte sub-block to determine what type of AE it is char buf[11]; io->read_proc(buf, 11, 1, handle); - if ( !memcmp(buf, "NETSCAPE2.0", 11) || !memcmp(buf, "ANIMEXTS1.0", 11)) { //Not everybody recognizes ANIMEXTS1.0 but it is valid + if( !memcmp(buf, "NETSCAPE2.0", 11) || !memcmp(buf, "ANIMEXTS1.0", 11) ) { //Not everybody recognizes ANIMEXTS1.0 but it is valid io->read_proc(&b, 1, 1, handle); - if ( b == 3 ) { //we're supposed to have a 3 byte sub-block now + if( b == 3 ) { //we're supposed to have a 3 byte sub-block now io->read_proc(&b, 1, 1, handle); //this should be 0x01 but isn't really important io->read_proc(&w, 2, 1, handle); #ifdef FREEIMAGE_BIGENDIAN SwapShort(&w); #endif loop = w; - if ( loop > 0 ) loop++; + if( loop > 0 ) loop++; break; } } @@ -1007,7 +1007,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { FreeImage_SetMetadataEx(FIMD_ANIMATION, dib, "Loop", ANIMTAG_LOOP, FIDT_LONG, 1, 4, &loop); //Comment Extension - for ( idx = 0; idx < info->comment_extension_offsets.size(); idx++ ) { + for( idx = 0; idx < info->comment_extension_offsets.size(); idx++ ) { io->seek_proc(handle, (long)info->comment_extension_offsets[idx], SEEK_SET); std::string comment; char buf[255]; @@ -1025,7 +1025,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { } //Graphic Control Extension - if ( info->graphic_control_extension_offsets[page] != 0 ) { + if( info->graphic_control_extension_offsets[page] != 0 ) { io->seek_proc(handle, (long)(info->graphic_control_extension_offsets[page] + 1), SEEK_SET); io->read_proc(&packed, 1, 1, handle); io->read_proc(&w, 2, 1, handle); @@ -1037,9 +1037,9 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { disposal_method = (packed & GIF_PACKED_GCE_DISPOSAL) >> 2; delay_time = w * 10; //convert cs to ms transparent_color = b; - if ( have_transparent ) { + if( have_transparent ) { int size = 1 << bpp; - if ( transparent_color <= size ) { + if( transparent_color <= size ) { BYTE table[256]; memset(table, 0xFF, size); table[transparent_color] = 0; @@ -1054,7 +1054,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { delete stringtable; } catch (const char *msg) { - if ( dib != NULL ) { + if( dib != NULL ) { FreeImage_Unload(dib); } FreeImage_OutputMessageProc(s_format_id, msg); @@ -1066,12 +1066,12 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { static BOOL DLL_CALLCONV Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) { - if ( data == NULL ) { + if( data == NULL ) { return FALSE; } //GIFinfo *info = (GIFinfo *)data; - if ( page == -1 ) { + if( page == -1 ) { page = 0; } @@ -1081,7 +1081,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void FITAG *tag; int bpp = FreeImage_GetBPP(dib); - if ( bpp != 1 && bpp != 4 && bpp != 8 ) { + if( bpp != 1 && bpp != 4 && bpp != 8 ) { throw "Only 1, 4, or 8 bpp images supported"; } @@ -1089,22 +1089,22 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void int disposal_method = GIF_DISPOSAL_BACKGROUND, delay_time = 100, transparent_color = 0; WORD left = 0, top = 0, width = (WORD)FreeImage_GetWidth(dib), height = (WORD)FreeImage_GetHeight(dib); WORD output_height = height; - if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "FrameLeft", FIDT_SHORT, &tag)) { + if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "FrameLeft", FIDT_SHORT, &tag) ) { left = *(WORD *)FreeImage_GetTagValue(tag); } - if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "FrameTop", FIDT_SHORT, &tag)) { + if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "FrameTop", FIDT_SHORT, &tag) ) { top = *(WORD *)FreeImage_GetTagValue(tag); } - if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "NoLocalPalette", FIDT_BYTE, &tag)) { + if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "NoLocalPalette", FIDT_BYTE, &tag) ) { no_local_palette = *(BYTE *)FreeImage_GetTagValue(tag) ? true : false; } - if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "Interlaced", FIDT_BYTE, &tag)) { + if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "Interlaced", FIDT_BYTE, &tag) ) { interlaced = *(BYTE *)FreeImage_GetTagValue(tag) ? true : false; } - if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "FrameTime", FIDT_LONG, &tag)) { + if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "FrameTime", FIDT_LONG, &tag) ) { delay_time = *(LONG *)FreeImage_GetTagValue(tag); } - if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "DisposalMethod", FIDT_BYTE, &tag)) { + if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "DisposalMethod", FIDT_BYTE, &tag) ) { disposal_method = *(BYTE *)FreeImage_GetTagValue(tag); } @@ -1116,17 +1116,17 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void SwapShort(&height); #endif - if ( page == 0 ) { + if( page == 0 ) { //gather some info WORD logicalwidth = width; // width has already been swapped... - if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "LogicalWidth", FIDT_SHORT, &tag)) { + if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "LogicalWidth", FIDT_SHORT, &tag) ) { logicalwidth = *(WORD *)FreeImage_GetTagValue(tag); #ifdef FREEIMAGE_BIGENDIAN SwapShort(&logicalwidth); #endif } WORD logicalheight = height; // height has already been swapped... - if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "LogicalHeight", FIDT_SHORT, &tag)) { + if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "LogicalHeight", FIDT_SHORT, &tag) ) { logicalheight = *(WORD *)FreeImage_GetTagValue(tag); #ifdef FREEIMAGE_BIGENDIAN SwapShort(&logicalheight); @@ -1134,9 +1134,9 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void } RGBQUAD *globalpalette = NULL; int globalpalette_size = 0; - if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "GlobalPalette", FIDT_PALETTE, &tag)) { + if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "GlobalPalette", FIDT_PALETTE, &tag) ) { globalpalette_size = FreeImage_GetTagCount(tag); - if ( globalpalette_size >= 2 ) { + if( globalpalette_size >= 2 ) { globalpalette = (RGBQUAD *)FreeImage_GetTagValue(tag); } } @@ -1147,36 +1147,36 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void packed = GIF_PACKED_LSD_COLORRES; b = 0; RGBQUAD background_color; - if ( globalpalette != NULL ) { + if( globalpalette != NULL ) { packed |= GIF_PACKED_LSD_HAVEGCT; - if ( globalpalette_size < 4 ) { + if( globalpalette_size < 4 ) { globalpalette_size = 2; packed |= 0 & GIF_PACKED_LSD_GCTSIZE; - } else if ( globalpalette_size < 8 ) { + } else if( globalpalette_size < 8 ) { globalpalette_size = 4; packed |= 1 & GIF_PACKED_LSD_GCTSIZE; - } else if ( globalpalette_size < 16 ) { + } else if( globalpalette_size < 16 ) { globalpalette_size = 8; packed |= 2 & GIF_PACKED_LSD_GCTSIZE; - } else if ( globalpalette_size < 32 ) { + } else if( globalpalette_size < 32 ) { globalpalette_size = 16; packed |= 3 & GIF_PACKED_LSD_GCTSIZE; - } else if ( globalpalette_size < 64 ) { + } else if( globalpalette_size < 64 ) { globalpalette_size = 32; packed |= 4 & GIF_PACKED_LSD_GCTSIZE; - } else if ( globalpalette_size < 128 ) { + } else if( globalpalette_size < 128 ) { globalpalette_size = 64; packed |= 5 & GIF_PACKED_LSD_GCTSIZE; - } else if ( globalpalette_size < 256 ) { + } else if( globalpalette_size < 256 ) { globalpalette_size = 128; packed |= 6 & GIF_PACKED_LSD_GCTSIZE; } else { globalpalette_size = 256; packed |= 7 & GIF_PACKED_LSD_GCTSIZE; } - if ( FreeImage_GetBackgroundColor(dib, &background_color)) { - for ( int i = 0; i < globalpalette_size; i++ ) { - if ( background_color.rgbRed == globalpalette[i].rgbRed && + if( FreeImage_GetBackgroundColor(dib, &background_color) ) { + for( int i = 0; i < globalpalette_size; i++ ) { + if( background_color.rgbRed == globalpalette[i].rgbRed && background_color.rgbGreen == globalpalette[i].rgbGreen && background_color.rgbBlue == globalpalette[i].rgbBlue ) { @@ -1194,7 +1194,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void io->write_proc(&b, 1, 1, handle); //Global Color Table - if ( globalpalette != NULL ) { + if( globalpalette != NULL ) { int i = 0; while( i < globalpalette_size ) { io->write_proc(&globalpalette[i].rgbRed, 1, 1, handle); @@ -1206,13 +1206,13 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void //Application Extension LONG loop = 0; - if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "Loop", FIDT_LONG, &tag)) { + if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "Loop", FIDT_LONG, &tag) ) { loop = *(LONG *)FreeImage_GetTagValue(tag); } - if ( loop != 1 ) { + if( loop != 1 ) { //the Netscape extension is really "repeats" not "loops" - if ( loop > 1 ) loop--; - if ( loop > 0xFFFF ) loop = 0xFFFF; + if( loop > 1 ) loop--; + if( loop > 0xFFFF ) loop = 0xFFFF; w = (WORD)loop; #ifdef FREEIMAGE_BIGENDIAN SwapShort(&w); @@ -1227,9 +1227,9 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void FIMETADATA *mdhandle = NULL; FITAG *tag = NULL; mdhandle = FreeImage_FindFirstMetadata(FIMD_COMMENTS, dib, &tag); - if ( mdhandle ) { + if( mdhandle ) { do { - if ( FreeImage_GetTagType(tag) == FIDT_ASCII ) { + if( FreeImage_GetTagType(tag) == FIDT_ASCII ) { int length = FreeImage_GetTagLength(tag) - 1; char *value = (char *)FreeImage_GetTagValue(tag); io->write_proc((void *)"\x21\xFE", 2, 1, handle); @@ -1250,11 +1250,11 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void } //Graphic Control Extension - if ( FreeImage_IsTransparent(dib)) { + if( FreeImage_IsTransparent(dib) ) { int count = FreeImage_GetTransparencyCount(dib); BYTE *table = FreeImage_GetTransparencyTable(dib); - for ( int i = 0; i < count; i++ ) { - if ( table[i] == 0 ) { + for( int i = 0; i < count; i++ ) { + if( table[i] == 0 ) { have_transparent = true; transparent_color = i; break; @@ -1263,7 +1263,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void } io->write_proc((void *)"\x21\xF9\x04", 3, 1, handle); b = (BYTE)((disposal_method << 2) & GIF_PACKED_GCE_DISPOSAL); - if ( have_transparent ) b |= GIF_PACKED_GCE_HAVETRANS; + if( have_transparent ) b |= GIF_PACKED_GCE_HAVETRANS; io->write_proc(&b, 1, 1, handle); //Notes about delay time for GIFs: //IE5/IE6 have a minimum and default of 100ms @@ -1287,14 +1287,14 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void io->write_proc(&width, 2, 1, handle); io->write_proc(&height, 2, 1, handle); packed = 0; - if ( !no_local_palette ) packed |= GIF_PACKED_ID_HAVELCT | ((bpp - 1) & GIF_PACKED_ID_LCTSIZE); - if ( interlaced ) packed |= GIF_PACKED_ID_INTERLACED; + if( !no_local_palette ) packed |= GIF_PACKED_ID_HAVELCT | ((bpp - 1) & GIF_PACKED_ID_LCTSIZE); + if( interlaced ) packed |= GIF_PACKED_ID_INTERLACED; io->write_proc(&packed, 1, 1, handle); //Local Color Table - if ( !no_local_palette ) { + if( !no_local_palette ) { int palsize = 1 << bpp; - for ( int i = 0; i < palsize; i++ ) { + for( int i = 0; i < palsize; i++ ) { io->write_proc(&pal[i].rgbRed, 1, 1, handle); io->write_proc(&pal[i].rgbGreen, 1, 1, handle); io->write_proc(&pal[i].rgbBlue, 1, 1, handle); @@ -1316,9 +1316,9 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void b = sizeof(buf); while( y < output_height ) { memcpy(stringtable->FillInputBuffer(line), FreeImage_GetScanLine(dib, output_height - y - 1), line); - while( stringtable->Compress(bufptr, &size)) { + while( stringtable->Compress(bufptr, &size) ) { bufptr += size; - if ( bufptr - buf == sizeof(buf)) { + if( bufptr - buf == sizeof(buf) ) { io->write_proc(&b, 1, 1, handle); io->write_proc(buf, sizeof(buf), 1, handle); size = sizeof(buf); @@ -1327,9 +1327,9 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void size = (int)(sizeof(buf) - (bufptr - buf)); } } - if ( interlaced ) { + if( interlaced ) { y += g_GifInterlaceIncrement[interlacepass]; - if ( y >= output_height && ++interlacepass < GIF_INTERLACE_PASSES ) { + if( y >= output_height && ++interlacepass < GIF_INTERLACE_PASSES ) { y = g_GifInterlaceOffset[interlacepass]; } } else { @@ -1339,14 +1339,14 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void size = (int)(bufptr - buf); BYTE last[4]; w = (WORD)stringtable->CompressEnd(last); - if ( size + w >= sizeof(buf)) { + if( size + w >= sizeof(buf) ) { //one last full size sub-block io->write_proc(&b, 1, 1, handle); io->write_proc(buf, size, 1, handle); io->write_proc(last, sizeof(buf) - size, 1, handle); //and possibly a tiny additional sub-block b = (BYTE)(w - (sizeof(buf) - size)); - if ( b > 0 ) { + if( b > 0 ) { io->write_proc(&b, 1, 1, handle); io->write_proc(last + w - b, b, 1, handle); } diff --git a/plugins/AdvaImg/src/FreeImage/PluginHDR.cpp b/plugins/AdvaImg/src/FreeImage/PluginHDR.cpp index a0334e1143..d8c24adc31 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginHDR.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginHDR.cpp @@ -127,7 +127,7 @@ rgbe_GetLine(FreeImageIO *io, fi_handle handle, char *buffer, int length) { int i; memset(buffer, 0, length); for(i = 0; i < length; i++) { - if (!io->read_proc(&buffer[i], 1, 1, handle)) + if(!io->read_proc(&buffer[i], 1, 1, handle)) return FALSE; if(buffer[i] == 0x0A) break; @@ -196,7 +196,7 @@ rgbe_ReadHeader(FreeImageIO *io, fi_handle handle, unsigned *width, unsigned *he header_info->exposure = 1.0; // get the first line - if (!rgbe_GetLine(io, handle, buf, HDR_MAXLINE)) + if(!rgbe_GetLine(io, handle, buf, HDR_MAXLINE)) return rgbe_Error(rgbe_read_error, NULL); // check the signature @@ -208,19 +208,19 @@ rgbe_ReadHeader(FreeImageIO *io, fi_handle handle, unsigned *width, unsigned *he else { header_info->valid |= RGBE_VALID_PROGRAMTYPE; for(i = 0; i < sizeof(header_info->programtype) - 1; i++) { - if ((buf[i+2] == 0) || isspace(buf[i+2])) + if((buf[i+2] == 0) || isspace(buf[i+2])) break; header_info->programtype[i] = buf[i+2]; } header_info->programtype[i] = 0; } - for (;;) { + for(;;) { // get next line - if (!rgbe_GetLine(io, handle, buf, HDR_MAXLINE)) + if(!rgbe_GetLine(io, handle, buf, HDR_MAXLINE)) return rgbe_Error(rgbe_read_error, NULL); - if ((buf[0] == 0) || (buf[0] == '\n')) { + if((buf[0] == 0) || (buf[0] == '\n')) { // end of header so break out of loop bHeaderFound = TRUE; break; @@ -236,17 +236,17 @@ rgbe_ReadHeader(FreeImageIO *io, fi_handle handle, unsigned *width, unsigned *he header_info->exposure = tempf; header_info->valid |= RGBE_VALID_EXPOSURE; } - else if ((buf[0] == '#') && (buf[1] == 0x20)) { + else if((buf[0] == '#') && (buf[1] == 0x20)) { header_info->valid |= RGBE_VALID_COMMENT; strcpy(header_info->comment, buf); } } - if (!bHeaderFound || !bFormatFound) { + if(!bHeaderFound || !bFormatFound) { return rgbe_Error(rgbe_format_error, "invalid header"); } // get next line - if (!rgbe_GetLine(io, handle, buf, HDR_MAXLINE)) + if(!rgbe_GetLine(io, handle, buf, HDR_MAXLINE)) return rgbe_Error(rgbe_read_error, NULL); // get the image width & height @@ -364,14 +364,14 @@ rgbe_ReadPixels_RLE(FreeImageIO *io, fi_handle handle, FIRGBF *data, int scanlin free(scanline_buffer); return rgbe_Error(rgbe_read_error,NULL); } - if ((rgbe[0] != 2) || (rgbe[1] != 2) || (rgbe[2] & 0x80)) { + if((rgbe[0] != 2) || (rgbe[1] != 2) || (rgbe[2] & 0x80)) { // this file is not run length encoded rgbe_RGBEToFloat(data, rgbe); data ++; free(scanline_buffer); return rgbe_ReadPixels(io, handle, data, scanline_width * num_scanlines - 1); } - if ((((int)rgbe[2]) << 8 | rgbe[3]) != scanline_width) { + if((((int)rgbe[2]) << 8 | rgbe[3]) != scanline_width) { free(scanline_buffer); return rgbe_Error(rgbe_format_error,"wrong scanline width"); } @@ -394,7 +394,7 @@ rgbe_ReadPixels_RLE(FreeImageIO *io, fi_handle handle, FIRGBF *data, int scanlin if(buf[0] > 128) { // a run of the same value count = buf[0] - 128; - if ((count == 0) || (count > ptr_end - ptr)) { + if((count == 0) || (count > ptr_end - ptr)) { free(scanline_buffer); return rgbe_Error(rgbe_format_error, "bad scanline data"); } @@ -404,12 +404,12 @@ rgbe_ReadPixels_RLE(FreeImageIO *io, fi_handle handle, FIRGBF *data, int scanlin else { // a non-run count = buf[0]; - if ((count == 0) || (count > ptr_end - ptr)) { + if((count == 0) || (count > ptr_end - ptr)) { free(scanline_buffer); return rgbe_Error(rgbe_format_error, "bad scanline data"); } *ptr++ = buf[1]; - if (--count > 0) { + if(--count > 0) { if(io->read_proc(ptr, 1, sizeof(BYTE) * count, handle) < 1) { free(scanline_buffer); return rgbe_Error(rgbe_read_error, NULL); @@ -530,7 +530,7 @@ rgbe_WritePixels_RLE(FreeImageIO *io, fi_handle handle, FIRGBF *data, unsigned s // first red, then green, then blue, then exponent for(int i = 0; i < 4; i++) { BOOL bOK = rgbe_WriteBytes_RLE(io, handle, &buffer[i*scanline_width], scanline_width); - if (!bOK) { + if(!bOK) { free(buffer); return bOK; } @@ -606,7 +606,7 @@ static FIBITMAP * DLL_CALLCONV Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { FIBITMAP *dib = NULL; - if (!handle) { + if(!handle) { return NULL; } @@ -624,7 +624,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // allocate a RGBF image dib = FreeImage_AllocateHeaderT(header_only, FIT_RGBF, width, height); - if (!dib) { + if(!dib) { throw FI_MSG_ERROR_MEMORY; } @@ -640,7 +640,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { for(unsigned y = 0; y < height; y++) { FIRGBF *scanline = (FIRGBF*)FreeImage_GetScanLine(dib, height - 1 - y); - if (!rgbe_ReadPixels_RLE(io, handle, scanline, width, 1)) { + if(!rgbe_ReadPixels_RLE(io, handle, scanline, width, 1)) { FreeImage_Unload(dib); return NULL; } @@ -659,9 +659,11 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { static BOOL DLL_CALLCONV Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) { - if (!dib) return FALSE; + if(!dib) return FALSE; - if(FreeImage_GetImageType(dib) != FIT_RGBF) { + 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; } @@ -676,7 +678,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void rgbe_WriteMetadata(dib, &header_info); // fill a comment sprintf(header_info.comment, "# Made with FreeImage %s", FreeImage_GetVersion()); - if (!rgbe_WriteHeader(io, handle, width, height, &header_info)) { + if(!rgbe_WriteHeader(io, handle, width, height, &header_info)) { return FALSE; } @@ -684,7 +686,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void for(unsigned y = 0; y < height; y++) { FIRGBF *scanline = (FIRGBF*)FreeImage_GetScanLine(dib, height - 1 - y); - if (!rgbe_WritePixels_RLE(io, handle, scanline, width, 1)) { + if(!rgbe_WritePixels_RLE(io, handle, scanline, width, 1)) { return FALSE; } } diff --git a/plugins/AdvaImg/src/FreeImage/PluginICO.cpp b/plugins/AdvaImg/src/FreeImage/PluginICO.cpp index d0ece3514c..7f41a0d841 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginICO.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginICO.cpp @@ -100,7 +100,7 @@ CalculateImageOffset(std::vector<FIBITMAP*>& vPages, int nIndex ) { // calculate the ICO header size dwSize = sizeof(ICONHEADER); // add the ICONDIRENTRY's - dwSize += (DWORD)( vPages.size() * sizeof(ICONDIRENTRY)); + dwSize += (DWORD)( vPages.size() * sizeof(ICONDIRENTRY) ); // add the sizes of the previous images for(int k = 0; k < nIndex; k++) { FIBITMAP *icon_dib = (FIBITMAP*)vPages[k]; @@ -232,7 +232,7 @@ Open(FreeImageIO *io, fi_handle handle, BOOL read) { SwapIconHeader(lpIH); #endif - if (!(lpIH->idReserved == 0) || !(lpIH->idType == 1)) { + if(!(lpIH->idReserved == 0) || !(lpIH->idType == 1)) { // Not an ICO file free(lpIH); return NULL; @@ -295,7 +295,7 @@ LoadStandardIcon(FreeImageIO *io, fi_handle handle, int flags, BOOL header_only) return NULL; } - if ( bmih.biBitCount <= 8 ) { + if( bmih.biBitCount <= 8 ) { // read the palette data io->read_proc(FreeImage_GetPalette(dib), CalculateUsedPaletteEntries(bit_count) * sizeof(RGBQUAD), 1, handle); #if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB @@ -339,7 +339,7 @@ LoadStandardIcon(FreeImageIO *io, fi_handle handle, int flags, BOOL header_only) // bitmap has been loaded successfully! // convert to 32bpp and generate an alpha channel - if ((flags & ICO_MAKEALPHA) == ICO_MAKEALPHA) { + if((flags & ICO_MAKEALPHA) == ICO_MAKEALPHA) { FIBITMAP *dib32 = FreeImage_ConvertTo32Bits(dib); FreeImage_Unload(dib); @@ -350,7 +350,7 @@ LoadStandardIcon(FreeImageIO *io, fi_handle handle, int flags, BOOL header_only) int width_and = WidthBytes(width); BYTE *line_and = (BYTE *)malloc(width_and); - if ( line_and == NULL ) { + if( line_and == NULL ) { FreeImage_Unload(dib32); return NULL; } @@ -361,7 +361,7 @@ LoadStandardIcon(FreeImageIO *io, fi_handle handle, int flags, BOOL header_only) io->read_proc(line_and, width_and, 1, handle); for(int x = 0; x < width; x++) { quad->rgbReserved = (line_and[x>>3] & (0x80 >> (x & 0x07))) != 0 ? 0 : 0xFF; - if ( quad->rgbReserved == 0 ) { + if( quad->rgbReserved == 0 ) { quad->rgbBlue ^= 0xFF; quad->rgbGreen ^= 0xFF; quad->rgbRed ^= 0xFF; @@ -409,7 +409,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { io->seek_proc(handle, 0, SEEK_SET); io->seek_proc(handle, icon_list[page].dwImageOffset, SEEK_CUR); - if ((icon_list[page].bWidth == 0) && (icon_list[page].bHeight == 0)) { + if((icon_list[page].bWidth == 0) && (icon_list[page].bHeight == 0)) { // Vista icon support dib = FreeImage_LoadFromHandle(FIF_PNG, io, handle, header_only ? FIF_LOAD_NOPIXELS : PNG_DEFAULT); } @@ -530,7 +530,7 @@ SaveStandardIcon(FreeImageIO *io, FIBITMAP *dib, fi_handle handle) { #endif // AND mask BYTE *and_mask = (BYTE*)malloc(size_and); - if (!and_mask) { + if(!and_mask) { return FALSE; } @@ -642,14 +642,14 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void std::vector<FIBITMAP*> vPages; int k; - if (!dib || !handle || !data) { + if(!dib || !handle || !data) { return FALSE; } // check format limits unsigned w = FreeImage_GetWidth(dib); unsigned h = FreeImage_GetHeight(dib); - if ((w < 16) || (w > 256) || (h < 16) || (h > 256) || (w != h)) { + if((w < 16) || (w > 256) || (h < 16) || (h > 256) || (w != h)) { FreeImage_OutputMessageProc(s_format_id, "Unsupported icon size: width x height = %d x %d", w, h); return FALSE; } @@ -667,7 +667,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void // load all icons for(k = 0; k < icon_header->idCount; k++) { icon_dib = Load(io, handle, k, flags, data); - if (!icon_dib) { + if(!icon_dib) { throw FI_MSG_ERROR_DIB_MEMORY; } vPages.push_back(icon_dib); @@ -694,7 +694,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void // save the icon descriptions ICONDIRENTRY *icon_list = (ICONDIRENTRY *)malloc(icon_header->idCount * sizeof(ICONDIRENTRY)); - if (!icon_list) { + if(!icon_list) { throw FI_MSG_ERROR_MEMORY; } memset(icon_list, 0, icon_header->idCount * sizeof(ICONDIRENTRY)); @@ -710,7 +710,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void icon_list[k].bReserved = 0; icon_list[k].wPlanes = bmih->biPlanes; icon_list[k].wBitCount = bmih->biBitCount; - if ( (icon_list[k].wPlanes * icon_list[k].wBitCount) >= 8 ) { + if( (icon_list[k].wPlanes * icon_list[k].wBitCount) >= 8 ) { icon_list[k].bColorCount = 0; } else { icon_list[k].bColorCount = (BYTE)(1 << (icon_list[k].wPlanes * icon_list[k].wBitCount)); @@ -731,7 +731,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void for(k = 0; k < icon_header->idCount; k++) { icon_dib = (FIBITMAP*)vPages[k]; - if ((icon_list[k].bWidth == 0) && (icon_list[k].bHeight == 0)) { + if((icon_list[k].bWidth == 0) && (icon_list[k].bHeight == 0)) { // Vista icon support FreeImage_SaveToHandle(FIF_PNG, icon_dib, io, handle, PNG_DEFAULT); } diff --git a/plugins/AdvaImg/src/FreeImage/PluginIFF.cpp b/plugins/AdvaImg/src/FreeImage/PluginIFF.cpp index b6cd45d6db..ae1f903f82 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginIFF.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginIFF.cpp @@ -220,7 +220,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { SwapLong(&type); #endif - if ((type != ID_ILBM) && (type != ID_PBM)) + if((type != ID_ILBM) && (type != ID_PBM)) return NULL; size -= 4; @@ -266,7 +266,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { depth = planes > 8 ? 24 : 8; - if ( depth == 24 ) { + if( depth == 24 ) { dib = FreeImage_Allocate(width, height, depth, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); } else { dib = FreeImage_Allocate(width, height, depth); @@ -358,7 +358,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // t = [0..127] => copy the next t+1 bytes literally unsigned size_to_read = t + 1; - if ((size_to_read + x) > src_size) { + if((size_to_read + x) > src_size) { // sanity check for buffer overruns size_to_read = src_size - x; io->read_proc(src + x, size_to_read, 1, handle); @@ -373,7 +373,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { io->read_proc(&b, 1, 1, handle); unsigned size_to_copy = (unsigned)(-(int)t + 1); - if ((size_to_copy + x) > src_size) { + if((size_to_copy + x) > src_size) { // sanity check for buffer overruns size_to_copy = src_size - x; memset(src + x, b, size_to_copy); diff --git a/plugins/AdvaImg/src/FreeImage/PluginJ2K.cpp b/plugins/AdvaImg/src/FreeImage/PluginJ2K.cpp index 6e772afdaa..ae8a6ae88a 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginJ2K.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginJ2K.cpp @@ -1,339 +1,339 @@ -// ========================================================== -// JPEG2000 J2K codestream Loader and Writer -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" -#include "../LibOpenJPEG/openjpeg.h" - -// ========================================================== -// Plugin Interface -// ========================================================== - -static int s_format_id; - -// ========================================================== -// Helper functions (see J2KHelper.cpp) -// ========================================================== - -FIBITMAP* J2KImageToFIBITMAP(int format_id, const opj_image_t *image); -opj_image_t* FIBITMAPToJ2KImage(int format_id, FIBITMAP *dib, const opj_cparameters_t *parameters); - -// ========================================================== -// Internal functions -// ========================================================== - -/** -OpenJPEG Error callback -*/ -static void j2k_error_callback(const char *msg, void *client_data) { - FreeImage_OutputMessageProc(s_format_id, "Error: %s", msg); -} -/** -OpenJPEG Warning callback -*/ -static void j2k_warning_callback(const char *msg, void *client_data) { - FreeImage_OutputMessageProc(s_format_id, "Warning: %s", msg); -} - -// ========================================================== -// Plugin Implementation -// ========================================================== - -static const char * DLL_CALLCONV -Format() { - return "J2K"; -} - -static const char * DLL_CALLCONV -Description() { - return "JPEG-2000 codestream"; -} - -static const char * DLL_CALLCONV -Extension() { - return "j2k,j2c"; -} - -static const char * DLL_CALLCONV -RegExpr() { - return NULL; -} - -static const char * DLL_CALLCONV -MimeType() { - return "image/j2k"; -} - -static BOOL DLL_CALLCONV -Validate(FreeImageIO *io, fi_handle handle) { - BYTE jpc_signature[] = { 0xFF, 0x4F }; - BYTE signature[2] = { 0, 0 }; - - long tell = io->tell_proc(handle); - io->read_proc(signature, 1, sizeof(jpc_signature), handle); - io->seek_proc(handle, tell, SEEK_SET); - - return (memcmp(jpc_signature, signature, sizeof(jpc_signature)) == 0); -} - -static BOOL DLL_CALLCONV -SupportsExportDepth(int depth) { - return ( - (depth == 8) || - (depth == 24) || - (depth == 32) - ); -} - -static BOOL DLL_CALLCONV -SupportsExportType(FREE_IMAGE_TYPE type) { - return ( - (type == FIT_BITMAP) || - (type == FIT_UINT16) || - (type == FIT_RGB16) || - (type == FIT_RGBA16) - ); -} - -// ---------------------------------------------------------- - -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) { - if (handle) { - opj_dparameters_t parameters; // decompression parameters - opj_event_mgr_t event_mgr; // event manager - opj_image_t *image = NULL; // decoded image - - BYTE *src = NULL; - long file_length; - - opj_dinfo_t* dinfo = NULL; // handle to a decompressor - opj_cio_t *cio = NULL; - - FIBITMAP *dib = NULL; - - // check the file format - if (!Validate(io, handle)) { - return NULL; - } - - // configure the event callbacks - memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); - event_mgr.error_handler = j2k_error_callback; - event_mgr.warning_handler = j2k_warning_callback; - event_mgr.info_handler = NULL; - - // set decoding parameters to default values - opj_set_default_decoder_parameters(¶meters); - - try { - // read the input file and put it in memory - - long start_pos = io->tell_proc(handle); - io->seek_proc(handle, 0, SEEK_END); - file_length = io->tell_proc(handle) - start_pos; - io->seek_proc(handle, start_pos, SEEK_SET); - src = (BYTE*)malloc(file_length * sizeof(BYTE)); - if (!src) { - throw FI_MSG_ERROR_MEMORY; - } - if(io->read_proc(src, 1, file_length, handle) < 1) { - throw "Error while reading input stream"; - } - - // decode the JPEG-2000 codestream - - // get a decoder handle - dinfo = opj_create_decompress(CODEC_J2K); - - // catch events using our callbacks - opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, NULL); - - // setup the decoder decoding parameters using user parameters - opj_setup_decoder(dinfo, ¶meters); - - // open a byte stream - cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); - - // decode the stream and fill the image structure - image = opj_decode(dinfo, cio); - if (!image) { - throw "Failed to decode image!\n"; - } - - // close the byte stream - opj_cio_close(cio); - cio = NULL; - - // free the memory containing the code-stream - free(src); - src = NULL; - - // free the codec context - opj_destroy_decompress(dinfo); - - // create output image - dib = J2KImageToFIBITMAP(s_format_id, image); - if (!dib) throw "Failed to import JPEG2000 image"; - - // free image data structure - opj_image_destroy(image); - - return dib; - - } catch (const char *text) { - if(src) free(src); - if(dib) FreeImage_Unload(dib); - // free remaining structures - opj_destroy_decompress(dinfo); - opj_image_destroy(image); - // close the byte stream - if(cio) opj_cio_close(cio); - - 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) { - if ((dib) && (handle)) { - BOOL bSuccess; - opj_cparameters_t parameters; // compression parameters - opj_event_mgr_t event_mgr; // event manager - opj_image_t *image = NULL; // image to encode - opj_cinfo_t* cinfo = NULL; // codec context - opj_cio_t *cio = NULL; // memory byte stream - - // configure the event callbacks - memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); - event_mgr.error_handler = j2k_error_callback; - event_mgr.warning_handler = j2k_warning_callback; - event_mgr.info_handler = NULL; - - // set encoding parameters to default values - opj_set_default_encoder_parameters(¶meters); - - 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; - } - parameters.tcp_numlayers++; - parameters.cp_disto_alloc = 1; - - try { - // convert the dib to a OpenJPEG image - image = FIBITMAPToJ2KImage(s_format_id, dib, ¶meters); - if (!image) return FALSE; - - // decide if MCT should be used - parameters.tcp_mct = (image->numcomps == 3) ? 1 : 0; - - // encode the destination image - - // get a J2K compressor handle - cinfo = opj_create_compress(CODEC_J2K); - - // catch events using our callbacks - opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, NULL); - - // setup the encoder parameters using the current image and using user parameters - opj_setup_encoder(cinfo, ¶meters, image); - - // open a byte stream for writing, allocate memory for all tiles - cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0); - - // encode the image - bSuccess = opj_encode(cinfo, cio, image, NULL/*parameters.index*/); - if (!bSuccess) { - throw "Failed to encode image"; - } - int codestream_length = cio_tell(cio); - - // write the buffer to user's IO handle - io->write_proc(cio->buffer, 1, codestream_length, handle); - - // close and free the byte stream - opj_cio_close(cio); - - // free remaining compression structures - opj_destroy_compress(cinfo); - - // free image data - opj_image_destroy(image); - - return TRUE; - - } catch (const char *text) { - if(cio) opj_cio_close(cio); - if(cinfo) opj_destroy_compress(cinfo); - if(image) opj_image_destroy(image); - FreeImage_OutputMessageProc(s_format_id, text); - return FALSE; - } - } - - return FALSE; -} - -// ========================================================== -// Init -// ========================================================== - -void DLL_CALLCONV -InitJ2K(Plugin *plugin, int format_id) { - s_format_id = format_id; - - plugin->format_proc = Format; - plugin->description_proc = Description; - plugin->extension_proc = Extension; - plugin->regexpr_proc = RegExpr; - plugin->open_proc = Open; - plugin->close_proc = Close; - plugin->pagecount_proc = NULL; - plugin->pagecapability_proc = NULL; - plugin->load_proc = Load; - plugin->save_proc = Save; - plugin->validate_proc = Validate; - plugin->mime_proc = MimeType; - plugin->supports_export_bpp_proc = SupportsExportDepth; - plugin->supports_export_type_proc = SupportsExportType; - plugin->supports_icc_profiles_proc = NULL; -} +// ==========================================================
+// JPEG2000 J2K codestream Loader and Writer
+//
+// Design and implementation by
+// - Hervé Drolon (drolon@infonie.fr)
+//
+// This file is part of FreeImage 3
+//
+// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
+// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
+// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
+// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
+// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
+// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
+// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
+// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+// THIS DISCLAIMER.
+//
+// Use at your own risk!
+// ==========================================================
+
+#include "FreeImage.h"
+#include "Utilities.h"
+#include "../LibOpenJPEG/openjpeg.h"
+
+// ==========================================================
+// Plugin Interface
+// ==========================================================
+
+static int s_format_id;
+
+// ==========================================================
+// Helper functions (see J2KHelper.cpp)
+// ==========================================================
+
+FIBITMAP* J2KImageToFIBITMAP(int format_id, const opj_image_t *image);
+opj_image_t* FIBITMAPToJ2KImage(int format_id, FIBITMAP *dib, const opj_cparameters_t *parameters);
+
+// ==========================================================
+// Internal functions
+// ==========================================================
+
+/**
+OpenJPEG Error callback
+*/
+static void j2k_error_callback(const char *msg, void *client_data) {
+ FreeImage_OutputMessageProc(s_format_id, "Error: %s", msg);
+}
+/**
+OpenJPEG Warning callback
+*/
+static void j2k_warning_callback(const char *msg, void *client_data) {
+ FreeImage_OutputMessageProc(s_format_id, "Warning: %s", msg);
+}
+
+// ==========================================================
+// Plugin Implementation
+// ==========================================================
+
+static const char * DLL_CALLCONV
+Format() {
+ return "J2K";
+}
+
+static const char * DLL_CALLCONV
+Description() {
+ return "JPEG-2000 codestream";
+}
+
+static const char * DLL_CALLCONV
+Extension() {
+ return "j2k,j2c";
+}
+
+static const char * DLL_CALLCONV
+RegExpr() {
+ return NULL;
+}
+
+static const char * DLL_CALLCONV
+MimeType() {
+ return "image/j2k";
+}
+
+static BOOL DLL_CALLCONV
+Validate(FreeImageIO *io, fi_handle handle) {
+ BYTE jpc_signature[] = { 0xFF, 0x4F };
+ BYTE signature[2] = { 0, 0 };
+
+ long tell = io->tell_proc(handle);
+ io->read_proc(signature, 1, sizeof(jpc_signature), handle);
+ io->seek_proc(handle, tell, SEEK_SET);
+
+ return (memcmp(jpc_signature, signature, sizeof(jpc_signature)) == 0);
+}
+
+static BOOL DLL_CALLCONV
+SupportsExportDepth(int depth) {
+ return (
+ (depth == 8) ||
+ (depth == 24) ||
+ (depth == 32)
+ );
+}
+
+static BOOL DLL_CALLCONV
+SupportsExportType(FREE_IMAGE_TYPE type) {
+ return (
+ (type == FIT_BITMAP) ||
+ (type == FIT_UINT16) ||
+ (type == FIT_RGB16) ||
+ (type == FIT_RGBA16)
+ );
+}
+
+// ----------------------------------------------------------
+
+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) {
+ if (handle) {
+ opj_dparameters_t parameters; // decompression parameters
+ opj_event_mgr_t event_mgr; // event manager
+ opj_image_t *image = NULL; // decoded image
+
+ BYTE *src = NULL;
+ long file_length;
+
+ opj_dinfo_t* dinfo = NULL; // handle to a decompressor
+ opj_cio_t *cio = NULL;
+
+ FIBITMAP *dib = NULL;
+
+ // check the file format
+ if(!Validate(io, handle)) {
+ return NULL;
+ }
+
+ // configure the event callbacks
+ memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
+ event_mgr.error_handler = j2k_error_callback;
+ event_mgr.warning_handler = j2k_warning_callback;
+ event_mgr.info_handler = NULL;
+
+ // set decoding parameters to default values
+ opj_set_default_decoder_parameters(¶meters);
+
+ try {
+ // read the input file and put it in memory
+
+ long start_pos = io->tell_proc(handle);
+ io->seek_proc(handle, 0, SEEK_END);
+ file_length = io->tell_proc(handle) - start_pos;
+ io->seek_proc(handle, start_pos, SEEK_SET);
+ src = (BYTE*)malloc(file_length * sizeof(BYTE));
+ if(!src) {
+ throw FI_MSG_ERROR_MEMORY;
+ }
+ if(io->read_proc(src, 1, file_length, handle) < 1) {
+ throw "Error while reading input stream";
+ }
+
+ // decode the JPEG-2000 codestream
+
+ // get a decoder handle
+ dinfo = opj_create_decompress(CODEC_J2K);
+
+ // catch events using our callbacks
+ opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, NULL);
+
+ // setup the decoder decoding parameters using user parameters
+ opj_setup_decoder(dinfo, ¶meters);
+
+ // open a byte stream
+ cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
+
+ // decode the stream and fill the image structure
+ image = opj_decode(dinfo, cio);
+ if(!image) {
+ throw "Failed to decode image!\n";
+ }
+
+ // close the byte stream
+ opj_cio_close(cio);
+ cio = NULL;
+
+ // free the memory containing the code-stream
+ free(src);
+ src = NULL;
+
+ // free the codec context
+ opj_destroy_decompress(dinfo);
+
+ // create output image
+ dib = J2KImageToFIBITMAP(s_format_id, image);
+ if(!dib) throw "Failed to import JPEG2000 image";
+
+ // free image data structure
+ opj_image_destroy(image);
+
+ return dib;
+
+ } catch (const char *text) {
+ if(src) free(src);
+ if(dib) FreeImage_Unload(dib);
+ // free remaining structures
+ opj_destroy_decompress(dinfo);
+ opj_image_destroy(image);
+ // close the byte stream
+ if(cio) opj_cio_close(cio);
+
+ 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) {
+ if ((dib) && (handle)) {
+ BOOL bSuccess;
+ opj_cparameters_t parameters; // compression parameters
+ opj_event_mgr_t event_mgr; // event manager
+ opj_image_t *image = NULL; // image to encode
+ opj_cinfo_t* cinfo = NULL; // codec context
+ opj_cio_t *cio = NULL; // memory byte stream
+
+ // configure the event callbacks
+ memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
+ event_mgr.error_handler = j2k_error_callback;
+ event_mgr.warning_handler = j2k_warning_callback;
+ event_mgr.info_handler = NULL;
+
+ // set encoding parameters to default values
+ opj_set_default_encoder_parameters(¶meters);
+
+ 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;
+ }
+ parameters.tcp_numlayers++;
+ parameters.cp_disto_alloc = 1;
+
+ try {
+ // convert the dib to a OpenJPEG image
+ image = FIBITMAPToJ2KImage(s_format_id, dib, ¶meters);
+ if(!image) return FALSE;
+
+ // decide if MCT should be used
+ parameters.tcp_mct = (image->numcomps == 3) ? 1 : 0;
+
+ // encode the destination image
+
+ // get a J2K compressor handle
+ cinfo = opj_create_compress(CODEC_J2K);
+
+ // catch events using our callbacks
+ opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, NULL);
+
+ // setup the encoder parameters using the current image and using user parameters
+ opj_setup_encoder(cinfo, ¶meters, image);
+
+ // open a byte stream for writing, allocate memory for all tiles
+ cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
+
+ // encode the image
+ bSuccess = opj_encode(cinfo, cio, image, NULL/*parameters.index*/);
+ if (!bSuccess) {
+ throw "Failed to encode image";
+ }
+ int codestream_length = cio_tell(cio);
+
+ // write the buffer to user's IO handle
+ io->write_proc(cio->buffer, 1, codestream_length, handle);
+
+ // close and free the byte stream
+ opj_cio_close(cio);
+
+ // free remaining compression structures
+ opj_destroy_compress(cinfo);
+
+ // free image data
+ opj_image_destroy(image);
+
+ return TRUE;
+
+ } catch (const char *text) {
+ if(cio) opj_cio_close(cio);
+ if(cinfo) opj_destroy_compress(cinfo);
+ if(image) opj_image_destroy(image);
+ FreeImage_OutputMessageProc(s_format_id, text);
+ return FALSE;
+ }
+ }
+
+ return FALSE;
+}
+
+// ==========================================================
+// Init
+// ==========================================================
+
+void DLL_CALLCONV
+InitJ2K(Plugin *plugin, int format_id) {
+ s_format_id = format_id;
+
+ plugin->format_proc = Format;
+ plugin->description_proc = Description;
+ plugin->extension_proc = Extension;
+ plugin->regexpr_proc = RegExpr;
+ plugin->open_proc = Open;
+ plugin->close_proc = Close;
+ plugin->pagecount_proc = NULL;
+ plugin->pagecapability_proc = NULL;
+ plugin->load_proc = Load;
+ plugin->save_proc = Save;
+ plugin->validate_proc = Validate;
+ plugin->mime_proc = MimeType;
+ plugin->supports_export_bpp_proc = SupportsExportDepth;
+ plugin->supports_export_type_proc = SupportsExportType;
+ plugin->supports_icc_profiles_proc = NULL;
+}
diff --git a/plugins/AdvaImg/src/FreeImage/PluginJNG.cpp b/plugins/AdvaImg/src/FreeImage/PluginJNG.cpp new file mode 100644 index 0000000000..817e731168 --- /dev/null +++ b/plugins/AdvaImg/src/FreeImage/PluginJNG.cpp @@ -0,0 +1,162 @@ +// ========================================================== +// JNG loader +// +// Design and implementation by +// - Herve Drolon (drolon@infonie.fr) +// +// This file is part of FreeImage 3 +// +// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY +// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES +// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE +// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED +// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT +// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY +// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL +// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER +// THIS DISCLAIMER. +// +// Use at your own risk! +// ========================================================== + +#include "FreeImage.h" +#include "Utilities.h" + +// ========================================================== +// Plugin Interface +// ========================================================== + +static int s_format_id; + +// ---------------------------------------------------------- + +#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"; +} + +static const char * DLL_CALLCONV +Description() { + return "JPEG Network Graphics"; +} + +static const char * DLL_CALLCONV +Extension() { + return "jng"; +} + +static const char * DLL_CALLCONV +RegExpr() { + return NULL; +} + +static const char * DLL_CALLCONV +MimeType() { + return "image/x-mng"; +} + +static BOOL DLL_CALLCONV +Validate(FreeImageIO *io, fi_handle handle) { + BYTE jng_signature[8] = { 139, 74, 78, 71, 13, 10, 26, 10 }; + BYTE signature[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + + io->read_proc(&signature, 1, JNG_SIGNATURE_SIZE, handle); + + return (memcmp(jng_signature, signature, JNG_SIGNATURE_SIZE) == 0) ? TRUE : FALSE; +} + +static BOOL DLL_CALLCONV +SupportsExportDepth(int depth) { + return ( + (depth == 8) || + (depth == 24) || + (depth == 32) + ); +} + +static BOOL DLL_CALLCONV +SupportsExportType(FREE_IMAGE_TYPE type) { + return (type == FIT_BITMAP) ? TRUE : FALSE; +} + +static BOOL DLL_CALLCONV +SupportsICCProfiles() { + return TRUE; +} + +static BOOL DLL_CALLCONV +SupportsNoPixels() { + return TRUE; +} + + +// ---------------------------------------------------------- + +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; + + plugin->format_proc = Format; + plugin->description_proc = Description; + plugin->extension_proc = Extension; + plugin->regexpr_proc = RegExpr; + plugin->open_proc = Open; + plugin->close_proc = Close; + plugin->pagecount_proc = NULL; + plugin->pagecapability_proc = NULL; + plugin->load_proc = Load; + plugin->save_proc = Save; + plugin->validate_proc = Validate; + plugin->mime_proc = MimeType; + plugin->supports_export_bpp_proc = SupportsExportDepth; + plugin->supports_export_type_proc = SupportsExportType; + plugin->supports_icc_profiles_proc = SupportsICCProfiles; + plugin->supports_no_pixels_proc = SupportsNoPixels; +} diff --git a/plugins/AdvaImg/src/FreeImage/PluginJP2.cpp b/plugins/AdvaImg/src/FreeImage/PluginJP2.cpp index ed1cb267bb..261697fb5c 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginJP2.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginJP2.cpp @@ -1,339 +1,339 @@ -// ========================================================== -// JPEG2000 JP2 file format Loader and Writer -// -// Design and implementation by -// - Hervé Drolon (drolon@infonie.fr) -// -// This file is part of FreeImage 3 -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY -// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES -// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE -// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED -// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT -// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY -// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL -// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER -// THIS DISCLAIMER. -// -// Use at your own risk! -// ========================================================== - -#include "FreeImage.h" -#include "Utilities.h" -#include "../LibOpenJPEG/openjpeg.h" - -// ========================================================== -// Plugin Interface -// ========================================================== - -static int s_format_id; - -// ========================================================== -// Helper functions (see J2KHelper.cpp) -// ========================================================== - -FIBITMAP* J2KImageToFIBITMAP(int format_id, const opj_image_t *image); -opj_image_t* FIBITMAPToJ2KImage(int format_id, FIBITMAP *dib, const opj_cparameters_t *parameters); - -// ========================================================== -// Internal functions -// ========================================================== - -/** -OpenJPEG Error callback -*/ -static void jp2_error_callback(const char *msg, void *client_data) { - FreeImage_OutputMessageProc(s_format_id, "Error: %s", msg); -} -/** -OpenJPEG Warning callback -*/ -static void jp2_warning_callback(const char *msg, void *client_data) { - FreeImage_OutputMessageProc(s_format_id, "Warning: %s", msg); -} - -// ========================================================== -// Plugin Implementation -// ========================================================== - -static const char * DLL_CALLCONV -Format() { - return "JP2"; -} - -static const char * DLL_CALLCONV -Description() { - return "JPEG-2000 File Format"; -} - -static const char * DLL_CALLCONV -Extension() { - return "jp2"; -} - -static const char * DLL_CALLCONV -RegExpr() { - return NULL; -} - -static const char * DLL_CALLCONV -MimeType() { - return "image/jp2"; -} - -static BOOL DLL_CALLCONV -Validate(FreeImageIO *io, fi_handle handle) { - BYTE jp2_signature[] = { 0x00, 0x00, 0x00, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A }; - BYTE signature[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - - long tell = io->tell_proc(handle); - io->read_proc(signature, 1, sizeof(jp2_signature), handle); - io->seek_proc(handle, tell, SEEK_SET); - - return (memcmp(jp2_signature, signature, sizeof(jp2_signature)) == 0); -} - -static BOOL DLL_CALLCONV -SupportsExportDepth(int depth) { - return ( - (depth == 8) || - (depth == 24) || - (depth == 32) - ); -} - -static BOOL DLL_CALLCONV -SupportsExportType(FREE_IMAGE_TYPE type) { - return ( - (type == FIT_BITMAP) || - (type == FIT_UINT16) || - (type == FIT_RGB16) || - (type == FIT_RGBA16) - ); -} - -// ---------------------------------------------------------- - -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) { - if (handle) { - opj_dparameters_t parameters; // decompression parameters - opj_event_mgr_t event_mgr; // event manager - opj_image_t *image = NULL; // decoded image - - BYTE *src = NULL; - long file_length; - - opj_dinfo_t* dinfo = NULL; // handle to a decompressor - opj_cio_t *cio = NULL; - - FIBITMAP *dib = NULL; - - // check the file format - if (!Validate(io, handle)) { - return NULL; - } - - // configure the event callbacks - memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); - event_mgr.error_handler = jp2_error_callback; - event_mgr.warning_handler = jp2_warning_callback; - event_mgr.info_handler = NULL; - - // set decoding parameters to default values - opj_set_default_decoder_parameters(¶meters); - - try { - // read the input file and put it in memory - - long start_pos = io->tell_proc(handle); - io->seek_proc(handle, 0, SEEK_END); - file_length = io->tell_proc(handle) - start_pos; - io->seek_proc(handle, start_pos, SEEK_SET); - src = (BYTE*)malloc(file_length * sizeof(BYTE)); - if (!src) { - throw FI_MSG_ERROR_MEMORY; - } - if(io->read_proc(src, 1, file_length, handle) < 1) { - throw "Error while reading input stream"; - } - - // decode the JPEG-2000 file - - // get a decoder handle - dinfo = opj_create_decompress(CODEC_JP2); - - // catch events using our callbacks - opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, NULL); - - // setup the decoder decoding parameters using user parameters - opj_setup_decoder(dinfo, ¶meters); - - // open a byte stream - cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); - - // decode the stream and fill the image structure - image = opj_decode(dinfo, cio); - if (!image) { - throw "Failed to decode image!\n"; - } - - // close the byte stream - opj_cio_close(cio); - cio = NULL; - - // free the memory containing the code-stream - free(src); - src = NULL; - - // free the codec context - opj_destroy_decompress(dinfo); - - // create output image - dib = J2KImageToFIBITMAP(s_format_id, image); - if (!dib) throw "Failed to import JPEG2000 image"; - - // free image data structure - opj_image_destroy(image); - - return dib; - - } catch (const char *text) { - if(src) free(src); - if(dib) FreeImage_Unload(dib); - // free remaining structures - opj_destroy_decompress(dinfo); - opj_image_destroy(image); - // close the byte stream - if(cio) opj_cio_close(cio); - - 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) { - if ((dib) && (handle)) { - BOOL bSuccess; - opj_cparameters_t parameters; // compression parameters - opj_event_mgr_t event_mgr; // event manager - opj_image_t *image = NULL; // image to encode - opj_cinfo_t* cinfo = NULL; // codec context - opj_cio_t *cio = NULL; // memory byte stream - - // configure the event callbacks - memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); - event_mgr.error_handler = jp2_error_callback; - event_mgr.warning_handler = jp2_warning_callback; - event_mgr.info_handler = NULL; - - // set encoding parameters to default values - opj_set_default_encoder_parameters(¶meters); - - 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; - } - parameters.tcp_numlayers++; - parameters.cp_disto_alloc = 1; - - try { - // convert the dib to a OpenJPEG image - image = FIBITMAPToJ2KImage(s_format_id, dib, ¶meters); - if (!image) return FALSE; - - // decide if MCT should be used - parameters.tcp_mct = (image->numcomps == 3) ? 1 : 0; - - // encode the destination image - - // get a J2K compressor handle - cinfo = opj_create_compress(CODEC_JP2); - - // catch events using our callbacks - opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, NULL); - - // setup the encoder parameters using the current image and using user parameters - opj_setup_encoder(cinfo, ¶meters, image); - - // open a byte stream for writing, allocate memory for all tiles - cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0); - - // encode the image - bSuccess = opj_encode(cinfo, cio, image, NULL/*parameters.index*/); - if (!bSuccess) { - throw "Failed to encode image"; - } - int codestream_length = cio_tell(cio); - - // write the buffer to user's IO handle - io->write_proc(cio->buffer, 1, codestream_length, handle); - - // close and free the byte stream - opj_cio_close(cio); - - // free remaining compression structures - opj_destroy_compress(cinfo); - - // free image data - opj_image_destroy(image); - - return TRUE; - - } catch (const char *text) { - if(cio) opj_cio_close(cio); - if(cinfo) opj_destroy_compress(cinfo); - if(image) opj_image_destroy(image); - FreeImage_OutputMessageProc(s_format_id, text); - return FALSE; - } - } - - return FALSE; -} - -// ========================================================== -// Init -// ========================================================== - -void DLL_CALLCONV -InitJP2(Plugin *plugin, int format_id) { - s_format_id = format_id; - - plugin->format_proc = Format; - plugin->description_proc = Description; - plugin->extension_proc = Extension; - plugin->regexpr_proc = RegExpr; - plugin->open_proc = Open; - plugin->close_proc = Close; - plugin->pagecount_proc = NULL; - plugin->pagecapability_proc = NULL; - plugin->load_proc = Load; - plugin->save_proc = Save; - plugin->validate_proc = Validate; - plugin->mime_proc = MimeType; - plugin->supports_export_bpp_proc = SupportsExportDepth; - plugin->supports_export_type_proc = SupportsExportType; - plugin->supports_icc_profiles_proc = NULL; -} +// ==========================================================
+// JPEG2000 JP2 file format Loader and Writer
+//
+// Design and implementation by
+// - Hervé Drolon (drolon@infonie.fr)
+//
+// This file is part of FreeImage 3
+//
+// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
+// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
+// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
+// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
+// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
+// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
+// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
+// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
+// THIS DISCLAIMER.
+//
+// Use at your own risk!
+// ==========================================================
+
+#include "FreeImage.h"
+#include "Utilities.h"
+#include "../LibOpenJPEG/openjpeg.h"
+
+// ==========================================================
+// Plugin Interface
+// ==========================================================
+
+static int s_format_id;
+
+// ==========================================================
+// Helper functions (see J2KHelper.cpp)
+// ==========================================================
+
+FIBITMAP* J2KImageToFIBITMAP(int format_id, const opj_image_t *image);
+opj_image_t* FIBITMAPToJ2KImage(int format_id, FIBITMAP *dib, const opj_cparameters_t *parameters);
+
+// ==========================================================
+// Internal functions
+// ==========================================================
+
+/**
+OpenJPEG Error callback
+*/
+static void jp2_error_callback(const char *msg, void *client_data) {
+ FreeImage_OutputMessageProc(s_format_id, "Error: %s", msg);
+}
+/**
+OpenJPEG Warning callback
+*/
+static void jp2_warning_callback(const char *msg, void *client_data) {
+ FreeImage_OutputMessageProc(s_format_id, "Warning: %s", msg);
+}
+
+// ==========================================================
+// Plugin Implementation
+// ==========================================================
+
+static const char * DLL_CALLCONV
+Format() {
+ return "JP2";
+}
+
+static const char * DLL_CALLCONV
+Description() {
+ return "JPEG-2000 File Format";
+}
+
+static const char * DLL_CALLCONV
+Extension() {
+ return "jp2";
+}
+
+static const char * DLL_CALLCONV
+RegExpr() {
+ return NULL;
+}
+
+static const char * DLL_CALLCONV
+MimeType() {
+ return "image/jp2";
+}
+
+static BOOL DLL_CALLCONV
+Validate(FreeImageIO *io, fi_handle handle) {
+ BYTE jp2_signature[] = { 0x00, 0x00, 0x00, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A };
+ BYTE signature[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+ long tell = io->tell_proc(handle);
+ io->read_proc(signature, 1, sizeof(jp2_signature), handle);
+ io->seek_proc(handle, tell, SEEK_SET);
+
+ return (memcmp(jp2_signature, signature, sizeof(jp2_signature)) == 0);
+}
+
+static BOOL DLL_CALLCONV
+SupportsExportDepth(int depth) {
+ return (
+ (depth == 8) ||
+ (depth == 24) ||
+ (depth == 32)
+ );
+}
+
+static BOOL DLL_CALLCONV
+SupportsExportType(FREE_IMAGE_TYPE type) {
+ return (
+ (type == FIT_BITMAP) ||
+ (type == FIT_UINT16) ||
+ (type == FIT_RGB16) ||
+ (type == FIT_RGBA16)
+ );
+}
+
+// ----------------------------------------------------------
+
+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) {
+ if (handle) {
+ opj_dparameters_t parameters; // decompression parameters
+ opj_event_mgr_t event_mgr; // event manager
+ opj_image_t *image = NULL; // decoded image
+
+ BYTE *src = NULL;
+ long file_length;
+
+ opj_dinfo_t* dinfo = NULL; // handle to a decompressor
+ opj_cio_t *cio = NULL;
+
+ FIBITMAP *dib = NULL;
+
+ // check the file format
+ if(!Validate(io, handle)) {
+ return NULL;
+ }
+
+ // configure the event callbacks
+ memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
+ event_mgr.error_handler = jp2_error_callback;
+ event_mgr.warning_handler = jp2_warning_callback;
+ event_mgr.info_handler = NULL;
+
+ // set decoding parameters to default values
+ opj_set_default_decoder_parameters(¶meters);
+
+ try {
+ // read the input file and put it in memory
+
+ long start_pos = io->tell_proc(handle);
+ io->seek_proc(handle, 0, SEEK_END);
+ file_length = io->tell_proc(handle) - start_pos;
+ io->seek_proc(handle, start_pos, SEEK_SET);
+ src = (BYTE*)malloc(file_length * sizeof(BYTE));
+ if(!src) {
+ throw FI_MSG_ERROR_MEMORY;
+ }
+ if(io->read_proc(src, 1, file_length, handle) < 1) {
+ throw "Error while reading input stream";
+ }
+
+ // decode the JPEG-2000 file
+
+ // get a decoder handle
+ dinfo = opj_create_decompress(CODEC_JP2);
+
+ // catch events using our callbacks
+ opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, NULL);
+
+ // setup the decoder decoding parameters using user parameters
+ opj_setup_decoder(dinfo, ¶meters);
+
+ // open a byte stream
+ cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
+
+ // decode the stream and fill the image structure
+ image = opj_decode(dinfo, cio);
+ if(!image) {
+ throw "Failed to decode image!\n";
+ }
+
+ // close the byte stream
+ opj_cio_close(cio);
+ cio = NULL;
+
+ // free the memory containing the code-stream
+ free(src);
+ src = NULL;
+
+ // free the codec context
+ opj_destroy_decompress(dinfo);
+
+ // create output image
+ dib = J2KImageToFIBITMAP(s_format_id, image);
+ if(!dib) throw "Failed to import JPEG2000 image";
+
+ // free image data structure
+ opj_image_destroy(image);
+
+ return dib;
+
+ } catch (const char *text) {
+ if(src) free(src);
+ if(dib) FreeImage_Unload(dib);
+ // free remaining structures
+ opj_destroy_decompress(dinfo);
+ opj_image_destroy(image);
+ // close the byte stream
+ if(cio) opj_cio_close(cio);
+
+ 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) {
+ if ((dib) && (handle)) {
+ BOOL bSuccess;
+ opj_cparameters_t parameters; // compression parameters
+ opj_event_mgr_t event_mgr; // event manager
+ opj_image_t *image = NULL; // image to encode
+ opj_cinfo_t* cinfo = NULL; // codec context
+ opj_cio_t *cio = NULL; // memory byte stream
+
+ // configure the event callbacks
+ memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
+ event_mgr.error_handler = jp2_error_callback;
+ event_mgr.warning_handler = jp2_warning_callback;
+ event_mgr.info_handler = NULL;
+
+ // set encoding parameters to default values
+ opj_set_default_encoder_parameters(¶meters);
+
+ 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;
+ }
+ parameters.tcp_numlayers++;
+ parameters.cp_disto_alloc = 1;
+
+ try {
+ // convert the dib to a OpenJPEG image
+ image = FIBITMAPToJ2KImage(s_format_id, dib, ¶meters);
+ if(!image) return FALSE;
+
+ // decide if MCT should be used
+ parameters.tcp_mct = (image->numcomps == 3) ? 1 : 0;
+
+ // encode the destination image
+
+ // get a J2K compressor handle
+ cinfo = opj_create_compress(CODEC_JP2);
+
+ // catch events using our callbacks
+ opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, NULL);
+
+ // setup the encoder parameters using the current image and using user parameters
+ opj_setup_encoder(cinfo, ¶meters, image);
+
+ // open a byte stream for writing, allocate memory for all tiles
+ cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
+
+ // encode the image
+ bSuccess = opj_encode(cinfo, cio, image, NULL/*parameters.index*/);
+ if (!bSuccess) {
+ throw "Failed to encode image";
+ }
+ int codestream_length = cio_tell(cio);
+
+ // write the buffer to user's IO handle
+ io->write_proc(cio->buffer, 1, codestream_length, handle);
+
+ // close and free the byte stream
+ opj_cio_close(cio);
+
+ // free remaining compression structures
+ opj_destroy_compress(cinfo);
+
+ // free image data
+ opj_image_destroy(image);
+
+ return TRUE;
+
+ } catch (const char *text) {
+ if(cio) opj_cio_close(cio);
+ if(cinfo) opj_destroy_compress(cinfo);
+ if(image) opj_image_destroy(image);
+ FreeImage_OutputMessageProc(s_format_id, text);
+ return FALSE;
+ }
+ }
+
+ return FALSE;
+}
+
+// ==========================================================
+// Init
+// ==========================================================
+
+void DLL_CALLCONV
+InitJP2(Plugin *plugin, int format_id) {
+ s_format_id = format_id;
+
+ plugin->format_proc = Format;
+ plugin->description_proc = Description;
+ plugin->extension_proc = Extension;
+ plugin->regexpr_proc = RegExpr;
+ plugin->open_proc = Open;
+ plugin->close_proc = Close;
+ plugin->pagecount_proc = NULL;
+ plugin->pagecapability_proc = NULL;
+ plugin->load_proc = Load;
+ plugin->save_proc = Save;
+ plugin->validate_proc = Validate;
+ plugin->mime_proc = MimeType;
+ plugin->supports_export_bpp_proc = SupportsExportDepth;
+ plugin->supports_export_type_proc = SupportsExportType;
+ plugin->supports_icc_profiles_proc = NULL;
+}
diff --git a/plugins/AdvaImg/src/FreeImage/PluginJPEG.cpp b/plugins/AdvaImg/src/FreeImage/PluginJPEG.cpp index b69ace95bc..b3bc9f27f3 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginJPEG.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginJPEG.cpp @@ -757,7 +757,7 @@ read_markers(j_decompress_ptr cinfo, FIBITMAP *dib) { continue; } if(memcmp(marker->data, "JFXX" , 5) == 0) { - if (!cinfo->saw_JFIF_marker || cinfo->JFIF_minor_version < 2) { + if(!cinfo->saw_JFIF_marker || cinfo->JFIF_minor_version < 2) { FreeImage_OutputMessageProc(s_format_id, "Warning: non-standard JFXX segment"); } jpeg_read_jfxx(dib, marker->data, marker->data_length); @@ -785,7 +785,7 @@ read_markers(j_decompress_ptr cinfo, FIBITMAP *dib) { BYTE *icc_profile = NULL; unsigned icc_length = 0; - if ( jpeg_read_icc_profile(cinfo, &icc_profile, &icc_length)) { + if( jpeg_read_icc_profile(cinfo, &icc_profile, &icc_length) ) { // copy ICC profile data FreeImage_CreateICCProfile(dib, icc_profile, icc_length); // clean up @@ -995,11 +995,11 @@ static BOOL jpeg_write_jfxx(j_compress_ptr cinfo, FIBITMAP *dib) { // get the thumbnail to be stored FIBITMAP* thumbnail = FreeImage_GetThumbnail(dib); - if (!thumbnail) { + if(!thumbnail) { return TRUE; } // check for a compatible output format - if ((FreeImage_GetImageType(thumbnail) != FIT_BITMAP) || (FreeImage_GetBPP(thumbnail) != 8) && (FreeImage_GetBPP(thumbnail) != 24)) { + if((FreeImage_GetImageType(thumbnail) != FIT_BITMAP) || (FreeImage_GetBPP(thumbnail) != 8) && (FreeImage_GetBPP(thumbnail) != 24)) { FreeImage_OutputMessageProc(s_format_id, FI_MSG_WARNING_INVALID_THUMBNAIL); return FALSE; } @@ -1319,30 +1319,35 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { 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.num_components == 4) && (cinfo.out_color_space == JCS_CMYK)) { + if((cinfo.output_components == 4) && (cinfo.out_color_space == JCS_CMYK)) { // CMYK image - if ((flags & JPEG_CMYK) == JPEG_CMYK) { + 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; + 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; + 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.num_components, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - if (!dib) throw FI_MSG_ERROR_DIB_MEMORY; + 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; - if (cinfo.num_components == 1) { + if (cinfo.output_components == 1) { // build a greyscale palette RGBQUAD *colors = FreeImage_GetPalette(dib); @@ -1385,7 +1390,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // step 7a: while (scan lines remain to be read) jpeg_read_scanlines(...); - if ((cinfo.out_color_space == JCS_CMYK) && ((flags & JPEG_CMYK) != JPEG_CMYK)) { + if((cinfo.out_color_space == JCS_CMYK) && ((flags & JPEG_CMYK) != JPEG_CMYK)) { // convert from CMYK to RGB JSAMPARRAY buffer; // output row buffer @@ -1411,7 +1416,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { dst += 3; } } - } else if ((cinfo.out_color_space == JCS_CMYK) && ((flags & JPEG_CMYK) == JPEG_CMYK)) { + } 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 @@ -1466,7 +1471,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { jpeg_destroy_decompress(&cinfo); // check for automatic Exif rotation - if (!header_only && ((flags & JPEG_EXIFROTATE) == JPEG_EXIFROTATE)) { + if(!header_only && ((flags & JPEG_EXIFROTATE) == JPEG_EXIFROTATE)) { rotate_exif(&dib); } @@ -1560,12 +1565,12 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void jpeg_set_defaults(&cinfo); // progressive-JPEG support - if ((flags & JPEG_PROGRESSIVE) == JPEG_PROGRESSIVE) { + if((flags & JPEG_PROGRESSIVE) == JPEG_PROGRESSIVE) { jpeg_simple_progression(&cinfo); } // compute optimal Huffman coding tables for the image - if ((flags & JPEG_OPTIMIZE) == JPEG_OPTIMIZE) { + if((flags & JPEG_OPTIMIZE) == JPEG_OPTIMIZE) { cinfo.optimize_coding = TRUE; } @@ -1590,7 +1595,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void // set subsampling options if required if(cinfo.in_color_space == JCS_RGB) { - if ((flags & JPEG_SUBSAMPLING_411) == JPEG_SUBSAMPLING_411) { + 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 @@ -1599,7 +1604,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void 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) { + } 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 @@ -1608,7 +1613,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void 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) + } 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 @@ -1619,7 +1624,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void 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) + 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 diff --git a/plugins/AdvaImg/src/FreeImage/PluginPCD.cpp b/plugins/AdvaImg/src/FreeImage/PluginPCD.cpp index 87cbe967b2..ff0c5b8679 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginPCD.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginPCD.cpp @@ -155,7 +155,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { try { // allocate the dib and write out the header dib = FreeImage_AllocateHeader(header_only, width, height, bpp, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - if (!dib) throw FI_MSG_ERROR_DIB_MEMORY; + if(!dib) throw FI_MSG_ERROR_DIB_MEMORY; if(header_only) { return dib; @@ -173,7 +173,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { BYTE *y1 = (BYTE*)malloc(width * sizeof(BYTE)); BYTE *y2 = (BYTE*)malloc(width * sizeof(BYTE)); BYTE *cbcr = (BYTE*)malloc(width * sizeof(BYTE)); - if (!y1 || !y2 || !cbcr) throw FI_MSG_ERROR_MEMORY; + if(!y1 || !y2 || !cbcr) throw FI_MSG_ERROR_MEMORY; BYTE *yl[] = { y1, y2 }; diff --git a/plugins/AdvaImg/src/FreeImage/PluginPCX.cpp b/plugins/AdvaImg/src/FreeImage/PluginPCX.cpp index a6feb5fea7..cd75629ddc 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginPCX.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginPCX.cpp @@ -84,9 +84,9 @@ pcx_validate(FreeImageIO *io, fi_handle handle) { // version if(signature[1] <= 5) { // encoding - if ((signature[2] == 0) || (signature[2] == 1)) { + if((signature[2] == 0) || (signature[2] == 1)) { // bits per pixel per plane - if ((signature[3] == 1) || (signature[3] == 8)) { + if((signature[3] == 1) || (signature[3] == 8)) { return TRUE; } } @@ -339,7 +339,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { BYTE *ReadBuf = NULL; // buffer; BOOL bIsRLE; // True if the file is run-length encoded - if (!handle) { + if(!handle) { return NULL; } @@ -351,7 +351,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { long start_pos = io->tell_proc(handle); BOOL validated = pcx_validate(io, handle); io->seek_proc(handle, start_pos, SEEK_SET); - if (!validated) { + if(!validated) { throw FI_MSG_ERROR_MAGIC_NUMBER; } @@ -478,10 +478,10 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // --------------- line = (BYTE*)malloc(linelength * sizeof(BYTE)); - if (!line) throw FI_MSG_ERROR_MEMORY; + if(!line) throw FI_MSG_ERROR_MEMORY; ReadBuf = (BYTE*)malloc(IO_BUF_SIZE * sizeof(BYTE)); - if (!ReadBuf) throw FI_MSG_ERROR_MEMORY; + if(!ReadBuf) throw FI_MSG_ERROR_MEMORY; bits = FreeImage_GetScanLine(dib, height - 1); @@ -513,7 +513,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { unsigned x, y, written; buffer = (BYTE*)malloc(width * sizeof(BYTE)); - if (!buffer) throw FI_MSG_ERROR_MEMORY; + if(!buffer) throw FI_MSG_ERROR_MEMORY; for (y = 0; y < height; y++) { written = readline(*io, handle, line, linelength, bIsRLE, ReadBuf, &ReadPos); @@ -553,7 +553,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { free(buffer); - } else if ((header.planes == 3) && (header.bpp == 8)) { + } else if((header.planes == 3) && (header.bpp == 8)) { BYTE *pline; for (unsigned y = 0; y < height; y++) { diff --git a/plugins/AdvaImg/src/FreeImage/PluginPFM.cpp b/plugins/AdvaImg/src/FreeImage/PluginPFM.cpp index 8ccbd48ba5..231e8baa22 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginPFM.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginPFM.cpp @@ -48,7 +48,7 @@ pfm_get_line(FreeImageIO *io, fi_handle handle, char *buffer, int length) { int i; memset(buffer, 0, length); for(i = 0; i < length; i++) { - if (!io->read_proc(&buffer[i], 1, 1, handle)) + if(!io->read_proc(&buffer[i], 1, 1, handle)) return FALSE; if(buffer[i] == 0x0A) break; @@ -67,7 +67,7 @@ pfm_get_int(FreeImageIO *io, fi_handle handle) { // skip forward to start of next number - if (!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; + if(!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; while (1) { // eat comments @@ -78,7 +78,7 @@ pfm_get_int(FreeImageIO *io, fi_handle handle) { firstchar = TRUE; while (1) { - if (!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; + if(!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; if (firstchar && c == ' ') { // loop off 1 sp after # @@ -96,7 +96,7 @@ pfm_get_int(FreeImageIO *io, fi_handle handle) { break; } - if (!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; + if(!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; } // we're at the start of a number, continue until we hit a non-number @@ -106,7 +106,7 @@ pfm_get_int(FreeImageIO *io, fi_handle handle) { while (1) { i = (i * 10) + (c - '0'); - if (!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; + if(!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; if (c < '0' || c > '9') break; @@ -231,7 +231,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { if(bResult) { bResult = (sscanf(line_buffer, "%f", &scalefactor) == 1) ? TRUE : FALSE; } - if (!bResult) { + if(!bResult) { throw "Read error: invalid PFM header"; } @@ -251,7 +251,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { if(image_type == FIT_RGBF) { const unsigned lineWidth = 3 * width; lineBuffer = (float*)malloc(lineWidth * sizeof(float)); - if (!lineBuffer) { + if(!lineBuffer) { throw FI_MSG_ERROR_MEMORY; } @@ -285,7 +285,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { } else if(image_type == FIT_FLOAT) { const unsigned lineWidth = width; lineBuffer = (float*)malloc(lineWidth * sizeof(float)); - if (!lineBuffer) { + if(!lineBuffer) { throw FI_MSG_ERROR_MEMORY; } @@ -330,10 +330,10 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { static BOOL DLL_CALLCONV Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) { - if (!dib || !handle) return FALSE; + if(!dib || !handle) return FALSE; FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); - if ((image_type != FIT_RGBF) && (image_type != FIT_FLOAT)) { + if((image_type != FIT_RGBF) && (image_type != FIT_FLOAT)) { return FALSE; } diff --git a/plugins/AdvaImg/src/FreeImage/PluginPICT.cpp b/plugins/AdvaImg/src/FreeImage/PluginPICT.cpp index 0c44cb2d1f..99958a489c 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginPICT.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginPICT.cpp @@ -1168,7 +1168,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // io->seek_proc( handle, 122, SEEK_CUR ); // found = TRUE; BYTE data[ 2 ]; - if ( io->read_proc( data, 2, 1, handle ) ) { + if( io->read_proc( data, 2, 1, handle ) ) { io->seek_proc( handle, -2, SEEK_CUR ); if ( data[0] == 0xFF && data[1] == 0xD8 ) { diff --git a/plugins/AdvaImg/src/FreeImage/PluginPNG.cpp b/plugins/AdvaImg/src/FreeImage/PluginPNG.cpp index ad398a87e8..27fb545161 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginPNG.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginPNG.cpp @@ -104,7 +104,7 @@ ReadMetadata(png_structp png_ptr, png_infop info_ptr, FIBITMAP *dib) { for(int i = 0; i < num_text; i++) { // create a tag tag = FreeImage_CreateTag(); - if (!tag) return FALSE; + if(!tag) return FALSE; DWORD tag_length = (DWORD) MAX(text_ptr[i].text_length, text_ptr[i].itxt_length); @@ -354,7 +354,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { } #ifndef FREEIMAGE_BIGENDIAN - if ((image_type == FIT_UINT16) || (image_type == FIT_RGB16) || (image_type == FIT_RGBA16)) { + if((image_type == FIT_UINT16) || (image_type == FIT_RGB16) || (image_type == FIT_RGBA16)) { // turn on 16 bit byte swapping png_set_swap(png_ptr); } @@ -503,7 +503,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color); - if ((color_type == PNG_COLOR_TYPE_GRAY) && trans_color) { + if((color_type == PNG_COLOR_TYPE_GRAY) && trans_color) { // single transparent color if (trans_color->gray < palette_entries) { BYTE table[256]; @@ -511,7 +511,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { table[trans_color->gray] = 0; FreeImage_SetTransparencyTable(dib, table, palette_entries); } - } else if ((color_type == PNG_COLOR_TYPE_PALETTE) && trans_alpha) { + } else if((color_type == PNG_COLOR_TYPE_PALETTE) && trans_alpha) { // transparency table FreeImage_SetTransparencyTable(dib, (BYTE *)trans_alpha, num_trans); } @@ -726,7 +726,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void pixel_depth = FreeImage_GetBPP(dib); BOOL bInterlaced = FALSE; - if ( (flags & PNG_INTERLACED) == PNG_INTERLACED) { + if( (flags & PNG_INTERLACED) == PNG_INTERLACED) { interlace_type = PNG_INTERLACE_ADAM7; bInterlaced = TRUE; } else { @@ -735,9 +735,9 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void // set the ZLIB compression level or default to PNG default compression level (ZLIB level = 6) int zlib_level = flags & 0x0F; - if ((zlib_level >= 1) && (zlib_level <= 9)) { + if((zlib_level >= 1) && (zlib_level <= 9)) { png_set_compression_level(png_ptr, zlib_level); - } else if ((flags & PNG_Z_NO_COMPRESSION) == PNG_Z_NO_COMPRESSION) { + } else if((flags & PNG_Z_NO_COMPRESSION) == PNG_Z_NO_COMPRESSION) { png_set_compression_level(png_ptr, Z_NO_COMPRESSION); } @@ -758,17 +758,27 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void bit_depth = 16; } + // check for transparent images + BOOL bIsTransparent = + (image_type == FIT_BITMAP) && FreeImage_IsTransparent(dib) && (FreeImage_GetTransparencyCount(dib) > 0) ? TRUE : FALSE; + switch (FreeImage_GetColorType(dib)) { case FIC_MINISWHITE: - // Invert monochrome files to have 0 as black and 1 as white (no break here) - png_set_invert_mono(png_ptr); + if(!bIsTransparent) { + // Invert monochrome files to have 0 as black and 1 as white (no break here) + png_set_invert_mono(png_ptr); + } + // (fall through) case FIC_MINISBLACK: - png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, - PNG_COLOR_TYPE_GRAY, interlace_type, - PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); - - break; + if(!bIsTransparent) { + png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, + PNG_COLOR_TYPE_GRAY, interlace_type, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + break; + } + // If a monochrome image is transparent, save it with a palette + // (fall through) case FIC_PALETTE: { @@ -846,7 +856,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void // set the transparency table - if (FreeImage_IsTransparent(dib) && (FreeImage_GetTransparencyCount(dib) > 0)) { + if (bIsTransparent) { png_set_tRNS(png_ptr, info_ptr, FreeImage_GetTransparencyTable(dib), FreeImage_GetTransparencyCount(dib), NULL); } diff --git a/plugins/AdvaImg/src/FreeImage/PluginPNM.cpp b/plugins/AdvaImg/src/FreeImage/PluginPNM.cpp index a30f858851..3155315559 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginPNM.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginPNM.cpp @@ -37,7 +37,7 @@ GetInt(FreeImageIO *io, fi_handle handle) { // skip forward to start of next number - if (!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; + if(!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; while (1) { // eat comments @@ -48,7 +48,7 @@ GetInt(FreeImageIO *io, fi_handle handle) { firstchar = TRUE; while (1) { - if (!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; + if(!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; if (firstchar && c == ' ') { // loop off 1 sp after # @@ -66,7 +66,7 @@ GetInt(FreeImageIO *io, fi_handle handle) { break; } - if (!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; + if(!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; } // we're at the start of a number, continue until we hit a non-number @@ -76,7 +76,7 @@ GetInt(FreeImageIO *io, fi_handle handle) { while (1) { i = (i * 10) + (c - '0'); - if (!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; + if(!io->read_proc(&c, 1, 1, handle)) throw FI_MSG_ERROR_PARSING; if (c < '0' || c > '9') break; @@ -239,9 +239,9 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { int height = GetInt(io, handle); int maxval = 1; - if ((id_two == '2') || (id_two == '5') || (id_two == '3') || (id_two == '6')) { + if((id_two == '2') || (id_two == '5') || (id_two == '3') || (id_two == '6')) { maxval = GetInt(io, handle); - if ((maxval <= 0) || (maxval > 65535)) { + if((maxval <= 0) || (maxval > 65535)) { FreeImage_OutputMessageProc(s_format_id, "Invalid max value : %d", maxval); throw (const char*)NULL; } @@ -539,7 +539,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void char buffer[256]; // temporary buffer whose size should be enough for what we need - if (!dib || !handle) return FALSE; + if(!dib || !handle) return FALSE; FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib); diff --git a/plugins/AdvaImg/src/FreeImage/PluginRAS.cpp b/plugins/AdvaImg/src/FreeImage/PluginRAS.cpp index 08fc0c9e17..08fd558450 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginRAS.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginRAS.cpp @@ -203,7 +203,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { BYTE *bits; // Pointer to dib data WORD x, y; - if (!handle) { + if(!handle) { return NULL; } @@ -309,7 +309,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // Read SUN raster colormap int numcolors = 1 << header.depth; - if ((DWORD)(3 * numcolors) > header.maplength) { + if((DWORD)(3 * numcolors) > header.maplength) { // some RAS may have less colors than the full palette numcolors = header.maplength / 3; } else { diff --git a/plugins/AdvaImg/src/FreeImage/PluginRAW.cpp b/plugins/AdvaImg/src/FreeImage/PluginRAW.cpp index 4611824f4d..bf5d82169c 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginRAW.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginRAW.cpp @@ -44,56 +44,63 @@ private: FreeImageIO *_io; fi_handle _handle; long _eof; + INT64 _fsize; public: LibRaw_freeimage_datastream(FreeImageIO *io, fi_handle handle) : _io(io), _handle(handle) { long start_pos = io->tell_proc(handle); io->seek_proc(handle, 0, SEEK_END); _eof = io->tell_proc(handle); + _fsize = _eof - start_pos; io->seek_proc(handle, start_pos, SEEK_SET); } + ~LibRaw_freeimage_datastream() { } - virtual void * make_jas_stream() { - return NULL; - } - virtual int valid() { + + int valid() { return (_io && _handle); } - virtual int read(void *buffer, size_t size, size_t count) { + + int read(void *buffer, size_t size, size_t count) { if(substream) return substream->read(buffer, size, count); return _io->read_proc(buffer, (unsigned)size, (unsigned)count, _handle); - } - virtual int eof() { - if(substream) return substream->eof(); - return (_io->tell_proc(_handle) >= _eof); - } - virtual int seek(INT64 offset, int origin) { + } + + int seek(INT64 offset, int origin) { if(substream) return substream->seek(offset, origin); return _io->seek_proc(_handle, (long)offset, origin); - } - virtual INT64 tell() { + } + + INT64 tell() { if(substream) return substream->tell(); return _io->tell_proc(_handle); } - virtual int get_char() { + + INT64 size() { + return _fsize; + } + + int get_char() { int c = 0; if(substream) return substream->get_char(); - if (!_io->read_proc(&c, 1, 1, _handle)) return -1; + if(!_io->read_proc(&c, 1, 1, _handle)) return -1; return c; } - virtual char* gets(char *buffer, int length) { + + char* gets(char *buffer, int length) { if (substream) return substream->gets(buffer, length); memset(buffer, 0, length); for(int i = 0; i < length; i++) { - if (!_io->read_proc(&buffer[i], 1, 1, _handle)) + if(!_io->read_proc(&buffer[i], 1, 1, _handle)) return NULL; if(buffer[i] == 0x0A) break; } return buffer; } - virtual int scanf_one(const char *fmt, void* val) { + + int scanf_one(const char *fmt, void* val) { std::string buffer; char element = 0; bool bDone = false; @@ -118,6 +125,15 @@ public: return sscanf(buffer.c_str(), fmt, val); } + + int eof() { + if(substream) return substream->eof(); + return (_io->tell_proc(_handle) >= _eof); + } + + void * make_jas_stream() { + return NULL; + } }; // ---------------------------------------------------------- @@ -137,7 +153,7 @@ libraw_ConvertToDib(libraw_processed_image_t *image) { if(bpp == 16) { // allocate output dib dib = FreeImage_AllocateT(FIT_RGB16, width, height); - if (!dib) { + if(!dib) { throw FI_MSG_ERROR_DIB_MEMORY; } // write data @@ -154,7 +170,7 @@ libraw_ConvertToDib(libraw_processed_image_t *image) { } else if(bpp == 8) { // allocate output dib dib = FreeImage_AllocateT(FIT_BITMAP, width, height, 24); - if (!dib) { + if(!dib) { throw FI_MSG_ERROR_DIB_MEMORY; } // write data @@ -184,20 +200,20 @@ Get the embedded JPEG preview image from RAW picture with included Exif Data. @return Returns the loaded dib if successfull, returns NULL otherwise */ static FIBITMAP * -libraw_LoadEmbeddedPreview(LibRaw& RawProcessor, int flags) { +libraw_LoadEmbeddedPreview(LibRaw *RawProcessor, int flags) { FIBITMAP *dib = NULL; libraw_processed_image_t *thumb_image = NULL; try { // unpack data - if(RawProcessor.unpack_thumb() != LIBRAW_SUCCESS) { + if(RawProcessor->unpack_thumb() != LIBRAW_SUCCESS) { // run silently "LibRaw : failed to run unpack_thumb" return NULL; } // retrieve thumb image int error_code = 0; - thumb_image = RawProcessor.dcraw_make_mem_thumb(&error_code); + thumb_image = RawProcessor->dcraw_make_mem_thumb(&error_code); if(thumb_image) { if(thumb_image->type != LIBRAW_IMAGE_BITMAP) { // attach the binary data to a memory stream @@ -221,14 +237,14 @@ libraw_LoadEmbeddedPreview(LibRaw& RawProcessor, int flags) { } // clean-up and return - RawProcessor.dcraw_clear_mem(thumb_image); + RawProcessor->dcraw_clear_mem(thumb_image); return dib; } catch(const char *text) { // clean-up and return if(thumb_image) { - RawProcessor.dcraw_clear_mem(thumb_image); + RawProcessor->dcraw_clear_mem(thumb_image); } if(text != NULL) { FreeImage_OutputMessageProc(s_format_id, text); @@ -244,7 +260,7 @@ Load raw data and convert to FIBITMAP @return Returns the loaded dib if successfull, returns NULL otherwise */ static FIBITMAP * -libraw_LoadRawData(LibRaw& RawProcessor, int bitspersample) { +libraw_LoadRawData(LibRaw *RawProcessor, int bitspersample) { FIBITMAP *dib = NULL; libraw_processed_image_t *processed_image = NULL; @@ -253,39 +269,39 @@ libraw_LoadRawData(LibRaw& RawProcessor, int bitspersample) { // ----------------------- // (-6) 16-bit or 8-bit - RawProcessor.imgdata.params.output_bps = bitspersample; + RawProcessor->imgdata.params.output_bps = bitspersample; // (-g power toe_slope) if(bitspersample == 16) { // set -g 1 1 for linear curve - RawProcessor.imgdata.params.gamm[0] = 1; - RawProcessor.imgdata.params.gamm[1] = 1; + RawProcessor->imgdata.params.gamm[0] = 1; + RawProcessor->imgdata.params.gamm[1] = 1; } else if(bitspersample == 8) { // by default settings for rec. BT.709 are used: power 2.222 (i.e. gamm[0]=1/2.222) and slope 4.5 - RawProcessor.imgdata.params.gamm[0] = 1/2.222; - RawProcessor.imgdata.params.gamm[1] = 4.5; + RawProcessor->imgdata.params.gamm[0] = 1/2.222; + RawProcessor->imgdata.params.gamm[1] = 4.5; } // (-W) Don't use automatic increase of brightness by histogram - RawProcessor.imgdata.params.no_auto_bright = 1; + RawProcessor->imgdata.params.no_auto_bright = 1; // (-a) Use automatic white balance obtained after averaging over the entire image - RawProcessor.imgdata.params.use_auto_wb = 1; + RawProcessor->imgdata.params.use_auto_wb = 1; // (-q 3) Adaptive homogeneity-directed demosaicing algorithm (AHD) - RawProcessor.imgdata.params.user_qual = 3; + RawProcessor->imgdata.params.user_qual = 3; // ----------------------- // unpack data - if(RawProcessor.unpack() != LIBRAW_SUCCESS) { + if(RawProcessor->unpack() != LIBRAW_SUCCESS) { throw "LibRaw : failed to unpack data"; } // process data (... most consuming task ...) - if(RawProcessor.dcraw_process() != LIBRAW_SUCCESS) { + if(RawProcessor->dcraw_process() != LIBRAW_SUCCESS) { throw "LibRaw : failed to process data"; } // retrieve processed image int error_code = 0; - processed_image = RawProcessor.dcraw_make_mem_image(&error_code); + processed_image = RawProcessor->dcraw_make_mem_image(&error_code); if(processed_image) { // type SHOULD be LIBRAW_IMAGE_BITMAP, but we'll check if(processed_image->type != LIBRAW_IMAGE_BITMAP) { @@ -303,14 +319,14 @@ libraw_LoadRawData(LibRaw& RawProcessor, int bitspersample) { dib = libraw_ConvertToDib(processed_image); // clean-up and return - RawProcessor.dcraw_clear_mem(processed_image); + RawProcessor->dcraw_clear_mem(processed_image); return dib; } catch(const char *text) { // clean-up and return if(processed_image) { - RawProcessor.dcraw_clear_mem(processed_image); + RawProcessor->dcraw_clear_mem(processed_image); } FreeImage_OutputMessageProc(s_format_id, text); } @@ -396,23 +412,92 @@ MimeType() { return "image/x-dcraw"; } +static BOOL +HasMagicHeader(FreeImageIO *io, fi_handle handle) { + const unsigned signature_size = 32; + BYTE signature[signature_size] = { 0 }; + + // Canon (CR2), Intel byte order + const BYTE CR2_II[] = { 0x49, 0x49, 0x2A, 0x00, 0x10, 0x00, 0x00, 0x00, 0x43, 0x52, 0x02, 0x00 }; + // Canon (CR2), Motorola byte order + const BYTE CR2_MM[] = { 0x4D, 0x4D, 0x2A, 0x00, 0x10, 0x00, 0x00, 0x00, 0x43, 0x52, 0x02, 0x00 }; + // Canon (CRW), Intel byte order + const BYTE CRW_II[] = { 0x49, 0x49, 0x1A, 0x00, 0x00, 0x00, 0x48, 0x45, 0x41, 0x50, 0x43, 0x43, 0x44, 0x52, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + // Minolta (MRW) + const BYTE MRW[] = { 0x00, 0x4D, 0x52, 0x4D, 0x00 }; + // Olympus (ORF), Intel byte order + const BYTE ORF_IIRS[] = { 0x49, 0x49, 0x52, 0x53, 0x08, 0x00, 0x00, 0x00 }; + const BYTE ORF_IIRO[] = { 0x49, 0x49, 0x52, 0x4F, 0x08, 0x00, 0x00, 0x00 }; + // Olympus (ORF), Motorola byte order + const BYTE ORF_MMOR[] = { 0x4D, 0x4D, 0x4F, 0x52, 0x00, 0x00, 0x00, 0x08 }; + // Fujifilm (RAF) + const BYTE RAF[] = { 0x46, 0x55, 0x4A, 0x49, 0x46, 0x49, 0x4C, 0x4D, 0x43, 0x43, 0x44, 0x2D, 0x52, 0x41, 0x57, 0x20, 0x30, 0x32, 0x30, 0x31 }; + // Panasonic (RW2) or Leica (RWL) + const BYTE RW2_II[] = { 0x49, 0x49, 0x55, 0x00, 0x18, 0x00, 0x00, 0x00, 0x88, 0xE7, 0x74, 0xD8, 0xF8, 0x25, 0x1D, 0x4D, 0x94, 0x7A, 0x6E, 0x77, 0x82, 0x2B, 0x5D, 0x6A }; + + if(io->read_proc(signature, 1, signature_size, handle) != signature_size) { + return FALSE; + } + if(memcmp(CR2_II, signature, 12) == 0) + return TRUE; + if(memcmp(CR2_MM, signature, 12) == 0) + return TRUE; + if(memcmp(CRW_II, signature, 26) == 0) + return TRUE; + if(memcmp(MRW, signature, 5) == 0) + return TRUE; + if(memcmp(ORF_IIRS, signature, 8) == 0) + return TRUE; + if(memcmp(ORF_IIRO, signature, 8) == 0) + return TRUE; + if(memcmp(ORF_MMOR, signature, 8) == 0) + return TRUE; + if(memcmp(RAF, signature, 20) == 0) + return TRUE; + if(memcmp(RW2_II, signature, 24) == 0) + return TRUE; + + return FALSE; +} + static BOOL DLL_CALLCONV Validate(FreeImageIO *io, fi_handle handle) { - LibRaw RawProcessor; - BOOL bSuccess = TRUE; - - // wrap the input datastream - LibRaw_freeimage_datastream datastream(io, handle); - - // open the datastream - if(RawProcessor.open_datastream(&datastream) != LIBRAW_SUCCESS) { - bSuccess = FALSE; // LibRaw : failed to open input stream (unknown format) + // some RAW files have a magic signature (most of them have a TIFF signature) + // try to check this in order to speed up the file identification + { + long tell = io->tell_proc(handle); + if( HasMagicHeader(io, handle) ) { + return TRUE; + } else { + io->seek_proc(handle, tell, SEEK_SET); + } } - // clean-up internal memory allocations - RawProcessor.recycle(); + // no magic signature : we need to open the file (it will take more time to identify it) + // do not declare RawProcessor on the stack as it may be huge (300 KB) + { + LibRaw *RawProcessor = new(std::nothrow) LibRaw; + + if(RawProcessor) { + BOOL bSuccess = TRUE; + + // wrap the input datastream + LibRaw_freeimage_datastream datastream(io, handle); - return bSuccess; + // open the datastream + if(RawProcessor->open_datastream(&datastream) != LIBRAW_SUCCESS) { + bSuccess = FALSE; // LibRaw : failed to open input stream (unknown format) + } + + // clean-up internal memory allocations + RawProcessor->recycle(); + delete RawProcessor; + + return bSuccess; + } + } + + return FALSE; } static BOOL DLL_CALLCONV @@ -440,11 +525,17 @@ SupportsNoPixels() { static FIBITMAP * DLL_CALLCONV Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { FIBITMAP *dib = NULL; - LibRaw RawProcessor; + LibRaw *RawProcessor = NULL; BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS; try { + // do not declare RawProcessor on the stack as it may be huge (300 KB) + RawProcessor = new(std::nothrow) LibRaw; + if(!RawProcessor) { + throw FI_MSG_ERROR_MEMORY; + } + // wrap the input datastream LibRaw_freeimage_datastream datastream(io, handle); @@ -453,30 +544,30 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // -------------------------------------------- // (-s [0..N-1]) Select one raw image from input file - RawProcessor.imgdata.params.shot_select = 0; + RawProcessor->imgdata.params.shot_select = 0; // (-w) Use camera white balance, if possible (otherwise, fallback to auto_wb) - RawProcessor.imgdata.params.use_camera_wb = 1; + RawProcessor->imgdata.params.use_camera_wb = 1; // (-h) outputs the image in 50% size - RawProcessor.imgdata.params.half_size = ((flags & RAW_HALFSIZE) == RAW_HALFSIZE) ? 1 : 0; + RawProcessor->imgdata.params.half_size = ((flags & RAW_HALFSIZE) == RAW_HALFSIZE) ? 1 : 0; // open the datastream - if(RawProcessor.open_datastream(&datastream) != LIBRAW_SUCCESS) { + if(RawProcessor->open_datastream(&datastream) != LIBRAW_SUCCESS) { throw "LibRaw : failed to open input stream (unknown format)"; } if(header_only) { // header only mode - dib = FreeImage_AllocateHeaderT(header_only, FIT_RGB16, RawProcessor.imgdata.sizes.width, RawProcessor.imgdata.sizes.height); + dib = FreeImage_AllocateHeaderT(header_only, FIT_RGB16, RawProcessor->imgdata.sizes.width, RawProcessor->imgdata.sizes.height); } - else if ((flags & RAW_PREVIEW) == RAW_PREVIEW) { + else if((flags & RAW_PREVIEW) == RAW_PREVIEW) { // try to get the embedded JPEG dib = libraw_LoadEmbeddedPreview(RawProcessor, 0); - if (!dib) { + if(!dib) { // no JPEG preview: try to load as 8-bit/sample (i.e. RGB 24-bit) dib = libraw_LoadRawData(RawProcessor, 8); } } - else if ((flags & RAW_DISPLAY) == RAW_DISPLAY) { + else if((flags & RAW_DISPLAY) == RAW_DISPLAY) { // load raw data as 8-bit/sample (i.e. RGB 24-bit) dib = libraw_LoadRawData(RawProcessor, 8); } @@ -486,8 +577,8 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { } // save ICC profile if present - if(dib && (NULL != RawProcessor.imgdata.color.profile)) { - FreeImage_CreateICCProfile(dib, RawProcessor.imgdata.color.profile, RawProcessor.imgdata.color.profile_length); + if(dib && (NULL != RawProcessor->imgdata.color.profile)) { + FreeImage_CreateICCProfile(dib, RawProcessor->imgdata.color.profile, RawProcessor->imgdata.color.profile_length); } // try to get JPEG embedded Exif metadata @@ -500,15 +591,19 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { } // clean-up internal memory allocations - RawProcessor.recycle(); + RawProcessor->recycle(); + delete RawProcessor; return dib; } catch(const char *text) { + if(RawProcessor) { + RawProcessor->recycle(); + delete RawProcessor; + } if(dib) { FreeImage_Unload(dib); } - RawProcessor.recycle(); FreeImage_OutputMessageProc(s_format_id, text); } diff --git a/plugins/AdvaImg/src/FreeImage/PluginSGI.cpp b/plugins/AdvaImg/src/FreeImage/PluginSGI.cpp index 3ac189e0ef..0fd162b1d4 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginSGI.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginSGI.cpp @@ -265,7 +265,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // read the Offset Tables int index_len = height * zsize; pRowIndex = (LONG*)malloc(index_len * sizeof(LONG)); - if (!pRowIndex) { + if(!pRowIndex) { throw FI_MSG_ERROR_MEMORY; } @@ -282,7 +282,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // Discard row size index for (i = 0; i < (int)(index_len * sizeof(LONG)); i++) { BYTE packed = 0; - if ( io->read_proc(&packed, sizeof(BYTE), 1, handle) < 1 ) { + if( io->read_proc(&packed, sizeof(BYTE), 1, handle) < 1 ) { throw SGI_EOF_IN_RLE_INDEX; } } @@ -307,7 +307,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { } dib = FreeImage_Allocate(width, height, bitcount); - if (!dib) { + if(!dib) { throw FI_MSG_ERROR_DIB_MEMORY; } diff --git a/plugins/AdvaImg/src/FreeImage/PluginTARGA.cpp b/plugins/AdvaImg/src/FreeImage/PluginTARGA.cpp index 4e3f1a720a..5fb1f53ee0 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginTARGA.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginTARGA.cpp @@ -176,7 +176,7 @@ FIBITMAP* TargaThumbnail::toFIBITMAP() { const unsigned line_size = _depth * _w / 8; FIBITMAP* dib = FreeImage_Allocate(_w, _h, _depth); - if (!dib) { + if(!dib) { return NULL; } @@ -1203,14 +1203,14 @@ saveRLE(FIBITMAP* dib, FreeImageIO* io, fi_handle handle) { // read next pixel from dib - if ( x + 1*pixel_size < line_size) { + if( x + 1*pixel_size < line_size) { AssignPixel(next, (bits + x + 1*pixel_size), pixel_size); } else { // last pixel in line // include current pixel and flush - if (!has_rle) { + if(!has_rle) { writeToPacket(packet, current, pixel_size); packet += pixel_size; @@ -1231,7 +1231,7 @@ saveRLE(FIBITMAP* dib, FreeImageIO* io, fi_handle handle) { // has rle - if (!has_rle) { + if(!has_rle) { // flush non rle packet flushPacket(line, pixel_size, packet_begin, packet, packet_count, has_rle); diff --git a/plugins/AdvaImg/src/FreeImage/PluginTIFF.cpp b/plugins/AdvaImg/src/FreeImage/PluginTIFF.cpp index 54f81e0938..72218a2564 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginTIFF.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginTIFF.cpp @@ -153,7 +153,7 @@ _tiffWriteProc(thandle_t handle, void *buf, tmsize_t size) { static toff_t _tiffSeekProc(thandle_t handle, toff_t off, int whence) { fi_TIFFIO *fio = (fi_TIFFIO*)handle; - fio->io->seek_proc(fio->handle, off, whence); + fio->io->seek_proc(fio->handle, (long)off, whence); return fio->io->tell_proc(fio->handle); } @@ -450,7 +450,7 @@ static FIBITMAP* CreateImageType(BOOL header_only, FREE_IMAGE_TYPE fit, int width, int height, uint16 bitspersample, uint16 samplesperpixel) { FIBITMAP *dib = NULL; - if ((width < 0) || (height < 0)) { + if((width < 0) || (height < 0)) { // check for malicious images return NULL; } @@ -462,7 +462,7 @@ CreateImageType(BOOL header_only, FREE_IMAGE_TYPE fit, int width, int height, ui if(bpp == 16) { - if ((samplesperpixel == 2) && (bitspersample == 8)) { + if((samplesperpixel == 2) && (bitspersample == 8)) { // 8-bit indexed + 8-bit alpha channel -> convert to 8-bit transparent dib = FreeImage_AllocateHeader(header_only, width, height, 8); } else { @@ -562,7 +562,7 @@ ReadImageType(TIFF *tiff, uint16 bitspersample, uint16 samplesperpixel) { break; case 48: // 3 x half float => convert to RGBF - if ((samplesperpixel == 3) && (bitspersample == 16)) { + if((samplesperpixel == 3) && (bitspersample == 16)) { fit = FIT_RGBF; } break; @@ -683,7 +683,7 @@ WriteCompression(TIFF *tiff, uint16 bitspersample, uint16 samplesperpixel, uint1 } else if ((flags & TIFF_LZW) == TIFF_LZW) { compression = COMPRESSION_LZW; } else if ((flags & TIFF_JPEG) == TIFF_JPEG) { - if (((bitsperpixel == 8) && (photometric != PHOTOMETRIC_PALETTE)) || (bitsperpixel == 24)) { + if(((bitsperpixel == 8) && (photometric != PHOTOMETRIC_PALETTE)) || (bitsperpixel == 24)) { compression = COMPRESSION_JPEG; // RowsPerStrip must be multiple of 8 for JPEG uint32 rowsperstrip = (uint32) -1; @@ -736,7 +736,7 @@ WriteCompression(TIFF *tiff, uint16 bitspersample, uint16 samplesperpixel, uint1 // and many palette-color images. But natural 24-bit color images and some 8-bit // grayscale images do much better with differencing. - if ((bitspersample == 8) || (bitspersample == 16)) { + if((bitspersample == 8) || (bitspersample == 16)) { if ((bitsperpixel >= 8) && (photometric != PHOTOMETRIC_PALETTE)) { TIFFSetField(tiff, TIFFTAG_PREDICTOR, 2); } else { @@ -746,13 +746,20 @@ WriteCompression(TIFF *tiff, uint16 bitspersample, uint16 samplesperpixel, uint1 TIFFSetField(tiff, TIFFTAG_PREDICTOR, 1); } } - else if(compression == COMPRESSION_CCITTFAX3) { - // try to be compliant with the TIFF Class F specification - // that documents the TIFF tags specific to FAX applications - // see http://palimpsest.stanford.edu/bytopic/imaging/std/tiff-f.html - uint32 group3options = GROUP3OPT_2DENCODING | GROUP3OPT_FILLBITS; - TIFFSetField(tiff, TIFFTAG_GROUP3OPTIONS, group3options); // 2d-encoded, has aligned EOL - TIFFSetField(tiff, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB); // lsb-to-msb fillorder + else if((compression == COMPRESSION_CCITTFAX3) || (compression == COMPRESSION_CCITTFAX4)) { + uint32 imageLength = 0; + TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &imageLength); + // overwrite previous RowsPerStrip + TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, imageLength); + + if(compression == COMPRESSION_CCITTFAX3) { + // try to be compliant with the TIFF Class F specification + // that documents the TIFF tags specific to FAX applications + // see http://palimpsest.stanford.edu/bytopic/imaging/std/tiff-f.html + uint32 group3options = GROUP3OPT_2DENCODING | GROUP3OPT_FILLBITS; + TIFFSetField(tiff, TIFFTAG_GROUP3OPTIONS, group3options); // 2d-encoded, has aligned EOL + TIFFSetField(tiff, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB); // lsb-to-msb fillorder + } } } @@ -793,7 +800,7 @@ tiff_read_xmp_profile(TIFF *tiff, FIBITMAP *dib) { if (TIFFGetField(tiff, TIFFTAG_XMLPACKET, &profile_size, &profile) == 1) { // create a tag FITAG *tag = FreeImage_CreateTag(); - if (!tag) return FALSE; + if(!tag) return FALSE; FreeImage_SetTagID(tag, TIFFTAG_XMLPACKET); // 700 FreeImage_SetTagKey(tag, g_TagLib_XMPFieldName); @@ -832,7 +839,7 @@ tiff_read_exif_profile(TIFF *tiff, FIBITMAP *dib) { if(TIFFGetField(tiff, TIFFTAG_EXIFIFD, &exif_offset)) { // read EXIF tags - if (!TIFFReadEXIFDirectory(tiff, exif_offset)) { + if(!TIFFReadEXIFDirectory(tiff, exif_offset)) { return FALSE; } @@ -877,7 +884,7 @@ tiff_write_iptc_profile(TIFF *tiff, FIBITMAP *dib) { uint32 iptc_size = profile_size; iptc_size += (4-(iptc_size & 0x03)); // Round up for long word alignment BYTE *iptc_profile = (BYTE*)malloc(iptc_size); - if (!iptc_profile) { + if(!iptc_profile) { free(profile); return FALSE; } @@ -986,17 +993,22 @@ MimeType() { static BOOL DLL_CALLCONV Validate(FreeImageIO *io, fi_handle handle) { - BYTE tiff_id1[] = { 0x49, 0x49, 0x2A, 0x00 }; - BYTE tiff_id2[] = { 0x4D, 0x4D, 0x00, 0x2A }; + BYTE tiff_id1[] = { 0x49, 0x49, 0x2A, 0x00 }; // Classic TIFF, little-endian + BYTE tiff_id2[] = { 0x4D, 0x4D, 0x00, 0x2A }; // Classic TIFF, big-endian + BYTE tiff_id3[] = { 0x49, 0x49, 0x2B, 0x00 }; // Big TIFF, little-endian + BYTE tiff_id4[] = { 0x4D, 0x4D, 0x00, 0x2B }; // Big TIFF, big-endian BYTE signature[4] = { 0, 0, 0, 0 }; io->read_proc(signature, 1, 4, handle); if(memcmp(tiff_id1, signature, 4) == 0) return TRUE; - if(memcmp(tiff_id2, signature, 4) == 0) return TRUE; + if(memcmp(tiff_id3, signature, 4) == 0) + return TRUE; + if(memcmp(tiff_id4, signature, 4) == 0) + return TRUE; return FALSE; } @@ -1046,7 +1058,7 @@ static void * DLL_CALLCONV Open(FreeImageIO *io, fi_handle handle, BOOL read) { // wrapper for TIFF I/O fi_TIFFIO *fio = (fi_TIFFIO*)malloc(sizeof(fi_TIFFIO)); - if (!fio) return NULL; + if(!fio) return NULL; fio->io = io; fio->handle = handle; @@ -1106,7 +1118,7 @@ IsValidBitsPerSample(uint16 photometric, uint16 bitspersample, uint16 samplesper switch(bitspersample) { case 1: case 4: - if ((photometric == PHOTOMETRIC_MINISWHITE) || (photometric == PHOTOMETRIC_MINISBLACK) || (photometric == PHOTOMETRIC_PALETTE)) { + if((photometric == PHOTOMETRIC_MINISWHITE) || (photometric == PHOTOMETRIC_MINISBLACK) || (photometric == PHOTOMETRIC_PALETTE)) { return TRUE; } else { return FALSE; @@ -1155,12 +1167,12 @@ FindLoadMethod(TIFF *tif, FREE_IMAGE_TYPE image_type, int flags) { switch(photometric) { // convert to 24 or 32 bits RGB if the image is full color case PHOTOMETRIC_RGB: - if ((image_type == FIT_RGB16) || (image_type == FIT_RGBA16)) { + if((image_type == FIT_RGB16) || (image_type == FIT_RGBA16)) { // load 48-bit RGB and 64-bit RGBA without conversion loadMethod = LoadAsGenericStrip; } else if(image_type == FIT_RGBF) { - if ((samplesperpixel == 3) && (bitspersample == 16)) { + if((samplesperpixel == 3) && (bitspersample == 16)) { // load 3 x 16-bit half as RGBF loadMethod = LoadAsHalfFloat; } @@ -1182,7 +1194,7 @@ FindLoadMethod(TIFF *tif, FREE_IMAGE_TYPE image_type, int flags) { // to avoid multiple conversions. Conversion can be done by changing // the profile from it's original CMYK to an RGB profile with an // apropriate color management system. Works with non-tiled TIFFs. - if (!bIsTiled) { + if(!bIsTiled) { loadMethod = LoadAsCMYK; } break; @@ -1192,7 +1204,7 @@ FindLoadMethod(TIFF *tif, FREE_IMAGE_TYPE image_type, int flags) { // When samplesperpixel = 2 and bitspersample = 8, set the image as a // 8-bit indexed image + 8-bit alpha layer image // and convert to a 8-bit image with a transparency table - if ((samplesperpixel > 1) && (bitspersample == 8)) { + if((samplesperpixel > 1) && (bitspersample == 8)) { loadMethod = LoadAs8BitTrns; } else { loadMethod = LoadAsGenericStrip; @@ -1203,7 +1215,7 @@ FindLoadMethod(TIFF *tif, FREE_IMAGE_TYPE image_type, int flags) { break; } - if ((loadMethod == LoadAsGenericStrip) && bIsTiled) { + if((loadMethod == LoadAsGenericStrip) && bIsTiled) { loadMethod = LoadAsTiled; } @@ -1249,7 +1261,7 @@ ReadThumbnail(FreeImageIO *io, fi_handle handle, void *data, TIFF *tiff, FIBITMA // ... or read the first subIFD - if (!thumbnail) { + if(!thumbnail) { uint16 subIFD_count = 0; uint64* subIFD_offsets = NULL; // ### Theoretically this should also read the first subIFD from a Photoshop-created file with "pyramid". @@ -1276,7 +1288,7 @@ ReadThumbnail(FreeImageIO *io, fi_handle handle, void *data, TIFF *tiff, FIBITMA // ... or read Photoshop thumbnail - if (!thumbnail) { + if(!thumbnail) { uint32 ps_size = 0; void *ps_data = NULL; @@ -1399,7 +1411,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { uint32 *raster = NULL; - if (!header_only) { + if(!header_only) { raster = (uint32*)_TIFFmalloc(width * height * sizeof(uint32)); if (raster == NULL) { @@ -1443,7 +1455,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { ReadResolution(tif, dib); - if (!header_only) { + if(!header_only) { // read the raster lines and save them in the DIB // with RGB mode, we have to change the order of the 3 samples RGB @@ -1636,7 +1648,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { alpha = FreeImage_Allocate(width, height, 8); } - if (!alpha) { + if(!alpha) { FreeImage_OutputMessageProc(s_format_id, "Failed to allocate temporary alpha channel"); } else { alpha_bits = FreeImage_GetScanLine(alpha, height - 1); @@ -1658,7 +1670,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { ReadResolution(tif, dib); - if (!header_only) { + if(!header_only) { // calculate the line + pitch (separate for scr & dest) @@ -1706,7 +1718,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { for(BYTE *pixel = bits, *al_pixel = alpha_bits, *src_pixel = buf + l * src_line; pixel < bits + dib_pitch; pixel += dibBpp, al_pixel += alpha_Bpp, src_pixel += srcBpp) { // copy pixel byte by byte BYTE b = 0; - for ( ; b < dibBpp; ++b) { + for( ; b < dibBpp; ++b) { pixel[b] = src_pixel[b]; } // TODO write the remaining bytes to extra channel(s) @@ -1814,7 +1826,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { free(buf); - if (!asCMYK) { + if(!asCMYK) { ConvertCMYKtoRGBA(dib); // The ICC Profile is invalid, clear it @@ -1862,7 +1874,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { ReadPalette(tif, photometric, bitspersample, dib); - if (!header_only) { + if(!header_only) { // calculate the line + pitch (separate for scr & dest) const tmsize_t src_line = TIFFScanlineSize(tif); @@ -2000,7 +2012,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { ReadPalette(tif, photometric, bitspersample, dib); // get the tile geometry - if (!TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tileWidth) || !TIFFGetField(tif, TIFFTAG_TILELENGTH, &tileHeight)) { + if(!TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tileWidth) || !TIFFGetField(tif, TIFFTAG_TILELENGTH, &tileHeight)) { throw "Invalid tiled TIFF image"; } @@ -2142,7 +2154,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { ReadResolution(tif, dib); - if (!header_only) { + if(!header_only) { // calculate the line + pitch (separate for scr & dest) @@ -2268,7 +2280,7 @@ SaveOneTIFF(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flag bitspersample = bitsperpixel / samplesperpixel; photometric = GetPhotometric(dib); - if ((bitsperpixel == 8) && FreeImage_IsTransparent(dib)) { + if((bitsperpixel == 8) && FreeImage_IsTransparent(dib)) { // 8-bit transparent picture : convert later to 8-bit + 8-bit alpha samplesperpixel = 2; bitspersample = 8; @@ -2276,7 +2288,7 @@ SaveOneTIFF(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flag else if(bitsperpixel == 32) { // 32-bit images : check for CMYK or alpha transparency - if ((((iccProfile->flags & FIICC_COLOR_IS_CMYK) == FIICC_COLOR_IS_CMYK) || ((flags & TIFF_CMYK) == TIFF_CMYK))) { + if((((iccProfile->flags & FIICC_COLOR_IS_CMYK) == FIICC_COLOR_IS_CMYK) || ((flags & TIFF_CMYK) == TIFF_CMYK))) { // CMYK support photometric = PHOTOMETRIC_SEPARATED; TIFFSetField(out, TIFFTAG_INKSET, INKSET_CMYK); @@ -2301,7 +2313,7 @@ SaveOneTIFF(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flag samplesperpixel = 4; bitspersample = bitsperpixel / samplesperpixel; - if ((((iccProfile->flags & FIICC_COLOR_IS_CMYK) == FIICC_COLOR_IS_CMYK) || ((flags & TIFF_CMYK) == TIFF_CMYK))) { + if((((iccProfile->flags & FIICC_COLOR_IS_CMYK) == FIICC_COLOR_IS_CMYK) || ((flags & TIFF_CMYK) == TIFF_CMYK))) { // CMYK support photometric = PHOTOMETRIC_SEPARATED; TIFFSetField(out, TIFFTAG_INKSET, INKSET_CMYK); @@ -2321,7 +2333,7 @@ SaveOneTIFF(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flag samplesperpixel = 3; bitspersample = bitsperpixel / samplesperpixel; // the library converts to and from floating-point XYZ CIE values - if ((flags & TIFF_LOGLUV) == TIFF_LOGLUV) { + if((flags & TIFF_LOGLUV) == TIFF_LOGLUV) { photometric = PHOTOMETRIC_LOGLUV; TIFFSetField(out, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_FLOAT); // TIFFSetField(out, TIFFTAG_STONITS, 1.0); // assume unknown @@ -2421,7 +2433,7 @@ SaveOneTIFF(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flag // thumbnail tag - if ((ifd == 0) && (ifdCount > 1)) { + if((ifd == 0) && (ifdCount > 1)) { uint16 nsubifd = 1; uint64 subifd[1]; subifd[0] = 0; @@ -2442,7 +2454,7 @@ SaveOneTIFF(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flag case 4 : case 8 : { - if ((bitsperpixel == 8) && FreeImage_IsTransparent(dib)) { + if((bitsperpixel == 8) && FreeImage_IsTransparent(dib)) { // 8-bit transparent picture : convert to 8-bit + 8-bit alpha // get the transparency table @@ -2564,7 +2576,7 @@ SaveOneTIFF(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flag // write out the directory tag if we wrote a page other than -1 or if we have a thumbnail to write later - if ( (page >= 0) || ((ifd == 0) && (ifdCount > 1)) ) { + if( (page >= 0) || ((ifd == 0) && (ifdCount > 1)) ) { TIFFWriteDirectory(out); // else: TIFFClose will WriteDirectory } @@ -2594,7 +2606,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void } bResult = SaveOneTIFF(io, bitmap, handle, page, flags, data, ifd, ifdCount); - if (!bResult) { + if(!bResult) { return FALSE; } } diff --git a/plugins/AdvaImg/src/FreeImage/PluginXBM.cpp b/plugins/AdvaImg/src/FreeImage/PluginXBM.cpp index 140029e862..0aac48ca27 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginXBM.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginXBM.cpp @@ -109,14 +109,14 @@ readXBMFile(FreeImageIO *io, fi_handle handle, int *widthP, int *heightP, char * while(!found_declaration && !eof) { - if ( readLine(line, MAX_LINE, io, handle) == NULL) { + if( readLine(line, MAX_LINE, io, handle) == NULL) { eof = TRUE; } else { - if ( strlen( line ) == MAX_LINE - 1 ) + if( strlen( line ) == MAX_LINE - 1 ) return( ERR_XBM_LINE ); - if ( sscanf(line, "#define %s %d", name_and_type, &v) == 2 ) { - if ( ( t = strrchr( name_and_type, '_' ) ) == NULL ) + if( sscanf(line, "#define %s %d", name_and_type, &v) == 2 ) { + if( ( t = strrchr( name_and_type, '_' ) ) == NULL ) t = name_and_type; else t++; @@ -127,11 +127,11 @@ readXBMFile(FreeImageIO *io, fi_handle handle, int *widthP, int *heightP, char * continue; } - if ( sscanf( line, "static short %s = {", name_and_type ) == 1 ) { + if( sscanf( line, "static short %s = {", name_and_type ) == 1 ) { version = 10; found_declaration = TRUE; } - else if ( sscanf( line, "static char %s = {", name_and_type ) == 1 ) { + else if( sscanf( line, "static char %s = {", name_and_type ) == 1 ) { version = 11; found_declaration = TRUE; } @@ -142,12 +142,12 @@ readXBMFile(FreeImageIO *io, fi_handle handle, int *widthP, int *heightP, char * } } - if (!found_declaration) + if(!found_declaration) return( ERR_XBM_DECL ); - if (*widthP == -1 ) + if(*widthP == -1 ) return( ERR_XBM_WIDTH ); - if ( *heightP == -1 ) + if( *heightP == -1 ) return( ERR_XBM_HEIGHT ); padding = 0; @@ -189,7 +189,7 @@ readXBMFile(FreeImageIO *io, fi_handle handle, int *widthP, int *heightP, char * hex_table['f'] = 15; if(version == 10) { - for ( bytes = 0, ptr = *dataP; bytes < raster_length; bytes += 2 ) { + for( bytes = 0, ptr = *dataP; bytes < raster_length; bytes += 2 ) { while( ( c1 = readChar(io, handle) ) != 'x' ) { if ( c1 == EOF ) return( ERR_XBM_EOFREAD ); @@ -197,14 +197,14 @@ readXBMFile(FreeImageIO *io, fi_handle handle, int *widthP, int *heightP, char * c1 = readChar(io, handle); c2 = readChar(io, handle); - if ( c1 == EOF || c2 == EOF ) + if( c1 == EOF || c2 == EOF ) return( ERR_XBM_EOFREAD ); value1 = ( hex_table[c1] << 4 ) + hex_table[c2]; if ( value1 >= 256 ) return( ERR_XBM_SYNTAX ); c1 = readChar(io, handle); c2 = readChar(io, handle); - if ( c1 == EOF || c2 == EOF ) + if( c1 == EOF || c2 == EOF ) return( ERR_XBM_EOFREAD ); value2 = ( hex_table[c1] << 4 ) + hex_table[c2]; if ( value2 >= 256 ) @@ -219,7 +219,7 @@ readXBMFile(FreeImageIO *io, fi_handle handle, int *widthP, int *heightP, char * /* ** skip until digit is found */ - for ( ; ; ) { + for( ; ; ) { c1 = readChar(io, handle); if ( c1 == EOF ) return( ERR_XBM_EOFREAD ); @@ -230,7 +230,7 @@ readXBMFile(FreeImageIO *io, fi_handle handle, int *widthP, int *heightP, char * /* ** loop on digits */ - for ( ; ; ) { + for( ; ; ) { c2 = readChar(io, handle); if ( c2 == EOF ) return( ERR_XBM_EOFREAD ); @@ -327,7 +327,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // allocate a new dib dib = FreeImage_Allocate(width, height, 1); - if (!dib) throw (char*)ERR_XBM_MEMORY; + if(!dib) throw (char*)ERR_XBM_MEMORY; // write the palette data RGBQUAD *pal = FreeImage_GetPalette(dib); @@ -347,7 +347,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { count = 0; mask = 1; } - if (*bP & mask) { + if(*bP & mask) { // Set bit(x, y) to 0 bits[x >> 3] &= (0xFF7F >> (x & 0x7)); } else { diff --git a/plugins/AdvaImg/src/FreeImage/PluginXPM.cpp b/plugins/AdvaImg/src/FreeImage/PluginXPM.cpp index 16db443c47..a698321958 100644 --- a/plugins/AdvaImg/src/FreeImage/PluginXPM.cpp +++ b/plugins/AdvaImg/src/FreeImage/PluginXPM.cpp @@ -53,7 +53,7 @@ FindChar(FreeImageIO *io, fi_handle handle, BYTE look_for) { BYTE c; io->read_proc(&c, sizeof(BYTE), 1, handle); while(c != look_for) { - if ( io->read_proc(&c, sizeof(BYTE), 1, handle) != 1 ) + if( io->read_proc(&c, sizeof(BYTE), 1, handle) != 1 ) return FALSE; } return TRUE; @@ -62,14 +62,14 @@ FindChar(FreeImageIO *io, fi_handle handle, BYTE look_for) { // find start of string, read data until ending quote found, allocate memory and return a string static char * ReadString(FreeImageIO *io, fi_handle handle) { - if ( !FindChar(io, handle,'"') ) + if( !FindChar(io, handle,'"') ) return NULL; BYTE c; std::string s; io->read_proc(&c, sizeof(BYTE), 1, handle); while(c != '"') { s += c; - if ( io->read_proc(&c, sizeof(BYTE), 1, handle) != 1 ) + if( io->read_proc(&c, sizeof(BYTE), 1, handle) != 1 ) return NULL; } char *cstr = (char *)malloc(s.length()+1); @@ -166,16 +166,16 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS; //find the starting brace - if ( !FindChar(io, handle,'{') ) + if( !FindChar(io, handle,'{') ) throw "Could not find starting brace"; //read info string str = ReadString(io, handle); - if (!str) + if(!str) throw "Error reading info string"; int width, height, colors, cpp; - if ( sscanf(str, "%d %d %d %d", &width, &height, &colors, &cpp) != 4 ) { + if( sscanf(str, "%d %d %d %d", &width, &height, &colors, &cpp) != 4 ) { free(str); throw "Improperly formed info string"; } @@ -193,7 +193,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { FILE_RGBA rgba; str = ReadString(io, handle); - if (!str) + if(!str) throw "Error reading color strings"; std::string chrs(str,cpp); //create a string for the color chars using the first cpp chars @@ -207,14 +207,14 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { } //prefer the color visual - if ( strstr(keys," c ") ) { + if( strstr(keys," c ") ) { char *clr = strstr(keys," c ") + 3; while( *clr == ' ' ) clr++; //find the start of the hex rgb value - if ( *clr == '#' ) { + if( *clr == '#' ) { int red = 0, green = 0, blue = 0, n; clr++; //end string at first space, if any found - if ( strchr(clr,' ') ) + if( strchr(clr,' ') ) *(strchr(clr,' ')) = '\0'; //parse hex color, it can be #rgb #rrggbb #rrrgggbbb or #rrrrggggbbbb switch( strlen(clr) ) { @@ -239,14 +239,14 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { n = 0; break; } - if ( n != 3 ) { + if( n != 3 ) { free(str); throw "Improperly formed hex color value"; } rgba.r = (BYTE)red; rgba.g = (BYTE)green; rgba.b = (BYTE)blue; - } else if ( !strncmp(clr,"None",4) || !strncmp(clr,"none",4) ) { + } else if( !strncmp(clr,"None",4) || !strncmp(clr,"none",4) ) { rgba.r = rgba.g = rgba.b = 0xFF; } else { char *tmp = clr; @@ -256,8 +256,8 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { //part of the color name. How many named color end with a 1 or 2 character //word? Probably none in our list at least. while( (tmp = strchr(tmp,' ')) != NULL ) { - if ( tmp[1] != ' ' ) { - if ( (tmp[2] == ' ') || (tmp[2] != ' ' && tmp[3] == ' ') ) { + if( tmp[1] != ' ' ) { + if( (tmp[2] == ' ') || (tmp[2] != ' ' && tmp[3] == ' ') ) { tmp[0] = '\0'; break; } @@ -288,7 +288,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { rawpal[chrs] = rgba; //build palette if needed - if ( colors <= 256 ) { + if( colors <= 256 ) { RGBQUAD *pal = FreeImage_GetPalette(dib); pal[i].rgbBlue = rgba.b; pal[i].rgbGreen = rgba.g; @@ -308,7 +308,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { for(int y = 0; y < height; y++ ) { BYTE *line = FreeImage_GetScanLine(dib, height - y - 1); str = ReadString(io, handle); - if (!str) + if(!str) throw "Error reading pixel strings"; char *pixel_ptr = str; @@ -317,7 +317,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { std::string chrs(pixel_ptr,cpp); FILE_RGBA rgba = rawpal[chrs]; - if ( colors > 256 ) { + if( colors > 256 ) { line[FI_RGBA_BLUE] = rgba.b; line[FI_RGBA_GREEN] = rgba.g; line[FI_RGBA_RED] = rgba.r; @@ -338,7 +338,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { } catch(const char *text) { FreeImage_OutputMessageProc(s_format_id, text); - if ( dib != NULL ) + if( dib != NULL ) FreeImage_Unload(dib); return NULL; @@ -355,7 +355,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void footer[] = "\"\n};\n", buf[256]; //256 is more then enough to sprintf 4 ints into, or the base-92 chars and #rrggbb line - if ( io->write_proc(header, (unsigned int)strlen(header), 1, handle) != 1 ) + if( io->write_proc(header, (unsigned int)strlen(header), 1, handle) != 1 ) return FALSE; int width = FreeImage_GetWidth(dib), height = FreeImage_GetHeight(dib), bpp = FreeImage_GetBPP(dib); @@ -378,7 +378,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void for(x = 0; x < width; x++ ) { FILE_RGB rgb; DWORDRGBA u; - if ( bpp > 8 ) { + if( bpp > 8 ) { u.rgba.b = rgb.b = line[FI_RGBA_BLUE]; u.rgba.g = rgb.g = line[FI_RGBA_GREEN]; u.rgba.r = rgb.r = line[FI_RGBA_RED]; @@ -391,7 +391,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void rgb.r = pal[u.index].rgbRed; line++; } - if ( color2chrs.find(u.index) == color2chrs.end() ) { //new color + if( color2chrs.find(u.index) == color2chrs.end() ) { //new color std::string chrs(Base92(num_colors)); color2chrs[u.index] = chrs; chrs2color[num_colors] = rgb; @@ -403,22 +403,22 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void int cpp = (int)(log((double)num_colors)/log(92.0)) + 1; sprintf(buf, "%d %d %d %d", FreeImage_GetWidth(dib), FreeImage_GetHeight(dib), num_colors, cpp ); - if ( io->write_proc(buf, (unsigned int)strlen(buf), 1, handle) != 1 ) + if( io->write_proc(buf, (unsigned int)strlen(buf), 1, handle) != 1 ) return FALSE; - if ( io->write_proc(start_colors, (unsigned int)strlen(start_colors), 1, handle) != 1 ) + if( io->write_proc(start_colors, (unsigned int)strlen(start_colors), 1, handle) != 1 ) return FALSE; //write colors, using map of chrs->rgb for(x = 0; x < num_colors; x++ ) { sprintf(buf, "%*s c #%02x%02x%02x", cpp, Base92(x), chrs2color[x].r, chrs2color[x].g, chrs2color[x].b ); - if ( io->write_proc(buf, (unsigned int)strlen(buf), 1, handle) != 1 ) + if( io->write_proc(buf, (unsigned int)strlen(buf), 1, handle) != 1 ) return FALSE; - if ( x == num_colors - 1 ) { - if ( io->write_proc(start_pixels, (unsigned int)strlen(start_pixels), 1, handle) != 1 ) + if( x == num_colors - 1 ) { + if( io->write_proc(start_pixels, (unsigned int)strlen(start_pixels), 1, handle) != 1 ) return FALSE; } else { - if ( io->write_proc(new_line, (unsigned int)strlen(new_line), 1, handle) != 1 ) + if( io->write_proc(new_line, (unsigned int)strlen(new_line), 1, handle) != 1 ) return FALSE; } } @@ -429,7 +429,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void BYTE *line = FreeImage_GetScanLine(dib, height - y - 1); for(x = 0; x < width; x++ ) { DWORDRGBA u; - if ( bpp > 8 ) { + if( bpp > 8 ) { u.rgba.b = line[FI_RGBA_BLUE]; u.rgba.g = line[FI_RGBA_GREEN]; u.rgba.r = line[FI_RGBA_RED]; @@ -440,14 +440,14 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void line++; } sprintf(buf, "%*s", cpp, (char *)color2chrs[u.index].c_str()); - if ( io->write_proc(buf, cpp, 1, handle) != 1 ) + if( io->write_proc(buf, cpp, 1, handle) != 1 ) return FALSE; } - if ( y == height - 1 ) { - if ( io->write_proc(footer, (unsigned int)strlen(footer), 1, handle) != 1 ) + if( y == height - 1 ) { + if( io->write_proc(footer, (unsigned int)strlen(footer), 1, handle) != 1 ) return FALSE; } else { - if ( io->write_proc(new_line, (unsigned int)strlen(new_line), 1, handle) != 1 ) + if( io->write_proc(new_line, (unsigned int)strlen(new_line), 1, handle) != 1 ) return FALSE; } } diff --git a/plugins/AdvaImg/src/FreeImage/ToneMapping.cpp b/plugins/AdvaImg/src/FreeImage/ToneMapping.cpp index 33ae08ea59..27f8c95a07 100644 --- a/plugins/AdvaImg/src/FreeImage/ToneMapping.cpp +++ b/plugins/AdvaImg/src/FreeImage/ToneMapping.cpp @@ -38,7 +38,7 @@ FreeImage_ToneMapping(FIBITMAP *dib, FREE_IMAGE_TMO tmo, double first_param, dou switch(tmo) { // Adaptive logarithmic mapping (F. Drago, 2003) case FITMO_DRAGO03: - if ((first_param == 0) && (second_param == 0)) { + if((first_param == 0) && (second_param == 0)) { // use default values (gamma = 2.2, exposure = 0) return FreeImage_TmoDrago03(dib, 2.2, 0); } else { @@ -48,7 +48,7 @@ FreeImage_ToneMapping(FIBITMAP *dib, FREE_IMAGE_TMO tmo, double first_param, dou break; // Dynamic range reduction inspired by photoreceptor phhysiology (E. Reinhard, 2005) case FITMO_REINHARD05: - if ((first_param == 0) && (second_param == 0)) { + if((first_param == 0) && (second_param == 0)) { // use default values by setting intensity to 0 and contrast to 0 return FreeImage_TmoReinhard05(dib, 0, 0); } else { @@ -58,7 +58,7 @@ FreeImage_ToneMapping(FIBITMAP *dib, FREE_IMAGE_TMO tmo, double first_param, dou break; // Gradient Domain HDR Compression (R. Fattal, 2002) case FITMO_FATTAL02: - if ((first_param == 0) && (second_param == 0)) { + if((first_param == 0) && (second_param == 0)) { // use default values by setting color saturation to 0.5 and attenuation to 0.85 return FreeImage_TmoFattal02(dib, 0.5, 0.85); } else { diff --git a/plugins/AdvaImg/src/FreeImage/WuQuantizer.cpp b/plugins/AdvaImg/src/FreeImage/WuQuantizer.cpp index 532fbfc3e6..041eae368b 100644 --- a/plugins/AdvaImg/src/FreeImage/WuQuantizer.cpp +++ b/plugins/AdvaImg/src/FreeImage/WuQuantizer.cpp @@ -66,7 +66,7 @@ WuQuantizer::WuQuantizer(FIBITMAP *dib) { // Allocate Qadd Qadd = (WORD *)malloc(sizeof(WORD) * width * height); - if (!gm2 || !wt || !mr || !mg || !mb || !Qadd) { + if(!gm2 || !wt || !mr || !mg || !mb || !Qadd) { if(gm2) free(gm2); if(wt) free(wt); if(mr) free(mr); @@ -127,10 +127,10 @@ WuQuantizer::Hist3D(LONG *vwt, LONG *vmr, LONG *vmg, LONG *vmb, float *m2, int R } } - if ( ReserveSize > 0 ) { + if( ReserveSize > 0 ) { int max = 0; for(i = 0; i < SIZE_3D; i++) { - if ( vwt[i] > max ) max = vwt[i]; + if( vwt[i] > max ) max = vwt[i]; } max++; for(i = 0; i < ReserveSize; i++) { diff --git a/plugins/AdvaImg/src/FreeImage/tmoColorConvert.cpp b/plugins/AdvaImg/src/FreeImage/tmoColorConvert.cpp index 367cb13c96..66869b2806 100644 --- a/plugins/AdvaImg/src/FreeImage/tmoColorConvert.cpp +++ b/plugins/AdvaImg/src/FreeImage/tmoColorConvert.cpp @@ -61,10 +61,10 @@ static const float CIE_y_b = 0.060F; static const float CIE_x_w = 0.3127F; // Illuminant D65
static const float CIE_y_w = 0.3290F;
-static const float CIE_D = ( CIE_x_r*(CIE_y_g - CIE_y_b) + CIE_x_g*(CIE_y_b - CIE_y_r) + CIE_x_b*(CIE_y_r - CIE_y_g));
-static const float CIE_C_rD = ( (1/CIE_y_w) * ( CIE_x_w*(CIE_y_g - CIE_y_b) - CIE_y_w*(CIE_x_g - CIE_x_b) + CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g));
-static const float CIE_C_gD = ( (1/CIE_y_w) * ( CIE_x_w*(CIE_y_b - CIE_y_r) - CIE_y_w*(CIE_x_b - CIE_x_r) - CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r));
-static const float CIE_C_bD = ( (1/CIE_y_w) * ( CIE_x_w*(CIE_y_r - CIE_y_g) - CIE_y_w*(CIE_x_r - CIE_x_g) + CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r));
+static const float CIE_D = ( CIE_x_r*(CIE_y_g - CIE_y_b) + CIE_x_g*(CIE_y_b - CIE_y_r) + CIE_x_b*(CIE_y_r - CIE_y_g) );
+static const float CIE_C_rD = ( (1/CIE_y_w) * ( CIE_x_w*(CIE_y_g - CIE_y_b) - CIE_y_w*(CIE_x_g - CIE_x_b) + CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g) );
+static const float CIE_C_gD = ( (1/CIE_y_w) * ( CIE_x_w*(CIE_y_b - CIE_y_r) - CIE_y_w*(CIE_x_b - CIE_x_r) - CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r) );
+static const float CIE_C_bD = ( (1/CIE_y_w) * ( CIE_x_w*(CIE_y_r - CIE_y_g) - CIE_y_w*(CIE_x_r - CIE_x_g) + CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r) );
/**
RGB to XYZ (no white balance)
@@ -275,7 +275,7 @@ ClampConvertRGBFTo24(FIBITMAP *src) { const unsigned height = FreeImage_GetHeight(src);
FIBITMAP *dst = FreeImage_Allocate(width, height, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
- if (!dst) return NULL;
+ if(!dst) return NULL;
const unsigned src_pitch = FreeImage_GetPitch(src);
const unsigned dst_pitch = FreeImage_GetPitch(dst);
@@ -321,7 +321,7 @@ ConvertRGBFToY(FIBITMAP *src) { const unsigned height = FreeImage_GetHeight(src);
FIBITMAP *dst = FreeImage_AllocateT(FIT_FLOAT, width, height);
- if (!dst) return NULL;
+ if(!dst) return NULL;
const unsigned src_pitch = FreeImage_GetPitch(src);
const unsigned dst_pitch = FreeImage_GetPitch(dst);
@@ -415,8 +415,8 @@ static void findMaxMinPercentile(FIBITMAP *Y, float minPrct, float *minLum, floa std::sort(vY.begin(), vY.end());
- *minLum = vY.at( int(minPrct * vY.size()));
- *maxLum = vY.at( int(maxPrct * vY.size()));
+ *minLum = vY.at( int(minPrct * vY.size()) );
+ *maxLum = vY.at( int(maxPrct * vY.size()) );
}
/**
@@ -444,7 +444,7 @@ NormalizeY(FIBITMAP *Y, float minPrct, float maxPrct) { int pitch = FreeImage_GetPitch(Y);
// find max & min luminance values
- if ((minPrct > 0) || (maxPrct < 1)) {
+ if((minPrct > 0) || (maxPrct < 1)) {
maxLum = 0, minLum = 0;
findMaxMinPercentile(Y, minPrct, &minLum, maxPrct, &maxLum);
} else {
diff --git a/plugins/AdvaImg/src/FreeImage/tmoDrago03.cpp b/plugins/AdvaImg/src/FreeImage/tmoDrago03.cpp index b820bb3577..a61534474d 100644 --- a/plugins/AdvaImg/src/FreeImage/tmoDrago03.cpp +++ b/plugins/AdvaImg/src/FreeImage/tmoDrago03.cpp @@ -258,13 +258,13 @@ FIBITMAP* DLL_CALLCONV FreeImage_TmoDrago03(FIBITMAP *src, double gamma, double exposure) {
float maxLum, minLum, avgLum;
- if (!FreeImage_HasPixels(src)) return NULL;
+ if(!FreeImage_HasPixels(src)) return NULL;
// working RGBF variable
FIBITMAP *dib = NULL;
dib = FreeImage_ConvertToRGBF(src);
- if (!dib) return NULL;
+ if(!dib) return NULL;
// default algorithm parameters
const float biasParam = 0.85F;
diff --git a/plugins/AdvaImg/src/FreeImage/tmoFattal02.cpp b/plugins/AdvaImg/src/FreeImage/tmoFattal02.cpp index bcd4524523..88f054412a 100644 --- a/plugins/AdvaImg/src/FreeImage/tmoFattal02.cpp +++ b/plugins/AdvaImg/src/FreeImage/tmoFattal02.cpp @@ -54,7 +54,7 @@ static FIBITMAP* GaussianLevel5x5(FIBITMAP *dib) { h_dib = FreeImage_AllocateT(image_type, width, height);
v_dib = FreeImage_AllocateT(image_type, width, height);
- if (!h_dib || !v_dib) throw(1);
+ if(!h_dib || !v_dib) throw(1);
const unsigned pitch = FreeImage_GetPitch(dib) / sizeof(float);
@@ -166,7 +166,7 @@ static FIBITMAP* GradientLevel(FIBITMAP *H, float *avgGrad, int k) { const unsigned height = FreeImage_GetHeight(H);
G = FreeImage_AllocateT(image_type, width, height);
- if (!G) throw(1);
+ if(!G) throw(1);
const unsigned pitch = FreeImage_GetPitch(H) / sizeof(float);
@@ -246,7 +246,7 @@ static FIBITMAP* PhiMatrix(FIBITMAP **gradients, float *avgGrad, int nlevels, fl try {
phi = (FIBITMAP**)malloc(nlevels * sizeof(FIBITMAP*));
- if (!phi) throw(1);
+ if(!phi) throw(1);
memset(phi, 0, nlevels * sizeof(FIBITMAP*));
for(int k = nlevels-1; k >= 0; k--) {
@@ -266,7 +266,7 @@ static FIBITMAP* PhiMatrix(FIBITMAP **gradients, float *avgGrad, int nlevels, fl if(ALPHA == 0) ALPHA = EPSILON;
phi[k] = FreeImage_AllocateT(FIT_FLOAT, width, height);
- if (!phi[k]) throw(1);
+ if(!phi[k]) throw(1);
src_pixel = (float*)FreeImage_GetBits(Gk);
dst_pixel = (float*)FreeImage_GetBits(phi[k]);
@@ -283,9 +283,9 @@ static FIBITMAP* PhiMatrix(FIBITMAP **gradients, float *avgGrad, int nlevels, fl }
if(k < nlevels-1) {
- // compute PHI(k) = L( PHI(k+1)) * phi(k)
+ // compute PHI(k) = L( PHI(k+1) ) * phi(k)
FIBITMAP *L = FreeImage_Rescale(phi[k+1], width, height, FILTER_BILINEAR);
- if (!L) throw(1);
+ if(!L) throw(1);
src_pixel = (float*)FreeImage_GetBits(L);
dst_pixel = (float*)FreeImage_GetBits(phi[k]);
@@ -345,9 +345,9 @@ static FIBITMAP* Divergence(FIBITMAP *H, FIBITMAP *PHI) { const unsigned height = FreeImage_GetHeight(H);
Gx = FreeImage_AllocateT(image_type, width, height);
- if (!Gx) throw(1);
+ if(!Gx) throw(1);
Gy = FreeImage_AllocateT(image_type, width, height);
- if (!Gy) throw(1);
+ if(!Gy) throw(1);
const unsigned pitch = FreeImage_GetPitch(H) / sizeof(float);
@@ -377,20 +377,20 @@ static FIBITMAP* Divergence(FIBITMAP *H, FIBITMAP *PHI) { // calculate the divergence
divG = FreeImage_AllocateT(image_type, width, height);
- if (!divG) throw(1);
+ if(!divG) throw(1);
gx = (float*)FreeImage_GetBits(Gx);
gy = (float*)FreeImage_GetBits(Gy);
divg = (float*)FreeImage_GetBits(divG);
- for(unsigned y0 = 0; y0 < height; y0++) {
+ for(unsigned y = 0; y < height; y++) {
for(unsigned x = 0; x < width; x++) {
// backward difference approximation
// divG = Gx(x, y) - Gx(x-1, y) + Gy(x, y) - Gy(x, y-1)
- const unsigned index = y0*pitch + x;
+ const unsigned index = y*pitch + x;
divg[index] = gx[index] + gy[index];
if(x > 0) divg[index] -= gx[index-1];
- if(y0 > 0) divg[index] -= gy[index-pitch];
+ if(y > 0) divg[index] -= gy[index-pitch];
}
}
@@ -421,7 +421,7 @@ static FIBITMAP* LogLuminance(FIBITMAP *Y) { try {
// get the luminance channel
FIBITMAP *H = FreeImage_Clone(Y);
- if (!H) throw(1);
+ if(!H) throw(1);
const unsigned width = FreeImage_GetWidth(H);
const unsigned height = FreeImage_GetHeight(H);
@@ -446,7 +446,7 @@ static FIBITMAP* LogLuminance(FIBITMAP *Y) { // normalize to range 0..100 and take the logarithm
const float scale = 100.F / (maxLum - minLum);
bits = (BYTE*)FreeImage_GetBits(H);
- for(unsigned y0 = 0; y0 < height; y0++) {
+ for(unsigned y = 0; y < height; y++) {
float *pixel = (float*)bits;
for(unsigned x = 0; x < width; x++) {
const float value = (pixel[x] - minLum) * scale;
@@ -509,7 +509,7 @@ static FIBITMAP* tmoFattal02(FIBITMAP *Y, float alpha, float beta) { try {
// get the normalized luminance
FIBITMAP *H = LogLuminance(Y);
- if (!H) throw(1);
+ if(!H) throw(1);
// get the number of levels for the pyramid
const unsigned width = FreeImage_GetWidth(H);
@@ -522,19 +522,19 @@ static FIBITMAP* tmoFattal02(FIBITMAP *Y, float alpha, float beta) { // create the Gaussian pyramid
pyramid = (FIBITMAP**)malloc(nlevels * sizeof(FIBITMAP*));
- if (!pyramid) throw(1);
+ if(!pyramid) throw(1);
memset(pyramid, 0, nlevels * sizeof(FIBITMAP*));
- if (!GaussianPyramid(H, pyramid, nlevels)) throw(1);
+ if(!GaussianPyramid(H, pyramid, nlevels)) throw(1);
// calculate gradient magnitude and its average value on each pyramid level
gradients = (FIBITMAP**)malloc(nlevels * sizeof(FIBITMAP*));
- if (!gradients) throw(1);
+ if(!gradients) throw(1);
memset(gradients, 0, nlevels * sizeof(FIBITMAP*));
avgGrad = (float*)malloc(nlevels * sizeof(float));
- if (!avgGrad) throw(1);
+ if(!avgGrad) throw(1);
- if (!GradientPyramid(pyramid, nlevels, gradients, avgGrad)) throw(1);
+ if(!GradientPyramid(pyramid, nlevels, gradients, avgGrad)) throw(1);
// free the Gaussian pyramid
for(k = 0; k < nlevels; k++) {
@@ -544,7 +544,7 @@ static FIBITMAP* tmoFattal02(FIBITMAP *Y, float alpha, float beta) { // compute the gradient attenuation function PHI(x, y)
phy = PhiMatrix(gradients, avgGrad, nlevels, alpha, beta);
- if (!phy) throw(1);
+ if(!phy) throw(1);
// free the gradient pyramid
for(k = 0; k < nlevels; k++) {
@@ -556,7 +556,7 @@ static FIBITMAP* tmoFattal02(FIBITMAP *Y, float alpha, float beta) { // compute gradients in x and y directions, attenuate them with the attenuation matrix,
// then compute the divergence div G from the attenuated gradient.
divG = Divergence(H, phy);
- if (!divG) throw(1);
+ if(!divG) throw(1);
// H & phy no longer needed
FreeImage_Unload(H); H = NULL;
@@ -564,7 +564,7 @@ static FIBITMAP* tmoFattal02(FIBITMAP *Y, float alpha, float beta) { // solve the PDE (Poisson equation) using a multigrid solver and 3 cycles
FIBITMAP *U = FreeImage_MultigridPoissonSolver(divG, 3);
- if (!U) throw(1);
+ if(!U) throw(1);
FreeImage_Unload(divG);
@@ -618,21 +618,21 @@ FreeImage_TmoFattal02(FIBITMAP *dib, double color_saturation, double attenuation FIBITMAP *Yout = NULL;
FIBITMAP *dst = NULL;
- if (!FreeImage_HasPixels(dib)) return NULL;
+ if(!FreeImage_HasPixels(dib)) return NULL;
try {
// convert to RGBF
src = FreeImage_ConvertToRGBF(dib);
- if (!src) throw(1);
+ if(!src) throw(1);
// get the luminance channel
Yin = ConvertRGBFToY(src);
- if (!Yin) throw(1);
+ if(!Yin) throw(1);
// perform the tone mapping
Yout = tmoFattal02(Yin, alpha, beta);
- if (!Yout) throw(1);
+ if(!Yout) throw(1);
// clip low and high values and normalize to [0..1]
//NormalizeY(Yout, 0.001F, 0.995F);
diff --git a/plugins/AdvaImg/src/FreeImage/tmoReinhard05.cpp b/plugins/AdvaImg/src/FreeImage/tmoReinhard05.cpp index 969aa4c950..f91b41c062 100644 --- a/plugins/AdvaImg/src/FreeImage/tmoReinhard05.cpp +++ b/plugins/AdvaImg/src/FreeImage/tmoReinhard05.cpp @@ -59,7 +59,7 @@ ToneMappingReinhard05(FIBITMAP *dib, FIBITMAP *Y, float f, float m, float a, flo // check input parameters - if ((FreeImage_GetImageType(dib) != FIT_RGBF) || (FreeImage_GetImageType(Y) != FIT_FLOAT)) { + if((FreeImage_GetImageType(dib) != FIT_RGBF) || (FreeImage_GetImageType(Y) != FIT_FLOAT)) { return FALSE; } @@ -81,7 +81,7 @@ ToneMappingReinhard05(FIBITMAP *dib, FIBITMAP *Y, float f, float m, float a, flo // get statistics about the data (but only if its really needed) f = exp(-f); - if ((m == 0) || (a != 1) && (c != 1)) { + if((m == 0) || (a != 1) && (c != 1)) { // avoid these calculations if its not needed after ... LuminanceFromY(Y, &maxLum, &minLum, &Lav, &Llav); k = (log(maxLum) - Llav) / (log(maxLum) - log(minLum)); @@ -103,7 +103,7 @@ ToneMappingReinhard05(FIBITMAP *dib, FIBITMAP *Y, float f, float m, float a, flo bits = (BYTE*)FreeImage_GetBits(dib); Ybits = (BYTE*)FreeImage_GetBits(Y); - if ((a == 1) && (c == 0)) { + if((a == 1) && (c == 0)) { // when using default values, use a fastest code for(y = 0; y < height; y++) { @@ -113,7 +113,7 @@ ToneMappingReinhard05(FIBITMAP *dib, FIBITMAP *Y, float f, float m, float a, flo for(x = 0; x < width; x++) { I_a = Y[x]; // luminance(x, y) for (i = 0; i < 3; i++) { - *color /= ( *color + pow(f * I_a, m)); + *color /= ( *color + pow(f * I_a, m) ); max_color = (*color > max_color) ? *color : max_color; min_color = (*color < min_color) ? *color : min_color; @@ -131,7 +131,7 @@ ToneMappingReinhard05(FIBITMAP *dib, FIBITMAP *Y, float f, float m, float a, flo // channel averages Cav[0] = Cav[1] = Cav[2] = 0; - if ((a != 1) && (c != 0)) { + if((a != 1) && (c != 0)) { // channel averages are not needed when (a == 1) or (c == 0) bits = (BYTE*)FreeImage_GetBits(dib); for(y = 0; y < height; y++) { @@ -164,7 +164,7 @@ ToneMappingReinhard05(FIBITMAP *dib, FIBITMAP *Y, float f, float m, float a, flo I_l = c * *color + (1-c) * L; I_g = c * Cav[i] + (1-c) * Lav; I_a = a * I_l + (1-a) * I_g; - *color /= ( *color + pow(f * I_a, m)); + *color /= ( *color + pow(f * I_a, m) ); max_color = (*color > max_color) ? *color : max_color; min_color = (*color < min_color) ? *color : min_color; @@ -215,17 +215,17 @@ User parameters control intensity, contrast, and level of adaptation */ FIBITMAP* DLL_CALLCONV FreeImage_TmoReinhard05Ex(FIBITMAP *src, double intensity, double contrast, double adaptation, double color_correction) { - if (!FreeImage_HasPixels(src)) return NULL; + if(!FreeImage_HasPixels(src)) return NULL; // working RGBF variable FIBITMAP *dib = NULL, *Y = NULL; dib = FreeImage_ConvertToRGBF(src); - if (!dib) return NULL; + if(!dib) return NULL; // get the Luminance channel Y = ConvertRGBFToY(dib); - if (!Y) { + if(!Y) { FreeImage_Unload(dib); return NULL; } |