[gimp] Revert "plug-ins: various fixes and nitpicking to file-webp."



commit d9da211f9d8e86f66248bc6f7b76de8bc074cb54
Author: Michael Natterer <mitch gimp org>
Date:   Tue Nov 15 00:22:30 2016 +0100

    Revert "plug-ins: various fixes and nitpicking to file-webp."
    
    This reverts commit 58e6f6ca35720d96fdc4e5127bcea8453ceaa802.
    
    Sorry, I have a patch that gets rid of most code from the original patch.
    Will re-apply some of your cleanups later.

 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, 49 insertions(+), 83 deletions(-)
---
diff --git a/plug-ins/file-webp/file-webp-dialog.c b/plug-ins/file-webp/file-webp-dialog.c
index 2d24b77..a99e067 100644
--- a/plug-ins/file-webp/file-webp-dialog.c
+++ b/plug-ins/file-webp/file-webp-dialog.c
@@ -29,30 +29,50 @@
 
 #include "libgimp/stdplugins-intl.h"
 
-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 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 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"    },
+};
 
-static void
-preset_update (GimpIntComboBox *combo_box,
-               gpointer         data)
+
+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) {
   if (! gimp_int_combo_box_get_active (combo_box, (gint*) data))
-    * (WebPPreset*) data = WEBP_PRESET_DEFAULT;
+    * (enum WebPPreset*) data = WEBP_PRESET_DEFAULT;
 }
 
-static GtkWidget *
-new_combo_from_presets (WebPPreset *preset)
+static GtkWidget*
+new_combo_from_presets (enum WebPPreset *preset)
 {
   gint i;
   GtkWidget* combo = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
-  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,
+  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);
diff --git a/plug-ins/file-webp/file-webp-save.c b/plug-ins/file-webp/file-webp-save.c
index a292f31..fb667a6 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 e8a3aff..bf3b2bc 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
 {
-  WebPPreset      preset;
+  enum WebPPreset preset;
   gboolean        lossless;
   gboolean        animation;
   gboolean        loop;
@@ -39,23 +39,7 @@ typedef struct
   gboolean        force_delay;
 } WebPSaveParams;
 
-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"    },
-};
+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 06f7b45..453e3a3 100644
--- a/plug-ins/file-webp/file-webp.c
+++ b/plug-ins/file-webp/file-webp.c
@@ -36,14 +36,13 @@
 #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 =
 {
@@ -75,9 +74,6 @@ 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" },
@@ -90,14 +86,14 @@ query (void)
     { GIMP_PDB_IMAGE, "image", "Output image" }
   };
 
-  static GimpParamDef save_arguments[] =
+  static const 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",        NULL },
+    { 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)" 
},
@@ -131,31 +127,6 @@ 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",
@@ -172,7 +143,6 @@ 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
@@ -328,11 +298,3 @@ 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]