#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
/* 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);
}
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");
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();