heif_testsuite: Use 'GraphicsMagick' instead of 'libmm-utility' 71/255071/5 accepted/tizen/unified/20210317.115904 submit/tizen/20210316.062438
authorjiyong.min <jiyong.min@samsung.com>
Thu, 11 Mar 2021 01:35:22 +0000 (10:35 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Mon, 15 Mar 2021 00:59:18 +0000 (09:59 +0900)
 - To avoid a dependency conflict, 'libmm-utility' is changed to 'GraphicsMagick'.

Change-Id: I5aa1449a91b2a61c2f975d5a48715b0fe912c299

packaging/libheif.spec
src/heif.c
test/CMakeLists.txt
test/heif_testsuite.c

index 0754ad7..58d25e1 100644 (file)
@@ -17,9 +17,7 @@ BuildRequires:  pkgconfig(libavformat)
 BuildRequires: pkgconfig(libavutil)
 BuildRequires: pkgconfig(libswscale)
 BuildRequires:  pkgconfig(mm-common)
-BuildRequires:  pkgconfig(mmutil-common)
-BuildRequires:  pkgconfig(mmutil-jpeg)
-BuildRequires:  pkgconfig(mmutil-magick)
+BuildRequires:  pkgconfig(GraphicsMagick)
 BuildRoot:  %{_tmppath}/%{name}-%{version}-build
 
 %description
index 3dc636a..3547ea2 100644 (file)
@@ -28,9 +28,7 @@
 #include "heif_extractor.h"
 #include "heif_decoder.h"
 
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(arr)                (sizeof(arr) / sizeof((arr)[0]))
-#endif
+
 #define HEIF_ATTRS_NAME                "heif-image"
 #define HEIC_MIMETYPE          "image/heic"
 #define DEFAULT_MIMETYPE       HEIC_MIMETYPE
@@ -156,7 +154,7 @@ int heif_get_image_info_from_file(const char *path, heif_image_info_h *image_inf
                return ret;
        }
 
-       ret = mm_attrs_new(g_heif_attrs, ARRAY_SIZE(g_heif_attrs), HEIF_ATTRS_NAME, NULL, NULL, &attrs);
+       ret = mm_attrs_new(g_heif_attrs, G_N_ELEMENTS(g_heif_attrs), HEIF_ATTRS_NAME, NULL, NULL, &attrs);
        if (ret != MM_ERROR_NONE) {
                heif_error("mm_attrs_new fail %d", ret);
                ret = LIBHEIF_ERROR_INVALID_OPERATION;
@@ -190,7 +188,7 @@ int heif_get_image_info_from_buffer(unsigned char *data, size_t size, heif_image
                return ret;
        }
 
-       ret = mm_attrs_new(g_heif_attrs, ARRAY_SIZE(g_heif_attrs), HEIF_ATTRS_NAME, NULL, NULL, &attrs);
+       ret = mm_attrs_new(g_heif_attrs, G_N_ELEMENTS(g_heif_attrs), HEIF_ATTRS_NAME, NULL, NULL, &attrs);
        if (ret != MM_ERROR_NONE) {
                heif_error("mm_attrs_new fail %d", ret);
                ret = LIBHEIF_ERROR_INVALID_OPERATION;
index 6d102dc..bc6d13a 100644 (file)
@@ -2,7 +2,7 @@ SET(fw_name "heif")
 SET(fw_test "${fw_name}-test")
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(${fw_test} REQUIRED glib-2.0 dlog mmutil-common mmutil-jpeg mmutil-magick)
+pkg_check_modules(${fw_test} REQUIRED glib-2.0 dlog GraphicsMagick)
 FOREACH(flag ${${fw_test}_CFLAGS})
     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
index 116f6c7..21d4d2c 100644 (file)
@@ -22,9 +22,7 @@
 #include <stdio.h>
 #include <glib.h>
 
-#include <mm_util_image.h>
-#include <mm_util_jpeg.h>
-#include <mm_util_magick.h>
+#include <magick/api.h>
 
 #include <heif.h>
 #include <heif_source.h>
@@ -44,7 +42,7 @@ typedef enum {
 
 static const char *g_test_decode_file_jpeg[] = {
        [HEIF_COLOR_FORMAT_NONE] = NULL,
-       [HEIF_COLOR_FORMAT_YUV420P] = "/opt/usr/home/owner/media/test_heif_file_yuv420p.jpg",
+       [HEIF_COLOR_FORMAT_YUV420P] = NULL,
        [HEIF_COLOR_FORMAT_RGB24] = "/opt/usr/home/owner/media/test_heif_file_rgb24.jpg",
        [HEIF_COLOR_FORMAT_ARGB] = "/opt/usr/home/owner/media/test_heif_file_argb.jpg",
        [HEIF_COLOR_FORMAT_BGRA] = "/opt/usr/home/owner/media/test_heif_file_bgra.jpg",
@@ -60,7 +58,7 @@ static const char *g_test_decode_file_png[] = {
 };
 static const char *g_test_decode_buff_jpeg[] = {
        [HEIF_COLOR_FORMAT_NONE] = NULL,
-       [HEIF_COLOR_FORMAT_YUV420P] = "/opt/usr/home/owner/media/test_heif_buff_yuv420p.jpg",
+       [HEIF_COLOR_FORMAT_YUV420P] = NULL,
        [HEIF_COLOR_FORMAT_RGB24] = "/opt/usr/home/owner/media/test_heif_buff_rgb24.jpg",
        [HEIF_COLOR_FORMAT_ARGB] = "/opt/usr/home/owner/media/test_heif_buff_argb.jpg",
        [HEIF_COLOR_FORMAT_BGRA] = "/opt/usr/home/owner/media/test_heif_buff_bgra.jpg",
@@ -76,7 +74,7 @@ static const char *g_test_decode_buff_png[] = {
 };
 static const char *g_test_thumb_file_jpeg[] = {
        [HEIF_COLOR_FORMAT_NONE] = NULL,
-       [HEIF_COLOR_FORMAT_YUV420P] = "/opt/usr/home/owner/media/test_heif_thumb_file_yuv420p.jpg",
+       [HEIF_COLOR_FORMAT_YUV420P] = NULL,
        [HEIF_COLOR_FORMAT_RGB24] = "/opt/usr/home/owner/media/test_heif_thumb_file_rgb24.jpg",
        [HEIF_COLOR_FORMAT_ARGB] = "/opt/usr/home/owner/media/test_heif_thumb_file_argb.jpg",
        [HEIF_COLOR_FORMAT_BGRA] = "/opt/usr/home/owner/media/test_heif_thumb_file_bgra.jpg",
@@ -92,7 +90,7 @@ static const char *g_test_thumb_file_png[] = {
 };
 static const char *g_test_thumb_buff_jpeg[] = {
        [HEIF_COLOR_FORMAT_NONE] = NULL,
-       [HEIF_COLOR_FORMAT_YUV420P] = "/opt/usr/home/owner/media/test_heif_thumb_buff_yuv420p.jpg",
+       [HEIF_COLOR_FORMAT_YUV420P] = NULL,
        [HEIF_COLOR_FORMAT_RGB24] = "/opt/usr/home/owner/media/test_heif_thumb_buff_rgb24.jpg",
        [HEIF_COLOR_FORMAT_ARGB] = "/opt/usr/home/owner/media/test_heif_thumb_buff_argb.jpg",
        [HEIF_COLOR_FORMAT_BGRA] = "/opt/usr/home/owner/media/test_heif_thumb_buff_bgra.jpg",
@@ -121,10 +119,8 @@ static bool __test_get_info(int mode);
 static bool __test_decode(int mode);
 static bool __test_thumb(int mode);
 static int __get_image_attrs(heif_image_info_h image_info);
-// encode image using libmm-utility
-static int __convert_heif_image_to_mm_image(heif_image_h heif_image, mm_util_image_h *mm_image);
-static int __save_to_jpeg(heif_image_h source, const char *path);
-static int __save_to_png(heif_image_h source, const char *path);
+// encode image using GraphicsMagick
+static int __save_image_to_file(heif_image_h source, const char *path);
 
 
 int main(int argc, char *argv[])
@@ -294,7 +290,7 @@ static bool __test_get_info(int mode)
        switch (mode) {
        case TEST_GETINFO_FILE:
                ret = heif_get_image_info_from_file(g_path, &image_info);
-               if (ret < 0) {
+               if (ret != LIBHEIF_ERROR_NONE) {
                        g_print("\t[HEIF_TEST] heif_get_image_info_from_file fail %d\n", ret);
                        return false;
                }
@@ -302,7 +298,7 @@ static bool __test_get_info(int mode)
                g_print("[HEIF_TEST] heif_get_image_info_from_file succeed !!!\n");
 
                ret = __get_image_attrs(image_info);
-               if (ret < 0) {
+               if (ret != LIBHEIF_ERROR_NONE) {
                        g_print("\t[HEIF_TEST] __get_image_attrs fail %d\n", ret);
                        result = false;
                }
@@ -317,7 +313,7 @@ static bool __test_get_info(int mode)
                }
 
                ret = heif_get_image_info_from_buffer((unsigned char *)((void *)buffer), (size_t)size, &image_info);
-               if (ret < 0) {
+               if (ret != LIBHEIF_ERROR_NONE) {
                        g_print("\t[HEIF_TEST] heif_get_image_info_from_buffer fail %d\n", ret);
                        g_free(buffer);
                        return false;
@@ -326,7 +322,7 @@ static bool __test_get_info(int mode)
                g_print("[HEIF_TEST] heif_get_image_info_from_buffer succeed !!!\n");
 
                ret = __get_image_attrs(image_info);
-               if (ret < 0) {
+               if (ret != LIBHEIF_ERROR_NONE) {
                        g_print("\t[HEIF_TEST] __get_image_attrs fail %d\n", ret);
                        result = false;
                }
@@ -354,20 +350,20 @@ static bool __test_decode(int mode)
        switch (mode) {
        case TEST_DECODE_FILE:
                ret = heif_decode_image_from_file(g_path, g_color, &image);
-               if (ret < 0) {
+               if (ret != LIBHEIF_ERROR_NONE) {
                        g_print("\t[HEIF_TEST] heif_decode_image_from_file(format:%u) fail %d\n", g_color, ret);
                        return false;
                }
 
                g_print("[HEIF_TEST] heif_decode_image_from_file succeed !!!\n");
 
-               ret = __save_to_jpeg(image, g_test_decode_file_jpeg[g_color]);
-               if (ret < 0)
-                       g_print("\t[HEIF_TEST] __save_to_jpeg fail %d\n", ret);
+               ret = __save_image_to_file(image, g_test_decode_file_jpeg[g_color]);
+               if (ret != LIBHEIF_ERROR_NONE)
+                       g_print("\t[HEIF_TEST] __save_to_image fail %d\n", ret);
 
-               ret = __save_to_png(image, g_test_decode_file_png[g_color]);
-               if (ret < 0)
-                       g_print("\t[HEIF_TEST] __save_to_png fail %d\n", ret);
+               ret = __save_image_to_file(image, g_test_decode_file_png[g_color]);
+               if (ret != LIBHEIF_ERROR_NONE)
+                       g_print("\t[HEIF_TEST] __save_to_image fail %d\n", ret);
 
                break;
 
@@ -380,20 +376,20 @@ static bool __test_decode(int mode)
                }
 
                ret = heif_decode_image_from_buffer((unsigned char *)((void *)buffer), (size_t)size, g_color, &image);
-               if (ret < 0) {
+               if (ret != LIBHEIF_ERROR_NONE) {
                        g_print("\t[HEIF_TEST] heif_decode_image_from_buffer fail %d\n", ret);
                        return false;
                }
 
                g_print("[HEIF_TEST] heif_decode_image_from_buffer succeed !!!\n");
 
-               ret = __save_to_jpeg(image, g_test_decode_buff_jpeg[g_color]);
-               if (ret < 0)
-                       g_print("\t[HEIF_TEST] __save_to_jpeg fail %d\n", ret);
+               ret = __save_image_to_file(image, g_test_decode_buff_jpeg[g_color]);
+               if (ret != LIBHEIF_ERROR_NONE)
+                       g_print("\t[HEIF_TEST] __save_to_image fail %d\n", ret);
 
-               ret = __save_to_png(image, g_test_decode_buff_png[g_color]);
-               if (ret < 0)
-                       g_print("\t[HEIF_TEST] __save_to_png fail %d\n", ret);
+               ret = __save_image_to_file(image, g_test_decode_buff_png[g_color]);
+               if (ret != LIBHEIF_ERROR_NONE)
+                       g_print("\t[HEIF_TEST] __save_to_image fail %d\n", ret);
 
                g_free(buffer);
                break;
@@ -418,20 +414,20 @@ static bool __test_thumb(int mode)
        switch (mode) {
        case TEST_THUMB_FILE:
                ret = heif_decode_thumb_from_file(g_path, g_color, &thumbnail);
-               if (ret < 0) {
+               if (ret != LIBHEIF_ERROR_NONE) {
                        g_print("\t[HEIF_TEST] heif_decode_thumb_from_file(format:%u) fail %d\n", g_color, ret);
                        return false;
                }
 
                g_print("[HEIF_TEST] heif_decode_thumb_from_file succeed !!!\n");
 
-               ret = __save_to_jpeg(thumbnail, g_test_thumb_file_jpeg[g_color]);
-               if (ret < 0)
-                       g_print("\t[HEIF_TEST] __save_to_jpeg fail %d\n", ret);
+               ret = __save_image_to_file(thumbnail, g_test_thumb_file_jpeg[g_color]);
+               if (ret != LIBHEIF_ERROR_NONE)
+                       g_print("\t[HEIF_TEST] __save_to_image fail %d\n", ret);
 
-               ret = __save_to_png(thumbnail, g_test_thumb_file_png[g_color]);
-               if (ret < 0)
-                       g_print("\t[HEIF_TEST] __save_to_png fail %d\n", ret);
+               ret = __save_image_to_file(thumbnail, g_test_thumb_file_png[g_color]);
+               if (ret != LIBHEIF_ERROR_NONE)
+                       g_print("\t[HEIF_TEST] __save_to_image fail %d\n", ret);
 
                break;
 
@@ -444,20 +440,20 @@ static bool __test_thumb(int mode)
                }
 
                ret = heif_decode_thumb_from_buffer((unsigned char *)((void *)buffer), (size_t)size, g_color, &thumbnail);
-               if (ret < 0) {
+               if (ret != LIBHEIF_ERROR_NONE) {
                        g_print("\t[HEIF_TEST] heif_decode_thumb_from_buffer fail %d\n", ret);
                        return false;
                }
 
                g_print("[HEIF_TEST] heif_decode_thumb_from_buffer succeed !!!\n");
 
-               ret = __save_to_jpeg(thumbnail, g_test_thumb_buff_jpeg[g_color]);
-               if (ret < 0)
-                       g_print("\t[HEIF_TEST] __save_to_jpeg fail %d\n", ret);
+               ret = __save_image_to_file(thumbnail, g_test_thumb_buff_jpeg[g_color]);
+               if (ret != LIBHEIF_ERROR_NONE)
+                       g_print("\t[HEIF_TEST] __save_to_image fail %d\n", ret);
 
-               ret = __save_to_png(thumbnail, g_test_thumb_buff_png[g_color]);
-               if (ret < 0)
-                       g_print("\t[HEIF_TEST] __save_to_png fail %d\n", ret);
+               ret = __save_image_to_file(thumbnail, g_test_thumb_buff_png[g_color]);
+               if (ret != LIBHEIF_ERROR_NONE)
+                       g_print("\t[HEIF_TEST] __save_to_image fail %d\n", ret);
 
                g_free(buffer);
                break;
@@ -510,126 +506,140 @@ static int __get_image_attrs(heif_image_info_h image_info)
        return ret;
 }
 
-static int __convert_heif_image_to_mm_image(heif_image_h heif_image, mm_util_image_h *mm_image)
+static void __magick_log_method(const ExceptionType excep, const char *message)
 {
-       int ret = LIBHEIF_ERROR_NONE;
-       mm_util_color_format_e color = MM_UTIL_COLOR_RGB24;
-       unsigned int width = 0, height = 0;
-       heif_color_format_e format;
-       unsigned char *data = NULL;
-       size_t size = 0;
+       /* To exclude time, user time and pid */
+       unsigned int start_idx = 31;
 
-       ret = heif_image_get_image(heif_image, &width, &height, &format, &data, &size);
-       if (ret != LIBHEIF_ERROR_NONE) {
-               g_print("\t[HEIF_TEST] heif_image_get_image fail %d\n", ret);
-               return ret;
-       }
+       if (!message || (strlen(message) < start_idx))
+               start_idx = 0;
 
-       g_print("[HEIF_TEST][SOURCE] width: %u, height: %u format: %u data: %p, size: %zu\n", width, height, format, data, size);
+       g_print("\t\t[GM][Ex:%3u] %s", excep, message + start_idx);
+}
 
+static const char * __magick_get_map(heif_color_format_e format)
+{
        switch (format) {
        case HEIF_COLOR_FORMAT_RGB24:
-               color = MM_UTIL_COLOR_RGB24;
-               break;
-
+               return "RGB";
        case HEIF_COLOR_FORMAT_ARGB:
-               color = MM_UTIL_COLOR_ARGB;
-               break;
-
+               return "ARGB";
        case HEIF_COLOR_FORMAT_BGRA:
-               color = MM_UTIL_COLOR_BGRA;
-               break;
-
+               return "BGRA";
        case HEIF_COLOR_FORMAT_RGBA:
-               color = MM_UTIL_COLOR_RGBA;
-               break;
+               return "RGBA";
+       default:
+               g_print("\t[HEIF_TEST] not supported format. [%d]", format);
+               return NULL;
+       }
+}
 
-       case HEIF_COLOR_FORMAT_YUV420P:
-               color = MM_UTIL_COLOR_YUV420;
-               break;
+static Image *__magick_get_image(heif_image_h source, ExceptionInfo *exception)
+{
+       unsigned int width = 0, height = 0;
+       heif_color_format_e format = HEIF_COLOR_FORMAT_NONE;
+       unsigned char *data = NULL;
+       size_t size = 0;
+       const char *map = NULL;
+       Image *image = NULL;
 
-       default:
-               g_print("\t[HEIF_TEST] invalid color: %d\n", format);
-               return MM_UTIL_ERROR_INVALID_PARAMETER;
+       if (!exception) {
+               g_print("\t[HEIF_TEST] invalid exception\n");
+               return NULL;
+       }
+
+       if (heif_image_get_image(source, &width, &height, &format, &data, &size) != LIBHEIF_ERROR_NONE) {
+               g_print("\t[HEIF_TEST] heif_image_get_image fail\n");
+               return NULL;
        }
 
-       ret = mm_image_create_image(width, height, color, data, size, mm_image);
-       if (ret != MM_UTIL_ERROR_NONE) {
-               g_print("\t[HEIF_TEST] mm_image_create_image fail %d\n", ret);
-               return ret;
+       map = __magick_get_map(format);
+       if (!map) {
+               g_print("\t[HEIF_TEST] __magick_get_map fail\n");
+               return NULL;
+       }
+
+       g_print("[HEIF_TEST][SOURCE] width: %u, height: %u format: %u data: %p, size: %zu\n", width, height, format, data, size);
+
+       image = ConstituteImage(width, height, map, CharPixel, data, exception);
+       if (!image) {
+               g_print("\t[HEIF_TEST] ConstituteImage fail\n");
+               if (exception->severity != UndefinedException)
+                       CatchException(exception);
        }
 
-       return LIBHEIF_ERROR_NONE;
+       return image;
 }
 
-static int __save_to_jpeg(heif_image_h source, const char *path)
+static int __magick_write_image_to_file(Image *image, const char *path, ExceptionInfo *exception)
 {
-       int ret = 0;
-       mm_util_image_h mm_image = NULL;
+       int ret = LIBHEIF_ERROR_NONE;
+       ImageInfo *_image_info = NULL;
 
-       if (!source) {
-               g_print("\t[HEIF_TEST] source: %p\n", source);
-               return MM_UTIL_ERROR_INVALID_PARAMETER;
+       if (!image || !path || !exception) {
+               g_print("\t[HEIF_TEST] invalid %s\n",
+                       (!image) ? "image" : ((!path) ? "path" : "exception"));
+               return LIBHEIF_ERROR_INVALID_PARAMETER;
        }
 
-       ret = __convert_heif_image_to_mm_image(source, &mm_image);
-       if (ret < 0) {
-               g_print("\t[HEIF_TEST] __convert_heif_image_to_mm_image fail %d\n", ret);
-               goto END;
+       _image_info = CloneImageInfo(0);
+       if (!_image_info) {
+               g_print("\t[HEIF_TEST] CloneImageInfo fail\n");
+               return LIBHEIF_ERROR_INVALID_OPERATION;
        }
 
-       ret = mm_util_jpeg_encode_to_file(mm_image, 100, path);
-       if (ret < 0)
-               g_print("\t[HEIF_TEST] mm_util_jpeg_encode_to_file fail %d\n", ret);
+       g_strlcpy(image->filename, path, sizeof(image->filename));
+       image->filename[MaxTextExtent-1] = '\0';
 
-END:
-       mm_image_destroy_image(mm_image);
+       DeleteImageProfile(image, "EXIF");
+       DeleteImageProfile(image, "8BIM");
+       DeleteImageProfile(image, "ICM");
+       DeleteImageProfile(image, "IPTC");
+       DeleteImageProfile(image, "XMP");
+
+       AddDefinition(_image_info, "jpeg", "dct-method", "FASTEST", exception);
+       AddDefinition(_image_info, "jpeg", "optimize-coding", "FALSE", exception);
+       AddDefinition(_image_info, "webp", "lossless", "TRUE", exception);
+
+       if (WriteImage (_image_info, image) == MagickFalse) {
+               g_print("\t[HEIF_TEST] WriteImage fail\n");
+               if (exception->severity != UndefinedException)
+                       CatchException(exception);
+
+               ret = LIBHEIF_ERROR_INVALID_OPERATION;
+       }
+
+       DestroyImageInfo(_image_info);
 
        return ret;
 }
 
-static int __save_to_png(heif_image_h source, const char *path)
+
+static int __save_image_to_file(heif_image_h source, const char *path)
 {
        int ret = 0;
-       mm_util_image_h mm_image = NULL;
-       mm_util_enc_opt_h enc_opt = NULL;
+       ExceptionInfo exception;
+       Image *image = NULL;
 
-       if (!source) {
-               g_print("\t[HEIF_TEST] source: %p\n", source);
-               return MM_UTIL_ERROR_INVALID_PARAMETER;
+       if (!path) {
+               g_print("\t[HEIF_TEST] save function not supported\n");
+               return LIBHEIF_ERROR_NONE;
        }
 
-       ret = __convert_heif_image_to_mm_image(source, &mm_image);
-       if (ret < 0) {
-               g_print("\t[HEIF_TEST] __convert_heif_image_to_mm_image fail %d\n", ret);
-               goto END;
-       }
+       g_print("[HEIF_TEST] path [%s]", path);
 
-       ret = mm_util_enc_opt_create(&enc_opt);
-       if (ret < 0) {
-               g_print("\t[HEIF_TEST] mm_util_enc_opt_create fail %d\n", ret);
-               goto END;
-       }
+       InitializeMagick(NULL);
+       GetExceptionInfo(&exception);
 
-       ret = mm_util_enc_opt_set_codec(enc_opt, IMG_CODEC_PNG);
-       if (ret < 0) {
-               g_print("\t[HEIF_TEST] mm_util_enc_opt_set_codec fail %d\n", ret);
-               goto END;
-       }
-
-       ret = mm_util_enc_opt_set_png_compression(enc_opt, 1);
-       if (ret < 0) {
-               g_print("\t[HEIF_TEST] mm_util_enc_opt_set_png_compression fail %d\n", ret);
-               goto END;
-       }
+       SetLogEventMask("warning, error, fatalerror, exception");
+       SetLogMethod(__magick_log_method);
 
-       ret = mm_util_encode_image_to_file(mm_image, enc_opt, path);
-       if (ret < 0)
-               g_print("\t[HEIF_TEST] mm_util_encode_image_to_file fail %d\n", ret);
+       image = __magick_get_image(source, &exception);
+       ret = __magick_write_image_to_file(image, path, &exception);
+       DestroyImageList(image);
 
-END:
-       mm_image_destroy_image(mm_image);
-       mm_util_enc_opt_destroy(enc_opt);
+       DestroyExceptionInfo(&exception);
+       DestroyMagick();
 
        return ret;
 }