freeimage support fix - transparent paletized images

This commit is contained in:
Vadim Lopatin 2014-04-17 17:09:47 +04:00
parent 4ae03b56dc
commit e18955321a
1 changed files with 12 additions and 9 deletions

View File

@ -118,10 +118,12 @@ static if (USE_FREEIMAGE) {
int transparentIndex = 0; int transparentIndex = 0;
int transparencyCount = 0; int transparencyCount = 0;
RGBQUAD * palette = null; RGBQUAD * palette = null;
ubyte * transparencyTable = null;
if (colorType == FIC_PALETTE) { if (colorType == FIC_PALETTE) {
palette = FreeImage_GetPalette(dib); palette = FreeImage_GetPalette(dib);
transparentIndex = FreeImage_GetTransparentIndex(dib); transparentIndex = FreeImage_GetTransparentIndex(dib);
transparencyCount = FreeImage_GetTransparencyCount(dib); transparencyCount = FreeImage_GetTransparencyCount(dib);
transparencyTable = FreeImage_GetTransparencyTable(dib);
} }
int size = width*height*pixelSize; int size = width*height*pixelSize;
@ -137,16 +139,17 @@ static if (USE_FREEIMAGE) {
for( int j = 0; j < width; ++j, ++dst, src += pixelSize ) { for( int j = 0; j < width; ++j, ++dst, src += pixelSize ) {
if (colorType == FIC_PALETTE) { if (colorType == FIC_PALETTE) {
ubyte index = src[0]; ubyte index = src[0];
if (transparentIndex >= 0 && index >= transparentIndex && index < transparentIndex + transparencyCount) { a = 0;
dst[0] = 0xFFFFFFFF; if (transparencyTable !is null) {
} else { a = transparencyTable[index] ^ 0xFF;
RGBQUAD pcolor = palette[index]; } else if (transparentIndex >= 0 && index >= transparentIndex && index < transparentIndex + transparencyCount) {
a = pcolor.rgbReserved; a = 0xFF;
r = pcolor.rgbRed;
g = pcolor.rgbGreen;
b = pcolor.rgbBlue;
dst[0] = (a << 24) | (r << 16) | (g << 8) | b;
} }
RGBQUAD pcolor = palette[index];
r = pcolor.rgbRed;
g = pcolor.rgbGreen;
b = pcolor.rgbBlue;
dst[0] = (a << 24) | (r << 16) | (g << 8) | b;
} else { } else {
a = 0; a = 0;
switch (pixelSize) { switch (pixelSize) {