[gimp] Bug 773450 - Animated WEBP images should be able to set frame delay..
- From: Jehan Pagès <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Bug 773450 - Animated WEBP images should be able to set frame delay..
- Date: Mon, 14 Nov 2016 23:01:06 +0000 (UTC)
commit 9ac455f4adf06300934d5e3bc76e4e8c37abce20
Author: Pascal Massimino <pascal massimino gmail com>
Date: Tue Nov 8 21:45:39 2016 +0100
Bug 773450 - Animated WEBP images should be able to set frame delay..
- change the *preset field to a proper enum
- clean-up some code related to preset
- change the UI dialogs to use a GimpIntComboBox.
- misc style fixes
plug-ins/file-webp/file-webp-dialog.c | 83 +++++++++++++++------------------
plug-ins/file-webp/file-webp-save.c | 41 +---------------
plug-ins/file-webp/file-webp-save.h | 24 +++++----
plug-ins/file-webp/file-webp.c | 38 ++++++++-------
4 files changed, 72 insertions(+), 114 deletions(-)
---
diff --git a/plug-ins/file-webp/file-webp-dialog.c b/plug-ins/file-webp/file-webp-dialog.c
index 213798b..a99e067 100644
--- a/plug-ins/file-webp/file-webp-dialog.c
+++ b/plug-ins/file-webp/file-webp-dialog.c
@@ -29,56 +29,58 @@
#include "libgimp/stdplugins-intl.h"
-
-static GtkListStore * save_dialog_presets (void);
-static void save_dialog_preset_changed (GtkWidget *widget,
- gchar **data);
+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 struct
+static const struct
{
- const gchar *id;
+ const enum WebPPreset preset;
const gchar *label;
} presets[] =
{
- { "default", "Default" },
- { "picture", "Picture" },
- { "photo", "Photo" },
- { "drawing", "Drawing" },
- { "icon", "Icon" },
- { "text", "Text" },
- { 0 }
+ { WEBP_PRESET_DEFAULT, "Default" },
+ { WEBP_PRESET_PICTURE, "Picture" },
+ { WEBP_PRESET_PHOTO, "Photo" },
+ { WEBP_PRESET_DRAWING, "Drawing" },
+ { WEBP_PRESET_ICON, "Icon" },
+ { WEBP_PRESET_TEXT, "Text" },
};
-static GtkListStore *
-save_dialog_presets (void)
-{
- GtkListStore *list_store;
- gint i;
-
- list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
-
- for (i = 0; presets[i].id; ++i)
- gtk_list_store_insert_with_values (list_store,
- NULL,
- -1,
- 0, presets[i].id,
- 1, presets[i].label,
- -1);
- return list_store;
+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
-save_dialog_preset_changed (GtkWidget *widget,
- gchar **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;
+}
+
+static GtkWidget*
+new_combo_from_presets (enum WebPPreset *preset)
{
- g_free (*data);
- *data = gimp_string_combo_box_get_active (GIMP_STRING_COMBO_BOX (widget));
+ 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,
+ -1);
+ gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo), *preset,
+ G_CALLBACK (preset_update), preset);
+ gtk_widget_show (combo);
+ return combo;
}
+
static void
save_dialog_toggle_scale (GtkWidget *widget,
gpointer data)
@@ -102,7 +104,6 @@ save_dialog (WebPSaveParams *params,
GtkWidget *save_exif;
GtkWidget *save_xmp;
GtkWidget *preset_label;
- GtkListStore *preset_list;
GtkWidget *preset_combo;
GtkWidget *lossless_checkbox;
GtkWidget *animation_checkbox;
@@ -187,20 +188,10 @@ save_dialog (WebPSaveParams *params,
gtk_widget_show (preset_label);
/* Create the combobox containing the presets */
- preset_list = save_dialog_presets ();
- preset_combo = gimp_string_combo_box_new (GTK_TREE_MODEL (preset_list), 0, 1);
- g_object_unref (preset_list);
-
- gimp_string_combo_box_set_active (GIMP_STRING_COMBO_BOX (preset_combo),
- params->preset);
+ preset_combo = new_combo_from_presets (¶ms->preset);
gtk_table_attach (GTK_TABLE (table), preset_combo,
1, 3, 2, 3,
GTK_FILL, GTK_FILL, 0, 0);
- gtk_widget_show (preset_combo);
-
- g_signal_connect (preset_combo, "changed",
- G_CALLBACK (save_dialog_preset_changed),
- ¶ms->preset);
/* Create the lossless checkbox */
lossless_checkbox = gtk_check_button_new_with_label (_("Lossless"));
diff --git a/plug-ins/file-webp/file-webp-save.c b/plug-ins/file-webp/file-webp-save.c
index c38d8b6..fb667a6 100644
--- a/plug-ins/file-webp/file-webp-save.c
+++ b/plug-ins/file-webp/file-webp-save.c
@@ -34,7 +34,6 @@
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
-#include <webp/encode.h>
#include <webp/mux.h>
#include "file-webp-save.h"
@@ -42,7 +41,6 @@
#include "libgimp/stdplugins-intl.h"
-WebPPreset webp_preset_by_name (gchar *name);
int webp_anim_file_writer (FILE *outfile,
const uint8_t *data,
size_t data_size);
@@ -69,35 +67,6 @@ gboolean save_animation (const gchar *filename,
GError **error);
-WebPPreset
-webp_preset_by_name (gchar *name)
-{
- if (! strcmp (name, "picture"))
- {
- return WEBP_PRESET_PICTURE;
- }
- else if (! strcmp (name, "photo"))
- {
- return WEBP_PRESET_PHOTO;
- }
- else if (! strcmp (name, "drawing"))
- {
- return WEBP_PRESET_DRAWING;
- }
- else if (! strcmp (name, "icon"))
- {
- return WEBP_PRESET_ICON;
- }
- else if (! strcmp (name, "text"))
- {
- return WEBP_PRESET_TEXT;
- }
- else
- {
- return WEBP_PRESET_DEFAULT;
- }
-}
-
int
webp_anim_file_writer (FILE *outfile,
const uint8_t *data,
@@ -231,9 +200,7 @@ save_layer (const gchar *filename,
/* Initialize the WebP configuration with a preset and fill in the
* remaining values */
- WebPConfigPreset (&config,
- webp_preset_by_name (params->preset),
- params->quality);
+ WebPConfigPreset (&config, params->preset, params->quality);
config.lossless = params->lossless;
config.method = 6; /* better quality */
@@ -532,13 +499,9 @@ save_animation (const gchar *filename,
break;
}
- WebPConfigInit (&config);
- WebPConfigPreset (&config,
- webp_preset_by_name (params->preset),
- params->quality);
+ WebPConfigPreset (&config, params->preset, params->quality);
config.lossless = params->lossless;
- config.quality = params->quality;
config.method = 6; /* better quality */
config.alpha_quality = params->alpha_quality;
config.exact = 1;
diff --git a/plug-ins/file-webp/file-webp-save.h b/plug-ins/file-webp/file-webp-save.h
index 006996b..bf3b2bc 100644
--- a/plug-ins/file-webp/file-webp-save.h
+++ b/plug-ins/file-webp/file-webp-save.h
@@ -22,22 +22,24 @@
#ifndef __WEBP_SAVE_H__
#define __WEBP_SAVE_H__
+#include <webp/encode.h>
typedef struct
{
- gchar *preset;
- gboolean lossless;
- gboolean animation;
- gboolean loop;
- gfloat quality;
- gfloat alpha_quality;
- gboolean exif;
- gboolean iptc;
- gboolean xmp;
- gint delay;
- gboolean force_delay;
+ enum WebPPreset preset;
+ gboolean lossless;
+ gboolean animation;
+ gboolean loop;
+ gfloat quality;
+ gfloat alpha_quality;
+ gboolean exif;
+ gboolean iptc;
+ gboolean xmp;
+ gint delay;
+ gboolean force_delay;
} WebPSaveParams;
+WebPPreset get_preset_from_id (gint id);
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 8171f7c..453e3a3 100644
--- a/plug-ins/file-webp/file-webp.c
+++ b/plug-ins/file-webp/file-webp.c
@@ -56,6 +56,22 @@ const GimpPlugInInfo PLUG_IN_INFO =
MAIN()
static void
+set_default_params (WebPSaveParams* params)
+{
+ params->preset = WEBP_PRESET_DEFAULT;
+ params->lossless = FALSE;
+ params->animation = FALSE;
+ params->loop = TRUE;
+ params->quality = 90.0f;
+ params->alpha_quality = 100.0f;
+ params->exif = TRUE;
+ params->iptc = TRUE;
+ params->xmp = TRUE;
+ params->delay = 200;
+ params->force_delay = FALSE;
+}
+
+static void
query (void)
{
static const GimpParamDef load_arguments[] =
@@ -77,7 +93,7 @@ query (void)
{ 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_STRING, "preset", "Name of preset to use" },
+ { GIMP_PDB_INT32, "preset", "preset (Default=0, Picture=1, Photo=2, Drawing=3, Icon=4,
Text=5)" },
{ 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)"
},
@@ -188,21 +204,10 @@ run (const gchar *name,
{
case GIMP_RUN_WITH_LAST_VALS:
case GIMP_RUN_INTERACTIVE:
- /* Default settings. */
- params.lossless = FALSE;
- params.animation = FALSE;
- params.loop = TRUE;
- params.quality = 90.0f;
- params.alpha_quality = 100.0f;
- params.exif = TRUE;
- params.iptc = TRUE;
- params.xmp = TRUE;
- params.delay = 200;
- params.force_delay = FALSE;
+ /* Default settings */
+ set_default_params (¶ms);
/* Possibly override with session data */
gimp_get_data (SAVE_PROC, ¶ms);
- /* can't serialize strings, so restore default */
- params.preset = g_strdup ("default");
export = gimp_export_image (&image_ID, &drawable_ID, "WebP",
GIMP_EXPORT_CAN_HANDLE_RGB |
@@ -226,7 +231,7 @@ run (const gchar *name,
}
else
{
- params.preset = g_strdup (param[5].data.d_string);
+ params.preset = get_preset_from_id (param[5].data.d_int32);
params.lossless = param[6].data.d_int32;
params.quality = param[7].data.d_float;
params.alpha_quality = param[8].data.d_float;
@@ -270,8 +275,6 @@ run (const gchar *name,
}
}
- g_free (params.preset);
- params.preset = NULL;
g_free (layers);
@@ -281,7 +284,6 @@ run (const gchar *name,
if (status == GIMP_PDB_SUCCESS)
{
/* save parameters for later */
- /* we can't serialize strings this way. params.preset isn't saved. */
gimp_set_data (SAVE_PROC, ¶ms, sizeof (params));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]