Add to use GraphicsMagick when webp format encoding and decoding 54/237654/18 submit/tizen/20200803.051111 submit/tizen/20200804.230708
authorjiyong.min <jiyong.min@samsung.com>
Thu, 2 Jul 2020 06:58:38 +0000 (15:58 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Thu, 23 Jul 2020 02:40:48 +0000 (11:40 +0900)
Change-Id: Ic30a3d8d45a9a70fcdec37da60d7bb5069612f74

magick/include/mm_util_magick.h
magick/mm_util_magick.c
magick/test/mm_util_magick_testsuite.c

index d66b42a..4c155a2 100644 (file)
@@ -22,6 +22,8 @@
 #ifndef __MM_UTILITY_MAGICK_H__
 #define __MM_UTILITY_MAGICK_H__
 
+#include <stdbool.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -36,6 +38,7 @@ typedef enum {
        IMG_CODEC_PNG,
        IMG_CODEC_GIF,
        IMG_CODEC_BMP,
+       IMG_CODEC_WEBP,
        IMG_CODEC_WBMP = 100,           // used by only media-content
        IMG_CODEC_UNKNOWN_TYPE,
 } mm_util_img_codec_type;
@@ -64,6 +67,7 @@ int mm_util_encode_image_to_buffer(mm_util_image_h decoded_image, mm_util_enc_op
 int mm_util_enc_opt_create(mm_util_enc_opt_h *enc_opt);
 int mm_util_enc_opt_set_codec(mm_util_enc_opt_h enc_opt, mm_util_img_codec_type codec);
 int mm_util_enc_opt_set_png_compression(mm_util_enc_opt_h enc_opt, unsigned int compression);
+int mm_util_enc_opt_set_webp_lossless(mm_util_enc_opt_h enc_opt, bool lossless);
 void mm_util_enc_opt_destroy(mm_util_enc_opt_h enc_opt);
 
 #ifdef __cplusplus
index a12234d..efae217 100644 (file)
@@ -19,7 +19,6 @@
  *
  */
 
-#include <stdbool.h>
 #include <glib.h>
 #include <glib/gstdio.h>
 #include <unistd.h>
@@ -34,6 +33,7 @@
 typedef struct {
        mm_util_img_codec_type codec;
        unsigned int compression;
+       bool lossless;
 } mm_util_enc_opt_t;
 
 static bool __mm_util_check_rotation(mm_util_rotate_type_e rotation);
@@ -313,6 +313,7 @@ static int __mm_util_write_image_to_file(Image *image, mm_util_enc_opt_t *option
        int ret = MM_UTIL_ERROR_NONE;
        ImageInfo *_image_info = NULL;
        ExceptionInfo exception;
+       mm_util_img_codec_type codec = IMG_CODEC_JPEG;
 
        mm_util_fenter();
 
@@ -333,33 +334,35 @@ static int __mm_util_write_image_to_file(Image *image, mm_util_enc_opt_t *option
        DeleteImageProfile(image, "IPTC");
        DeleteImageProfile(image, "XMP");
 
-       if (option) {
-               switch(option->codec) {
-               case IMG_CODEC_JPEG:
-                       AddDefinition(_image_info, "jpeg", "dct-method", "FASTEST", &exception);
-                       AddDefinition(_image_info, "jpeg", "optimize-coding", "FALSE", &exception);
-                       break;
-
-               case IMG_CODEC_PNG:
-                       mm_util_sec_debug("PNG compression: %d", option->compression);
-                       _image_info->quality = option->compression * 10;
-                       break;
-
-               case IMG_CODEC_GIF:
-                       /* fall through */
-               case IMG_CODEC_BMP:
-                       /* fall through */
-               case IMG_CODEC_WBMP:
-                       break;
-
-               default:
-                       mm_util_error("invalid codec [%d]", option->codec);
-                       break;
-               }
-       } else {
-               /* used by only media-content */
+       if (option)
+               codec = option->codec;
+
+       switch (codec) {
+       case IMG_CODEC_JPEG:
                AddDefinition(_image_info, "jpeg", "dct-method", "FASTEST", &exception);
                AddDefinition(_image_info, "jpeg", "optimize-coding", "FALSE", &exception);
+               break;
+
+       case IMG_CODEC_PNG:
+               mm_util_sec_debug("PNG compression: %d", option->compression);
+               _image_info->quality = option->compression * 10;
+               break;
+
+       case IMG_CODEC_WEBP:
+               mm_util_sec_debug("WEBP lossless: %s", (option->lossless ? "TRUE" : "FALSE"));
+               AddDefinition(_image_info, "webp", "lossless", (option->lossless ? "TRUE" : "FALSE"), &exception);
+               break;
+
+       case IMG_CODEC_GIF:
+               /* fall through */
+       case IMG_CODEC_BMP:
+               /* fall through */
+       case IMG_CODEC_WBMP:
+               break;
+
+       default:
+               mm_util_error("invalid codec [%d]", codec);
+               break;
        }
 
        if (WriteImage (_image_info, image) == MagickFalse) {
@@ -470,6 +473,9 @@ static int __mm_util_make_tmp_file(mm_util_img_codec_type type, char **path)
        case IMG_CODEC_BMP:
                template = "XXXXXX.bmp";
                break;
+       case IMG_CODEC_WEBP:
+               template = "XXXXXX.webp";
+               break;
        default:
                mm_util_error("invalid type [%u]", type);
                return MM_UTIL_ERROR_INVALID_PARAMETER;
@@ -997,7 +1003,7 @@ int mm_util_encode_image_to_file(mm_util_image_h decoded_image, mm_util_enc_opt_
        if (_opt->codec == IMG_CODEC_BMP) {
                /*
                  GraphicsMagick doesn't support alpha overlay(compression method:BI_ALPHABITFIELDS) for bmp.
-                 Officialy BMP format supports alpha overlay since BMP4(version 4), but GraphicsMagick
+                 Officially BMP format supports alpha overlay since BMP4(version 4), but GraphicsMagick
                  support BMP, BMP2(v2) and BMP3(v3) except BMP4.
                  So decoded_image should be converted to RGB888(RGB24) which has not alpha overlay.
                  ps. BMP4 image does not guarantee backward compatibility. BMP4 is not visible on old devices.
@@ -1171,6 +1177,7 @@ int mm_util_enc_opt_create(mm_util_enc_opt_h *enc_opt)
        enc_option = g_new0(mm_util_enc_opt_t, 1);
        enc_option->codec = IMG_CODEC_UNKNOWN_TYPE;
        enc_option->compression = DEFAULT_PNG_COMPRESSION;
+       enc_option->lossless = false;
 
        *enc_opt = enc_option;
 
@@ -1201,7 +1208,19 @@ int mm_util_enc_opt_set_png_compression(mm_util_enc_opt_h enc_opt, unsigned int
        return MM_UTIL_ERROR_NONE;
 }
 
+int mm_util_enc_opt_set_webp_lossless(mm_util_enc_opt_h enc_opt, bool lossless)
+{
+       mm_util_enc_opt_t *enc_option = (mm_util_enc_opt_t *)enc_opt;
+
+       mm_util_retvm_if(!enc_opt, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid enc_opt");
+       mm_util_retvm_if(enc_option->codec != IMG_CODEC_WEBP, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid codec [%d]", enc_option->codec);
+
+       enc_option->lossless = lossless;
+
+       return MM_UTIL_ERROR_NONE;
+}
+
 void mm_util_enc_opt_destroy(mm_util_enc_opt_h enc_opt)
 {
        g_free(enc_opt);
-}
\ No newline at end of file
+}
index 7ac1753..fd06832 100644 (file)
@@ -31,16 +31,16 @@ typedef enum {
 
 #define MM_UTIL_SAFE_FREE(src) { if (src) { free(src); src = NULL; } }
 
-static int _magick_rotate_P_P_test(mm_util_rotate_type_e rotation);
-static int _magick_rotate_P_B_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format);
-static int _magick_rotate_B_P_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format);
-static int _magick_rotate_B_B_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format);
-static int _magick_resize_P_P_test(unsigned int req_width, unsigned int req_height);
-static int _magick_resize_P_B_test(unsigned int req_width, unsigned int req_height, mm_util_color_format_e req_format);
-static int _magick_resize_B_P_test(unsigned int req_width, unsigned int req_height, mm_util_color_format_e req_format);
-static int _magick_resize_B_B_test(unsigned int req_width, unsigned int req_height, mm_util_color_format_e req_format);
-static int _magick_convert_B_B_test(mm_util_color_format_e in_format, mm_util_color_format_e out_format);
-static int _magick_resize_and_rotate_P_P_test(unsigned int req_width, unsigned int req_height);
+static int __magick_rotate_P_P_test(mm_util_rotate_type_e rotation);
+static int __magick_rotate_P_B_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format);
+static int __magick_rotate_B_P_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format);
+static int __magick_rotate_B_B_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format);
+static int __magick_resize_P_P_test(unsigned int req_width, unsigned int req_height);
+static int __magick_resize_P_B_test(unsigned int req_width, unsigned int req_height, mm_util_color_format_e req_format);
+static int __magick_resize_B_P_test(unsigned int req_width, unsigned int req_height, mm_util_color_format_e req_format);
+static int __magick_resize_B_B_test(unsigned int req_width, unsigned int req_height, mm_util_color_format_e req_format);
+static int __magick_convert_B_B_test(mm_util_color_format_e in_format, mm_util_color_format_e out_format);
+static int __magick_resize_and_rotate_P_P_test(unsigned int req_width, unsigned int req_height);
 
 static char *__get_dst_path(mm_util_rotate_type_e rotation)
 {
@@ -88,19 +88,6 @@ static char *__get_dst_raw_path(mm_util_rotate_type_e rotation)
        return NULL;
 }
 
-static void __write_to_file(const char *out_path, unsigned char *buffer, size_t buffer_size)
-{
-       FILE *fp = NULL;
-
-       fp = fopen(out_path, "w");
-       if (fp != NULL) {
-               fwrite(buffer, 1, buffer_size, fp);
-               fclose(fp);
-       }
-
-       return;
-}
-
 static void __save_to_file(mm_util_image_h handle, const char *out_path)
 {
        int ret = MM_UTIL_ERROR_NONE;
@@ -109,6 +96,7 @@ static void __save_to_file(mm_util_image_h handle, const char *out_path)
        unsigned int height = 0;
        size_t size = 0;
        mm_util_color_format_e format = MM_UTIL_COLOR_NUM;
+       GError *error = NULL;
 
        ret = mm_image_get_image(handle, &width, &height, &format, &buffer, &size);
        if (ret != MM_UTIL_ERROR_NONE) {
@@ -118,9 +106,12 @@ static void __save_to_file(mm_util_image_h handle, const char *out_path)
 
        printf("[save to file] buffer[%p], width[%u], height[%u], size[%zu], format [%d], out_path [%s]\n", buffer, width, height, size, format, out_path);
 
-       __write_to_file(out_path, buffer, size);
+       if (!g_file_set_contents(out_path, (gchar *)buffer, (gssize)size, &error))
+               printf("Fail g_file_set_contents [%s: %s]", out_path, (error ? error->message : "none"));
 
        MM_UTIL_SAFE_FREE(buffer);
+       if (error)
+               g_error_free(error);
 
        return;
 }
@@ -153,7 +144,7 @@ static int __get_buffer_for_test(mm_util_color_format_e req_format, unsigned cha
        return ret;
 }
 
-static int _magick_rotate_P_P_test(mm_util_rotate_type_e rotation)
+static int __magick_rotate_P_P_test(mm_util_rotate_type_e rotation)
 {
        int ret = MM_UTIL_ERROR_NONE;
        char * src_path = "/opt/usr/home/owner/origin.jpg";
@@ -167,7 +158,7 @@ static int _magick_rotate_P_P_test(mm_util_rotate_type_e rotation)
        return ret;
 }
 
-static int _magick_resize_P_P_test(unsigned int req_width, unsigned int req_height)
+static int __magick_resize_P_P_test(unsigned int req_width, unsigned int req_height)
 {
        int ret = MM_UTIL_ERROR_NONE;
        char * src_path = "/opt/usr/home/owner/origin.jpg";
@@ -185,13 +176,13 @@ static int _magick_resize_P_P_test(unsigned int req_width, unsigned int req_heig
        return ret;
 }
 
-static int _magick_rotate_P_B_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format)
+static int __magick_rotate_P_B_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format)
 {
        int ret = MM_UTIL_ERROR_NONE;
        mm_util_image_h dst_handle = NULL;
        char * src_path = "/opt/usr/home/owner/origin.jpg";
 
-       printf("* Rotate P B Test * rotation = [%d] foramt = [%d] \n", rotation, req_format);
+       printf("* Rotate P B Test * rotation = [%d] format = [%d] \n", rotation, req_format);
 
        ret = mm_util_rotate_P_B(src_path, rotation, req_format, &dst_handle);
        if (ret != MM_UTIL_ERROR_NONE) {
@@ -206,7 +197,7 @@ static int _magick_rotate_P_B_test(mm_util_rotate_type_e rotation, mm_util_color
        return ret;
 }
 
-static int _magick_resize_P_B_test(unsigned int req_width, unsigned int req_height, mm_util_color_format_e req_format)
+static int __magick_resize_P_B_test(unsigned int req_width, unsigned int req_height, mm_util_color_format_e req_format)
 {
        int ret = MM_UTIL_ERROR_NONE;
        mm_util_image_h dst_handle = NULL;
@@ -215,7 +206,7 @@ static int _magick_resize_P_B_test(unsigned int req_width, unsigned int req_heig
        memset(dst_path, 0x00, sizeof(dst_path));
        snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/resize_pb_%u_%u.raw", req_width, req_height);
 
-       printf("* Resize P B Test * W * H [%u * %u], foramt [%d], path [%s]\n", req_width, req_height, req_format, dst_path);
+       printf("* Resize P B Test * W * H [%u * %u], format [%d], path [%s]\n", req_width, req_height, req_format, dst_path);
 
        ret = mm_util_resize_P_B(src_path, req_width, req_height, req_format, &dst_handle);
        if (ret != MM_UTIL_ERROR_NONE) {
@@ -230,7 +221,7 @@ static int _magick_resize_P_B_test(unsigned int req_width, unsigned int req_heig
        return ret;
 }
 
-static int _magick_rotate_B_P_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format)
+static int __magick_rotate_B_P_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format)
 {
        int ret = MM_UTIL_ERROR_NONE;
        mm_util_image_h src_handle = NULL;
@@ -266,7 +257,7 @@ static int _magick_rotate_B_P_test(mm_util_rotate_type_e rotation, mm_util_color
        return ret;
 }
 
-static int _magick_resize_B_P_test(unsigned int req_width, unsigned int req_height, mm_util_color_format_e req_format)
+static int __magick_resize_B_P_test(unsigned int req_width, unsigned int req_height, mm_util_color_format_e req_format)
 {
        int ret = MM_UTIL_ERROR_NONE;
        mm_util_image_h src_handle = NULL;
@@ -279,7 +270,7 @@ static int _magick_resize_B_P_test(unsigned int req_width, unsigned int req_heig
        memset(dst_path, 0x00, sizeof(dst_path));
        snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/resize_bp_%u_%u.jpg", req_width, req_height);
 
-       printf("* Resize B P Test * W * H [%u * %u], foramt [%d], path [%s]\n", req_width, req_height, req_format, dst_path);
+       printf("* Resize B P Test * W * H [%u * %u], format [%d], path [%s]\n", req_width, req_height, req_format, dst_path);
 
        ret = __get_buffer_for_test(req_format, &buffer, &width, &height, &size, &format);
        if (ret != MM_UTIL_ERROR_NONE) {
@@ -305,7 +296,7 @@ static int _magick_resize_B_P_test(unsigned int req_width, unsigned int req_heig
        return ret;
 }
 
-static int _magick_rotate_B_B_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format)
+static int __magick_rotate_B_B_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format)
 {
        int ret = MM_UTIL_ERROR_NONE;
        mm_util_image_h src_handle = NULL;
@@ -345,7 +336,7 @@ static int _magick_rotate_B_B_test(mm_util_rotate_type_e rotation, mm_util_color
        return ret;
 }
 
-static int _magick_resize_B_B_test(unsigned int req_width, unsigned int req_height, mm_util_color_format_e req_format)
+static int __magick_resize_B_B_test(unsigned int req_width, unsigned int req_height, mm_util_color_format_e req_format)
 {
        int ret = MM_UTIL_ERROR_NONE;
        mm_util_image_h src_handle = NULL;
@@ -359,7 +350,7 @@ static int _magick_resize_B_B_test(unsigned int req_width, unsigned int req_heig
        memset(dst_path, 0x00, sizeof(dst_path));
        snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/resize_bb_%u_%u.raw", req_width, req_height);
 
-       printf("* Resize B B Test * W * H [%u * %u], foramt [%d], path [%s]\n", req_width, req_height, req_format, dst_path);
+       printf("* Resize B B Test * W * H [%u * %u], format [%d], path [%s]\n", req_width, req_height, req_format, dst_path);
 
        ret = __get_buffer_for_test(req_format, &buffer, &width, &height, &size, &format);
        if (ret != MM_UTIL_ERROR_NONE) {
@@ -388,7 +379,7 @@ static int _magick_resize_B_B_test(unsigned int req_width, unsigned int req_heig
        return ret;
 }
 
-static int _magick_convert_B_B_test(mm_util_color_format_e in_format, mm_util_color_format_e out_format)
+static int __magick_convert_B_B_test(mm_util_color_format_e in_format, mm_util_color_format_e out_format)
 {
        int ret = MM_UTIL_ERROR_NONE;
        mm_util_image_h src_handle = NULL;
@@ -408,7 +399,7 @@ static int _magick_convert_B_B_test(mm_util_color_format_e in_format, mm_util_co
        }
 
        snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/convert_bb_%u_%u_%d_%d.raw", width, height, in_format, out_format);
-       printf("* Convert B B Test * input_foramt [%d], output_formt [%d] path [%s]\n", in_format, out_format, dst_path);
+       printf("* Convert B B Test * input_format [%d], output_formt [%d] path [%s]\n", in_format, out_format, dst_path);
 
        ret = mm_image_create_image(width, height, format, buffer, size, &src_handle);
        if (ret != MM_UTIL_ERROR_NONE) {
@@ -431,7 +422,7 @@ static int _magick_convert_B_B_test(mm_util_color_format_e in_format, mm_util_co
        return ret;
 }
 
-static int _magick_resize_and_rotate_P_P_test(unsigned int req_width, unsigned int req_height)
+static int __magick_resize_and_rotate_P_P_test(unsigned int req_width, unsigned int req_height)
 {
        int ret = MM_UTIL_ERROR_NONE;
        char * src_path = "/opt/usr/home/owner/origin.jpg";
@@ -448,6 +439,244 @@ static int _magick_resize_and_rotate_P_P_test(unsigned int req_width, unsigned i
        return ret;
 }
 
+static int __magick_decenc_file_png_test(mm_util_color_format_e format, unsigned int comp_level)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       char * src_path = "/opt/usr/home/owner/origin.png";
+       char dst_path[1024] = {0, };
+       mm_util_image_h decoded_image = NULL;
+       mm_util_enc_opt_h enc_option = NULL;
+
+       memset(dst_path, 0x00, sizeof(dst_path));
+       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_file_png_test_%d_%u.png", format, comp_level);
+
+       printf("* PNG test [%s] \n", dst_path);
+
+       ret = mm_util_decode_image_from_file(src_path, format, &decoded_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_decode_image_from_file [0x%x]\n", ret);
+               return ret;
+       }
+
+       ret = mm_util_enc_opt_create(&enc_option);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_enc_opt_create [0x%x]\n", ret);
+               goto END;
+       }
+
+       ret = mm_util_enc_opt_set_codec(enc_option, IMG_CODEC_PNG);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_enc_opt_set_codec [0x%x]\n", ret);
+               goto END;
+       }
+
+       ret = mm_util_enc_opt_set_png_compression(enc_option, comp_level);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_enc_opt_set_png_compression [0x%x]\n", ret);
+               goto END;
+       }
+
+       ret = mm_util_encode_image_to_file(decoded_image, enc_option, dst_path);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail mm_util_encode_image_to_file [0x%x]\n", ret);
+
+END:
+       mm_util_enc_opt_destroy(enc_option);
+       mm_image_destroy_image(decoded_image);
+
+       return ret;
+}
+
+static int __magick_decenc_buffer_png_test(mm_util_color_format_e format, unsigned int comp_level)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       char * src_path = "/opt/usr/home/owner/origin.png";
+       char dst_path[1024] = {0, };
+       mm_util_image_h decoded_image = NULL;
+       mm_util_enc_opt_h enc_option = NULL;
+       gchar *src_buffer = NULL;
+       gsize src_buffer_size = 0;
+       void *buffer = NULL;
+       size_t buffer_size = 0;
+       GError *error = NULL;
+
+       memset(dst_path, 0x00, sizeof(dst_path));
+       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_buffer_png_test_%d_%u.png", format, comp_level);
+
+       printf("* PNG test [%s] \n", dst_path);
+
+       if (!g_file_get_contents(src_path, &src_buffer, &src_buffer_size, &error)) {
+               printf("Fail g_file_get_contents [%s: %s]\n", src_path, (error ? error->message : "none"));
+               if (error)
+                       g_error_free(error);
+               return ret;
+       }
+
+       ret = mm_util_decode_image_from_buffer((void *)src_buffer, (size_t)src_buffer_size, format, &decoded_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_decode_image_from_buffer [0x%x]\n", ret);
+               g_free(src_buffer);
+               return ret;
+       }
+
+       g_free(src_buffer);
+
+       ret = mm_util_enc_opt_create(&enc_option);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_enc_opt_create [0x%x]\n", ret);
+               goto END;
+       }
+
+       ret = mm_util_enc_opt_set_codec(enc_option, IMG_CODEC_PNG);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_enc_opt_set_codec [0x%x]\n", ret);
+               goto END;
+       }
+
+       ret = mm_util_enc_opt_set_png_compression(enc_option, comp_level);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_enc_opt_set_png_compression [0x%x]\n", ret);
+               goto END;
+       }
+
+       ret = mm_util_encode_image_to_buffer(decoded_image, enc_option, &buffer, &buffer_size);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_encode_image_to_buffer [0x%x]\n", ret);
+               goto END;
+       }
+
+       if (!g_file_set_contents(dst_path, (gchar *)buffer, (gssize)buffer_size, &error))
+               printf("Fail g_file_set_contents [%s: %s]", dst_path, (error ? error->message : "none"));
+
+END:
+       mm_util_enc_opt_destroy(enc_option);
+       mm_image_destroy_image(decoded_image);
+       g_free(buffer);
+       if (error)
+               g_error_free(error);
+
+       return ret;
+}
+
+static int __magick_decenc_file_webp_test(mm_util_color_format_e format, bool lossless)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       char * src_path = "/opt/usr/home/owner/origin.webp";
+       char dst_path[1024] = {0, };
+       mm_util_image_h decoded_image = NULL;
+       mm_util_enc_opt_h enc_option = NULL;
+
+       memset(dst_path, 0x00, sizeof(dst_path));
+       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_file_webp_test_%d_%s.webp", format, (lossless ? "ll" : "nor"));
+
+       printf("* WEBP test [%s] \n", dst_path);
+
+       ret = mm_util_decode_image_from_file(src_path, format, &decoded_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_decode_image_from_file [0x%x]\n", ret);
+               return ret;
+       }
+
+       ret = mm_util_enc_opt_create(&enc_option);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_enc_opt_create [0x%x]\n", ret);
+               goto END;
+       }
+
+       ret = mm_util_enc_opt_set_codec(enc_option, IMG_CODEC_WEBP);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_enc_opt_set_codec [0x%x]\n", ret);
+               goto END;
+       }
+
+       ret = mm_util_enc_opt_set_webp_lossless(enc_option, lossless);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_enc_opt_set_webp_lossless [0x%x]\n", ret);
+               goto END;
+       }
+
+       ret = mm_util_encode_image_to_file(decoded_image, enc_option, dst_path);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail mm_util_encode_image_to_file [0x%x]\n", ret);
+
+END:
+       mm_util_enc_opt_destroy(enc_option);
+       mm_image_destroy_image(decoded_image);
+
+       return ret;
+}
+
+static int __magick_decenc_buffer_webp_test(mm_util_color_format_e format, bool lossless)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       char * src_path = "/opt/usr/home/owner/origin.webp";
+       char dst_path[1024] = {0, };
+       mm_util_image_h decoded_image = NULL;
+       mm_util_enc_opt_h enc_option = NULL;
+       gchar *src_buffer = NULL;
+       gsize src_buffer_size = 0;
+       void *buffer = NULL;
+       size_t buffer_size = 0;
+       GError *error = NULL;
+
+       memset(dst_path, 0x00, sizeof(dst_path));
+       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_buffer_webp_test_%d_%s.webp", format, (lossless ? "ll" : "nor"));
+
+       printf("* WEBP test [%s] \n", dst_path);
+
+       if (!g_file_get_contents(src_path, &src_buffer, &src_buffer_size, &error)) {
+               printf("Fail g_file_get_contents [%s: %s]\n", src_path, (error ? error->message : "none"));
+               if (error)
+                       g_error_free(error);
+               return ret;
+       }
+
+       ret = mm_util_decode_image_from_buffer((void *)src_buffer, (size_t)src_buffer_size, format, &decoded_image);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_decode_image_from_buffer [0x%x]\n", ret);
+               g_free(src_buffer);
+               return ret;
+       }
+
+       g_free(src_buffer);
+
+       ret = mm_util_enc_opt_create(&enc_option);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_enc_opt_create [0x%x]\n", ret);
+               goto END;
+       }
+
+       ret = mm_util_enc_opt_set_codec(enc_option, IMG_CODEC_WEBP);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_enc_opt_set_codec [0x%x]\n", ret);
+               goto END;
+       }
+
+       ret = mm_util_enc_opt_set_webp_lossless(enc_option, lossless);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_enc_opt_set_webp_lossless [0x%x]\n", ret);
+               goto END;
+       }
+
+       ret = mm_util_encode_image_to_buffer(decoded_image, enc_option, &buffer, &buffer_size);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_encode_image_to_buffer [0x%x]\n", ret);
+               goto END;
+       }
+
+       if (!g_file_set_contents(dst_path, (gchar *)buffer, (gssize)buffer_size, &error))
+               printf("Fail g_file_set_contents [%s: %s]", dst_path, (error ? error->message : "none"));
+
+END:
+       mm_util_enc_opt_destroy(enc_option);
+       mm_image_destroy_image(decoded_image);
+       g_free(buffer);
+       if (error)
+               g_error_free(error);
+
+       return ret;
+}
+
 int main(int argc, char *argv[])
 {
        int ret = MM_UTIL_ERROR_NONE;
@@ -457,79 +686,123 @@ int main(int argc, char *argv[])
                printf("Choose menu!! ex) mm_util_magick_testsuite 1\n");
 
        } else if (strcmp(argv[1], "1") == 0) {
-               ret = _magick_rotate_P_P_test(MM_UTIL_ROTATE_0);
-               ret = _magick_rotate_P_P_test(MM_UTIL_ROTATE_90);
-               ret = _magick_rotate_P_P_test(MM_UTIL_ROTATE_180);
-               ret = _magick_rotate_P_P_test(MM_UTIL_ROTATE_270);
-               ret = _magick_rotate_P_P_test(MM_UTIL_ROTATE_FLIP_HORZ);
-               ret = _magick_rotate_P_P_test(MM_UTIL_ROTATE_FLIP_VERT);
+               ret = __magick_rotate_P_P_test(MM_UTIL_ROTATE_0);
+               ret = __magick_rotate_P_P_test(MM_UTIL_ROTATE_90);
+               ret = __magick_rotate_P_P_test(MM_UTIL_ROTATE_180);
+               ret = __magick_rotate_P_P_test(MM_UTIL_ROTATE_270);
+               ret = __magick_rotate_P_P_test(MM_UTIL_ROTATE_FLIP_HORZ);
+               ret = __magick_rotate_P_P_test(MM_UTIL_ROTATE_FLIP_VERT);
 
        } else if (strcmp(argv[1], "2") == 0) {
-               ret = _magick_rotate_P_B_test(MM_UTIL_ROTATE_0, MM_UTIL_COLOR_ARGB);
-               ret = _magick_rotate_P_B_test(MM_UTIL_ROTATE_90, MM_UTIL_COLOR_RGB24);
-               ret = _magick_rotate_P_B_test(MM_UTIL_ROTATE_180, MM_UTIL_COLOR_ARGB);
-               ret = _magick_rotate_P_B_test(MM_UTIL_ROTATE_270, MM_UTIL_COLOR_BGRA);
-               ret = _magick_rotate_P_B_test(MM_UTIL_ROTATE_FLIP_HORZ, MM_UTIL_COLOR_RGBA);
-               ret = _magick_rotate_P_B_test(MM_UTIL_ROTATE_FLIP_VERT, MM_UTIL_COLOR_RGBA);
+               ret = __magick_rotate_P_B_test(MM_UTIL_ROTATE_0, MM_UTIL_COLOR_ARGB);
+               ret = __magick_rotate_P_B_test(MM_UTIL_ROTATE_90, MM_UTIL_COLOR_RGB24);
+               ret = __magick_rotate_P_B_test(MM_UTIL_ROTATE_180, MM_UTIL_COLOR_ARGB);
+               ret = __magick_rotate_P_B_test(MM_UTIL_ROTATE_270, MM_UTIL_COLOR_BGRA);
+               ret = __magick_rotate_P_B_test(MM_UTIL_ROTATE_FLIP_HORZ, MM_UTIL_COLOR_RGBA);
+               ret = __magick_rotate_P_B_test(MM_UTIL_ROTATE_FLIP_VERT, MM_UTIL_COLOR_RGBA);
 
        } else if (strcmp(argv[1], "3") == 0) {
-               ret = _magick_rotate_B_P_test(MM_UTIL_ROTATE_0, MM_UTIL_COLOR_ARGB);
-               ret = _magick_rotate_B_P_test(MM_UTIL_ROTATE_90, MM_UTIL_COLOR_RGB24);
-               ret = _magick_rotate_B_P_test(MM_UTIL_ROTATE_180, MM_UTIL_COLOR_ARGB);
-               ret = _magick_rotate_B_P_test(MM_UTIL_ROTATE_270, MM_UTIL_COLOR_BGRA);
-               ret = _magick_rotate_B_P_test(MM_UTIL_ROTATE_FLIP_HORZ, MM_UTIL_COLOR_RGBA);
-               ret = _magick_rotate_B_P_test(MM_UTIL_ROTATE_FLIP_VERT, MM_UTIL_COLOR_RGBA);
+               ret = __magick_rotate_B_P_test(MM_UTIL_ROTATE_0, MM_UTIL_COLOR_ARGB);
+               ret = __magick_rotate_B_P_test(MM_UTIL_ROTATE_90, MM_UTIL_COLOR_RGB24);
+               ret = __magick_rotate_B_P_test(MM_UTIL_ROTATE_180, MM_UTIL_COLOR_ARGB);
+               ret = __magick_rotate_B_P_test(MM_UTIL_ROTATE_270, MM_UTIL_COLOR_BGRA);
+               ret = __magick_rotate_B_P_test(MM_UTIL_ROTATE_FLIP_HORZ, MM_UTIL_COLOR_RGBA);
+               ret = __magick_rotate_B_P_test(MM_UTIL_ROTATE_FLIP_VERT, MM_UTIL_COLOR_RGBA);
 
        } else if (strcmp(argv[1], "4") == 0) {
-               ret = _magick_rotate_B_B_test(MM_UTIL_ROTATE_0, MM_UTIL_COLOR_ARGB);
-               ret = _magick_rotate_B_B_test(MM_UTIL_ROTATE_90, MM_UTIL_COLOR_RGB24);
-               ret = _magick_rotate_B_B_test(MM_UTIL_ROTATE_180, MM_UTIL_COLOR_ARGB);
-               ret = _magick_rotate_B_B_test(MM_UTIL_ROTATE_270, MM_UTIL_COLOR_BGRA);
-               ret = _magick_rotate_B_B_test(MM_UTIL_ROTATE_FLIP_HORZ, MM_UTIL_COLOR_RGBA);
-               ret = _magick_rotate_B_B_test(MM_UTIL_ROTATE_FLIP_VERT, MM_UTIL_COLOR_RGBA);
-               ret = _magick_rotate_B_B_test(100, MM_UTIL_COLOR_RGBA); //invalid parameter
+               ret = __magick_rotate_B_B_test(MM_UTIL_ROTATE_0, MM_UTIL_COLOR_ARGB);
+               ret = __magick_rotate_B_B_test(MM_UTIL_ROTATE_90, MM_UTIL_COLOR_RGB24);
+               ret = __magick_rotate_B_B_test(MM_UTIL_ROTATE_180, MM_UTIL_COLOR_ARGB);
+               ret = __magick_rotate_B_B_test(MM_UTIL_ROTATE_270, MM_UTIL_COLOR_BGRA);
+               ret = __magick_rotate_B_B_test(MM_UTIL_ROTATE_FLIP_HORZ, MM_UTIL_COLOR_RGBA);
+               ret = __magick_rotate_B_B_test(MM_UTIL_ROTATE_FLIP_VERT, MM_UTIL_COLOR_RGBA);
+               ret = __magick_rotate_B_B_test(100, MM_UTIL_COLOR_RGBA);        //invalid parameter
 
        } else if (strcmp(argv[1], "5") == 0) {
-               ret = _magick_resize_P_P_test(3000, 2000);
-               ret = _magick_resize_P_P_test(199, 299);
-               ret = _magick_resize_P_P_test(3, 2);
-               ret = _magick_resize_P_P_test(10000, 10000);
-               ret = _magick_resize_P_P_test(0, 2000); //invalid parameter
+               ret = __magick_resize_P_P_test(3000, 2000);
+               ret = __magick_resize_P_P_test(199, 299);
+               ret = __magick_resize_P_P_test(3, 2);
+               ret = __magick_resize_P_P_test(10000, 10000);
+               ret = __magick_resize_P_P_test(0, 2000); //invalid parameter
 
        } else if (strcmp(argv[1], "6") == 0) {
-               ret = _magick_resize_P_B_test(3000, 2000, MM_UTIL_COLOR_RGB24);
-               ret = _magick_resize_P_B_test(199, 299, MM_UTIL_COLOR_ARGB);
-               ret = _magick_resize_P_B_test(3, 2, MM_UTIL_COLOR_BGRA);
-               ret = _magick_resize_P_B_test(1000, 999, MM_UTIL_COLOR_RGBA);
-               ret = _magick_resize_P_B_test(10000, 999, MM_UTIL_COLOR_RGBA);
+               ret = __magick_resize_P_B_test(3000, 2000, MM_UTIL_COLOR_RGB24);
+               ret = __magick_resize_P_B_test(199, 299, MM_UTIL_COLOR_ARGB);
+               ret = __magick_resize_P_B_test(3, 2, MM_UTIL_COLOR_BGRA);
+               ret = __magick_resize_P_B_test(1000, 999, MM_UTIL_COLOR_RGBA);
+               ret = __magick_resize_P_B_test(10000, 999, MM_UTIL_COLOR_RGBA);
 
        } else if (strcmp(argv[1], "7") == 0) {
-               ret = _magick_resize_B_P_test(3000, 2000, MM_UTIL_COLOR_RGB24);
-               ret = _magick_resize_B_P_test(199, 299, MM_UTIL_COLOR_ARGB);
-               ret = _magick_resize_B_P_test(3, 2, MM_UTIL_COLOR_BGRA);
-               ret = _magick_resize_B_P_test(1000, 999, MM_UTIL_COLOR_RGBA);
-               ret = _magick_resize_B_P_test(10000, 999, MM_UTIL_COLOR_RGBA);
+               ret = __magick_resize_B_P_test(3000, 2000, MM_UTIL_COLOR_RGB24);
+               ret = __magick_resize_B_P_test(199, 299, MM_UTIL_COLOR_ARGB);
+               ret = __magick_resize_B_P_test(3, 2, MM_UTIL_COLOR_BGRA);
+               ret = __magick_resize_B_P_test(1000, 999, MM_UTIL_COLOR_RGBA);
+               ret = __magick_resize_B_P_test(10000, 999, MM_UTIL_COLOR_RGBA);
 
        } else if (strcmp(argv[1], "8") == 0) {
-               ret = _magick_resize_B_B_test(3000, 2000, MM_UTIL_COLOR_RGB24);
-               ret = _magick_resize_B_B_test(199, 299, MM_UTIL_COLOR_ARGB);
-               ret = _magick_resize_B_B_test(3, 2, MM_UTIL_COLOR_BGRA);
-               ret = _magick_resize_B_B_test(1000, 999, MM_UTIL_COLOR_RGBA);
-               ret = _magick_resize_B_B_test(10000, 999, MM_UTIL_COLOR_RGBA);
+               ret = __magick_resize_B_B_test(3000, 2000, MM_UTIL_COLOR_RGB24);
+               ret = __magick_resize_B_B_test(199, 299, MM_UTIL_COLOR_ARGB);
+               ret = __magick_resize_B_B_test(3, 2, MM_UTIL_COLOR_BGRA);
+               ret = __magick_resize_B_B_test(1000, 999, MM_UTIL_COLOR_RGBA);
+               ret = __magick_resize_B_B_test(10000, 999, MM_UTIL_COLOR_RGBA);
 
        } else if (strcmp(argv[1], "9") == 0) {
-               ret = _magick_convert_B_B_test(MM_UTIL_COLOR_RGB24, MM_UTIL_COLOR_RGBA);
-               ret = _magick_convert_B_B_test(MM_UTIL_COLOR_ARGB, MM_UTIL_COLOR_RGBA);
-               ret = _magick_convert_B_B_test(MM_UTIL_COLOR_BGRA, MM_UTIL_COLOR_RGBA);
-               ret = _magick_convert_B_B_test(MM_UTIL_COLOR_RGBA, MM_UTIL_COLOR_RGB24);
-               ret = _magick_convert_B_B_test(MM_UTIL_COLOR_BGRA, MM_UTIL_COLOR_RGB24);
+               ret = __magick_convert_B_B_test(MM_UTIL_COLOR_RGB24, MM_UTIL_COLOR_RGBA);
+               ret = __magick_convert_B_B_test(MM_UTIL_COLOR_ARGB, MM_UTIL_COLOR_RGBA);
+               ret = __magick_convert_B_B_test(MM_UTIL_COLOR_BGRA, MM_UTIL_COLOR_RGBA);
+               ret = __magick_convert_B_B_test(MM_UTIL_COLOR_RGBA, MM_UTIL_COLOR_RGB24);
+               ret = __magick_convert_B_B_test(MM_UTIL_COLOR_BGRA, MM_UTIL_COLOR_RGB24);
 
        } else if (strcmp(argv[1], "10") == 0) {
-               ret = _magick_resize_and_rotate_P_P_test(3000, 2000);
-               ret = _magick_resize_and_rotate_P_P_test(199, 299);
-               ret = _magick_resize_and_rotate_P_P_test(3, 2);
-               ret = _magick_resize_and_rotate_P_P_test(10000, 10000);
-               ret = _magick_resize_and_rotate_P_P_test(0, 2000); //invalid parameter
+               ret = __magick_resize_and_rotate_P_P_test(3000, 2000);
+               ret = __magick_resize_and_rotate_P_P_test(199, 299);
+               ret = __magick_resize_and_rotate_P_P_test(3, 2);
+               ret = __magick_resize_and_rotate_P_P_test(10000, 10000);
+               ret = __magick_resize_and_rotate_P_P_test(0, 2000); //invalid parameter
+
+       } else if (strcmp(argv[1], "11") == 0) {
+               ret = __magick_decenc_file_png_test(MM_UTIL_COLOR_ARGB, 0);
+               ret = __magick_decenc_file_png_test(MM_UTIL_COLOR_BGRA, 0);
+               ret = __magick_decenc_file_png_test(MM_UTIL_COLOR_RGBA, 0);
+
+               ret = __magick_decenc_file_png_test(MM_UTIL_COLOR_ARGB, 6);
+               ret = __magick_decenc_file_png_test(MM_UTIL_COLOR_BGRA, 6);
+               ret = __magick_decenc_file_png_test(MM_UTIL_COLOR_RGBA, 6);
+
+               ret = __magick_decenc_file_png_test(MM_UTIL_COLOR_ARGB, 9);
+               ret = __magick_decenc_file_png_test(MM_UTIL_COLOR_BGRA, 9);
+               ret = __magick_decenc_file_png_test(MM_UTIL_COLOR_RGBA, 9);
+
+       } else if (strcmp(argv[1], "12") == 0) {
+               ret = __magick_decenc_buffer_png_test(MM_UTIL_COLOR_ARGB, 0);
+               ret = __magick_decenc_buffer_png_test(MM_UTIL_COLOR_BGRA, 0);
+               ret = __magick_decenc_buffer_png_test(MM_UTIL_COLOR_RGBA, 0);
+
+               ret = __magick_decenc_buffer_png_test(MM_UTIL_COLOR_ARGB, 6);
+               ret = __magick_decenc_buffer_png_test(MM_UTIL_COLOR_BGRA, 6);
+               ret = __magick_decenc_buffer_png_test(MM_UTIL_COLOR_RGBA, 6);
+
+               ret = __magick_decenc_buffer_png_test(MM_UTIL_COLOR_ARGB, 9);
+               ret = __magick_decenc_buffer_png_test(MM_UTIL_COLOR_BGRA, 9);
+               ret = __magick_decenc_buffer_png_test(MM_UTIL_COLOR_RGBA, 9);
+
+       } else if (strcmp(argv[1], "13") == 0) {
+               ret = __magick_decenc_file_webp_test(MM_UTIL_COLOR_ARGB, false);
+               ret = __magick_decenc_file_webp_test(MM_UTIL_COLOR_BGRA, false);
+               ret = __magick_decenc_file_webp_test(MM_UTIL_COLOR_RGBA, false);
+
+               ret = __magick_decenc_file_webp_test(MM_UTIL_COLOR_ARGB, true);
+               ret = __magick_decenc_file_webp_test(MM_UTIL_COLOR_BGRA, true);
+               ret = __magick_decenc_file_webp_test(MM_UTIL_COLOR_RGBA, true);
+
+       } else if (strcmp(argv[1], "14") == 0) {
+               ret = __magick_decenc_buffer_webp_test(MM_UTIL_COLOR_ARGB, false);
+               ret = __magick_decenc_buffer_webp_test(MM_UTIL_COLOR_BGRA, false);
+               ret = __magick_decenc_buffer_webp_test(MM_UTIL_COLOR_RGBA, false);
+
+               ret = __magick_decenc_buffer_webp_test(MM_UTIL_COLOR_ARGB, true);
+               ret = __magick_decenc_buffer_webp_test(MM_UTIL_COLOR_BGRA, true);
+               ret = __magick_decenc_buffer_webp_test(MM_UTIL_COLOR_RGBA, true);
 
        } else {
                printf("Invalid parameter\n");