support 1, 2, 4 bit depths about PNG_COLOR_TYPE_GRAY 41/158341/5
authorJoogab Yun <joogab.yun@samsung.com>
Tue, 31 Oct 2017 06:24:07 +0000 (15:24 +0900)
committerJoogab Yun <joogab.yun@samsung.com>
Wed, 1 Nov 2017 07:38:21 +0000 (16:38 +0900)
Change-Id: Id3a7cf85b229e44f903d1c05640e05ab3bf0d188

platform-abstractions/tizen/image-loaders/loader-png.cpp

index 89bca77..09e8819 100755 (executable)
@@ -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 )
   {