From 75eceb9b2428d35cad8948d54f5c42c090cede54 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 16 Dec 2015 14:50:40 +0100 Subject: [PATCH] Fixed: loadPNG with RGB images was returning 32 --HG-- branch : develop --- code/nel/src/misc/bitmap_png.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/code/nel/src/misc/bitmap_png.cpp b/code/nel/src/misc/bitmap_png.cpp index cea0b7d0c..459437f5c 100644 --- a/code/nel/src/misc/bitmap_png.cpp +++ b/code/nel/src/misc/bitmap_png.cpp @@ -136,6 +136,36 @@ uint8 CBitmap::readPNG( NLMISC::IStream &f ) // get again width, height and the new bit-depth and color-type png_get_IHDR(png_ptr, info_ptr, &width, &height, &iBitDepth, &iColorType, NULL, NULL, NULL); + uint8 imageDepth; + + switch(iColorType) + { + case PNG_COLOR_TYPE_GRAY: + imageDepth = iBitDepth; + break; + + case PNG_COLOR_TYPE_PALETTE: + imageDepth = iBitDepth; + break; + + case PNG_COLOR_TYPE_RGB: + imageDepth = iBitDepth * 3; + break; + + case PNG_COLOR_TYPE_RGB_ALPHA: + imageDepth = iBitDepth * 4; + break; + + case PNG_COLOR_TYPE_GRAY_ALPHA: + imageDepth = iBitDepth * 2; + break; + + default: + imageDepth = iBitDepth * 4; + nlwarning("Unable to determine PNG color type: %d, consider it as RGBA", iColorType); + break; + } + // at this point, the image must be converted to an 24bit image RGB // rowbytes is the width x number of channels @@ -208,7 +238,7 @@ uint8 CBitmap::readPNG( NLMISC::IStream &f ) png_destroy_read_struct(&png_ptr, &info_ptr, NULL); //return the size of a pixel, either 8,24,32 bit - return uint8(dstChannels * iBitDepth); + return imageDepth; } /*-------------------------------------------------------------------*\