Fixed issue that the decoded image of 8-bit grayscale PNG was broken 85/234585/9 accepted/tizen/unified/20200529.124234 submit/tizen/20200528.071852
authorjiyong.min <jiyong.min@samsung.com>
Wed, 27 May 2020 08:07:04 +0000 (17:07 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Thu, 28 May 2020 01:47:08 +0000 (10:47 +0900)
  - cause:
    Libpng can trans gray to rgb if png is gray or gray with alpha.
    But decoding png set trans using 'png_set_gray_to_rgb()' if png is only
    grayscale with alpha.

  - solution:
    Set trans gray to rgb using 'png_set_gray_to_rgb' if png is gray or
    gray with alpha. Decoding the png should return only the rgba image,
    so converting rgb to rgba is also added.

Change-Id: Id99e25070890283e79af45f438dcb4c767575c3f

packaging/libmm-utility.spec
png/CMakeLists.txt
png/mm_util_png.c

index 0e93c0a..090e6c5 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.1.42
+Version:    0.1.43
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index e2d3dc8..0cf341b 100644 (file)
@@ -13,6 +13,7 @@ SET(INC_DIR
        )
 INCLUDE_DIRECTORIES(${INC_DIR}
        ../common/include
+       ../imgp/include
        )
 
 SET(dependents "dlog glib-2.0 libpng")
@@ -38,7 +39,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
 
 aux_source_directory(. SOURCES)
 ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
-TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS} mmutil_common)
+TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS} mmutil_common mmutil_imgp)
 SET_TARGET_PROPERTIES(${fw_name}
        PROPERTIES
        VERSION ${VERSION}
index b00d214..2b1999b 100755 (executable)
@@ -25,6 +25,7 @@
 #include <png.h>
 
 #include "mm_util_png.h"
+#include "mm_util_imgp.h"
 #include "mm_util_private.h"
 
 #define MM_UTIL_PNG_BYTES_TO_CHECK 4
@@ -111,9 +112,8 @@ static void __get_property(png_property_s *png_prop, png_structp png_ptr, png_in
 
        /* Gray scale converted to upscaled to 8 bits */
        if ((png_prop->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) || (png_prop->color_type == PNG_COLOR_TYPE_GRAY)) {
-               /* Gray scale with alpha channel converted to RGB */
-               if (png_prop->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
-                       png_set_gray_to_rgb(png_ptr);
+               /* Gray scale converted to RGB */
+               png_set_gray_to_rgb(png_ptr);
                if (png_prop->bit_depth < MM_UTIL_BIT_DEPTH_8)/* Convert to 8 bits */
                        png_set_expand_gray_1_2_4_to_8(png_ptr);
        }
@@ -151,6 +151,7 @@ static int __read_png(FILE *fp, void *memory, const size_t memory_size, mm_util_
        png_io_buf_s io_buf = {memory, memory_size, 0};
        png_property_s png_prop;
        void *_data = NULL;
+       mm_util_image_h decoded_image = NULL, converted_image = NULL;
 
        mm_util_retvm_if(((fp == NULL) && (memory == NULL)), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid png image");
        mm_util_retvm_if(!decoded, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image handle");
@@ -222,7 +223,25 @@ static int __read_png(FILE *fp, void *memory, const size_t memory_size, mm_util_
        png_read_end(png_ptr, info_ptr);
        png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
 
-       ret = mm_image_create_image((unsigned int)png_prop.width, (unsigned int)png_prop.height, MM_UTIL_COLOR_RGBA, _data, data_size, decoded);
+       if ((png_prop.color_type == PNG_COLOR_TYPE_GRAY_ALPHA) || (png_prop.color_type == PNG_COLOR_TYPE_GRAY)) {
+               ret = mm_image_create_image((unsigned int)png_prop.width, (unsigned int)png_prop.height, MM_UTIL_COLOR_RGB24,
+                                                               _data, data_size, &decoded_image);
+               if (ret != MM_UTIL_ERROR_NONE) {
+                       mm_util_error("mm_image_create_image failed (%d)", ret);
+                       MMUTIL_SAFE_FREE(_data);
+                       return ret;
+               }
+
+               ret = mm_util_convert_colorspace(decoded_image, MM_UTIL_COLOR_RGBA, &converted_image);
+               mm_image_destroy_image(decoded_image);
+               decoded_image = NULL;
+       } else {
+               ret = mm_image_create_image((unsigned int)png_prop.width, (unsigned int)png_prop.height, MM_UTIL_COLOR_RGBA,
+                                                               _data, data_size, &decoded_image);
+       }
+
+       *decoded = (converted_image) ? converted_image : decoded_image;
+
        MMUTIL_SAFE_FREE(_data);
 
        mm_util_fleave();