[gexiv2/gexiv2-0.10] Function to generate an XMP package: Bug #736587



commit 0b5eddd4d0217d1ef84cd2f74bfb8a3d6ac5e773
Author: Hartmut Kuhse <hk_priv gmx de>
Date:   Wed Oct 8 11:34:20 2014 -0700

    Function to generate an XMP package: Bug #736587
    
    XMP segment of metadata can now be returned as a packet (a
    NUL-terminated string).

 gexiv2/gexiv2-metadata-xmp.cpp |   16 ++++++++++++++++
 gexiv2/gexiv2-metadata.h       |   25 ++++++++++++++++++++++++-
 2 files changed, 40 insertions(+), 1 deletions(-)
---
diff --git a/gexiv2/gexiv2-metadata-xmp.cpp b/gexiv2/gexiv2-metadata-xmp.cpp
index ea5b9d3..4fc8077 100644
--- a/gexiv2/gexiv2-metadata-xmp.cpp
+++ b/gexiv2/gexiv2-metadata-xmp.cpp
@@ -30,6 +30,22 @@ void gexiv2_metadata_clear_xmp(GExiv2Metadata *self) {
     self->priv->image->xmpData().clear();
 }
 
+gchar *gexiv2_metadata_generate_xmp_packet(GExiv2Metadata *self, 
+    GExiv2XmpFormatFlags xmp_format_flags, guint32 padding) {
+    g_return_val_if_fail(GEXIV2_IS_METADATA (self), NULL);
+    g_return_val_if_fail(self->priv->image.get() != NULL, NULL);
+    
+    Exiv2::XmpData &xmp_data = self->priv->image->xmpData();
+    try {
+        if (Exiv2::XmpParser::encode(self->priv->image->xmpPacket(), xmp_data, xmp_format_flags, padding) == 
0)
+          return g_strdup(self->priv->image->xmpPacket().c_str());
+    } catch (Exiv2::Error& e) {
+        LOG_ERROR(e);
+    }
+    
+    return NULL;
+}
+
 gchar *gexiv2_metadata_get_xmp_packet(GExiv2Metadata *self) {
     g_return_val_if_fail(GEXIV2_IS_METADATA (self), NULL);
     g_return_val_if_fail(self->priv->image.get() != NULL, NULL);
diff --git a/gexiv2/gexiv2-metadata.h b/gexiv2/gexiv2-metadata.h
index bc4ebd3..1c2fd7d 100644
--- a/gexiv2/gexiv2-metadata.h
+++ b/gexiv2/gexiv2-metadata.h
@@ -72,6 +72,22 @@ typedef enum {
   GEXIV2_STRUCTURE_XA_LANG = 23
 } GExiv2StructureType;
 
+/**
+ * GExiv2XmpFormatFlags:
+ * Options to control the format of the serialized XMP packet
+ * Taken from: exiv2/src/xmp.hpp
+ *
+ */
+typedef enum {
+  GEXIV2_OMIT_PACKET_WRAPPER   = 0x0010UL,  //!< Omit the XML packet wrapper.
+  GEXIV2_READ_ONLY_PACKET      = 0x0020UL,  //!< Default is a writeable packet.
+  GEXIV2_USE_COMPACT_FORMAT    = 0x0040UL,  //!< Use a compact form of RDF.
+  GEXIV2_INCLUDE_THUMBNAIL_PAD = 0x0100UL,  //!< Include a padding allowance for a thumbnail image.
+  GEXIV2_EXACT_PACKET_LENGTH   = 0x0200UL,  //!< The padding parameter is the overall packet length.
+  GEXIV2_WRITE_ALIAS_COMMENTS  = 0x0400UL,  //!< Show aliases as XML comments.
+  GEXIV2_OMIT_ALL_FORMATTING   = 0x0800UL   //!< Omit all formatting whitespace.
+} GExiv2XmpFormatFlags;
+
 typedef struct _GExiv2Metadata                 GExiv2Metadata;
 typedef struct _GExiv2MetadataClass            GExiv2MetadataClass;
 typedef struct _GExiv2MetadataPrivate  GExiv2MetadataPrivate;
@@ -511,9 +527,16 @@ gboolean           gexiv2_metadata_has_xmp                         (GExiv2Metadata 
*self);
 void                   gexiv2_metadata_clear_xmp                       (GExiv2Metadata *self);
 
 /**
+ * gexiv2_metadata_generate_xmp_packet:
+ *
+ * Returns: (transfer full) (allow-none): Encode the XMP packet and return as a NUL-terminated string.
+ */
+gchar*         gexiv2_metadata_generate_xmp_packet     (GExiv2Metadata *self, GExiv2XmpFormatFlags 
xmp_format_flags, guint32 padding);
+
+/**
  * gexiv2_metadata_get_xmp_packet:
  *
- * Returns: (transfer full) (allow-none): The XMP tag's description
+ * Returns: (transfer full) (allow-none): The currently-encoded XMP packet (see 
gexiv2_metadata_generate_xmp_packet).
  */
 gchar*                 gexiv2_metadata_get_xmp_packet          (GExiv2Metadata *self);
 


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