[gimp/wip/bug790552-metadata-preferences: 4/4] plug-ins: file export should follow preferences regarding metadata.
- From: Jehan Pagès <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/bug790552-metadata-preferences: 4/4] plug-ins: file export should follow preferences regarding metadata.
- Date: Thu, 11 Jan 2018 04:34:13 +0000 (UTC)
commit afd808633fc4c991e21209e9d58b885cca7e316f
Author: Jehan <jehan girinstud io>
Date: Thu Jan 11 05:21:32 2018 +0100
plug-ins: file export should follow preferences regarding metadata.
Various plug-ins exporting metadata should now follow preferences, which
would override any default. Of course these preferences can still be
overriden by saved settings (global parasite), previous run settings,
and finally through the GUI when interactive.
plug-ins/common/file-png.c | 36 ++++++++++++++++++++--------------
plug-ins/file-jpeg/jpeg-save.c | 17 ++++++++++-----
plug-ins/file-jpeg/jpeg-save.h | 1 +
plug-ins/file-jpeg/jpeg.c | 9 +++++--
plug-ins/file-tiff/file-tiff.c | 5 ++++
plug-ins/file-webp/file-webp-save.c | 26 ++++++++++--------------
plug-ins/file-webp/file-webp-save.h | 16 ++++++++------
plug-ins/file-webp/file-webp.c | 22 +++++++++++++++++---
8 files changed, 82 insertions(+), 50 deletions(-)
---
diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c
index 47d4b2b..2d43973 100644
--- a/plug-ins/common/file-png.c
+++ b/plug-ins/common/file-png.c
@@ -184,8 +184,8 @@ static gboolean ia_has_transparent_pixels (GeglBuffer *buffer);
static gint find_unused_ia_color (GeglBuffer *buffer,
gint *colors);
-static void load_defaults (void);
-static void save_defaults (void);
+static void load_parasite (void);
+static void save_parasite (void);
static void load_gui_defaults (PngSaveGui *pg);
@@ -540,21 +540,25 @@ run (const gchar *name,
break;
}
+ /* Initialize with hardcoded defaults */
+ pngvals = defaults;
+
+ /* Override the defaults with preferences. */
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 ();
+ /* Override preferences from PNG export defaults (if saved). */
+ load_parasite ();
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
- /* possibly retrieve data */
+ /* Finally possibly retrieve data from previous run. */
gimp_get_data (SAVE_PROC, &pngvals);
alpha = gimp_drawable_has_alpha (drawable_ID);
@@ -676,7 +680,8 @@ run (const gchar *name,
}
else if (strcmp (name, GET_DEFAULTS_PROC) == 0)
{
- load_defaults ();
+ pngvals = defaults;
+ load_parasite ();
*nreturn_vals = 10;
@@ -701,7 +706,8 @@ run (const gchar *name,
{
if (nparams == 9)
{
- load_defaults ();
+ pngvals = defaults;
+ load_parasite ();
pngvals.interlaced = param[0].data.d_int32;
pngvals.compression_level = param[1].data.d_int32;
@@ -713,7 +719,7 @@ run (const gchar *name,
pngvals.comment = param[7].data.d_int32;
pngvals.save_transp_pixels = param[8].data.d_int32;
- save_defaults ();
+ save_parasite ();
}
else
{
@@ -2430,7 +2436,7 @@ save_dialog (gint32 image_ID,
g_signal_connect_swapped (gtk_builder_get_object (builder, "save-defaults"),
"clicked",
- G_CALLBACK (save_defaults),
+ G_CALLBACK (save_parasite),
&pg);
/* Show dialog and run */
@@ -2462,13 +2468,10 @@ save_dialog_response (GtkWidget *widget,
}
static void
-load_defaults (void)
+load_parasite (void)
{
GimpParasite *parasite;
- /* initialize with hardcoded defaults */
- pngvals = defaults;
-
parasite = gimp_get_parasite (PNG_DEFAULTS_PARASITE);
if (parasite)
@@ -2505,7 +2508,7 @@ load_defaults (void)
}
static void
-save_defaults (void)
+save_parasite (void)
{
GimpParasite *parasite;
gchar *def_str;
@@ -2538,7 +2541,10 @@ save_defaults (void)
static void
load_gui_defaults (PngSaveGui *pg)
{
- load_defaults ();
+ /* initialize with hardcoded defaults */
+ pngvals = defaults;
+ /* Override with parasite. */
+ load_parasite ();
#define SET_ACTIVE(field) \
if (gtk_widget_is_sensitive (pg->field)) \
diff --git a/plug-ins/file-jpeg/jpeg-save.c b/plug-ins/file-jpeg/jpeg-save.c
index 9c426f8..741adfe 100644
--- a/plug-ins/file-jpeg/jpeg-save.c
+++ b/plug-ins/file-jpeg/jpeg-save.c
@@ -1231,12 +1231,6 @@ save_dialog_response (GtkWidget *widget,
void
load_defaults (void)
{
- GimpParasite *parasite;
- gchar *def_str;
- JpegSaveVals tmpvals;
- gint num_fields;
- gint subsampling;
-
jsvals.quality = DEFAULT_QUALITY;
jsvals.smoothing = DEFAULT_SMOOTHING;
jsvals.optimize = DEFAULT_OPTIMIZE;
@@ -1252,6 +1246,16 @@ load_defaults (void)
jsvals.save_xmp = DEFAULT_XMP;
jsvals.save_iptc = DEFAULT_IPTC;
jsvals.use_orig_quality = DEFAULT_USE_ORIG_QUALITY;
+}
+
+void
+load_parasite (void)
+{
+ GimpParasite *parasite;
+ gchar *def_str;
+ JpegSaveVals tmpvals;
+ gint num_fields;
+ gint subsampling;
parasite = gimp_get_parasite (JPEG_DEFAULTS_PARASITE);
@@ -1333,6 +1337,7 @@ load_gui_defaults (JpegSaveGui *pg)
GtkAdjustment *restart_markers;
load_defaults ();
+ load_parasite ();
#define SET_ACTIVE_BTTN(field) \
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pg->field), jsvals.field)
diff --git a/plug-ins/file-jpeg/jpeg-save.h b/plug-ins/file-jpeg/jpeg-save.h
index 493318e..a00fe8c 100644
--- a/plug-ins/file-jpeg/jpeg-save.h
+++ b/plug-ins/file-jpeg/jpeg-save.h
@@ -51,5 +51,6 @@ gboolean save_image (const gchar *filename,
GError **error);
gboolean save_dialog (void);
void load_defaults (void);
+void load_parasite (void);
#endif /* __JPEG_SAVE_H__ */
diff --git a/plug-ins/file-jpeg/jpeg.c b/plug-ins/file-jpeg/jpeg.c
index 5808348..6756b6f 100644
--- a/plug-ins/file-jpeg/jpeg.c
+++ b/plug-ins/file-jpeg/jpeg.c
@@ -336,10 +336,13 @@ run (const gchar *name,
break;
}
+ /* Initialize with hardcoded defaults */
+ load_defaults ();
+
+ /* Override the defaults with preferences. */
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;
@@ -353,8 +356,8 @@ run (const gchar *name,
gimp_parasite_free (parasite);
}
- /* load defaults from gimp parasite */
- load_defaults ();
+ /* Override preferences from JPG export defaults (if saved). */
+ load_parasite ();
switch (run_mode)
{
diff --git a/plug-ins/file-tiff/file-tiff.c b/plug-ins/file-tiff/file-tiff.c
index d58d5ba..8a2aa36 100644
--- a/plug-ins/file-tiff/file-tiff.c
+++ b/plug-ins/file-tiff/file-tiff.c
@@ -358,9 +358,14 @@ run (const gchar *name,
break;
}
+ /* Override the defaults with preferences. */
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)
diff --git a/plug-ins/file-webp/file-webp-save.c b/plug-ins/file-webp/file-webp-save.c
index 9ed64b2..c47cea6 100644
--- a/plug-ins/file-webp/file-webp-save.c
+++ b/plug-ins/file-webp/file-webp-save.c
@@ -729,18 +729,18 @@ save_animation (const gchar *filename,
gboolean
-save_image (const gchar *filename,
- gint32 nLayers,
- gint32 *allLayers,
- gint32 image_ID,
- gint32 drawable_ID,
- WebPSaveParams *params,
- GError **error)
+save_image (const gchar *filename,
+ gint32 nLayers,
+ gint32 *allLayers,
+ gint32 image_ID,
+ gint32 drawable_ID,
+ GimpMetadata *metadata,
+ GimpMetadataSaveFlags metadata_flags,
+ WebPSaveParams *params,
+ GError **error)
{
- GimpMetadata *metadata;
- GimpMetadataSaveFlags metadata_flags;
- gboolean status = FALSE;
- GFile *file;
+ GFile *file;
+ gboolean status = FALSE;
if (nLayers == 0)
return FALSE;
@@ -768,10 +768,6 @@ save_image (const gchar *filename,
}
}
- metadata = gimp_image_metadata_save_prepare (image_ID,
- "image/webp",
- &metadata_flags);
-
if (metadata)
{
gimp_metadata_set_bits_per_sample (metadata, 8);
diff --git a/plug-ins/file-webp/file-webp-save.h b/plug-ins/file-webp/file-webp-save.h
index 9330ab8..b0f8bf1 100644
--- a/plug-ins/file-webp/file-webp-save.h
+++ b/plug-ins/file-webp/file-webp-save.h
@@ -41,13 +41,15 @@ typedef struct
} WebPSaveParams;
-gboolean save_image (const gchar *filename,
- gint32 nLayers,
- gint32 *allLayers,
- gint32 image_ID,
- gint32 drawable_ID,
- WebPSaveParams *params,
- GError **error);
+gboolean save_image (const gchar *filename,
+ gint32 nLayers,
+ gint32 *allLayers,
+ gint32 image_ID,
+ gint32 drawable_ID,
+ GimpMetadata *metadata,
+ GimpMetadataSaveFlags metadata_flags,
+ WebPSaveParams *params,
+ GError **error);
#endif /* __WEBP_SAVE_H__ */
diff --git a/plug-ins/file-webp/file-webp.c b/plug-ins/file-webp/file-webp.c
index 4c7407b..1711f6a 100644
--- a/plug-ins/file-webp/file-webp.c
+++ b/plug-ins/file-webp/file-webp.c
@@ -174,10 +174,12 @@ run (const gchar *name,
}
else if (! strcmp (name, SAVE_PROC))
{
- WebPSaveParams params;
- GimpExportReturn export = GIMP_EXPORT_CANCEL;
- gint32 *layers = NULL;
- gint32 n_layers;
+ GimpMetadata *metadata = NULL;
+ GimpMetadataSaveFlags metadata_flags;
+ WebPSaveParams params;
+ GimpExportReturn export = GIMP_EXPORT_CANCEL;
+ gint32 *layers = NULL;
+ gint32 n_layers;
if (run_mode == GIMP_RUN_INTERACTIVE ||
run_mode == GIMP_RUN_WITH_LAST_VALS)
@@ -205,6 +207,14 @@ run (const gchar *name,
params.delay = 200;
params.force_delay = FALSE;
+ /* Override the defaults with preferences. */
+ metadata = gimp_image_metadata_save_prepare (image_ID,
+ "image/webp",
+ &metadata_flags);
+ params.exif = (metadata_flags & GIMP_METADATA_SAVE_EXIF) != 0;
+ params.xmp = (metadata_flags & GIMP_METADATA_SAVE_XMP) != 0;
+ params.iptc = (metadata_flags & GIMP_METADATA_SAVE_IPTC) != 0;
+
/* Possibly override with session data */
gimp_get_data (SAVE_PROC, ¶ms);
@@ -275,6 +285,7 @@ run (const gchar *name,
n_layers, layers,
image_ID,
drawable_ID,
+ metadata, metadata_flags,
¶ms,
&error))
{
@@ -288,6 +299,9 @@ run (const gchar *name,
if (export == GIMP_EXPORT_EXPORT)
gimp_image_delete (image_ID);
+ if (metadata)
+ g_object_unref (metadata);
+
if (status == GIMP_PDB_SUCCESS)
{
/* save parameters for later */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]