changeset 18:403c67bcb76a

Use bpg_insert_md() and bpg_add_md_contents() in jpeg_get_metadata() also.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 26 Apr 2017 18:24:15 +0300
parents 91f27e9fdb60
children a9a60da06ae3
files bpgenc.c
diffstat 1 files changed, 8 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/bpgenc.c	Wed Apr 26 18:22:11 2017 +0300
+++ b/bpgenc.c	Wed Apr 26 18:24:15 2017 +0300
@@ -1337,15 +1337,14 @@
     static const char app1_xmp[] = "http://ns.adobe.com/xap/1.0/";
     static const char app2_iccp[] = "ICC_PROFILE";
     jpeg_saved_marker_ptr marker;
-    BPGMetaData *md, **plast_md, *first_md;
+    BPGMetaData *md_list;
     int has_exif, has_xmp, l, iccp_chunk_count, i;
     jpeg_saved_marker_ptr iccp_chunks[256];
 
     iccp_chunk_count = 0;
     has_exif = 0;
     has_xmp = 0;
-    first_md = NULL;
-    plast_md = &first_md;
+    md_list = NULL;
     for (marker = first_marker; marker != NULL; marker = marker->next) {
 #if 0
         printf("marker=APP%d len=%d\n",
@@ -1354,25 +1353,15 @@
         if (!has_exif && marker->marker == JPEG_APP0 + 1 &&
             marker->data_length > sizeof(app1_exif) &&
             !memcmp(marker->data, app1_exif, sizeof(app1_exif))) {
-            md = bpg_md_alloc(BPG_EXTENSION_TAG_EXIF);
             l = sizeof(app1_exif);
-            md->buf_len = marker->data_length - l;
-            md->buf = malloc(md->buf_len);
-            memcpy(md->buf, marker->data + l, md->buf_len);
-            *plast_md = md;
-            plast_md = &md->next;
+            bpg_add_md_contents(&md_list, BPG_EXTENSION_TAG_EXIF, marker->data_length - l, marker->data + l);
             has_exif = 1;
         } else if (!has_xmp && marker->marker == JPEG_APP0 + 1 &&
                    marker->data_length > sizeof(app1_xmp) &&
                    !memcmp(marker->data, app1_xmp, sizeof(app1_xmp)) &&
                    !has_xmp) {
-            md = bpg_md_alloc(BPG_EXTENSION_TAG_XMP);
             l = sizeof(app1_xmp);
-            md->buf_len = marker->data_length - l;
-            md->buf = malloc(md->buf_len);
-            memcpy(md->buf, marker->data + l, md->buf_len);
-            *plast_md = md;
-            plast_md = &md->next;
+            bpg_add_md_contents(&md_list, BPG_EXTENSION_TAG_XMP, marker->data_length - l, marker->data + l);
             has_xmp = 1;
         } else if (marker->marker == JPEG_APP0 + 2 &&
                    marker->data_length > (sizeof(app2_iccp) + 2) &&
@@ -1409,21 +1398,19 @@
             len += iccp_chunks[i]->data_length - hlen;
         }
         if (i == iccp_chunk_count) {
-            md = bpg_md_alloc(BPG_EXTENSION_TAG_ICCP);
+            BPGMetaData *md = bpg_md_alloc(BPG_EXTENSION_TAG_ICCP);
             md->buf_len = len;
             md->buf = malloc(md->buf_len);
-            idx = 0;
-            for(i = 0; i < iccp_chunk_count; i++) {
+            bpg_insert_md(&md_list, md);
+            for(i = 0, idx = 0; i < iccp_chunk_count; i++) {
                 l = iccp_chunks[i]->data_length - hlen;
                 memcpy(md->buf + idx, iccp_chunks[i]->data + hlen, l);
                 idx += l;
             }
             assert(idx == len);
-            *plast_md = md;
-            plast_md = &md->next;
         }
     }
-    return first_md;
+    return md_list;
 }
 
 Image *read_jpeg(BPGMetaData **pmd, FILE *f,