[gimp] plug-ins: Read Xmp data from EXR files



commit 4e144fea699f5e2dcaba34e158225aabf95e73c7
Author: Tobias Ellinghaus <me houz org>
Date:   Fri Apr 22 17:01:58 2016 +0200

    plug-ins: Read Xmp data from EXR files
    
    This commit needs review as it uses an ugly hack to make
    gimp_metadata_set_from_xmp() do what it wants.

 plug-ins/file-exr/Makefile.am        |    1 +
 plug-ins/file-exr/file-exr.c         |   42 +++++++++++++++++++++++++--------
 plug-ins/file-exr/openexr-wrapper.cc |   19 +++++++++++++++
 plug-ins/file-exr/openexr-wrapper.h  |    4 +++
 4 files changed, 56 insertions(+), 10 deletions(-)
---
diff --git a/plug-ins/file-exr/Makefile.am b/plug-ins/file-exr/Makefile.am
index f3bda1b..22533a1 100644
--- a/plug-ins/file-exr/Makefile.am
+++ b/plug-ins/file-exr/Makefile.am
@@ -32,6 +32,7 @@ AM_CPPFLAGS = \
 libexec_PROGRAMS = file-exr
 
 file_exr_SOURCES = \
+       exr-attribute-blob.h    \
        file-exr.c              \
        openexr-wrapper.cc      \
        openexr-wrapper.h
diff --git a/plug-ins/file-exr/file-exr.c b/plug-ins/file-exr/file-exr.c
index 71af9c6..4a2c053 100644
--- a/plug-ins/file-exr/file-exr.c
+++ b/plug-ins/file-exr/file-exr.c
@@ -171,8 +171,12 @@ load_image (const gchar  *filename,
   gint              begin;
   gint32            success = FALSE;
   gchar            *comment;
+  GimpMetadata     *metadata;
+  gboolean          have_metadata = FALSE;
   guchar           *exif_data;
   guint             exif_size;
+  guchar           *xmp_data;
+  guint             xmp_size;
 
 
   gimp_progress_init_printf (_("Opening '%s'"),
@@ -331,31 +335,49 @@ load_image (const gchar  *filename,
       g_free (comment);
     }
 
+  metadata = gimp_image_get_metadata (image);
+
+  if (metadata)
+    g_object_ref (metadata);
+  else
+    metadata = gimp_metadata_new ();
+
   /* check if the image contains Exif data and read it */
   exif_data = exr_loader_get_exif (loader, &exif_size);
   if (exif_data)
     {
-      GimpMetadata *metadata = gimp_image_get_metadata (image);
-
-      if (metadata)
-        g_object_ref (metadata);
-      else
-        metadata = gimp_metadata_new ();
-
       if (gimp_metadata_set_from_exif (metadata,
                                        exif_data,
                                        exif_size,
                                        NULL))
         {
-          gimp_image_set_metadata (image, metadata);
+          have_metadata = TRUE;
         }
 
-      g_object_unref (metadata);
       g_free (exif_data);
     }
 
-  // TODO: also read XMP data
+  /* try to read the Xmp data */
+  xmp_data = exr_loader_get_xmp (loader, &xmp_size);
+  if (xmp_data)
+    {
+      // FIXME:
+      // gimp_metadata_set_from_xmp skips the first 10 bytes.
+      // working around that like this might not be the right thing to do!
+      if (gimp_metadata_set_from_xmp (metadata,
+                                      xmp_data - 10,
+                                      xmp_size + 10,
+                                      NULL))
+        {
+          have_metadata = TRUE;
+        }
+      g_free (xmp_data);
+    }
+
+  if (have_metadata)
+    gimp_image_set_metadata (image, metadata);
 
+  g_object_unref (metadata);
 
   gimp_progress_update (1.0);
 
diff --git a/plug-ins/file-exr/openexr-wrapper.cc b/plug-ins/file-exr/openexr-wrapper.cc
index 8a0c9cb..6637a19 100644
--- a/plug-ins/file-exr/openexr-wrapper.cc
+++ b/plug-ins/file-exr/openexr-wrapper.cc
@@ -272,6 +272,18 @@ struct _EXRLoader
     return (guchar *)g_memdup (exif_data, *size);
   }
 
+  guchar *getXmp(guint *size) const {
+    guchar *result = NULL;
+    *size = 0;
+    const Imf::StringAttribute *xmp = file_.header().findTypedAttribute<Imf::StringAttribute>("xmp");
+    if (xmp)
+      {
+        *size = xmp->value().size();
+        result = (guchar *) g_memdup (xmp->value().data(), *size);
+      }
+    return result;
+  }
+
   size_t refcount_;
   InputFile file_;
   const Box2i data_window_;
@@ -392,6 +404,13 @@ exr_loader_get_exif (EXRLoader *loader,
   return loader->getExif (size);
 }
 
+guchar *
+exr_loader_get_xmp (EXRLoader *loader,
+                    guint *size)
+{
+  return loader->getXmp (size);
+}
+
 int
 exr_loader_read_pixel_row (EXRLoader *loader,
                            char *pixels,
diff --git a/plug-ins/file-exr/openexr-wrapper.h b/plug-ins/file-exr/openexr-wrapper.h
index c1d348a..fcb4984 100644
--- a/plug-ins/file-exr/openexr-wrapper.h
+++ b/plug-ins/file-exr/openexr-wrapper.h
@@ -60,6 +60,10 @@ guchar *
 exr_loader_get_exif (EXRLoader *loader,
                      guint *size);
 
+guchar *
+exr_loader_get_xmp (EXRLoader *loader,
+                    guint *size);
+
 int
 exr_loader_read_pixel_row (EXRLoader *loader,
                            char *pixels,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]