[gimp] libgimp: move "image" and "run_mode" from gimp_procedure_config_end_run()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimp: move "image" and "run_mode" from gimp_procedure_config_end_run()
- Date: Thu, 26 Sep 2019 10:10:05 +0000 (UTC)
commit 9cb62f5f9a31281ce2a5f0fcaec277e1cdebc500
Author: Michael Natterer <mitch gimp org>
Date: Thu Sep 26 00:44:52 2019 +0200
libgimp: move "image" and "run_mode" from gimp_procedure_config_end_run()
and remember them internally between begin_run() and end_run().
Simplifies plug-in code even more.
Move the begin_run() before gimp_export_image() block in all export
plug-ins.
libgimp/gimpprocedureconfig.c | 47 ++++++++++++++++++++++-----------------
libgimp/gimpprocedureconfig.h | 2 --
plug-ins/common/despeckle.c | 2 +-
plug-ins/common/file-gbr.c | 51 ++++++++++++++++++++-----------------------
plug-ins/common/file-heif.c | 8 +++----
plug-ins/common/file-pat.c | 49 +++++++++++++++++++----------------------
plug-ins/common/file-png.c | 34 ++++++++++++++---------------
plug-ins/common/file-sunras.c | 9 +++-----
plug-ins/file-sgi/sgi.c | 9 +++-----
9 files changed, 102 insertions(+), 109 deletions(-)
---
diff --git a/libgimp/gimpprocedureconfig.c b/libgimp/gimpprocedureconfig.c
index 0c2f91737b..9ad0c0dcd4 100644
--- a/libgimp/gimpprocedureconfig.c
+++ b/libgimp/gimpprocedureconfig.c
@@ -56,6 +56,9 @@ enum
struct _GimpProcedureConfigPrivate
{
GimpProcedure *procedure;
+
+ GimpImage *image;
+ GimpRunMode run_mode;
};
@@ -122,6 +125,8 @@ static void
gimp_procedure_config_init (GimpProcedureConfig *config)
{
config->priv = gimp_procedure_config_get_instance_private (config);
+
+ config->priv->run_mode = -1;
}
static void
@@ -344,6 +349,9 @@ gimp_procedure_config_begin_run (GimpProcedureConfig *config,
g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));
g_return_if_fail (args != NULL);
+ config->priv->image = image;
+ config->priv->run_mode = run_mode;
+
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE :
@@ -377,22 +385,21 @@ gimp_procedure_config_begin_run (GimpProcedureConfig *config,
/**
* gimp_procedure_config_end_run:
- * @config: a #GimpProcedureConfig
- * @image: a #GimpImage or %NULL
- * @run_mode: the #GimpRunMode passed to a #GimpProcedure's run()
- * @status: the return status of the #GimpProcedure's run()
+ * @config: a #GimpProcedureConfig
+ * @status: the return status of the #GimpProcedure's run()
*
* This function is the counterpart of
* gimp_procedure_conig_begin_run() and must always be called in pairs
* in a procedure's run(), before returning return values.
*
- * If @run_mode is %GIMP_RUN_INTERACTIVE, @config is saved as last
- * used values to be used when the procedure runs again. Additionally,
- * if @image is not %NULL, @config is attached to @image as last used
- * values for this image using a #GimpParasite and
- * gimp_image_attach_parasite().
+ * If the @run_mode passed to gimp_procedure_config_end_run() was
+ * %GIMP_RUN_INTERACTIVE, @config is saved as last used values to be
+ * used when the procedure runs again. Additionally, the @image passed
+ * gimp_procedure_config_begin_run() was not %NULL, @config is
+ * attached to @image as last used values for this image using a
+ * #GimpParasite and gimp_image_attach_parasite().
*
- * If @run_mode is not %GIMP_RUN_NONINTERACTIVE, this function also
+ * If @run_mode was not %GIMP_RUN_NONINTERACTIVE, this function also
* conveniently calls gimp_display_flush(), which is what most
* procedures want and doesn't do any harm if called redundantly.
*
@@ -401,24 +408,21 @@ gimp_procedure_config_begin_run (GimpProcedureConfig *config,
* Since: 3.0
**/
void
-gimp_procedure_config_end_run (GimpProcedureConfig *config,
- GimpImage *image,
- GimpRunMode run_mode,
- GimpPDBStatusType status)
+gimp_procedure_config_end_run (GimpProcedureConfig *config,
+ GimpPDBStatusType status)
{
g_return_if_fail (GIMP_IS_PROCEDURE_CONFIG (config));
- g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));
- if (run_mode != GIMP_RUN_NONINTERACTIVE)
+ if (config->priv->run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_displays_flush ();
- if (status == GIMP_PDB_SUCCESS &&
- run_mode == GIMP_RUN_INTERACTIVE)
+ if (status == GIMP_PDB_SUCCESS &&
+ config->priv->run_mode == GIMP_RUN_INTERACTIVE)
{
GError *error = NULL;
- if (image)
- gimp_procedure_config_save_parasite (config, image);
+ if (config->priv->image)
+ gimp_procedure_config_save_parasite (config, config->priv->image);
if (! gimp_procedure_config_save_last (config, &error))
{
@@ -427,6 +431,9 @@ gimp_procedure_config_end_run (GimpProcedureConfig *config,
g_clear_error (&error);
}
}
+
+ config->priv->image = NULL;
+ config->priv->run_mode = -1;
}
diff --git a/libgimp/gimpprocedureconfig.h b/libgimp/gimpprocedureconfig.h
index 238eba6dcb..7a913505d5 100644
--- a/libgimp/gimpprocedureconfig.h
+++ b/libgimp/gimpprocedureconfig.h
@@ -80,8 +80,6 @@ void gimp_procedure_config_begin_run (GimpProcedureConfig *config,
GimpRunMode run_mode,
const GimpValueArray *args);
void gimp_procedure_config_end_run (GimpProcedureConfig *config,
- GimpImage *image,
- GimpRunMode run_mode,
GimpPDBStatusType status);
diff --git a/plug-ins/common/despeckle.c b/plug-ins/common/despeckle.c
index 2611e9e601..0ad02b4fae 100644
--- a/plug-ins/common/despeckle.c
+++ b/plug-ins/common/despeckle.c
@@ -252,7 +252,7 @@ despeckle_run (GimpProcedure *procedure,
despeckle (drawable, G_OBJECT (config));
- gimp_procedure_config_end_run (config, NULL, run_mode, GIMP_PDB_SUCCESS);
+ gimp_procedure_config_end_run (config, GIMP_PDB_SUCCESS);
g_object_unref (config);
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
diff --git a/plug-ins/common/file-gbr.c b/plug-ins/common/file-gbr.c
index fcbbacd876..925fd668df 100644
--- a/plug-ins/common/file-gbr.c
+++ b/plug-ins/common/file-gbr.c
@@ -169,38 +169,13 @@ gbr_save (GimpProcedure *procedure,
GimpProcedureConfig *config;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
- GimpImage *orig_image;
gchar *description;
GError *error = NULL;
INIT_I18N ();
- orig_image = image;
-
- switch (run_mode)
- {
- case GIMP_RUN_INTERACTIVE:
- case GIMP_RUN_WITH_LAST_VALS:
- gimp_ui_init (PLUG_IN_BINARY);
-
- export = gimp_export_image (&image, &drawable, "GBR",
- GIMP_EXPORT_CAN_HANDLE_GRAY |
- GIMP_EXPORT_CAN_HANDLE_RGB |
- GIMP_EXPORT_CAN_HANDLE_INDEXED |
- GIMP_EXPORT_CAN_HANDLE_ALPHA);
-
- if (export == GIMP_EXPORT_CANCEL)
- return gimp_procedure_new_return_values (procedure,
- GIMP_PDB_CANCEL,
- NULL);
- break;
-
- default:
- break;
- }
-
config = gimp_procedure_create_config (procedure);
- gimp_procedure_config_begin_run (config, orig_image, run_mode, args);
+ gimp_procedure_config_begin_run (config, image, run_mode, args);
g_object_get (config,
"description", &description,
@@ -223,6 +198,28 @@ gbr_save (GimpProcedure *procedure,
g_free (description);
+ switch (run_mode)
+ {
+ case GIMP_RUN_INTERACTIVE:
+ case GIMP_RUN_WITH_LAST_VALS:
+ gimp_ui_init (PLUG_IN_BINARY);
+
+ export = gimp_export_image (&image, &drawable, "GBR",
+ GIMP_EXPORT_CAN_HANDLE_GRAY |
+ GIMP_EXPORT_CAN_HANDLE_RGB |
+ GIMP_EXPORT_CAN_HANDLE_INDEXED |
+ GIMP_EXPORT_CAN_HANDLE_ALPHA);
+
+ if (export == GIMP_EXPORT_CANCEL)
+ return gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_CANCEL,
+ NULL);
+ break;
+
+ default:
+ break;
+ }
+
if (run_mode == GIMP_RUN_INTERACTIVE)
{
if (! save_dialog (procedure, G_OBJECT (config)))
@@ -265,7 +262,7 @@ gbr_save (GimpProcedure *procedure,
gimp_value_array_unref (save_retvals);
}
- gimp_procedure_config_end_run (config, orig_image, run_mode, status);
+ gimp_procedure_config_end_run (config, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)
diff --git a/plug-ins/common/file-heif.c b/plug-ins/common/file-heif.c
index d8bd3dc97d..0ba3c609a1 100644
--- a/plug-ins/common/file-heif.c
+++ b/plug-ins/common/file-heif.c
@@ -259,6 +259,9 @@ heif_save (GimpProcedure *procedure,
INIT_I18N ();
gegl_init (NULL, NULL);
+ config = gimp_procedure_create_config (procedure);
+ gimp_procedure_config_begin_run (config, image, run_mode, args);
+
orig_image = image;
switch (run_mode)
@@ -281,9 +284,6 @@ heif_save (GimpProcedure *procedure,
break;
}
- config = gimp_procedure_create_config (procedure);
- gimp_procedure_config_begin_run (config, orig_image, run_mode, args);
-
if (run_mode == GIMP_RUN_INTERACTIVE)
{
if (! save_dialog (procedure, G_OBJECT (config)))
@@ -317,7 +317,7 @@ heif_save (GimpProcedure *procedure,
}
}
- gimp_procedure_config_end_run (config, orig_image, run_mode, status);
+ gimp_procedure_config_end_run (config, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)
diff --git a/plug-ins/common/file-pat.c b/plug-ins/common/file-pat.c
index d04a3e86a3..48ff53f2c5 100644
--- a/plug-ins/common/file-pat.c
+++ b/plug-ins/common/file-pat.c
@@ -148,37 +148,13 @@ pat_save (GimpProcedure *procedure,
GimpProcedureConfig *config;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
- GimpImage *orig_image;
gchar *description;
GError *error = NULL;
INIT_I18N ();
- orig_image = image;
-
- switch (run_mode)
- {
- case GIMP_RUN_INTERACTIVE:
- case GIMP_RUN_WITH_LAST_VALS:
- gimp_ui_init (PLUG_IN_BINARY);
-
- export = gimp_export_image (&image, &drawable, "PAT",
- GIMP_EXPORT_CAN_HANDLE_GRAY |
- GIMP_EXPORT_CAN_HANDLE_RGB |
- GIMP_EXPORT_CAN_HANDLE_INDEXED |
- GIMP_EXPORT_CAN_HANDLE_ALPHA);
-
- if (export == GIMP_EXPORT_CANCEL)
- return gimp_procedure_new_return_values (procedure, GIMP_PDB_CANCEL,
- NULL);
- break;
-
- default:
- break;
- }
-
config = gimp_procedure_create_config (procedure);
- gimp_procedure_config_begin_run (config, orig_image, run_mode, args);
+ gimp_procedure_config_begin_run (config, image, run_mode, args);
g_object_get (config,
"description", &description,
@@ -201,6 +177,27 @@ pat_save (GimpProcedure *procedure,
g_free (description);
+ switch (run_mode)
+ {
+ case GIMP_RUN_INTERACTIVE:
+ case GIMP_RUN_WITH_LAST_VALS:
+ gimp_ui_init (PLUG_IN_BINARY);
+
+ export = gimp_export_image (&image, &drawable, "PAT",
+ GIMP_EXPORT_CAN_HANDLE_GRAY |
+ GIMP_EXPORT_CAN_HANDLE_RGB |
+ GIMP_EXPORT_CAN_HANDLE_INDEXED |
+ GIMP_EXPORT_CAN_HANDLE_ALPHA);
+
+ if (export == GIMP_EXPORT_CANCEL)
+ return gimp_procedure_new_return_values (procedure, GIMP_PDB_CANCEL,
+ NULL);
+ break;
+
+ default:
+ break;
+ }
+
if (run_mode == GIMP_RUN_INTERACTIVE)
{
if (! save_dialog (procedure, G_OBJECT (config)))
@@ -238,7 +235,7 @@ pat_save (GimpProcedure *procedure,
gimp_value_array_unref (save_retvals);
}
- gimp_procedure_config_end_run (config, orig_image, run_mode, status);
+ gimp_procedure_config_end_run (config, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)
diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c
index 4c080c2023..6153d6b5b4 100644
--- a/plug-ins/common/file-png.c
+++ b/plug-ins/common/file-png.c
@@ -423,6 +423,21 @@ png_save (GimpProcedure *procedure,
INIT_I18N ();
gegl_init (NULL, NULL);
+ config = gimp_procedure_create_config (procedure);
+ gimp_procedure_config_begin_run (config, image, run_mode, args);
+
+#if 0
+ /* Override the defaults with preferences. */
+ metadata = gimp_image_metadata_save_prepare (image,
+ "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;
+ pngvals.save_profile = (metadata_flags & GIMP_METADATA_SAVE_COLOR_PROFILE) != 0;
+#endif
+
orig_image = image;
switch (run_mode)
@@ -446,21 +461,6 @@ png_save (GimpProcedure *procedure,
break;
}
- config = gimp_procedure_create_config (procedure);
- gimp_procedure_config_begin_run (config, orig_image, run_mode, args);
-
-#if 0
- /* Override the defaults with preferences. */
- metadata = gimp_image_metadata_save_prepare (orig_image,
- "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;
- pngvals.save_profile = (metadata_flags & GIMP_METADATA_SAVE_COLOR_PROFILE) != 0;
-#endif
-
alpha = gimp_drawable_has_alpha (drawable);
/* If the image has no transparency, then there is usually no need
@@ -536,7 +536,7 @@ png_save (GimpProcedure *procedure,
else
metadata_flags &= ~GIMP_METADATA_SAVE_COLOR_PROFILE;
- gimp_image_metadata_save_finish (orig_image,
+ gimp_image_metadata_save_finish (image,
"image/png",
metadata, metadata_flags,
file, NULL);
@@ -550,7 +550,7 @@ png_save (GimpProcedure *procedure,
}
}
- gimp_procedure_config_end_run (config, orig_image, run_mode, status);
+ gimp_procedure_config_end_run (config, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)
diff --git a/plug-ins/common/file-sunras.c b/plug-ins/common/file-sunras.c
index cadae0ee71..0b7c919f30 100644
--- a/plug-ins/common/file-sunras.c
+++ b/plug-ins/common/file-sunras.c
@@ -364,13 +364,13 @@ sunras_save (GimpProcedure *procedure,
GimpProcedureConfig *config;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
- GimpImage *orig_image;
GError *error = NULL;
INIT_I18N ();
gegl_init (NULL, NULL);
- orig_image = image;
+ config = gimp_procedure_create_config (procedure);
+ gimp_procedure_config_begin_run (config, image, run_mode, args);
switch (run_mode)
{
@@ -393,9 +393,6 @@ sunras_save (GimpProcedure *procedure,
break;
}
- config = gimp_procedure_create_config (procedure);
- gimp_procedure_config_begin_run (config, orig_image, run_mode, args);
-
if (run_mode == GIMP_RUN_INTERACTIVE)
{
if (! save_dialog (procedure, G_OBJECT (config)))
@@ -411,7 +408,7 @@ sunras_save (GimpProcedure *procedure,
}
}
- gimp_procedure_config_end_run (config, orig_image, run_mode, status);
+ gimp_procedure_config_end_run (config, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)
diff --git a/plug-ins/file-sgi/sgi.c b/plug-ins/file-sgi/sgi.c
index 926dce5ad1..e9bbe362c8 100644
--- a/plug-ins/file-sgi/sgi.c
+++ b/plug-ins/file-sgi/sgi.c
@@ -233,13 +233,13 @@ sgi_save (GimpProcedure *procedure,
GimpProcedureConfig *config;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
- GimpImage *orig_image;
GError *error = NULL;
INIT_I18N ();
gegl_init (NULL, NULL);
- orig_image = image;
+ config = gimp_procedure_create_config (procedure);
+ gimp_procedure_config_begin_run (config, image, run_mode, args);
switch (run_mode)
{
@@ -263,9 +263,6 @@ sgi_save (GimpProcedure *procedure,
break;
}
- config = gimp_procedure_create_config (procedure);
- gimp_procedure_config_begin_run (config, orig_image, run_mode, args);
-
if (run_mode == GIMP_RUN_INTERACTIVE)
{
if (! save_dialog (procedure, G_OBJECT (config)))
@@ -281,7 +278,7 @@ sgi_save (GimpProcedure *procedure,
}
}
- gimp_procedure_config_end_run (config, orig_image, run_mode, status);
+ gimp_procedure_config_end_run (config, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]