summaryrefslogtreecommitdiff
path: root/plugins/AdvaImg/src/FreeImage/Conversion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/AdvaImg/src/FreeImage/Conversion.cpp')
-rw-r--r--plugins/AdvaImg/src/FreeImage/Conversion.cpp66
1 files changed, 52 insertions, 14 deletions
diff --git a/plugins/AdvaImg/src/FreeImage/Conversion.cpp b/plugins/AdvaImg/src/FreeImage/Conversion.cpp
index 04cec65ab5..815057ad08 100644
--- a/plugins/AdvaImg/src/FreeImage/Conversion.cpp
+++ b/plugins/AdvaImg/src/FreeImage/Conversion.cpp
@@ -6,6 +6,7 @@
// - Hervé Drolon (drolon@infonie.fr)
// - Jani Kajala (janik@remedy.fi)
// - Mihail Naydenov (mnaydenov@users.sourceforge.net)
+// - Carsten Klein (cklein05@users.sourceforge.net)
//
// This file is part of FreeImage 3
//
@@ -372,7 +373,8 @@ FreeImage_ColorQuantizeEx(FIBITMAP *dib, FREE_IMAGE_QUANTIZE quantize, int Palet
if( ReserveSize < 0 ) ReserveSize = 0;
if( ReserveSize > PaletteSize ) ReserveSize = PaletteSize;
if (FreeImage_HasPixels(dib)) {
- if (FreeImage_GetBPP(dib) == 24) {
+ const unsigned bpp = FreeImage_GetBPP(dib);
+ if((FreeImage_GetImageType(dib) == FIT_BITMAP) && (bpp == 24 || bpp == 32)) {
switch(quantize) {
case FIQ_WUQUANT :
{
@@ -387,9 +389,14 @@ FreeImage_ColorQuantizeEx(FIBITMAP *dib, FREE_IMAGE_QUANTIZE quantize, int Palet
} catch (const char *) {
return NULL;
}
+ break;
}
case FIQ_NNQUANT :
{
+ if (bpp == 32) {
+ // 32-bit images not supported by NNQUANT
+ return NULL;
+ }
// sampling factor in range 1..30.
// 1 => slower (but better), 30 => faster. Default value is 1
const int sampling = 1;
@@ -402,6 +409,16 @@ FreeImage_ColorQuantizeEx(FIBITMAP *dib, FREE_IMAGE_QUANTIZE quantize, int Palet
}
return dst;
}
+ case FIQ_LFPQUANT :
+ {
+ LFPQuantizer Q(PaletteSize);
+ FIBITMAP *dst = Q.Quantize(dib, ReserveSize, ReservePalette);
+ if(dst) {
+ // copy metadata from src to dst
+ FreeImage_CloneMetadata(dst, dib);
+ }
+ return dst;
+ }
}
}
}
@@ -412,26 +429,47 @@ FreeImage_ColorQuantizeEx(FIBITMAP *dib, FREE_IMAGE_QUANTIZE quantize, int Palet
// ==========================================================
FIBITMAP * DLL_CALLCONV
-FreeImage_ConvertFromRawBits(BYTE *bits, int width, int height, int pitch, unsigned bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask, BOOL topdown) {
- FIBITMAP *dib = FreeImage_Allocate(width, height, bpp, red_mask, green_mask, blue_mask);
+FreeImage_ConvertFromRawBitsEx(BOOL copySource, BYTE *bits, FREE_IMAGE_TYPE type, int width, int height, int pitch, unsigned bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask, BOOL topdown) {
+ FIBITMAP *dib = NULL;
- if (dib != NULL) {
- if (topdown) {
- for (int i = height - 1; i >= 0; --i) {
- memcpy(FreeImage_GetScanLine(dib, i), bits, FreeImage_GetLine(dib));
- bits += pitch;
- }
- } else {
- for (int i = 0; i < height; ++i) {
- memcpy(FreeImage_GetScanLine(dib, i), bits, FreeImage_GetLine(dib));
- bits += pitch;
- }
+ if(copySource) {
+ // allocate a FIBITMAP with internally managed pixel buffer
+ dib = FreeImage_AllocateT(type, width, height, bpp, red_mask, green_mask, blue_mask);
+ if(!dib) {
+ return NULL;
+ }
+ // copy user provided pixel buffer into the dib
+ const unsigned linesize = FreeImage_GetLine(dib);
+ for(int y = 0; y < height; y++) {
+ memcpy(FreeImage_GetScanLine(dib, y), bits, linesize);
+ // next line in user's buffer
+ bits += pitch;
+ }
+ // flip pixels vertically if needed
+ if(topdown) {
+ FreeImage_FlipVertical(dib);
+ }
+ }
+ else {
+ // allocate a FIBITMAP using a wrapper to user provided pixel buffer
+ dib = FreeImage_AllocateHeaderForBits(bits, pitch, type, width, height, bpp, red_mask, green_mask, blue_mask);
+ if(!dib) {
+ return NULL;
+ }
+ // flip pixels vertically if needed
+ if(topdown) {
+ FreeImage_FlipVertical(dib);
}
}
return dib;
}
+FIBITMAP * DLL_CALLCONV
+FreeImage_ConvertFromRawBits(BYTE *bits, int width, int height, int pitch, unsigned bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask, BOOL topdown) {
+ return FreeImage_ConvertFromRawBitsEx(TRUE /* copySource */, bits, FIT_BITMAP, width, height, pitch, bpp, red_mask, green_mask, blue_mask, topdown);
+}
+
void DLL_CALLCONV
FreeImage_ConvertToRawBits(BYTE *bits, FIBITMAP *dib, int pitch, unsigned bpp, unsigned red_mask, unsigned green_mask, unsigned blue_mask, BOOL topdown) {
if (FreeImage_HasPixels(dib) && (bits != NULL)) {