[gimp] Bug 773450 - Animated WEBP images should be able to set frame delay...



commit 1afa322c57b1988846dd6b0aa0477f2cb3aad490
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...
    
    ...in the export dialog
    
    - 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
    - quite modified by mitch to be much less code

 plug-ins/file-webp/file-webp-dialog.c |  104 ++++++++++-----------------------
 plug-ins/file-webp/file-webp-save.c   |   40 +------------
 plug-ins/file-webp/file-webp-save.h   |   22 ++++----
 plug-ins/file-webp/file-webp.c        |   19 ++++---
 4 files changed, 55 insertions(+), 130 deletions(-)
---
diff --git a/plug-ins/file-webp/file-webp-dialog.c b/plug-ins/file-webp/file-webp-dialog.c
index 213798b..edda3e0 100644
--- a/plug-ins/file-webp/file-webp-dialog.c
+++ b/plug-ins/file-webp/file-webp-dialog.c
@@ -24,61 +24,18 @@
 #include <libgimp/gimp.h>
 #include <libgimp/gimpui.h>
 
+#include <webp/encode.h>
+
 #include "file-webp.h"
 #include "file-webp-dialog.h"
 
 #include "libgimp/stdplugins-intl.h"
 
 
-static GtkListStore * save_dialog_presets        (void);
-static void           save_dialog_preset_changed (GtkWidget  *widget,
-                                                  gchar     **data);
 static void           save_dialog_toggle_scale   (GtkWidget  *widget,
                                                   gpointer   data);
 
 
-static struct
-{
-  const gchar *id;
-  const gchar *label;
-} presets[] =
-{
-  { "default", "Default" },
-  { "picture", "Picture" },
-  { "photo",   "Photo"   },
-  { "drawing", "Drawing" },
-  { "icon",    "Icon"    },
-  { "text",    "Text"    },
-  { 0 }
-};
-
-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;
-}
-
-static void
-save_dialog_preset_changed (GtkWidget  *widget,
-                            gchar     **data)
-{
-  g_free (*data);
-  *data = gimp_string_combo_box_get_active (GIMP_STRING_COMBO_BOX (widget));
-}
-
 static void
 save_dialog_toggle_scale (GtkWidget *widget,
                           gpointer   data)
@@ -92,25 +49,24 @@ save_dialog (WebPSaveParams *params,
              gint32          image_ID,
              gint32          n_layers)
 {
-  GtkWidget     *dialog;
-  GtkWidget     *vbox;
-  GtkWidget     *label;
-  GtkWidget     *table;
-  GtkWidget     *expander;
-  GtkWidget     *frame;
-  GtkWidget     *vbox2;
-  GtkWidget     *save_exif;
-  GtkWidget     *save_xmp;
-  GtkWidget     *preset_label;
-  GtkListStore  *preset_list;
-  GtkWidget     *preset_combo;
-  GtkWidget     *lossless_checkbox;
-  GtkWidget     *animation_checkbox;
-  GtkObject     *quality_scale;
-  GtkObject     *alpha_quality_scale;
-  gboolean       animation_supported = FALSE;
-  gboolean       run;
-  gchar         *text;
+  GtkWidget *dialog;
+  GtkWidget *vbox;
+  GtkWidget *label;
+  GtkWidget *table;
+  GtkWidget *expander;
+  GtkWidget *frame;
+  GtkWidget *vbox2;
+  GtkWidget *save_exif;
+  GtkWidget *save_xmp;
+  GtkWidget *preset_label;
+  GtkWidget *preset_combo;
+  GtkWidget *lossless_checkbox;
+  GtkWidget *animation_checkbox;
+  GtkObject *quality_scale;
+  GtkObject *alpha_quality_scale;
+  gboolean   animation_supported = FALSE;
+  gboolean   run;
+  gchar     *text;
 
   animation_supported = n_layers > 1;
 
@@ -187,20 +143,22 @@ 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 = gimp_int_combo_box_new ("Default", WEBP_PRESET_DEFAULT,
+                                         "Picture", WEBP_PRESET_PICTURE,
+                                         "Photo",   WEBP_PRESET_PHOTO,
+                                         "Drawing", WEBP_PRESET_DRAWING,
+                                         "Icon",    WEBP_PRESET_ICON,
+                                         "Text",    WEBP_PRESET_TEXT,
+                                         NULL);
   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),
-                    &params->preset);
+  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (preset_combo),
+                              params->preset,
+                              G_CALLBACK (gimp_int_combo_box_get_active),
+                              &params->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..0d1f0fa 100644
--- a/plug-ins/file-webp/file-webp-save.c
+++ b/plug-ins/file-webp/file-webp-save.c
@@ -42,7 +42,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 +68,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 +201,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 +500,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..a996c84 100644
--- a/plug-ins/file-webp/file-webp-save.h
+++ b/plug-ins/file-webp/file-webp-save.h
@@ -25,17 +25,17 @@
 
 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;
+  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;
 
 
diff --git a/plug-ins/file-webp/file-webp.c b/plug-ins/file-webp/file-webp.c
index 8171f7c..ef7a969 100644
--- a/plug-ins/file-webp/file-webp.c
+++ b/plug-ins/file-webp/file-webp.c
@@ -77,7 +77,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,7 +188,8 @@ run (const gchar      *name,
         {
         case GIMP_RUN_WITH_LAST_VALS:
         case GIMP_RUN_INTERACTIVE:
-          /* Default settings. */
+          /* Default settings */
+          params.preset        = WEBP_PRESET_DEFAULT;
           params.lossless      = FALSE;
           params.animation     = FALSE;
           params.loop          = TRUE;
@@ -199,10 +200,9 @@ run (const gchar      *name,
           params.xmp           = TRUE;
           params.delay         = 200;
           params.force_delay   = FALSE;
+
           /*  Possibly override with session data  */
           gimp_get_data (SAVE_PROC, &params);
-          /* 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 +226,12 @@ run (const gchar      *name,
             }
           else
             {
-              params.preset        = g_strdup (param[5].data.d_string);
+              if (param[5].data.d_int32 < WEBP_PRESET_DEFAULT ||
+                  param[5].data.d_int32 > WEBP_PRESET_TEXT)
+                params.preset = WEBP_PRESET_DEFAULT;
+              else
+                params.preset = 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;
@@ -248,6 +253,7 @@ run (const gchar      *name,
       if (status == GIMP_PDB_SUCCESS)
         {
           layers = gimp_image_get_layers (image_ID, &n_layers);
+
           if (run_mode == GIMP_RUN_INTERACTIVE)
             {
               if (! save_dialog (&params, image_ID, n_layers))
@@ -270,8 +276,6 @@ run (const gchar      *name,
             }
         }
 
-      g_free (params.preset);
-      params.preset = NULL;
 
       g_free (layers);
 
@@ -281,7 +285,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, &params, sizeof (params));
         }
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]