Get proper Objectformat for HEIF image 94/295394/1
authorJihoon Jung <jh8801.jung@samsung.com>
Thu, 6 Jul 2023 08:40:55 +0000 (17:40 +0900)
committerJihoon Jung <jh8801.jung@samsung.com>
Thu, 6 Jul 2023 08:55:02 +0000 (17:55 +0900)
Change-Id: I72949fa40105f32e7da989a798cada255a119a40
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
src/libmtp.c

index 859c99c..30917c4 100644 (file)
@@ -9389,6 +9389,29 @@ int LIBMTP_Get_Object_Handles(LIBMTP_mtpdevice_t *device, uint32_t storage,
        return 0;
 }
 
+static const char *__get_filename_ext(const char *filename) {
+       const char *dot = strrchr(filename, '.');
+       if(!dot || dot == filename) return "";
+       return dot + 1;
+}
+
+static int __is_high_efficiency_image(char *filename)
+{
+       if (filename == NULL)
+               return 0;
+
+       const char *ext = __get_filename_ext(filename);
+       if (ext == NULL)
+               return 0;
+
+       if (0 == strncmp(ext, "heic", strlen(ext))
+       || 0 == strncmp(ext, "heif", strlen(ext))) {
+               return 1;
+       }
+
+       return 0;
+}
+
 MTPObjectInfo *LIBMTP_Get_Object_Info(LIBMTP_mtpdevice_t *device, uint32_t object_id)
 {
        PTPParams *params = (PTPParams *)device->params;
@@ -9443,7 +9466,14 @@ MTPObjectInfo *LIBMTP_Get_Object_Info(LIBMTP_mtpdevice_t *device, uint32_t objec
        else
                object_info->Keywords = NULL;
 
-       object_info->ObjectFormat = map_ptp_type_to_libmtp_type(object_info->ObjectFormat);
+       LIBMTP_INFO("Filename : %s, Object Format : %hu", object_info->Filename, object_info->ObjectFormat);
+       if (object_info->ObjectFormat == PTP_OFC_Defined && __is_high_efficiency_image(object_info->Filename)) {
+               LIBMTP_INFO("It is HEIF image");
+               object_info->ObjectFormat = LIBMTP_FILETYPE_HEIF;
+       } else {
+               object_info->ObjectFormat = map_ptp_type_to_libmtp_type(object_info->ObjectFormat);
+       }
+
        object_info->ThumbFormat = map_ptp_type_to_libmtp_type(object_info->ThumbFormat);
 
        return object_info;