[ACR-1623] Add heif image decoder 73/255073/10 accepted/tizen/unified/20210330.111243 submit/tizen/20210330.015847
authorjiyong.min <jiyong.min@samsung.com>
Thu, 11 Mar 2021 22:44:28 +0000 (07:44 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Tue, 16 Mar 2021 01:45:30 +0000 (10:45 +0900)
Change-Id: Ifbb5295a1b5d5fd8b7fda9e88ff2fd4ddb38dae5

CMakeLists.txt
doc/image_util_doc.h
include/image_util_decode.h
include/image_util_private.h
include/image_util_type.h
packaging/capi-media-image-util.spec
src/image_util_decode.c
src/image_util_encode.c
src/image_util_private.c
test/image_util_testsuite.c

index f3f6264..23badbc 100644 (file)
@@ -9,7 +9,7 @@ SET(INC_DIR include)
 INCLUDE_DIRECTORIES(${INC_DIR})
 
 # for package file
-SET(dependents "dlog mmutil-magick mmutil-common mmutil-gif mmutil-jpeg mmutil-imgp mmutil-anim capi-base-common capi-media-tool glib-2.0")
+SET(dependents "dlog mmutil-magick mmutil-common mmutil-gif mmutil-jpeg mmutil-imgp mmutil-anim mmutil-heif capi-base-common capi-media-tool glib-2.0")
 SET(pc_dependents "capi-base-common capi-media-tool")
 INCLUDE(FindPkgConfig)
 pkg_check_modules(${fw_name} REQUIRED ${dependents})
index ca38b37..438cb88 100755 (executable)
  *
  * Image Util API provides support for encoding and decoding of images. The API allows :
  *- Encoding of a JPEG/PNG/GIF/BMP and WEBP(Since 6.0) image.
- *- Decoding of a JPEG/PNG/GIF/BMP and WEBP(Since 6.0) image.
+ *- Decoding of a JPEG/PNG/GIF/BMP/WEBP(Since 6.0) and HEIF(Since 6.5) image.
  * Encoding supports gif images including the animated, but decoding gif does not support the animated.
  *
- * The decoding of a jpeg/png/gif/bmp image located at a given path, to a buffer can be done by calling #image_util_decode_run() function and decoding of a jpeg image on memory
+ * The decoding of a jpeg/png/gif/bmp/webp/heif image located at a given path, to a buffer can be done by calling #image_util_decode_run() function and decoding of a jpeg/png/gif/bmp/webp/heif image on memory
  * can be done by calling #image_util_decode_set_output_buffer(). Similarly, for encoding #image_util_encode_run() and #image_util_encode_set_output_buffer() functions can be called
  * to encode an image buffer to a jpeg/png/gif/bmp/webp image and a buffer respectively.
  *
index 465e2d0..3c34f45 100644 (file)
@@ -59,7 +59,8 @@ int image_util_decode_create(image_util_decode_h *handle);
 *             %http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.\n
 *             %http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.\n
 *             Finds out image type by reading the header of the image provided in input path.\n
-*             Since 6.0, this module supports WEBP image format.
+*             Since 6.0, this module supports WEBP image format.\n
+*             Since 6.5, this module supports HEIF image format.
 *
 * @param[in] handle The handle of image util decoding
 * @param[in] path The path to input image
@@ -94,7 +95,8 @@ int image_util_decode_set_input_path(image_util_decode_h handle, const char *pat
 * @remarks One of image_util_decode_set_input_path() or image_util_decode_set_input_buffer() should be set.\n
 *              If both are set then the latest input set, is considered.\n
 *              Finds out image type by reading the header of the image provided in input buffer.\n
-*              Since 6.0, this module supports WEBP image format.
+*              Since 6.0, this module supports WEBP image format.\n
+*              Since 6.5, this module supports HEIF image format.
 *
 * @param[in] handle The handle of image util decoding
 * @param[in] src_buffer The input image buffer
index ff08fc4..dae430b 100644 (file)
@@ -116,7 +116,7 @@ typedef struct {
 } transformation_s;
 
 #define IMAGE_UTIL_TYPE_CHECK(type) \
-       image_util_retvm_if((type < IMAGE_UTIL_JPEG || type > IMAGE_UTIL_WEBP), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid image type [%d]", type)
+       image_util_retvm_if((type < IMAGE_UTIL_JPEG || type > IMAGE_UTIL_HEIF), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid image type [%d]", type)
 
 #define IMAGE_UTIL_SUPPORT_TYPE_CHECK(value, support) \
        image_util_retvm_if((value != support), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "Not supported format")
index 80d7b9a..b62321c 100644 (file)
@@ -172,6 +172,7 @@ typedef enum {
        IMAGE_UTIL_GIF,          /**< Image format GIF */
        IMAGE_UTIL_BMP,          /**< Image format BMP */
        IMAGE_UTIL_WEBP,         /**< Image format WEBP (Since 6.0) */
+       IMAGE_UTIL_HEIF,         /**< Image format HEIF (Since 6.5) */
 } image_util_type_e;
 
 /**
index 5c90554..b10602f 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-image-util
 Summary:    A Image Utility library in Tizen Native API
-Version:    0.2.12
+Version:    0.3.0
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
@@ -13,6 +13,7 @@ BuildRequires:  pkgconfig(mmutil-imgp)
 BuildRequires:  pkgconfig(mmutil-gif)
 BuildRequires:  pkgconfig(mmutil-magick)
 BuildRequires:  pkgconfig(mmutil-anim)
+BuildRequires:  pkgconfig(mmutil-heif)
 BuildRequires:  pkgconfig(capi-base-common)
 BuildRequires:  pkgconfig(capi-media-tool)
 BuildRequires:  pkgconfig(glib-2.0)
index 57b0eb0..53eb162 100644 (file)
@@ -21,6 +21,7 @@
 #include <mm_util_gif.h>
 #include <mm_util_magick.h>
 #include <mm_util_image.h>
+#include <mm_util_heif.h>
 
 #include <image_util.h>
 #include <image_util_private.h>
@@ -103,6 +104,7 @@ static int __image_util_decode_check_image_type(const unsigned char *image_buffe
        static unsigned char _GIF_HEADER[] = { 'G', 'I', 'F' };
        static unsigned char _BMP_HEADER[] = { 'B', 'M' };
        static unsigned char _WEBP_HEADER[] = { 0x57, 0x45, 0x42, 0x50 };
+       static unsigned char _HEIF_HEADER[] = { 'f', 't', 'y', 'p' };
 
        static struct {
                image_util_type_e image_type;
@@ -114,8 +116,9 @@ static int __image_util_decode_check_image_type(const unsigned char *image_buffe
                { IMAGE_UTIL_PNG, _PNG_HEADER, sizeof(_PNG_HEADER), 0 },
                { IMAGE_UTIL_GIF, _GIF_HEADER, sizeof(_GIF_HEADER), 0 },
                { IMAGE_UTIL_BMP, _BMP_HEADER, sizeof(_BMP_HEADER), 0 },
-               { IMAGE_UTIL_WEBP, _WEBP_HEADER, sizeof(_WEBP_HEADER), 8 }
-       ,};
+               { IMAGE_UTIL_WEBP, _WEBP_HEADER, sizeof(_WEBP_HEADER), 8 },
+               { IMAGE_UTIL_HEIF, _HEIF_HEADER, sizeof(_HEIF_HEADER), 4 },
+       };
        unsigned int i = 0;
 
        image_util_retvm_if(!image_buffer, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid image_buffer");
@@ -268,6 +271,7 @@ static int __image_util_decode_internal(decode_s *_handle, mm_util_image_h *imag
                                err = mm_util_decode_from_jpeg_memory(_handle->src_buffer, _handle->src_size, colorspace, downscale, image_info);
                }
                break;
+
        case IMAGE_UTIL_GIF:
                {
                        if (_handle->path)
@@ -276,6 +280,7 @@ static int __image_util_decode_internal(decode_s *_handle, mm_util_image_h *imag
                                err = mm_util_decode_from_gif_memory(_handle->src_buffer, _handle->src_size, image_info);
                }
                break;
+
        case IMAGE_UTIL_PNG:
                /* fall through */
        case IMAGE_UTIL_BMP:
@@ -288,6 +293,16 @@ static int __image_util_decode_internal(decode_s *_handle, mm_util_image_h *imag
                                err = mm_util_decode_image_from_buffer(_handle->src_buffer, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_WEBP), _handle->colorspace, image_info);
                }
                break;
+
+       case IMAGE_UTIL_HEIF:
+               {
+                       if (_handle->path)
+                               err = mm_util_decode_heif_from_file(_handle->path, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_HEIF), image_info);
+                       else
+                               err = mm_util_decode_heif_from_buffer(_handle->src_buffer, _handle->src_size, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_HEIF), image_info);
+               }
+               break;
+
        default:
                image_util_error("Not supported format [%d]", _handle->image_type);
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
@@ -377,6 +392,10 @@ static int __image_util_decode_run_from_file(image_util_decode_h handle, const c
                ret = mm_util_decode_image_from_file(file_path, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_WEBP), image);
                break;
 
+       case IMAGE_UTIL_HEIF:
+               ret = mm_util_decode_heif_from_file(file_path, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_HEIF), image);
+               break;
+
        default:
                image_util_error("Not supported format [%d]", image_type);
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
@@ -428,6 +447,10 @@ static int __image_util_decode_run_from_buffer(image_util_decode_h handle, const
                ret = mm_util_decode_image_from_buffer((void *)buffer, buffer_size, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_WEBP), image);
                break;
 
