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



commit f57a61cdbff9cecfee311f52f6049ceb7bf8b2f3
Author: Michael Natterer <mitch gimp org>
Date:   Tue Nov 15 00:23:15 2016 +0100

    Revert "Bug 773450 - Animated WEBP images should be able to set frame delay.."
    
    This reverts commit 9ac455f4adf06300934d5e3bc76e4e8c37abce20.

 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, 114 insertions(+), 72 deletions(-)
---
diff --git a/plug-ins/file-webp/file-webp-dialog.c b/plug-ins/file-webp/file-webp-dialog.c
index a99e067..213798b 100644
--- a/plug-ins/file-webp/file-webp-dialog.c
+++ b/plug-ins/file-webp/file-webp-dialog.c
@@ -29,58 +29,56 @@
 
 #include "libgimp/stdplugins-intl.h"
 
-static GtkWidget*     new_combo_from_presets (enum WebPPreset *preset);
-static void           preset_update (GimpIntComboBox* combo_box,
-                                     gpointer data);
+
+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 const struct
+
+static struct
 {
-  const enum WebPPreset preset;
+  const gchar *id;
   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"    },
+  { "default", "Default" },
+  { "picture", "Picture" },
+  { "photo",   "Photo"   },
+  { "drawing", "Drawing" },
+  { "icon",    "Icon"    },
+  { "text",    "Text"    },
+  { 0 }
 };
 
-
-WebPPreset
-get_preset_from_id (gint id)
+static GtkListStore *
+save_dialog_presets (void)
 {
-  if (id >= 0 && id < sizeof (presets) / sizeof (presets[0]))
-    return presets[id].preset;
-  return presets[0].preset;
-}
+  GtkListStore *list_store;
+  gint          i;
 
-static void
-preset_update (GimpIntComboBox* combo_box, gpointer data) {
-  if (! gimp_int_combo_box_get_active (combo_box, (gint*) data))
-    * (enum WebPPreset*) data = WEBP_PRESET_DEFAULT;
+  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 GtkWidget*
-new_combo_from_presets (enum WebPPreset *preset)
+static void
+save_dialog_preset_changed (GtkWidget  *widget,
+                            gchar     **data)
 {
-  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;
+  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)
@@ -104,6 +102,7 @@ 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;
@@ -188,10 +187,20 @@ save_dialog (WebPSaveParams *params,
   gtk_widget_show (preset_label);
 
   /* Create the combobox containing the presets */
-  preset_combo = new_combo_from_presets (&params->preset);
+  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);
   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);
 
   /* 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 fb667a6..c38d8b6 100644
--- a/plug-ins/file-webp/file-webp-save.c
+++ b/plug-ins/file-webp/file-webp-save.c
@@ -34,6 +34,7 @@
 #include <libgimp/gimp.h>
 #include <libgimp/gimpui.h>
 
+#include <webp/encode.h>
 #include <webp/mux.h>
 
 #include "file-webp-save.h"
@@ -41,6 +42,7 @@
 #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);
@@ -67,6 +69,35 @@ 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,
@@ -200,7 +231,9 @@ save_layer (const gchar    *filename,
 
       /* Initialize the WebP configuration with a preset and fill in the
        * remaining values */
-      WebPConfigPreset (&config, params->preset, params->quality);
+      WebPConfigPreset (&config,
+                        webp_preset_by_name (params->preset),
+                        params->quality);
 
       config.lossless      = params->lossless;
       config.method        = 6;  /* better quality */
@@ -499,9 +532,13 @@ save_animation (const gchar    *filename,
               break;
             }
 
-          WebPConfigPreset (&config, params->preset, params->quality);
+          WebPConfigInit (&config);
+          WebPConfigPreset (&config,
+                            webp_preset_by_name (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 bf3b2bc..006996b 100644
--- a/plug-ins/file-webp/file-webp-save.h
+++ b/plug-ins/file-webp/file-webp-save.h
@@ -22,24 +22,22 @@
 #ifndef __WEBP_SAVE_H__
 #define __WEBP_SAVE_H__
 
-#include <webp/encode.h>
 
 typedef struct
 {
-  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;
+  gchar    *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 453e3a3..8171f7c 100644
--- a/plug-ins/file-webp/file-webp.c
+++ b/plug-ins/file-webp/file-webp.c
@@ -56,22 +56,6 @@ 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[] =
@@ -93,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_INT32,    "preset",        "preset (Default=0, Picture=1, Photo=2, Drawing=3, Icon=4, 
Text=5)" },
+    { GIMP_PDB_STRING,   "preset",        "Name of preset to use" },
     { 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)" 
},
@@ -204,10 +188,21 @@ run (const gchar      *name,
         {
         case GIMP_RUN_WITH_LAST_VALS:
         case GIMP_RUN_INTERACTIVE:
-          /* Default settings */
-          set_default_params (&params);
+          /* 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;
           /*  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     |
@@ -231,7 +226,7 @@ run (const gchar      *name,
             }
           else
             {
-              params.preset        = get_preset_from_id (param[5].data.d_int32);
+              params.preset        = g_strdup (param[5].data.d_string);
               params.lossless      = param[6].data.d_int32;
               params.quality       = param[7].data.d_float;
               params.alpha_quality = param[8].data.d_float;
@@ -275,6 +270,8 @@ run (const gchar      *name,
             }
         }
 
+      g_free (params.preset);
+      params.preset = NULL;
 
       g_free (layers);
 
@@ -284,6 +281,7 @@ 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]