From b5f4844ff81c7dbfeccd36c88bdcba13e4b26492 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Thu, 23 Apr 2020 09:34:34 +0900 Subject: [PATCH] Improve getting of xmp data Change-Id: Icf42af7e90d32155912f3bdb3e38ebaf1cb75b2b Signed-off-by: Minje Ahn --- src/common/media-svc-util.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/common/media-svc-util.c b/src/common/media-svc-util.c index 02fc585..4847673 100644 --- a/src/common/media-svc-util.c +++ b/src/common/media-svc-util.c @@ -809,9 +809,8 @@ static int __image_360_check(const char *path) unsigned char exif_app1_xmp[2] = {0, }; gsize exif_app1_xmp_size = 0; unsigned char exif_app1_xmp_t[2] = {0, }; - char *xmp_data = NULL; + GString *xmp_data = NULL; int fdata = 0; - int temp = 0; int result = 0; memset(exif_header, 0x00, sizeof(exif_header)); @@ -842,7 +841,6 @@ static int __image_360_check(const char *path) goto ERROR; if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) { - char *ptr = NULL; size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp); if (size <= 0) goto ERROR; @@ -851,8 +849,7 @@ static int __image_360_check(const char *path) if (exif_app1_xmp_size == 0) goto ERROR; - xmp_data = g_malloc(exif_app1_xmp_size); - ptr = xmp_data; + xmp_data = g_string_sized_new(exif_app1_xmp_size); do { exif_app1_xmp_size--; @@ -861,20 +858,17 @@ static int __image_360_check(const char *path) continue; if (fdata == '\0') continue; - *ptr = (char)fdata; - ptr++; - temp++; - } while (exif_app1_xmp_size > 0); - ptr -= temp; + xmp_data = g_string_append_c(xmp_data, (gchar)fdata); + } while (exif_app1_xmp_size > 0); - if (strstr(ptr, "UsePanoramaViewer") - && strstr(ptr, "True") - && strstr(ptr, "ProjectionType") - && strstr(ptr, "equirectangular")) + if (strstr(xmp_data->str, "UsePanoramaViewer") && + strstr(xmp_data->str, "True") && + strstr(xmp_data->str, "ProjectionType") && + strstr(xmp_data->str, "equirectangular")) result = 1; - g_free(xmp_data); + g_string_free(xmp_data, TRUE); } } -- 2.7.4