+       case IMAGE_UTIL_HEIF:
+               ret = mm_util_decode_heif_from_buffer((void *)buffer, buffer_size, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_HEIF), image);
+               break;
+
        default:
                image_util_error("Not supported format [%d]", image_type);
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
index ff563ea..2d9edd9 100644 (file)
@@ -118,6 +118,7 @@ int image_util_encode_create(image_util_type_e image_type, image_util_encode_h *
        image_util_fenter();
        image_util_retvm_if(!handle, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
        IMAGE_UTIL_TYPE_CHECK(image_type);
+       image_util_retvm_if(image_type == IMAGE_UTIL_HEIF, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid image type [%d]", image_type);
 
        encode_s *_handle = g_new0(encode_s, 1);
 
index baeabdc..106c782 100644 (file)
@@ -150,6 +150,24 @@ static int _convert_webp_colorspace_tbl[] = {
        [IMAGE_UTIL_COLORSPACE_NV61] = _NOT_SUPPORTED_COLORSPACE,
 };
 
+static int _convert_heif_colorspace_tbl[] = {
+       [IMAGE_UTIL_COLORSPACE_YV12] = MM_UTIL_COLOR_YUV420,
+       [IMAGE_UTIL_COLORSPACE_YUV422] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_I420] = MM_UTIL_COLOR_YUV420,
+       [IMAGE_UTIL_COLORSPACE_NV12] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_UYVY] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_YUYV] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_RGB565] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_RGB888] = MM_UTIL_COLOR_RGB24,
+       [IMAGE_UTIL_COLORSPACE_ARGB8888] = MM_UTIL_COLOR_ARGB,
+       [IMAGE_UTIL_COLORSPACE_BGRA8888] = MM_UTIL_COLOR_BGRA,
+       [IMAGE_UTIL_COLORSPACE_RGBA8888] = MM_UTIL_COLOR_RGBA,
+       [IMAGE_UTIL_COLORSPACE_BGRX8888] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_NV21] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_NV16] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_NV61] = _NOT_SUPPORTED_COLORSPACE,
+};
+
 unsigned int _get_number_of_colorspace(void)
 {
        return G_N_ELEMENTS(_convert_colorspace_tbl);
@@ -181,6 +199,9 @@ gboolean _is_supported_colorspace(image_util_colorspace_e colorspace, image_util
        case IMAGE_UTIL_WEBP:
                image_util_retvm_if((_convert_webp_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[webp] %d not supported format", colorspace);
                break;
+       case IMAGE_UTIL_HEIF:
+               image_util_retvm_if((_convert_heif_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[heif] %d not supported format", colorspace);
+               break;
        default:
                image_util_retvm_if(TRUE, FALSE, "Invalid image type");
        }
@@ -221,6 +242,9 @@ int _convert_type_of_colorspace_with_image_type(const image_util_colorspace_e co
        case IMAGE_UTIL_WEBP:
                new_colorspace = _convert_webp_colorspace_tbl[colorspace];
                break;
+       case IMAGE_UTIL_HEIF:
+               new_colorspace = _convert_heif_colorspace_tbl[colorspace];
+               break;
        default:
                image_util_error("Invalid image type");
        }
index 30fb4e6..342489e 100644 (file)
@@ -59,7 +59,7 @@
 #define FILE_FOR_ENCODE_AGIF           tzplatform_mkpath(TZ_USER_CONTENT, "imgutil_test_encode_agif")
 #define FILE_FOR_ENCODE_ANIM           tzplatform_mkpath(TZ_USER_CONTENT, "imgutil_test_encode_anim")
 
-#define IMAGE_UTIL_TYPE_MAX                    IMAGE_UTIL_WEBP
+#define IMAGE_UTIL_TYPE_MAX                    IMAGE_UTIL_HEIF
 
 /* parameters for testsuite */
 typedef enum {