[gimp] libgimp: make gimp_image_metadata_save_prepare() suggest GimpMetadataSaveFlags
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimp: make gimp_image_metadata_save_prepare() suggest GimpMetadataSaveFlags
- Date: Thu, 5 Jun 2014 00:15:23 +0000 (UTC)
commit 3a4fedea7c93c47c92587787bff5f8188e816a59
Author: Michael Natterer <mitch gimp org>
Date: Thu Jun 5 02:07:13 2014 +0200
libgimp: make gimp_image_metadata_save_prepare() suggest GimpMetadataSaveFlags
Return flags based on what metadata is actually present in the image.
Returning of a suggested value for GIMP_METADATA_SAVE_THUMBNAIL needs
support from gimp_image_metadata_load_prepare() and is still missing.
Port all plug-ins to use the new API, the suggested values are however
overridden by parasites and whatever special code was devised for the
individual plug-ins. This needs to be fixed.
libgimp/gimpmetadata.c | 22 ++++++++++++-
libgimp/gimpmetadata.h | 3 +-
plug-ins/common/file-png.c | 57 +++++++++++++++++++++++----------
plug-ins/common/file-tiff-save.c | 64 +++++++++++++++++++++++++-------------
plug-ins/file-jpeg/jpeg.c | 52 +++++++++++++++++++++---------
plug-ins/file-psd/psd-save.c | 32 +++++++++----------
6 files changed, 154 insertions(+), 76 deletions(-)
---
diff --git a/libgimp/gimpmetadata.c b/libgimp/gimpmetadata.c
index 06b21ae..3cb8e59 100644
--- a/libgimp/gimpmetadata.c
+++ b/libgimp/gimpmetadata.c
@@ -191,13 +191,17 @@ gimp_image_metadata_load_finish (gint32 image_ID,
* Since: GIMP 2.10
*/
GimpMetadata *
-gimp_image_metadata_save_prepare (gint32 image_ID,
- const gchar *mime_type)
+gimp_image_metadata_save_prepare (gint32 image_ID,
+ const gchar *mime_type,
+ GimpMetadataSaveFlags *suggested_flags)
{
GimpMetadata *metadata;
g_return_val_if_fail (image_ID > 0, NULL);
g_return_val_if_fail (mime_type != NULL, NULL);
+ g_return_val_if_fail (suggested_flags != NULL, NULL);
+
+ *suggested_flags = GIMP_METADATA_SAVE_ALL;
metadata = gimp_image_get_metadata (image_ID);
@@ -223,6 +227,9 @@ gimp_image_metadata_save_prepare (gint32 image_ID,
/* Exif */
+ if (! gexiv2_metadata_has_exif (metadata))
+ *suggested_flags &= ~GIMP_METADATA_SAVE_EXIF;
+
if (comment)
{
gexiv2_metadata_set_tag_string (metadata,
@@ -258,6 +265,9 @@ gimp_image_metadata_save_prepare (gint32 image_ID,
/* XMP */
+ if (! gexiv2_metadata_has_xmp (metadata))
+ *suggested_flags &= ~GIMP_METADATA_SAVE_XMP;
+
gexiv2_metadata_set_tag_string (metadata,
"Xmp.dc.Format",
mime_type);
@@ -291,6 +301,9 @@ gimp_image_metadata_save_prepare (gint32 image_ID,
/* IPTC */
+ if (! gexiv2_metadata_has_iptc (metadata))
+ *suggested_flags &= ~GIMP_METADATA_SAVE_IPTC;
+
g_snprintf (buffer, sizeof (buffer),
"%d-%d-%d",
g_date_time_get_year (datetime),
@@ -312,6 +325,11 @@ gimp_image_metadata_save_prepare (gint32 image_ID,
buffer);
g_date_time_unref (datetime);
+
+ /* Thumbnail */
+
+ if (FALSE /* FIXME if (original image had a thumbnail) */)
+ *suggested_flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
}
return metadata;
diff --git a/libgimp/gimpmetadata.h b/libgimp/gimpmetadata.h
index e30ed23..7cd4674 100644
--- a/libgimp/gimpmetadata.h
+++ b/libgimp/gimpmetadata.h
@@ -41,7 +41,8 @@ void gimp_image_metadata_load_finish (gint32 image_ID
gboolean interactive);
GimpMetadata * gimp_image_metadata_save_prepare (gint32 image_ID,
- const gchar *mime_type);
+ const gchar *mime_type,
+ GimpMetadataSaveFlags *suggested_flags);
gboolean gimp_image_metadata_save_finish (gint32 image_ID,
const gchar *mime_type,
GimpMetadata *metadata,
diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c
index 797492e..2698b50 100644
--- a/plug-ins/common/file-png.c
+++ b/plug-ins/common/file-png.c
@@ -491,13 +491,13 @@ run (const gchar *name,
strcmp (name, SAVE2_PROC) == 0 ||
strcmp (name, SAVE_DEFAULTS_PROC) == 0)
{
- gboolean alpha;
+ GimpMetadata *metadata;
+ GimpMetadataSaveFlags metadata_flags;
+ gboolean alpha;
image_ID = orig_image_ID = param[1].data.d_int32;
drawable_ID = param[2].data.d_int32;
- load_defaults ();
-
/* eventually export the image */
switch (run_mode)
{
@@ -522,6 +522,17 @@ run (const gchar *name,
break;
}
+ metadata = gimp_image_metadata_save_prepare (orig_image_ID,
+ "image/png",
+ &metadata_flags);
+
+ pngvals.save_exif = (metadata_flags & GIMP_METADATA_SAVE_EXIF) != 0;
+ pngvals.save_xmp = (metadata_flags & GIMP_METADATA_SAVE_XMP) != 0;
+ pngvals.save_iptc = (metadata_flags & GIMP_METADATA_SAVE_IPTC) != 0;
+ pngvals.save_thumbnail = (metadata_flags & GIMP_METADATA_SAVE_THUMBNAIL) != 0;
+
+ load_defaults ();
+
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
@@ -603,31 +614,38 @@ run (const gchar *name,
if (save_image (param[3].data.d_string,
image_ID, drawable_ID, orig_image_ID, &error))
{
- GimpMetadata *metadata;
-
- metadata = gimp_image_metadata_save_prepare (orig_image_ID,
- "image/png");
-
if (metadata)
{
- GFile *file;
- GimpMetadataSaveFlags flags = GIMP_METADATA_SAVE_ALL;
+ GFile *file;
gimp_metadata_set_bits_per_sample (metadata, 8);
- if (! pngvals.save_exif) flags &= ~GIMP_METADATA_SAVE_EXIF;
- if (! pngvals.save_xmp) flags &= ~GIMP_METADATA_SAVE_XMP;
- if (! pngvals.save_iptc) flags &= ~GIMP_METADATA_SAVE_IPTC;
- if (! pngvals.save_thumbnail) flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
+ if (pngvals.save_exif)
+ metadata_flags |= GIMP_METADATA_SAVE_EXIF;
+ else
+ metadata_flags &= ~GIMP_METADATA_SAVE_EXIF;
+
+ if (pngvals.save_xmp)
+ metadata_flags |= GIMP_METADATA_SAVE_XMP;
+ else
+ metadata_flags &= ~GIMP_METADATA_SAVE_XMP;
+
+ if (pngvals.save_iptc)
+ metadata_flags |= GIMP_METADATA_SAVE_IPTC;
+ else
+ metadata_flags &= ~GIMP_METADATA_SAVE_IPTC;
+
+ if (pngvals.save_thumbnail)
+ metadata_flags |= GIMP_METADATA_SAVE_THUMBNAIL;
+ else
+ metadata_flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
file = g_file_new_for_path (param[3].data.d_string);
gimp_image_metadata_save_finish (orig_image_ID,
"image/png",
- metadata, flags, file,
- NULL);
+ metadata, metadata_flags,
+ file, NULL);
g_object_unref (file);
-
- g_object_unref (metadata);
}
gimp_set_data (SAVE_PROC, &pngvals, sizeof (pngvals));
@@ -640,6 +658,9 @@ run (const gchar *name,
if (export == GIMP_EXPORT_EXPORT)
gimp_image_delete (image_ID);
+
+ if (metadata)
+ g_object_unref (metadata);
}
else if (strcmp (name, GET_DEFAULTS_PROC) == 0)
{
diff --git a/plug-ins/common/file-tiff-save.c b/plug-ins/common/file-tiff-save.c
index a1c2c1b..f88d102 100644
--- a/plug-ins/common/file-tiff-save.c
+++ b/plug-ins/common/file-tiff-save.c
@@ -227,11 +227,6 @@ run (const gchar *name,
{
static GimpParam values[2];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
- GimpParasite *parasite;
- gint32 image;
- gint32 drawable;
- gint32 orig_image;
- GimpExportReturn export = GIMP_EXPORT_CANCEL;
GError *error = NULL;
run_mode = param[0].data.d_int32;
@@ -252,8 +247,14 @@ run (const gchar *name,
(strcmp (name, SAVE2_PROC) == 0))
{
/* Plug-in is either file_tiff_save or file_tiff_save2 */
- image = orig_image = param[1].data.d_int32;
- drawable = param[2].data.d_int32;
+
+ GimpMetadata *metadata;
+ GimpMetadataSaveFlags metadata_flags;
+ GimpParasite *parasite;
+ gint32 image = param[1].data.d_int32;
+ gint32 drawable = param[2].data.d_int32;
+ gint32 orig_image = image;
+ GimpExportReturn export = GIMP_EXPORT_CANCEL;
/* Do this right this time, if POSSIBLE query for parasites, otherwise
or if there isn't one, choose the default comment from the gimprc. */
@@ -281,6 +282,15 @@ run (const gchar *name,
break;
}
+ metadata = gimp_image_metadata_save_prepare (orig_image,
+ "image/tiff",
+ &metadata_flags);
+
+ tsvals.save_exif = (metadata_flags & GIMP_METADATA_SAVE_EXIF) != 0;
+ tsvals.save_xmp = (metadata_flags & GIMP_METADATA_SAVE_XMP) != 0;
+ tsvals.save_iptc = (metadata_flags & GIMP_METADATA_SAVE_IPTC) != 0;
+ tsvals.save_thumbnail = (metadata_flags & GIMP_METADATA_SAVE_THUMBNAIL) != 0;
+
parasite = gimp_image_get_parasite (orig_image, "gimp-comment");
if (parasite)
{
@@ -365,31 +375,38 @@ run (const gchar *name,
if (save_image (param[3].data.d_string, image, drawable, orig_image,
&saved_bpp, &error))
{
- GimpMetadata *metadata;
-
- metadata = gimp_image_metadata_save_prepare (image,
- "image/tiff");
-
if (metadata)
{
- GFile *file;
- GimpMetadataSaveFlags flags = GIMP_METADATA_SAVE_ALL;
+ GFile *file;
gimp_metadata_set_bits_per_sample (metadata, saved_bpp);
- if (! tsvals.save_exif) flags &= ~GIMP_METADATA_SAVE_EXIF;
- if (! tsvals.save_xmp) flags &= ~GIMP_METADATA_SAVE_XMP;
- if (! tsvals.save_iptc) flags &= ~GIMP_METADATA_SAVE_IPTC;
- if (! tsvals.save_thumbnail) flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
+ if (tsvals.save_exif)
+ metadata_flags |= GIMP_METADATA_SAVE_EXIF;
+ else
+ metadata_flags &= ~GIMP_METADATA_SAVE_EXIF;
+
+ if (tsvals.save_xmp)
+ metadata_flags |= GIMP_METADATA_SAVE_XMP;
+ else
+ metadata_flags &= ~GIMP_METADATA_SAVE_XMP;
+
+ if (tsvals.save_iptc)
+ metadata_flags |= GIMP_METADATA_SAVE_IPTC;
+ else
+ metadata_flags &= ~GIMP_METADATA_SAVE_IPTC;
+
+ if (tsvals.save_thumbnail)
+ metadata_flags |= GIMP_METADATA_SAVE_THUMBNAIL;
+ else
+ metadata_flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
file = g_file_new_for_path (param[3].data.d_string);
gimp_image_metadata_save_finish (image,
"image/tiff",
- metadata, flags, file,
- NULL);
+ metadata, metadata_flags,
+ file, NULL);
g_object_unref (file);
-
- g_object_unref (metadata);
}
/* Store mvals data */
@@ -403,6 +420,9 @@ run (const gchar *name,
if (export == GIMP_EXPORT_EXPORT)
gimp_image_delete (image);
+
+ if (metadata)
+ g_object_unref (metadata);
}
else
{
diff --git a/plug-ins/file-jpeg/jpeg.c b/plug-ins/file-jpeg/jpeg.c
index 12d3d8c..0a2fa34 100644
--- a/plug-ins/file-jpeg/jpeg.c
+++ b/plug-ins/file-jpeg/jpeg.c
@@ -289,6 +289,9 @@ run (const gchar *name,
}
else if (strcmp (name, SAVE_PROC) == 0)
{
+ GimpMetadata *metadata;
+ GimpMetadataSaveFlags metadata_flags;
+
image_ID = orig_image_ID = param[1].data.d_int32;
drawable_ID = param[2].data.d_int32;
@@ -330,8 +333,14 @@ run (const gchar *name,
break;
}
- g_free (image_comment);
- image_comment = NULL;
+ metadata = gimp_image_metadata_save_prepare (orig_image_ID,
+ "image/jpeg",
+ &metadata_flags);
+
+ jsvals.save_exif = (metadata_flags & GIMP_METADATA_SAVE_EXIF) != 0;
+ jsvals.save_xmp = (metadata_flags & GIMP_METADATA_SAVE_XMP) != 0;
+ jsvals.save_iptc = (metadata_flags & GIMP_METADATA_SAVE_IPTC) != 0;
+ jsvals.save_thumbnail = (metadata_flags & GIMP_METADATA_SAVE_THUMBNAIL) != 0;
parasite = gimp_image_get_parasite (orig_image_ID, "gimp-comment");
if (parasite)
@@ -499,8 +508,6 @@ run (const gchar *name,
if (status == GIMP_PDB_SUCCESS)
{
- GimpMetadata *metadata;
-
/* pw - now we need to change the defaults to be whatever
* was used to save this image. Dump the old parasites
* and add new ones.
@@ -523,31 +530,44 @@ run (const gchar *name,
gimp_parasite_free (parasite);
/* write metadata */
- metadata = gimp_image_metadata_save_prepare (orig_image_ID,
- "image/jpeg");
if (metadata)
{
- GFile *file;
- GimpMetadataSaveFlags flags = GIMP_METADATA_SAVE_ALL;
+ GFile *file;
gimp_metadata_set_bits_per_sample (metadata, 8);
- if (! jsvals.save_exif) flags &= ~GIMP_METADATA_SAVE_EXIF;
- if (! jsvals.save_xmp) flags &= ~GIMP_METADATA_SAVE_XMP;
- if (! jsvals.save_iptc) flags &= ~GIMP_METADATA_SAVE_IPTC;
- if (! jsvals.save_thumbnail) flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
+ if (jsvals.save_exif)
+ metadata_flags |= GIMP_METADATA_SAVE_EXIF;
+ else
+ metadata_flags &= ~GIMP_METADATA_SAVE_EXIF;
+
+ if (jsvals.save_xmp)
+ metadata_flags |= GIMP_METADATA_SAVE_XMP;
+ else
+ metadata_flags &= ~GIMP_METADATA_SAVE_XMP;
+
+ if (jsvals.save_iptc)
+ metadata_flags |= GIMP_METADATA_SAVE_IPTC;
+ else
+ metadata_flags &= ~GIMP_METADATA_SAVE_IPTC;
+
+ if (jsvals.save_thumbnail)
+ metadata_flags |= GIMP_METADATA_SAVE_THUMBNAIL;
+ else
+ metadata_flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
file = g_file_new_for_path (param[3].data.d_string);
gimp_image_metadata_save_finish (orig_image_ID,
"image/jpeg",
- metadata, flags, file,
- NULL);
+ metadata, metadata_flags,
+ file, NULL);
g_object_unref (file);
-
- g_object_unref (metadata);
}
}
+
+ if (metadata)
+ g_object_unref (metadata);
}
else
{
diff --git a/plug-ins/file-psd/psd-save.c b/plug-ins/file-psd/psd-save.c
index f85da0f..709ecde 100644
--- a/plug-ins/file-psd/psd-save.c
+++ b/plug-ins/file-psd/psd-save.c
@@ -269,9 +269,11 @@ run (const gchar *name,
if (strcmp (name, SAVE_PROC) == 0)
{
- gint32 image_id;
- gint32 drawable_id;
- GimpExportReturn export = GIMP_EXPORT_IGNORE;
+ gint32 image_id;
+ gint32 drawable_id;
+ GimpMetadata *metadata;
+ GimpMetadataSaveFlags metadata_flags;
+ GimpExportReturn export = GIMP_EXPORT_IGNORE;
IFDBG printf ("\n---------------- %s ----------------\n",
param[3].data.d_string);
@@ -304,30 +306,23 @@ run (const gchar *name,
break;
}
+ metadata = gimp_image_metadata_save_prepare (image_id,
+ "image/x-psd",
+ &metadata_flags);
+
if (save_image (param[3].data.d_string, image_id, &error))
{
- GimpMetadata *metadata;
-
- metadata = gimp_image_metadata_save_prepare (image_id,
- "image/x-psd");
-
if (metadata)
{
- GFile *file;
- GimpMetadataSaveFlags flags = GIMP_METADATA_SAVE_ALL;
+ GFile *file;
gimp_metadata_set_bits_per_sample (metadata, 8);
- if (FALSE) flags &= ~GIMP_METADATA_SAVE_EXIF;
- if (FALSE) flags &= ~GIMP_METADATA_SAVE_XMP;
- if (FALSE) flags &= ~GIMP_METADATA_SAVE_IPTC;
- if (FALSE) flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
-
file = g_file_new_for_path (param[3].data.d_string);
gimp_image_metadata_save_finish (image_id,
"image/x-psd",
- metadata, flags, file,
- NULL);
+ metadata, metadata_flags,
+ file, NULL);
g_object_unref (file);
g_object_unref (metadata);
@@ -349,6 +344,9 @@ run (const gchar *name,
if (export == GIMP_EXPORT_EXPORT)
gimp_image_delete (image_id);
+
+ if (metadata)
+ g_object_unref (metadata);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]