From 7fb3685ba6bed4724b4f57d7a39a387f044a9e7f Mon Sep 17 00:00:00 2001 From: Matthew Wilber Date: Mon, 26 Apr 2004 23:09:19 +0000 Subject: [PATCH] Fixed low-depth grayscale issue, PNGTranslator can now read grayscale PNG images that are less than 8 bpp git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7324 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../translators/pngtranslator/PNGTranslator.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/add-ons/translators/pngtranslator/PNGTranslator.cpp b/src/add-ons/translators/pngtranslator/PNGTranslator.cpp index f97e2f987c..1a4fc27279 100644 --- a/src/add-ons/translators/pngtranslator/PNGTranslator.cpp +++ b/src/add-ons/translators/pngtranslator/PNGTranslator.cpp @@ -322,14 +322,6 @@ PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource, int bit_depth, color_type, interlace_type; png_get_IHDR(ppng, pinfo, &width, &height, &bit_depth, &color_type, &interlace_type, int_p_NULL, int_p_NULL); - - if ((color_type == PNG_COLOR_TYPE_GRAY || - color_type == PNG_COLOR_TYPE_GRAY_ALPHA) && bit_depth < 8) { - // libpng's gray to RGB conversion is not implemented - // for bit depths less than 8 - result = B_NO_TRANSLATOR; - break; - } // Setup image transformations to make converting it easier bool balpha = false; @@ -342,6 +334,11 @@ PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource, if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(ppng); + if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) + // In order to convert from low-depth gray images to RGB, + // I first need to convert them to grayscale, 8 bpp + png_set_gray_1_2_4_to_8(ppng); + if (png_get_valid(ppng, pinfo, PNG_INFO_tRNS)) { // if there is transparency data in the // PNG, but not in the form of an alpha channel