From 63646d36a6845fff483ef04b88c1987ddc0f589a Mon Sep 17 00:00:00 2001 From: Joogab Yun Date: Tue, 31 Oct 2017 15:24:07 +0900 Subject: [PATCH] [4.0] support 1, 2, 4 bit depths about PNG_COLOR_TYPE_GRAY Change-Id: Id3a7cf85b229e44f903d1c05640e05ab3bf0d188 --- .../tizen/image-loaders/loader-png.cpp | 45 +++++++++------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/platform-abstractions/tizen/image-loaders/loader-png.cpp b/platform-abstractions/tizen/image-loaders/loader-png.cpp index 89bca77..09e8819 100755 --- a/platform-abstractions/tizen/image-loaders/loader-png.cpp +++ b/platform-abstractions/tizen/image-loaders/loader-png.cpp @@ -162,37 +162,30 @@ bool LoadBitmapFromPng( const ImageLoader::Input& input, Integration::Bitmap& bi png_byte colortype = png_get_color_type(png, info); - if(colortype == PNG_COLOR_TYPE_GRAY) + if( colortype == PNG_COLOR_TYPE_GRAY || + colortype == PNG_COLOR_TYPE_GRAY_ALPHA ) { - switch( colordepth ) + if( png_get_valid(png, info, PNG_INFO_tRNS) ) { - case 8: - { - pixelFormat = Pixel::L8; - valid = true; - break; - } - default: - { - break; - } + colortype = PNG_COLOR_TYPE_GRAY_ALPHA; + /* expand transparency entry -> alpha channel if present */ + png_set_tRNS_to_alpha(png); + pixelFormat = Pixel::LA88; } - } - else if(colortype == PNG_COLOR_TYPE_GRAY_ALPHA) - { - switch(colordepth) + else { - case 8: - { - pixelFormat = Pixel::LA88; - valid = true; - break; - } - default: - { - break; - } + colortype = PNG_COLOR_TYPE_GRAY; + pixelFormat = Pixel::L8; + } + + if( colordepth < 8 ) + { + /* expand gray (w/reduced bits) -> 8-bit RGB if necessary */ + png_set_expand_gray_1_2_4_to_8(png); + /* pack all pixels to byte boundaries */ + png_set_packing(png); } + valid = true; } else if(colortype == PNG_COLOR_TYPE_RGB ) { -- 2.7.4