From eb680766d56e815086397361b286fd8055fb5377 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Thu, 3 Jan 2013 14:34:48 +0000 Subject: FreeImage updated to 3.15.4 removed not used formats git-svn-id: http://svn.miranda-ng.org/main/trunk@2926 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/AdvaImg/src/FreeImage/Conversion24.cpp | 90 ++++++++++++++++++-------- 1 file changed, 64 insertions(+), 26 deletions(-) (limited to 'plugins/AdvaImg/src/FreeImage/Conversion24.cpp') 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; } -- cgit v1.2.3