[gexiv2/wip/57] exif: Add gexiv2_metadata_get_exif_data
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gexiv2/wip/57] exif: Add gexiv2_metadata_get_exif_data
- Date: Wed, 9 Sep 2020 01:08:55 +0000 (UTC)
commit e57a28a90ee085780a91d2986f00a2dfcfa021d7
Author: Jens Georg <mail jensge org>
Date: Wed Sep 9 03:07:35 2020 +0200
exif: Add gexiv2_metadata_get_exif_data
Allow exporting the EXIF data as a binary blob
Fixes #57
gexiv2/gexiv2-metadata-exif.cpp | 36 ++++++++++++++++++++++++++++++++++++
gexiv2/gexiv2-metadata.h | 22 ++++++++++++++++++++++
2 files changed, 58 insertions(+)
---
diff --git a/gexiv2/gexiv2-metadata-exif.cpp b/gexiv2/gexiv2-metadata-exif.cpp
index f931b95..5ba4d2d 100644
--- a/gexiv2/gexiv2-metadata-exif.cpp
+++ b/gexiv2/gexiv2-metadata-exif.cpp
@@ -359,4 +359,40 @@ GBytes* gexiv2_metadata_get_exif_tag_raw (GExiv2Metadata *self, const gchar* tag
return NULL;
}
+GBytes * gexiv2_metadata_get_exif_data (GExiv2Metadata *self,
+ GExiv2ByteOrder byte_order,
+ GError **error) {
+ g_return_val_if_fail(GEXIV2_IS_METADATA (self), NULL);
+ g_return_val_if_fail(self->priv->image.get() != NULL, NULL);
+
+ Exiv2::ExifData &exif_data = self->priv->image->exifData();
+
+ if (exif_data.empty()) {
+ return NULL;
+ }
+
+ Exiv2::Blob blob;
+
+ try {
+ Exiv2::ExifParser::encode(blob,
+ byte_order == GEXIV2_BYTE_ORDER_LITTLE ?
+ Exiv2::littleEndian :
+ Exiv2::bigEndian,
+ exif_data);
+
+ if (blob.size() <= 0) {
+ return NULL;
+ }
+
+ gpointer data = g_malloc0(blob.size());
+ memcpy(data, blob.data(), blob.size());
+
+ return g_bytes_new_take (data, blob.size());
+ } catch (Exiv2::Error& e) {
+ g_set_error_literal (error, g_quark_from_string ("GExiv2"), e.code (), e.what ());
+ }
+
+ return NULL;
+}
+
G_END_DECLS
diff --git a/gexiv2/gexiv2-metadata.h b/gexiv2/gexiv2-metadata.h
index 620d25d..be748b2 100644
--- a/gexiv2/gexiv2-metadata.h
+++ b/gexiv2/gexiv2-metadata.h
@@ -157,6 +157,18 @@ typedef enum { /*< flags >*/
GEXIV2_OMIT_ALL_FORMATTING = 0x0800UL
} GExiv2XmpFormatFlags;
+/**
+ * GExiv2ByteOrder:
+ * @GEXIV2_BYTE_ORDER_LITTLE: Use little-endian byte order
+ * @GEXIV2_BYTE_ORDER_BIG: Use big-endian byte order
+ *
+ * Options to control the byte order of binary EXIF data exports
+ */
+typedef enum {
+ GEXIV2_BYTE_ORDER_LITTLE = 0,
+ GEXIV2_BYTE_ORDER_BIG = 1
+} GExiv2ByteOrder;
+
/**
* GExiv2Metadata:
*
@@ -684,6 +696,16 @@ void gexiv2_metadata_set_exif_thumbnail_from_buffer
(GExiv2Metadata *self, con
*/
void gexiv2_metadata_erase_exif_thumbnail (GExiv2Metadata *self);
+/**
+ * gexiv2_metadata_get_exif_data:
+ * @self: An instance of #GExiv2Metadata
+ * @byte_order: Whether to export the data in little or big endian format
+ * @error: (allow-none): A return location for a #GError or %NULL
+ *
+ * Returns: (transfer full) (allow-none): The content of the EXIF data or %NULL on error
+ * Since: 0.12.2
+ */
+GBytes * gexiv2_metadata_get_exif_data (GExiv2Metadata *self, GExiv2ByteOrder byte_order, GError
**error);
/*
* XMP functions
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]