Add heif format support to image information extractor 03/323903/4 accepted/tizen_unified accepted/tizen_unified_x tizen accepted/tizen/unified/20250519.121253 accepted/tizen/unified/x/20250520.031831
authorJiyong <jiyong.min@samsung.com>
Fri, 9 May 2025 02:07:47 +0000 (11:07 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Fri, 9 May 2025 13:47:29 +0000 (13:47 +0000)
Change-Id: I2988f79b3b95638b1074320e08e1d421ab3ddeb4

magick/CMakeLists.txt
magick/mm_util_info.c
packaging/libmm-utility.spec

index f429b49f2d40eec76c8a91e7dccbaaf6c189f796..7c9fff6b0c87851d8fc7d3988b942fd34415514c 100644 (file)
@@ -15,7 +15,7 @@ INCLUDE_DIRECTORIES(${INC_DIR}
     ../common/include
 )
 
-SET(dependents "dlog glib-2.0 GraphicsMagick")
+SET(dependents "dlog glib-2.0 GraphicsMagick heif")
 
 INCLUDE(FindPkgConfig)
 pkg_check_modules(${fw_name} REQUIRED ${dependents})
index c713c5f2c4d59809c280f186eac8ec0b060b9520..9f0c748f63a49169e163c1c85354af3af0664f34 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <stdio.h>
 #include <glib.h>
+#include <heif.h>
 #include "mm_util_private.h"
 #include "mm_util_magick.h"
 
@@ -44,13 +45,15 @@ static unsigned char gIfegJPEGHeader[] = { 0xFF, 0xD8 };
 static unsigned char gIfegGIFHeader[] = { "GIF" };
 static unsigned char gIfegBMPHeader[] = { 0x42, 0x4D };
 static unsigned char gIfegWBMPHeader[] = { 0x00, 0x00 };
+static unsigned char gIfegHEIFHeader[] = { 'f', 't', 'y', 'p' };
 
 static const image_signature_t signature_info[] = {
        { IMG_CODEC_JPEG, gIfegJPEGHeader, 2, 0},
        { IMG_CODEC_PNG, gIfegPNGHeader, 8, 0},
        { IMG_CODEC_GIF, gIfegGIFHeader, 3, 0},
        { IMG_CODEC_BMP, gIfegBMPHeader, 2, 0},
-       { IMG_CODEC_WBMP, gIfegWBMPHeader, 2, 0}
+       { IMG_CODEC_HEIF, gIfegHEIFHeader, 4, 4},
+       { IMG_CODEC_WBMP, gIfegWBMPHeader, 2, 0},
 };
 static const unsigned int signature_info_num = sizeof(signature_info) / sizeof(image_signature_t);
 
@@ -237,6 +240,43 @@ static int __mm_util_info_get_gif_size(const unsigned char *data, unsigned int d
        return MM_UTIL_ERROR_NONE;
 }
 
+static int __mm_util_info_get_heif_size(const char *path, unsigned int *width, unsigned int *height)
+{
+       int ret = LIBHEIF_ERROR_NONE;
+       heif_image_info_h image_info = NULL;
+       int _width, _height = 0;
+       const gchar *extension = g_strrstr(path, ".");
+
+       mm_util_retvm_if(!path, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid path");
+       mm_util_retvm_if(!width, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid width");
+       mm_util_retvm_if(!height, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid height");
+
+       // heif valid check
+       if (!extension || (g_ascii_strcasecmp(extension, ".heic") != 0)) {
+               mm_util_warn("invalid HEIF");
+               return MM_UTIL_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = heif_get_image_info_from_file(path, &image_info);
+       if (ret != LIBHEIF_ERROR_NONE) {
+               mm_util_warn("Failed to get image info from %s file [%d]", path, ret);
+               return MM_UTIL_ERROR_INVALID_OPERATION;
+       }
+
+       ret = heif_image_info_get_attrs(image_info, HEIF_IMAGE_WIDTH, &_width, HEIF_IMAGE_HEIGHT, &_height, NULL);
+       heif_image_info_free(image_info);
+
+       if (ret != LIBHEIF_ERROR_NONE) {
+               mm_util_sec_debug("Failed to get width & height for %s file [%d]", path, ret);
+               return MM_UTIL_ERROR_INVALID_OPERATION;
+       }
+
+       *width = _width;
+       *height = _height;
+
+       return MM_UTIL_ERROR_NONE;
+}
+
 static int __mm_util_info_get_wbmp_size(const unsigned char *data, unsigned int data_len, const char *path, unsigned int *width, unsigned int *height)
 {
        const gchar *extension = g_strrstr(path, ".");
@@ -311,6 +351,9 @@ static int __mm_util_get_image_info(const char *path, mm_util_img_codec_type *ty
        case IMG_CODEC_GIF:
                ret = __mm_util_info_get_gif_size(data, MINIMUM_HEADER_BYTES, &_width, &_height);
                break;
+       case IMG_CODEC_HEIF:
+               ret = __mm_util_info_get_heif_size(path, &_width, &_height);
+               break;
        case IMG_CODEC_WBMP:
                ret = __mm_util_info_get_wbmp_size(data, MINIMUM_HEADER_BYTES, path, &_width, &_height);
                break;
index bff355179d3e5c43a793cef59dd17562f192cc3d..cf8bd4e634f94801f6221bb5a8bbe03311bdd6a5 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.4.29
+Version:    0.5.0
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0