summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/media-svc-util.c85
1 files changed, 33 insertions, 52 deletions
diff --git a/src/common/media-svc-util.c b/src/common/media-svc-util.c
index 6ec8e7b..535402a 100644
--- a/src/common/media-svc-util.c
+++ b/src/common/media-svc-util.c
@@ -865,13 +865,12 @@ int image_360_check(char *path)
unsigned char exif_header[4] = {0, };
unsigned char exif_app1[2] = {0, };
unsigned char exif_app1_xmp[2] = {0, };
- long exif_app1_xmp_size = 0;
+ gsize exif_app1_xmp_size = 0;
unsigned char exif_app1_xmp_t[2] = {0, };
char *xmp_data = NULL;
- int size1 = 0;
- int size2 = 0;
int fdata = 0;
int temp = 0;
+ int result = 0;
memset(exif_header, 0x00, sizeof(exif_header));
memset(exif_app1, 0x00, sizeof(exif_app1));
@@ -891,10 +890,7 @@ int image_360_check(char *path)
if (size <= 0)
goto ERROR;
- size1 = exif_app1[0];
- size2 = exif_app1[1];
-
- app1_size = size1 * 256 + size2 - 2;
+ app1_size = (long)((exif_app1[0] << 8) | (exif_app1[1])) - 2 ;
if (fseek(fp, app1_size, SEEK_CUR) != 0)
goto ERROR;
@@ -904,64 +900,49 @@ int image_360_check(char *path)
goto ERROR;
if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
- int result = 0;
char *ptr = NULL;
size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
if (size <= 0)
goto ERROR;
- size1 = exif_app1_xmp_t[0];
- size2 = exif_app1_xmp_t[1];
-
- exif_app1_xmp_size = size1 * 256 + size2 - 2;
-
- if (exif_app1_xmp_size > 0) {
- xmp_data = (char *)malloc(exif_app1_xmp_size);
- memset(xmp_data, 0x0, exif_app1_xmp_size);
-
- ptr = xmp_data;
-
- while (exif_app1_xmp_size >= 0) {
- exif_app1_xmp_size--;
- fdata = fgetc(fp);
- if (fdata == EOF)
- continue;
- if (fdata == '\0')
- continue;
- *ptr = (char)fdata;
- ptr++;
- temp++;
- }
- ptr = ptr - temp;
-
- if (strstr(ptr, "UsePanoramaViewer")
- && strstr(ptr, "True")
- && strstr(ptr, "ProjectionType")
- && strstr(ptr, "equirectangular"))
- result = 1;
-
- SAFE_FREE(xmp_data);
- } else {
- media_svc_error("invalid exif_app1_xmp_size [%ld]", exif_app1_xmp_size);
- }
+ exif_app1_xmp_size = (long)((exif_app1_xmp_t[0] << 8) | (exif_app1_xmp_t[1])) - 2;
+ if (exif_app1_xmp_size == 0)
+ goto ERROR;
- if (fp) {
- fclose(fp);
- fp = NULL;
- }
- return result;
- } else {
- goto ERROR;
+ xmp_data = g_malloc(exif_app1_xmp_size);
+ ptr = xmp_data;
+
+ do {
+ exif_app1_xmp_size--;
+ fdata = fgetc(fp);
+ if (fdata == EOF)
+ continue;
+ if (fdata == '\0')
+ continue;
+ *ptr = (char)fdata;
+ ptr++;
+ temp++;
+ } while (exif_app1_xmp_size > 0);
+
+ ptr -= temp;
+
+ if (strstr(ptr, "UsePanoramaViewer")
+ && strstr(ptr, "True")
+ && strstr(ptr, "ProjectionType")
+ && strstr(ptr, "equirectangular"))
+ result = 1;
+
+ g_free(xmp_data);
}
- } else {
- goto ERROR;
}
+
ERROR:
if (fp) {
fclose(fp);
fp = NULL;
}
- return 0;
+
+ return result;
}
int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info)