[gimp] plug-ins: various fixes and nitpicking to file-webp.
- From: Jehan Pagès <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: various fixes and nitpicking to file-webp.
- Date: Mon, 14 Nov 2016 23:01:11 +0000 (UTC)
commit 58e6f6ca35720d96fdc4e5127bcea8453ceaa802
Author: Jehan <jehan girinstud io>
Date: Mon Nov 14 21:27:27 2016 +0100
plug-ins: various fixes and nitpicking to file-webp.
- get_preset_from_id() was defined in file-webp-dialog.c but used in
file-webp.c only. Move it there.
- Make the preset list available in file-webp-save.h header (since it
is specifically an encoder attribute) as static, because it is used
both in the dialog ("preset" choice list) and the main file (for match
of the "preset" parameter as internal ID to a WebPPreset when run as
non-interactive).
- Generate the "preset" parameter description from the preset list.
This way, even if this list were to change (in some hypothetical
future), the description (and in particular the list of possible
values and their int match) won't end up wrong.
- "enum WebPPreset" is typedef-ed to "WebPPreset".
- Use G_N_ELEMENTS to compute length of arrays on the stack (equivalent
to the current code but shorter and simpler to read).
- Many formatting fixes.
plug-ins/file-webp/file-webp-dialog.c | 50 +++++++++---------------------
plug-ins/file-webp/file-webp-save.c | 8 ++--
plug-ins/file-webp/file-webp-save.h | 20 +++++++++++-
plug-ins/file-webp/file-webp.c | 54 ++++++++++++++++++++++++++++-----
4 files changed, 83 insertions(+), 49 deletions(-)
---
diff --git a/plug-ins/file-webp/file-webp-dialog.c b/plug-ins/file-webp/file-webp-dialog.c
index a99e067..2d24b77 100644
--- a/plug-ins/file-webp/file-webp-dialog.c
+++ b/plug-ins/file-webp/file-webp-dialog.c
@@ -29,50 +29,30 @@
#include "libgimp/stdplugins-intl.h"
-static GtkWidget* new_combo_from_presets (enum WebPPreset *preset);
-static void preset_update (GimpIntComboBox* combo_box,
- gpointer data);
-static void save_dialog_toggle_scale (GtkWidget *widget,
- gpointer data);
+static void preset_update (GimpIntComboBox *combo_box,
+ gpointer data);
+static GtkWidget * new_combo_from_presets (WebPPreset *preset);
+static void save_dialog_toggle_scale (GtkWidget *widget,
+ gpointer data);
-static const struct
-{
- const enum WebPPreset preset;
- const gchar *label;
-} presets[] =
-{
- { WEBP_PRESET_DEFAULT, "Default" },
- { WEBP_PRESET_PICTURE, "Picture" },
- { WEBP_PRESET_PHOTO, "Photo" },
- { WEBP_PRESET_DRAWING, "Drawing" },
- { WEBP_PRESET_ICON, "Icon" },
- { WEBP_PRESET_TEXT, "Text" },
-};
-
-
-WebPPreset
-get_preset_from_id (gint id)
-{
- if (id >= 0 && id < sizeof (presets) / sizeof (presets[0]))
- return presets[id].preset;
- return presets[0].preset;
-}
static void
-preset_update (GimpIntComboBox* combo_box, gpointer data) {
+preset_update (GimpIntComboBox *combo_box,
+ gpointer data)
+{
if (! gimp_int_combo_box_get_active (combo_box, (gint*) data))
- * (enum WebPPreset*) data = WEBP_PRESET_DEFAULT;
+ * (WebPPreset*) data = WEBP_PRESET_DEFAULT;
}
-static GtkWidget*
-new_combo_from_presets (enum WebPPreset *preset)
+static GtkWidget *
+new_combo_from_presets (WebPPreset *preset)
{
gint i;
GtkWidget* combo = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
- for (i = 0; i < sizeof (presets) / sizeof( presets[0] ); ++i)
- gimp_int_combo_box_append (GIMP_INT_COMBO_BOX(combo),
- GIMP_INT_STORE_VALUE, (gint) presets[i].preset,
- GIMP_INT_STORE_LABEL, presets[i].label,
+ for (i = 0; i < G_N_ELEMENTS (webp_presets); ++i)
+ gimp_int_combo_box_append (GIMP_INT_COMBO_BOX (combo),
+ GIMP_INT_STORE_VALUE, (gint) webp_presets[i].preset,
+ GIMP_INT_STORE_LABEL, webp_presets[i].label,
-1);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo), *preset,
G_CALLBACK (preset_update), preset);
diff --git a/plug-ins/file-webp/file-webp-save.c b/plug-ins/file-webp/file-webp-save.c
index fb667a6..a292f31 100644
--- a/plug-ins/file-webp/file-webp-save.c
+++ b/plug-ins/file-webp/file-webp-save.c
@@ -298,7 +298,7 @@ save_layer (const gchar *filename,
&icc_data_size);
chunk.bytes = icc_data;
chunk.size = icc_data_size;
- WebPMuxSetChunk(mux, "ICCP", &chunk, 1);
+ WebPMuxSetChunk (mux, "ICCP", &chunk, 1);
g_object_unref (profile);
}
@@ -350,7 +350,7 @@ parse_ms_tag (const gchar *str)
offset++;
if (offset >= length)
- return(-1);
+ return -1;
if (! g_ascii_isdigit (str[++offset]))
goto find_another_bra;
@@ -364,7 +364,7 @@ parse_ms_tag (const gchar *str)
while ((offset < length) && (g_ascii_isdigit (str[offset])));
if (length - offset <= 2)
- return(-3);
+ return -3;
if ((g_ascii_toupper (str[offset]) != 'M') ||
(g_ascii_toupper (str[offset + 1]) != 'S'))
@@ -635,7 +635,7 @@ save_image (const gchar *filename,
if (nLayers == 0)
return FALSE;
- g_printerr("Saving WebP file %s\n", filename);
+ g_printerr ("Saving WebP file %s\n", filename);
if (nLayers == 1)
{
diff --git a/plug-ins/file-webp/file-webp-save.h b/plug-ins/file-webp/file-webp-save.h
index bf3b2bc..e8a3aff 100644
--- a/plug-ins/file-webp/file-webp-save.h
+++ b/plug-ins/file-webp/file-webp-save.h
@@ -26,7 +26,7 @@
typedef struct
{
- enum WebPPreset preset;
+ WebPPreset preset;
gboolean lossless;
gboolean animation;
gboolean loop;
@@ -39,7 +39,23 @@ typedef struct
gboolean force_delay;
} WebPSaveParams;
-WebPPreset get_preset_from_id (gint id);
+static const struct
+{
+ const WebPPreset preset;
+ const gchar *label;
+} webp_presets[] =
+{
+ /* The preset order is used as ID parameter in the PDB save procedure.
+ * So it is important to keep it stable in order not to break any
+ * script. Any new preset should be added to the end.
+ */
+ { WEBP_PRESET_DEFAULT, "Default" },
+ { WEBP_PRESET_PICTURE, "Picture" },
+ { WEBP_PRESET_PHOTO, "Photo" },
+ { WEBP_PRESET_DRAWING, "Drawing" },
+ { WEBP_PRESET_ICON, "Icon" },
+ { WEBP_PRESET_TEXT, "Text" },
+};
gboolean save_image (const gchar *filename,
gint32 nLayers,
diff --git a/plug-ins/file-webp/file-webp.c b/plug-ins/file-webp/file-webp.c
index 453e3a3..06f7b45 100644
--- a/plug-ins/file-webp/file-webp.c
+++ b/plug-ins/file-webp/file-webp.c
@@ -36,13 +36,14 @@
#include "libgimp/stdplugins-intl.h"
-static void query (void);
-static void run (const gchar *name,
- gint nparams,
- const GimpParam *param,
- gint *nreturn_vals,
- GimpParam **return_vals);
+static void query (void);
+static void run (const gchar *name,
+ gint nparams,
+ const GimpParam *param,
+ gint *nreturn_vals,
+ GimpParam **return_vals);
+static WebPPreset get_preset_from_id (gint id);
const GimpPlugInInfo PLUG_IN_INFO =
{
@@ -74,6 +75,9 @@ set_default_params (WebPSaveParams* params)
static void
query (void)
{
+ gchar *preset_param_desc;
+ gint i;
+
static const GimpParamDef load_arguments[] =
{
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
@@ -86,14 +90,14 @@ query (void)
{ GIMP_PDB_IMAGE, "image", "Output image" }
};
- static const GimpParamDef save_arguments[] =
+ static GimpParamDef save_arguments[] =
{
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
{ GIMP_PDB_IMAGE, "image", "Input image" },
{ GIMP_PDB_DRAWABLE, "drawable", "Drawable to save" },
{ GIMP_PDB_STRING, "filename", "The name of the file to save the image to" },
{ GIMP_PDB_STRING, "raw-filename", "The name entered" },
- { GIMP_PDB_INT32, "preset", "preset (Default=0, Picture=1, Photo=2, Drawing=3, Icon=4,
Text=5)" },
+ { GIMP_PDB_INT32, "preset", NULL },
{ GIMP_PDB_INT32, "lossless", "Use lossless encoding (0/1)" },
{ GIMP_PDB_FLOAT, "quality", "Quality of the image (0 <= quality <= 100)" },
{ GIMP_PDB_FLOAT, "alpha-quality", "Quality of the image's alpha channel (0 <= alpha-quality <= 100)"
},
@@ -127,6 +131,31 @@ query (void)
"",
"8,string,WEBP");
+ /*
+ * "preset" values in the PDB save proc are internal IDs, not
+ * necessarily corresponding to the constants from libwebp (though at
+ * time of writing, they are the same).
+ * Generate the "preset" parameter description from webp_presets, so
+ * that we don't have to edit multiple places if new presets are added
+ * in the future.
+ */
+ preset_param_desc = g_strdup_printf ("WebP encoder preset (%s=0",
+ webp_presets[0].label);
+ for (i = 1; i < G_N_ELEMENTS (webp_presets); ++i)
+ {
+ gchar *preset_param;
+ gchar *tmp;
+
+ preset_param = g_strdup_printf (", %s=%d%s", webp_presets[i].label, i,
+ i == G_N_ELEMENTS (webp_presets) - 1 ? ")" : "");
+
+ tmp = preset_param_desc;
+ preset_param_desc = g_strconcat (preset_param_desc, preset_param,
+ NULL);
+ g_free (preset_param);
+ g_free (tmp);
+ }
+ save_arguments[5].description = preset_param_desc;
gimp_install_procedure (SAVE_PROC,
"Saves files in the WebP image format",
"Saves files in the WebP image format",
@@ -143,6 +172,7 @@ query (void)
gimp_register_file_handler_mime (SAVE_PROC, "image/webp");
gimp_register_save_handler (SAVE_PROC, "webp", "");
+ g_free (preset_param_desc);
}
static void
@@ -298,3 +328,11 @@ run (const gchar *name,
values[0].data.d_status = status;
}
+
+static WebPPreset
+get_preset_from_id (gint id)
+{
+ if (id >= 0 && id < G_N_ELEMENTS (webp_presets))
+ return webp_presets[id].preset;
+ return webp_presets[0].preset;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]