libgimpbase: make GimpMetadata its own type derived from GExiv2Metadata

This commit is contained in:
Simon Budig 2017-01-30 16:42:27 +01:00
parent 53d4ad7c28
commit 884edf56ca
6 changed files with 219 additions and 140 deletions

View File

@ -100,7 +100,7 @@ gimp_image_metadata_load_prepare (gint32 image_ID,
}
#endif
gexiv2_metadata_erase_exif_thumbnail (metadata);
gexiv2_metadata_erase_exif_thumbnail (GEXIV2_METADATA (metadata));
}
return metadata;
@ -135,10 +135,10 @@ gimp_image_metadata_load_finish (gint32 image_ID,
{
gchar *comment;
comment = gexiv2_metadata_get_tag_interpreted_string (metadata,
comment = gexiv2_metadata_get_tag_interpreted_string (GEXIV2_METADATA (metadata),
"Exif.Photo.UserComment");
if (! comment)
comment = gexiv2_metadata_get_tag_interpreted_string (metadata,
comment = gexiv2_metadata_get_tag_interpreted_string (GEXIV2_METADATA (metadata),
"Exif.Image.ImageDescription");
if (comment)
@ -256,6 +256,7 @@ gimp_image_metadata_save_prepare (gint32 image_ID,
gdouble xres;
gdouble yres;
gchar buffer[32];
GExiv2Metadata *g2metadata = GEXIV2_METADATA (metadata);
image_width = gimp_image_width (image_ID);
image_height = gimp_image_height (image_ID);
@ -268,15 +269,15 @@ gimp_image_metadata_save_prepare (gint32 image_ID,
/* Exif */
if (! gexiv2_metadata_has_exif (metadata))
if (! gexiv2_metadata_has_exif (g2metadata))
*suggested_flags &= ~GIMP_METADATA_SAVE_EXIF;
if (comment)
{
gexiv2_metadata_set_tag_string (metadata,
gexiv2_metadata_set_tag_string (g2metadata,
"Exif.Photo.UserComment",
comment);
gexiv2_metadata_set_tag_string (metadata,
gexiv2_metadata_set_tag_string (g2metadata,
"Exif.Image.ImageDescription",
comment);
}
@ -289,11 +290,11 @@ gimp_image_metadata_save_prepare (gint32 image_ID,
g_date_time_get_hour (datetime),
g_date_time_get_minute (datetime),
g_date_time_get_second (datetime));
gexiv2_metadata_set_tag_string (metadata,
gexiv2_metadata_set_tag_string (g2metadata,
"Exif.Image.DateTime",
buffer);
gexiv2_metadata_set_tag_string (metadata,
gexiv2_metadata_set_tag_string (g2metadata,
"Exif.Image.Software",
PACKAGE_STRING);
@ -306,10 +307,10 @@ gimp_image_metadata_save_prepare (gint32 image_ID,
/* XMP */
if (! gexiv2_metadata_has_xmp (metadata))
if (! gexiv2_metadata_has_xmp (g2metadata))
*suggested_flags &= ~GIMP_METADATA_SAVE_XMP;
gexiv2_metadata_set_tag_string (metadata,
gexiv2_metadata_set_tag_string (g2metadata,
"Xmp.dc.Format",
mime_type);
@ -318,12 +319,12 @@ gimp_image_metadata_save_prepare (gint32 image_ID,
/* TIFF specific XMP data */
g_snprintf (buffer, sizeof (buffer), "%d", image_width);
gexiv2_metadata_set_tag_string (metadata,
gexiv2_metadata_set_tag_string (g2metadata,
"Xmp.tiff.ImageWidth",
buffer);
g_snprintf (buffer, sizeof (buffer), "%d", image_height);
gexiv2_metadata_set_tag_string (metadata,
gexiv2_metadata_set_tag_string (g2metadata,
"Xmp.tiff.ImageLength",
buffer);
@ -335,14 +336,14 @@ gimp_image_metadata_save_prepare (gint32 image_ID,
g_date_time_get_hour (datetime),
g_date_time_get_minute (datetime),
g_date_time_get_second (datetime));
gexiv2_metadata_set_tag_string (metadata,
gexiv2_metadata_set_tag_string (g2metadata,
"Xmp.tiff.DateTime",
buffer);
}
/* IPTC */
if (! gexiv2_metadata_has_iptc (metadata))
if (! gexiv2_metadata_has_iptc (g2metadata))
*suggested_flags &= ~GIMP_METADATA_SAVE_IPTC;
g_snprintf (buffer, sizeof (buffer),
@ -350,7 +351,7 @@ gimp_image_metadata_save_prepare (gint32 image_ID,
g_date_time_get_year (datetime),
g_date_time_get_month (datetime),
g_date_time_get_day_of_month (datetime));
gexiv2_metadata_set_tag_string (metadata,
gexiv2_metadata_set_tag_string (g2metadata,
"Iptc.Application2.DateCreated",
buffer);
@ -361,7 +362,7 @@ gimp_image_metadata_save_prepare (gint32 image_ID,
g_date_time_get_second (datetime),
g_date_time_get_hour (datetime),
g_date_time_get_minute (datetime));
gexiv2_metadata_set_tag_string (metadata,
gexiv2_metadata_set_tag_string (g2metadata,
"Iptc.Application2.TimeCreated",
buffer);
@ -401,7 +402,8 @@ gimp_image_metadata_save_finish (gint32 image_ID,
GFile *file,
GError **error)
{
GExiv2Metadata *new_metadata;
GimpMetadata *new_metadata;
GExiv2Metadata *new_g2metadata;
gboolean support_exif;
gboolean support_xmp;
gboolean support_iptc;
@ -423,25 +425,27 @@ gimp_image_metadata_save_finish (gint32 image_ID,
/* read metadata from saved file */
new_metadata = gimp_metadata_load_from_file (file, error);
new_g2metadata = GEXIV2_METADATA (new_metadata);
if (! new_metadata)
return FALSE;
support_exif = gexiv2_metadata_get_supports_exif (new_metadata);
support_xmp = gexiv2_metadata_get_supports_xmp (new_metadata);
support_iptc = gexiv2_metadata_get_supports_iptc (new_metadata);
support_exif = gexiv2_metadata_get_supports_exif (new_g2metadata);
support_xmp = gexiv2_metadata_get_supports_xmp (new_g2metadata);
support_iptc = gexiv2_metadata_get_supports_iptc (new_g2metadata);
if ((flags & GIMP_METADATA_SAVE_EXIF) && support_exif)
{
gchar **exif_data = gexiv2_metadata_get_exif_tags (metadata);
gchar **exif_data = gexiv2_metadata_get_exif_tags (GEXIV2_METADATA (metadata));
for (i = 0; exif_data[i] != NULL; i++)
{
if (! gexiv2_metadata_has_tag (new_metadata, exif_data[i]) &&
if (! gexiv2_metadata_has_tag (new_g2metadata, exif_data[i]) &&
gimp_metadata_is_tag_supported (exif_data[i], mime_type))
{
value = gexiv2_metadata_get_tag_string (metadata, exif_data[i]);
gexiv2_metadata_set_tag_string (new_metadata, exif_data[i],
value = gexiv2_metadata_get_tag_string (GEXIV2_METADATA (metadata),
exif_data[i]);
gexiv2_metadata_set_tag_string (new_g2metadata, exif_data[i],
value);
g_free (value);
}
@ -452,15 +456,15 @@ gimp_image_metadata_save_finish (gint32 image_ID,
if ((flags & GIMP_METADATA_SAVE_XMP) && support_xmp)
{
gchar **xmp_data = gexiv2_metadata_get_xmp_tags (metadata);
gchar **xmp_data = gexiv2_metadata_get_xmp_tags (GEXIV2_METADATA (metadata));
for (i = 0; xmp_data[i] != NULL; i++)
{
if (! gexiv2_metadata_has_tag (new_metadata, xmp_data[i]) &&
if (! gexiv2_metadata_has_tag (new_g2metadata, xmp_data[i]) &&
gimp_metadata_is_tag_supported (xmp_data[i], mime_type))
{
value = gexiv2_metadata_get_tag_string (metadata, xmp_data[i]);
gexiv2_metadata_set_tag_string (new_metadata, xmp_data[i],
value = gexiv2_metadata_get_tag_string (GEXIV2_METADATA (metadata), xmp_data[i]);
gexiv2_metadata_set_tag_string (new_g2metadata, xmp_data[i],
value);
g_free (value);
}
@ -471,15 +475,16 @@ gimp_image_metadata_save_finish (gint32 image_ID,
if ((flags & GIMP_METADATA_SAVE_IPTC) && support_iptc)
{
gchar **iptc_data = gexiv2_metadata_get_iptc_tags (metadata);
gchar **iptc_data = gexiv2_metadata_get_iptc_tags (GEXIV2_METADATA (metadata));
for (i = 0; iptc_data[i] != NULL; i++)
{
if (! gexiv2_metadata_has_tag (new_metadata, iptc_data[i]) &&
if (! gexiv2_metadata_has_tag (new_g2metadata, iptc_data[i]) &&
gimp_metadata_is_tag_supported (iptc_data[i], mime_type))
{
value = gexiv2_metadata_get_tag_string (metadata, iptc_data[i]);
gexiv2_metadata_set_tag_string (new_metadata, iptc_data[i],
value = gexiv2_metadata_get_tag_string (GEXIV2_METADATA (metadata),
iptc_data[i]);
gexiv2_metadata_set_tag_string (new_g2metadata, iptc_data[i],
value);
g_free (value);
}
@ -524,27 +529,27 @@ gimp_image_metadata_save_finish (gint32 image_ID,
{
gchar buffer[32];
gexiv2_metadata_set_exif_thumbnail_from_buffer (new_metadata,
gexiv2_metadata_set_exif_thumbnail_from_buffer (new_g2metadata,
(guchar *) thumb_buffer,
count);
g_snprintf (buffer, sizeof (buffer), "%d", thumbw);
gexiv2_metadata_set_tag_string (new_metadata,
gexiv2_metadata_set_tag_string (new_g2metadata,
"Exif.Thumbnail.ImageWidth",
buffer);
g_snprintf (buffer, sizeof (buffer), "%d", thumbh);
gexiv2_metadata_set_tag_string (new_metadata,
gexiv2_metadata_set_tag_string (new_g2metadata,
"Exif.Thumbnail.ImageLength",
buffer);
gexiv2_metadata_set_tag_string (new_metadata,
gexiv2_metadata_set_tag_string (new_g2metadata,
"Exif.Thumbnail.BitsPerSample",
"8 8 8");
gexiv2_metadata_set_tag_string (new_metadata,
gexiv2_metadata_set_tag_string (new_g2metadata,
"Exif.Thumbnail.SamplesPerPixel",
"3");
gexiv2_metadata_set_tag_string (new_metadata,
gexiv2_metadata_set_tag_string (new_g2metadata,
"Exif.Thumbnail.PhotometricInterpretation",
"6");
@ -579,7 +584,7 @@ gimp_image_metadata_load_thumbnail (GFile *file,
if (! metadata)
return -1;
if (! gexiv2_metadata_get_exif_thumbnail (metadata,
if (! gexiv2_metadata_get_exif_thumbnail (GEXIV2_METADATA (metadata),
&thumbnail_buffer,
&thumbnail_size))
{
@ -611,7 +616,7 @@ gimp_image_metadata_load_thumbnail (GFile *file,
gimp_image_insert_layer (image_ID, layer_ID, -1, 0);
gimp_image_metadata_rotate (image_ID,
gexiv2_metadata_get_orientation (metadata));
gexiv2_metadata_get_orientation (GEXIV2_METADATA (metadata)));
}
g_object_unref (metadata);
@ -731,7 +736,7 @@ gimp_image_metadata_rotate_query (gint32 image_ID,
GExiv2Orientation orientation;
gboolean query = interactive;
orientation = gexiv2_metadata_get_orientation (metadata);
orientation = gexiv2_metadata_get_orientation (GEXIV2_METADATA (metadata));
if (orientation <= GEXIV2_ORIENTATION_NORMAL ||
orientation > GEXIV2_ORIENTATION_MAX)
@ -771,9 +776,9 @@ gimp_image_metadata_rotate_query (gint32 image_ID,
gimp_image_metadata_rotate (image_ID, orientation);
gexiv2_metadata_set_tag_string (metadata,
gexiv2_metadata_set_tag_string (GEXIV2_METADATA (metadata),
"Exif.Image.Orientation", "1");
gexiv2_metadata_set_tag_string (metadata,
gexiv2_metadata_set_tag_string (GEXIV2_METADATA (metadata),
"Xmp.tiff.Orientation", "1");
}

View File

@ -55,7 +55,7 @@ typedef struct _GimpValueArray GimpValueArray;
typedef void (* GimpDatafileLoaderFunc) (const GimpDatafileData *file_data,
gpointer user_data);
typedef struct _GExiv2Metadata GimpMetadata;
typedef struct _GimpMetadata GimpMetadata;
/**

View File

@ -38,6 +38,32 @@
#include "libgimp/libgimp-intl.h"
typedef struct _GimpMetadataClass GimpMetadataClass;
typedef struct _GimpMetadataPrivate GimpMetadataPrivate;
struct _GimpMetadata
{
GExiv2Metadata parent_instance;
};
struct _GimpMetadataPrivate
{
};
struct _GimpMetadataClass
{
GExiv2MetadataClass parent_class;
/* Padding for future expansion */
void (*_gimp_reserved1) (void);
void (*_gimp_reserved2) (void);
void (*_gimp_reserved3) (void);
void (*_gimp_reserved4) (void);
void (*_gimp_reserved5) (void);
void (*_gimp_reserved6) (void);
void (*_gimp_reserved7) (void);
void (*_gimp_reserved8) (void);
};
/**
* SECTION: gimpmetadata
@ -142,6 +168,25 @@ static const guint8 wilber_jpg[] =
static const guint wilber_jpg_len = G_N_ELEMENTS (wilber_jpg);
G_DEFINE_TYPE_WITH_PRIVATE (GimpMetadata, gimp_metadata, GEXIV2_TYPE_METADATA)
static void
gimp_metadata_class_init (GimpMetadataClass *klass)
{
/* this is just a placeholder class to avoid being limited by
* GExiv2Metadata in the future...
*/
}
static void
gimp_metadata_init (GimpMetadata *metadata)
{
/* this is just a placeholder class to avoid being limited by
* GExiv2Metadata in the future...
*/
}
/**
* gimp_metadata_new:
@ -155,13 +200,15 @@ static const guint wilber_jpg_len = G_N_ELEMENTS (wilber_jpg);
GimpMetadata *
gimp_metadata_new (void)
{
GExiv2Metadata *metadata = NULL;
GimpMetadata *metadata = NULL;
if (gexiv2_initialize ())
{
metadata = gexiv2_metadata_new ();
metadata = g_object_new (GIMP_TYPE_METADATA, NULL);
gexiv2_metadata_new ();
if (! gexiv2_metadata_open_buf (metadata, wilber_jpg, wilber_jpg_len,
if (! gexiv2_metadata_open_buf (GEXIV2_METADATA (metadata),
wilber_jpg, wilber_jpg_len,
NULL))
{
g_object_unref (metadata);
@ -296,7 +343,7 @@ gimp_metadata_deserialize_text (GMarkupParseContext *context,
decoded = g_base64_decode (value, &len);
if (decoded[len - 1] == '\0')
gexiv2_metadata_set_tag_string (parse_data->metadata,
gexiv2_metadata_set_tag_string (GEXIV2_METADATA (parse_data->metadata),
parse_data->name,
(const gchar *) decoded);
@ -304,7 +351,7 @@ gimp_metadata_deserialize_text (GMarkupParseContext *context,
}
else
{
gexiv2_metadata_set_tag_string (parse_data->metadata,
gexiv2_metadata_set_tag_string (GEXIV2_METADATA (parse_data->metadata),
parse_data->name,
value);
}
@ -440,13 +487,14 @@ gimp_metadata_serialize (GimpMetadata *metadata)
g_string_append (string, "<?xml version='1.0' encoding='UTF-8'?>\n");
g_string_append (string, "<metadata>\n");
exif_data = gexiv2_metadata_get_exif_tags (metadata);
exif_data = gexiv2_metadata_get_exif_tags (GEXIV2_METADATA (metadata));
if (exif_data)
{
for (i = 0; exif_data[i] != NULL; i++)
{
value = gexiv2_metadata_get_tag_string (metadata, exif_data[i]);
value = gexiv2_metadata_get_tag_string (GEXIV2_METADATA (metadata),
exif_data[i]);
escaped = gimp_metadata_escape (exif_data[i], value, &base64);
g_free (value);
@ -456,13 +504,14 @@ gimp_metadata_serialize (GimpMetadata *metadata)
g_strfreev (exif_data);
}
xmp_data = gexiv2_metadata_get_xmp_tags (metadata);
xmp_data = gexiv2_metadata_get_xmp_tags (GEXIV2_METADATA (metadata));
if (xmp_data)
{
for (i = 0; xmp_data[i] != NULL; i++)
{
value = gexiv2_metadata_get_tag_string (metadata, xmp_data[i]);
value = gexiv2_metadata_get_tag_string (GEXIV2_METADATA (metadata),
xmp_data[i]);
escaped = gimp_metadata_escape (xmp_data[i], value, &base64);
g_free (value);
@ -472,13 +521,14 @@ gimp_metadata_serialize (GimpMetadata *metadata)
g_strfreev (xmp_data);
}
iptc_data = gexiv2_metadata_get_iptc_tags (metadata);
iptc_data = gexiv2_metadata_get_iptc_tags (GEXIV2_METADATA (metadata));
if (iptc_data)
{
for (i = 0; iptc_data[i] != NULL; i++)
{
value = gexiv2_metadata_get_tag_string (metadata, iptc_data[i]);
value = gexiv2_metadata_get_tag_string (GEXIV2_METADATA (metadata),
iptc_data[i]);
escaped = gimp_metadata_escape (iptc_data[i], value, &base64);
g_free (value);
@ -508,9 +558,9 @@ GimpMetadata *
gimp_metadata_load_from_file (GFile *file,
GError **error)
{
GExiv2Metadata *meta = NULL;
gchar *path;
gchar *filename;
GimpMetadata *meta = NULL;
gchar *path;
gchar *filename;
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@ -534,9 +584,9 @@ gimp_metadata_load_from_file (GFile *file,
if (gexiv2_initialize ())
{
meta = gexiv2_metadata_new ();
meta = g_object_new (GIMP_TYPE_METADATA, NULL);
if (! gexiv2_metadata_open_path (meta, filename, error))
if (! gexiv2_metadata_open_path (GEXIV2_METADATA (meta), filename, error))
{
g_object_unref (meta);
g_free (filename);
@ -592,7 +642,8 @@ gimp_metadata_save_to_file (GimpMetadata *metadata,
g_free (path);
success = gexiv2_metadata_save_file (metadata, filename, error);
success = gexiv2_metadata_save_file (GEXIV2_METADATA (metadata),
filename, error);
g_free (filename);
@ -624,7 +675,7 @@ gimp_metadata_set_from_exif (GimpMetadata *metadata,
guint8 data_size[2] = { 0, };
const guint8 eoi[2] = { 0xff, 0xd9 };
g_return_val_if_fail (GEXIV2_IS_METADATA (metadata), FALSE);
g_return_val_if_fail (GIMP_IS_METADATA (metadata), FALSE);
g_return_val_if_fail (exif_data != NULL, FALSE);
g_return_val_if_fail (exif_data_length > 0, FALSE);
g_return_val_if_fail (exif_data_length + 2 < 65536, FALSE);
@ -644,7 +695,7 @@ gimp_metadata_set_from_exif (GimpMetadata *metadata,
exif_metadata = gimp_metadata_new ();
if (! gexiv2_metadata_open_buf (exif_metadata,
if (! gexiv2_metadata_open_buf (GEXIV2_METADATA (exif_metadata),
exif_bytes->data, exif_bytes->len, error))
{
g_object_unref (exif_metadata);
@ -652,7 +703,7 @@ gimp_metadata_set_from_exif (GimpMetadata *metadata,
return FALSE;
}
if (! gexiv2_metadata_has_exif (exif_metadata))
if (! gexiv2_metadata_has_exif (GEXIV2_METADATA (exif_metadata)))
{
g_set_error (error, gimp_metadata_error_quark (), 0,
_("Parsing Exif data failed."));
@ -696,14 +747,14 @@ gimp_metadata_set_from_xmp (GimpMetadata *metadata,
xmp_metadata = gimp_metadata_new ();
if (! gexiv2_metadata_open_buf (xmp_metadata,
if (! gexiv2_metadata_open_buf (GEXIV2_METADATA (xmp_metadata),
xmp_data, xmp_data_length, error))
{
g_object_unref (xmp_metadata);
return FALSE;
}
if (! gexiv2_metadata_has_xmp (xmp_metadata))
if (! gexiv2_metadata_has_xmp (GEXIV2_METADATA (xmp_metadata)))
{
g_set_error (error, gimp_metadata_error_quark (), 0,
_("Parsing XMP data failed."));
@ -737,10 +788,12 @@ gimp_metadata_set_pixel_size (GimpMetadata *metadata,
g_return_if_fail (GEXIV2_IS_METADATA (metadata));
g_snprintf (buffer, sizeof (buffer), "%d", width);
gexiv2_metadata_set_tag_string (metadata, "Exif.Image.ImageWidth", buffer);
gexiv2_metadata_set_tag_string (GEXIV2_METADATA (metadata),
"Exif.Image.ImageWidth", buffer);
g_snprintf (buffer, sizeof (buffer), "%d", height);
gexiv2_metadata_set_tag_string (metadata, "Exif.Image.ImageLength", buffer);
gexiv2_metadata_set_tag_string (GEXIV2_METADATA (metadata),
"Exif.Image.ImageLength", buffer);
}
/**
@ -762,7 +815,8 @@ gimp_metadata_set_bits_per_sample (GimpMetadata *metadata,
g_snprintf (buffer, sizeof (buffer), "%d %d %d",
bits_per_sample, bits_per_sample, bits_per_sample);
gexiv2_metadata_set_tag_string (metadata, "Exif.Image.BitsPerSample", buffer);
gexiv2_metadata_set_tag_string (GEXIV2_METADATA (metadata),
"Exif.Image.BitsPerSample", buffer);
}
/**
@ -790,17 +844,17 @@ gimp_metadata_get_resolution (GimpMetadata *metadata,
g_return_val_if_fail (GEXIV2_IS_METADATA (metadata), FALSE);
if (gexiv2_metadata_get_exif_tag_rational (metadata,
if (gexiv2_metadata_get_exif_tag_rational (GEXIV2_METADATA (metadata),
"Exif.Image.XResolution",
&xnom, &xdenom) &&
gexiv2_metadata_get_exif_tag_rational (metadata,
gexiv2_metadata_get_exif_tag_rational (GEXIV2_METADATA (metadata),
"Exif.Image.YResolution",
&ynom, &ydenom))
{
gchar *un;
gint exif_unit = 2;
un = gexiv2_metadata_get_tag_string (metadata,
un = gexiv2_metadata_get_tag_string (GEXIV2_METADATA (metadata),
"Exif.Image.ResolutionUnit");
if (un)
{
@ -890,16 +944,17 @@ gimp_metadata_set_resolution (GimpMetadata *metadata,
break;
}
gexiv2_metadata_set_exif_tag_rational (metadata,
gexiv2_metadata_set_exif_tag_rational (GEXIV2_METADATA (metadata),
"Exif.Image.XResolution",
ROUND (xres * factor), factor);
gexiv2_metadata_set_exif_tag_rational (metadata,
gexiv2_metadata_set_exif_tag_rational (GEXIV2_METADATA (metadata),
"Exif.Image.YResolution",
ROUND (yres * factor), factor);
g_snprintf (buffer, sizeof (buffer), "%d", exif_unit);
gexiv2_metadata_set_tag_string (metadata, "Exif.Image.ResolutionUnit", buffer);
gexiv2_metadata_set_tag_string (GEXIV2_METADATA (metadata),
"Exif.Image.ResolutionUnit", buffer);
}
/**
@ -919,19 +974,21 @@ gimp_metadata_get_colorspace (GimpMetadata *metadata)
{
glong exif_cs = -1;
g_return_val_if_fail (GEXIV2_IS_METADATA (metadata),
g_return_val_if_fail (GIMP_IS_METADATA (metadata),
GIMP_METADATA_COLORSPACE_UNSPECIFIED);
/* the logic here was mostly taken from darktable and libkexiv2 */
if (gexiv2_metadata_has_tag (metadata, "Exif.Photo.ColorSpace"))
if (gexiv2_metadata_has_tag (GEXIV2_METADATA (metadata),
"Exif.Photo.ColorSpace"))
{
exif_cs = gexiv2_metadata_get_tag_long (metadata,
exif_cs = gexiv2_metadata_get_tag_long (GEXIV2_METADATA (metadata),
"Exif.Photo.ColorSpace");
}
else if (gexiv2_metadata_has_tag (metadata, "Xmp.exif.ColorSpace"))
else if (gexiv2_metadata_has_tag (GEXIV2_METADATA (metadata),
"Xmp.exif.ColorSpace"))
{
exif_cs = gexiv2_metadata_get_tag_long (metadata,
exif_cs = gexiv2_metadata_get_tag_long (GEXIV2_METADATA (metadata),
"Xmp.exif.ColorSpace");
}
@ -949,7 +1006,7 @@ gimp_metadata_get_colorspace (GimpMetadata *metadata)
{
gchar *iop_index;
iop_index = gexiv2_metadata_get_tag_string (metadata,
iop_index = gexiv2_metadata_get_tag_string (GEXIV2_METADATA (metadata),
"Exif.Iop.InteroperabilityIndex");
if (! g_strcmp0 (iop_index, "R03"))
@ -968,11 +1025,12 @@ gimp_metadata_get_colorspace (GimpMetadata *metadata)
g_free (iop_index);
}
if (gexiv2_metadata_has_tag (metadata, "Exif.Nikon3.ColorSpace"))
if (gexiv2_metadata_has_tag (GEXIV2_METADATA (metadata),
"Exif.Nikon3.ColorSpace"))
{
glong nikon_cs;
nikon_cs = gexiv2_metadata_get_tag_long (metadata,
nikon_cs = gexiv2_metadata_get_tag_long (GEXIV2_METADATA (metadata),
"Exif.Nikon3.ColorSpace");
if (nikon_cs == 0x01)
@ -985,11 +1043,12 @@ gimp_metadata_get_colorspace (GimpMetadata *metadata)
}
}
if (gexiv2_metadata_has_tag (metadata, "Exif.Canon.ColorSpace"))
if (gexiv2_metadata_has_tag (GEXIV2_METADATA (metadata),
"Exif.Canon.ColorSpace"))
{
glong canon_cs;
canon_cs = gexiv2_metadata_get_tag_long (metadata,
canon_cs = gexiv2_metadata_get_tag_long (GEXIV2_METADATA (metadata),
"Exif.Canon.ColorSpace");
if (canon_cs == 0x01)
@ -1024,59 +1083,59 @@ void
gimp_metadata_set_colorspace (GimpMetadata *metadata,
GimpMetadataColorspace colorspace)
{
g_return_if_fail (GEXIV2_IS_METADATA (metadata));
GExiv2Metadata *g2metadata = GEXIV2_METADATA (metadata);
switch (colorspace)
{
case GIMP_METADATA_COLORSPACE_UNSPECIFIED:
gexiv2_metadata_clear_tag (metadata, "Exif.Photo.ColorSpace");
gexiv2_metadata_clear_tag (metadata, "Xmp.exif.ColorSpace");
gexiv2_metadata_clear_tag (metadata, "Exif.Iop.InteroperabilityIndex");
gexiv2_metadata_clear_tag (metadata, "Exif.Nikon3.ColorSpace");
gexiv2_metadata_clear_tag (metadata, "Exif.Canon.ColorSpace");
gexiv2_metadata_clear_tag (g2metadata, "Exif.Photo.ColorSpace");
gexiv2_metadata_clear_tag (g2metadata, "Xmp.exif.ColorSpace");
gexiv2_metadata_clear_tag (g2metadata, "Exif.Iop.InteroperabilityIndex");
gexiv2_metadata_clear_tag (g2metadata, "Exif.Nikon3.ColorSpace");
gexiv2_metadata_clear_tag (g2metadata, "Exif.Canon.ColorSpace");
break;
case GIMP_METADATA_COLORSPACE_UNCALIBRATED:
gexiv2_metadata_set_tag_long (metadata, "Exif.Photo.ColorSpace", 0xffff);
if (gexiv2_metadata_has_tag (metadata, "Xmp.exif.ColorSpace"))
gexiv2_metadata_set_tag_long (metadata, "Xmp.exif.ColorSpace", 0xffff);
gexiv2_metadata_clear_tag (metadata, "Exif.Iop.InteroperabilityIndex");
gexiv2_metadata_clear_tag (metadata, "Exif.Nikon3.ColorSpace");
gexiv2_metadata_clear_tag (metadata, "Exif.Canon.ColorSpace");
gexiv2_metadata_set_tag_long (g2metadata, "Exif.Photo.ColorSpace", 0xffff);
if (gexiv2_metadata_has_tag (g2metadata, "Xmp.exif.ColorSpace"))
gexiv2_metadata_set_tag_long (g2metadata, "Xmp.exif.ColorSpace", 0xffff);
gexiv2_metadata_clear_tag (g2metadata, "Exif.Iop.InteroperabilityIndex");
gexiv2_metadata_clear_tag (g2metadata, "Exif.Nikon3.ColorSpace");
gexiv2_metadata_clear_tag (g2metadata, "Exif.Canon.ColorSpace");
break;
case GIMP_METADATA_COLORSPACE_SRGB:
gexiv2_metadata_set_tag_long (metadata, "Exif.Photo.ColorSpace", 0x01);
gexiv2_metadata_set_tag_long (g2metadata, "Exif.Photo.ColorSpace", 0x01);
if (gexiv2_metadata_has_tag (metadata, "Xmp.exif.ColorSpace"))
gexiv2_metadata_set_tag_long (metadata, "Xmp.exif.ColorSpace", 0x01);
if (gexiv2_metadata_has_tag (g2metadata, "Xmp.exif.ColorSpace"))
gexiv2_metadata_set_tag_long (g2metadata, "Xmp.exif.ColorSpace", 0x01);
if (gexiv2_metadata_has_tag (metadata, "Exif.Iop.InteroperabilityIndex"))
gexiv2_metadata_set_tag_string (metadata,
if (gexiv2_metadata_has_tag (g2metadata, "Exif.Iop.InteroperabilityIndex"))
gexiv2_metadata_set_tag_string (g2metadata,
"Exif.Iop.InteroperabilityIndex", "R98");
if (gexiv2_metadata_has_tag (metadata, "Exif.Nikon3.ColorSpace"))
gexiv2_metadata_set_tag_long (metadata, "Exif.Nikon3.ColorSpace", 0x01);
if (gexiv2_metadata_has_tag (g2metadata, "Exif.Nikon3.ColorSpace"))
gexiv2_metadata_set_tag_long (g2metadata, "Exif.Nikon3.ColorSpace", 0x01);
if (gexiv2_metadata_has_tag (metadata, "Exif.Canon.ColorSpace"))
gexiv2_metadata_set_tag_long (metadata, "Exif.Canon.ColorSpace", 0x01);
if (gexiv2_metadata_has_tag (g2metadata, "Exif.Canon.ColorSpace"))
gexiv2_metadata_set_tag_long (g2metadata, "Exif.Canon.ColorSpace", 0x01);
break;
case GIMP_METADATA_COLORSPACE_ADOBERGB:
gexiv2_metadata_set_tag_long (metadata, "Exif.Photo.ColorSpace", 0x02);
gexiv2_metadata_set_tag_long (g2metadata, "Exif.Photo.ColorSpace", 0x02);
if (gexiv2_metadata_has_tag (metadata, "Xmp.exif.ColorSpace"))
gexiv2_metadata_set_tag_long (metadata, "Xmp.exif.ColorSpace", 0x02);
if (gexiv2_metadata_has_tag (g2metadata, "Xmp.exif.ColorSpace"))
gexiv2_metadata_set_tag_long (g2metadata, "Xmp.exif.ColorSpace", 0x02);
if (gexiv2_metadata_has_tag (metadata, "Exif.Iop.InteroperabilityIndex"))
gexiv2_metadata_set_tag_string (metadata,
if (gexiv2_metadata_has_tag (g2metadata, "Exif.Iop.InteroperabilityIndex"))
gexiv2_metadata_set_tag_string (g2metadata,
"Exif.Iop.InteroperabilityIndex", "R03");
if (gexiv2_metadata_has_tag (metadata, "Exif.Nikon3.ColorSpace"))
gexiv2_metadata_set_tag_long (metadata, "Exif.Nikon3.ColorSpace", 0x02);
if (gexiv2_metadata_has_tag (g2metadata, "Exif.Nikon3.ColorSpace"))
gexiv2_metadata_set_tag_long (g2metadata, "Exif.Nikon3.ColorSpace", 0x02);
if (gexiv2_metadata_has_tag (metadata, "Exif.Canon.ColorSpace"))
gexiv2_metadata_set_tag_long (metadata, "Exif.Canon.ColorSpace", 0x02);
if (gexiv2_metadata_has_tag (g2metadata, "Exif.Canon.ColorSpace"))
gexiv2_metadata_set_tag_long (g2metadata, "Exif.Canon.ColorSpace", 0x02);
break;
}
}
@ -1151,20 +1210,22 @@ static void
gimp_metadata_add (GimpMetadata *src,
GimpMetadata *dest)
{
GExiv2Metadata *g2src = GEXIV2_METADATA (src);
GExiv2Metadata *g2dest = GEXIV2_METADATA (dest);
gchar *value;
gint i;
if (gexiv2_metadata_get_supports_exif (src) &&
gexiv2_metadata_get_supports_exif (dest))
if (gexiv2_metadata_get_supports_exif (g2src) &&
gexiv2_metadata_get_supports_exif (g2dest))
{
gchar **exif_data = gexiv2_metadata_get_exif_tags (src);
gchar **exif_data = gexiv2_metadata_get_exif_tags (g2src);
if (exif_data)
{
for (i = 0; exif_data[i] != NULL; i++)
{
value = gexiv2_metadata_get_tag_string (src, exif_data[i]);
gexiv2_metadata_set_tag_string (dest, exif_data[i], value);
value = gexiv2_metadata_get_tag_string (g2src, exif_data[i]);
gexiv2_metadata_set_tag_string (g2dest, exif_data[i], value);
g_free (value);
}
@ -1172,17 +1233,17 @@ gimp_metadata_add (GimpMetadata *src,
}
}
if (gexiv2_metadata_get_supports_xmp (src) &&
gexiv2_metadata_get_supports_xmp (dest))
if (gexiv2_metadata_get_supports_xmp (g2src) &&
gexiv2_metadata_get_supports_xmp (g2dest))
{
gchar **xmp_data = gexiv2_metadata_get_xmp_tags (src);
gchar **xmp_data = gexiv2_metadata_get_xmp_tags (g2src);
if (xmp_data)
{
for (i = 0; xmp_data[i] != NULL; i++)
{
value = gexiv2_metadata_get_tag_string (src, xmp_data[i]);
gexiv2_metadata_set_tag_string (dest, xmp_data[i], value);
value = gexiv2_metadata_get_tag_string (g2src, xmp_data[i]);
gexiv2_metadata_set_tag_string (g2dest, xmp_data[i], value);
g_free (value);
}
@ -1190,17 +1251,17 @@ gimp_metadata_add (GimpMetadata *src,
}
}
if (gexiv2_metadata_get_supports_iptc (src) &&
gexiv2_metadata_get_supports_iptc (dest))
if (gexiv2_metadata_get_supports_iptc (g2src) &&
gexiv2_metadata_get_supports_iptc (g2dest))
{
gchar **iptc_data = gexiv2_metadata_get_iptc_tags (src);
gchar **iptc_data = gexiv2_metadata_get_iptc_tags (g2src);
if (iptc_data)
{
for (i = 0; iptc_data[i] != NULL; i++)
{
value = gexiv2_metadata_get_tag_string (src, iptc_data[i]);
gexiv2_metadata_set_tag_string (dest, iptc_data[i], value);
value = gexiv2_metadata_get_tag_string (g2src, iptc_data[i]);
gexiv2_metadata_set_tag_string (g2dest, iptc_data[i], value);
g_free (value);
}

View File

@ -24,6 +24,13 @@
G_BEGIN_DECLS
#define GIMP_TYPE_METADATA (gimp_metadata_get_type ())
#define GIMP_METADATA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_METADATA, GimpMetadata))
#define GIMP_METADATA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_METADATA, GimpMetadataClass))
#define GIMP_IS_METADATA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_METADATA))
#define GIMP_IS_METADATA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_METADATA))
#define GIMP_METADATA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_METADATA, GimpMetadataClass))
typedef enum
{
GIMP_METADATA_LOAD_COMMENT = 1 << 0,
@ -52,6 +59,7 @@ typedef enum
GIMP_METADATA_COLORSPACE_ADOBERGB
} GimpMetadataColorspace;
GType gimp_metadata_get_type (void) G_GNUC_CONST;
GimpMetadata * gimp_metadata_new (void);
GimpMetadata * gimp_metadata_duplicate (GimpMetadata *metadata);

View File

@ -78,7 +78,7 @@ static void run (const gchar *name,
GimpParam **return_vals);
static gboolean metadata_dialog (gint32 image_id,
GExiv2Metadata *metadata);
GimpMetadata *metadata);
static void metadata_dialog_set_metadata (GExiv2Metadata *metadata,
GtkBuilder *builder);
@ -209,8 +209,8 @@ run (const gchar *name,
}
static gboolean
metadata_dialog (gint32 image_id,
GExiv2Metadata *metadata)
metadata_dialog (gint32 image_id,
GimpMetadata *metadata)
{
GtkBuilder *builder;
GtkWidget *dialog;
@ -271,7 +271,7 @@ metadata_dialog (gint32 image_id,
G_CALLBACK (metadata_dialog_iptc_callback),
builder);
metadata_dialog_set_metadata (metadata, builder);
metadata_dialog_set_metadata (GEXIV2_METADATA (metadata), builder);
gtk_dialog_run (GTK_DIALOG (dialog));
@ -472,7 +472,7 @@ metadata_dialog_iptc_callback (GtkWidget *dialog,
GtkBuilder *builder)
{
#if 0
GExiv2Metadata *metadata;
GimpMetadata *metadata;
gint i;
metadata = gimp_image_get_metadata (handler->image);
@ -486,7 +486,8 @@ metadata_dialog_iptc_callback (GtkWidget *dialog,
{
GtkEntry *entry = GTK_ENTRY (object);
gexiv2_metadata_set_tag_string (metadata, iptc_tags[i].tag,
gexiv2_metadata_set_tag_string (GEXIV2_METADATA (metadata),
iptc_tags[i].tag,
gtk_entry_get_text (entry));
}
else if (!strcmp ("multi", iptc_tags[i].mode))
@ -502,7 +503,8 @@ metadata_dialog_iptc_callback (GtkWidget *dialog,
gtk_text_buffer_get_end_iter (buffer, &end);
text = gtk_text_buffer_get_text (buffer, &start, &end, TRUE);
gexiv2_metadata_set_tag_string (metadata, iptc_tags[i].tag, text);
gexiv2_metadata_set_tag_string (GEXIV2_METADATA (metadata),
iptc_tags[i].tag, text);
g_free (text);
}
}

View File

@ -471,9 +471,12 @@ run (const gchar *name,
* exiv2 saves them with wrong type and the original values
* could be invalid, see also bug 761823
*/
gexiv2_metadata_clear_tag (metadata, "Exif.Image.0x0118");
gexiv2_metadata_clear_tag (metadata, "Exif.Image.0x0119");
gexiv2_metadata_clear_tag (metadata, "Exif.Image.PageNumber");
gexiv2_metadata_clear_tag (GEXIV2_METADATA (metadata),
"Exif.Image.0x0118");
gexiv2_metadata_clear_tag (GEXIV2_METADATA (metadata),
"Exif.Image.0x0119");
gexiv2_metadata_clear_tag (GEXIV2_METADATA (metadata),
"Exif.Image.PageNumber");
gimp_metadata_set_bits_per_sample (metadata, saved_bpp);