[gimp/gimp-2-10] plug-ins: WebP: save_dialog() before gimp_export()



commit 94b1e98767fe0a436d23e44cf59f69e1be43f916
Author: y-guyon <yguyon google com>
Date:   Wed Jul 24 13:01:42 2019 +0000

    plug-ins: WebP: save_dialog() before gimp_export()
    
    As mentioned in issue #1777, exporting non-animated WebP images was
    only keeping the current layer.
    Mimick file-gif-save.c: display the encoding settings pop-up earlier
    so that gimp_export_image() can merge the layers unless "As Animation"
    is enabled. Call gimp_image_get_layers() directly in save_image() in
    case the layers were merged (for clarity because layers are used only
    for animations).
    
    (cherry picked from commit 8f828d1899b3082313c58db47cf2f3c55dc0861a)

 plug-ins/file-webp/file-webp-dialog.c |  7 +--
 plug-ins/file-webp/file-webp-dialog.h |  3 +-
 plug-ins/file-webp/file-webp-save.c   | 36 +++++++-------
 plug-ins/file-webp/file-webp-save.h   |  2 -
 plug-ins/file-webp/file-webp.c        | 92 +++++++++++++++++------------------
 5 files changed, 67 insertions(+), 73 deletions(-)
---
diff --git a/plug-ins/file-webp/file-webp-dialog.c b/plug-ins/file-webp/file-webp-dialog.c
index 74b2d24fbe..fb4f97f0b3 100644
--- a/plug-ins/file-webp/file-webp-dialog.c
+++ b/plug-ins/file-webp/file-webp-dialog.c
@@ -81,8 +81,7 @@ show_maxkeyframe_hints (GtkAdjustment *adj,
 
 gboolean
 save_dialog (WebPSaveParams *params,
-             gint32          image_ID,
-             gint32          n_layers)
+             gint32          image_ID)
 {
   GtkWidget *dialog;
   GtkWidget *vbox;
@@ -96,12 +95,14 @@ save_dialog (WebPSaveParams *params,
   GtkWidget *combo;
   GtkObject *quality_scale;
   GtkObject *alpha_quality_scale;
+  gint32     nlayers;
   gboolean   animation_supported = FALSE;
   gboolean   run;
   gchar     *text;
   gint       row = 0;
 
-  animation_supported = n_layers > 1;
+  g_free (gimp_image_get_layers (image_ID, &nlayers));
+  animation_supported = nlayers > 1;
 
   /* Create the dialog */
   dialog = gimp_export_dialog_new (_("WebP"), PLUG_IN_BINARY, SAVE_PROC);
diff --git a/plug-ins/file-webp/file-webp-dialog.h b/plug-ins/file-webp/file-webp-dialog.h
index 834b4297f1..b5c85ad5b0 100644
--- a/plug-ins/file-webp/file-webp-dialog.h
+++ b/plug-ins/file-webp/file-webp-dialog.h
@@ -27,8 +27,7 @@
 
 
 gboolean   save_dialog (WebPSaveParams *params,
-                        gint32          image_ID,
-                        gint32          n_layers);
+                        gint32          image_ID);
 
 
 #endif /* __WEBP_DIALOG_H__ */
diff --git a/plug-ins/file-webp/file-webp-save.c b/plug-ins/file-webp/file-webp-save.c
index 2603a351b7..d3bc64793e 100644
--- a/plug-ins/file-webp/file-webp-save.c
+++ b/plug-ins/file-webp/file-webp-save.c
@@ -762,8 +762,6 @@ save_animation (const gchar    *filename,
 
 gboolean
 save_image (const gchar            *filename,
-            gint32                  nLayers,
-            gint32                 *allLayers,
             gint32                  image_ID,
             gint32                  drawable_ID,
             GimpMetadata           *metadata,
@@ -773,33 +771,33 @@ save_image (const gchar            *filename,
 {
   GFile    *file;
   gboolean  status = FALSE;
+  gint32   *layers;
+  gint      nlayers;
 
-  if (nLayers == 0)
-    return FALSE;
+  layers = gimp_image_get_layers (image_ID, &nlayers);
+
+  if (nlayers == 0)
+    {
+      g_free (layers);
+      return FALSE;
+    }
 
   g_printerr ("Saving WebP file %s\n", filename);
 
-  if (nLayers == 1)
+  if (params->animation)
     {
-      status = save_layer (filename, nLayers, image_ID, drawable_ID, params,
-                           error);
+      status = save_animation (filename,
+                               nlayers, layers, image_ID, drawable_ID, params,
+                               error);
     }
   else
     {
-      if (! params->animation)
-        {
-          status = save_layer (filename,
-                               nLayers, image_ID, drawable_ID, params,
-                               error);
-        }
-      else
-        {
-          status = save_animation (filename,
-                                   nLayers, allLayers, image_ID, drawable_ID,
-                                   params, error);
-        }
+      status = save_layer (filename,
+                           nlayers, image_ID, drawable_ID, params, error);
     }
 
+  g_free (layers);
+
   if (metadata)
     {
       gimp_metadata_set_bits_per_sample (metadata, 8);
diff --git a/plug-ins/file-webp/file-webp-save.h b/plug-ins/file-webp/file-webp-save.h
index b0b5a552be..3d4b425197 100644
--- a/plug-ins/file-webp/file-webp-save.h
+++ b/plug-ins/file-webp/file-webp-save.h
@@ -43,8 +43,6 @@ typedef struct
 
 
 gboolean   save_image (const gchar            *filename,
-                       gint32                  nLayers,
-                       gint32                 *allLayers,
                        gint32                  image_ID,
                        gint32                  drawable_ID,
                        GimpMetadata           *metadata,
diff --git a/plug-ins/file-webp/file-webp.c b/plug-ins/file-webp/file-webp.c
index 7c9d627731..a734c92c37 100644
--- a/plug-ins/file-webp/file-webp.c
+++ b/plug-ins/file-webp/file-webp.c
@@ -178,8 +178,6 @@ run (const gchar      *name,
       GimpMetadataSaveFlags  metadata_flags;
       WebPSaveParams         params;
       GimpExportReturn       export = GIMP_EXPORT_CANCEL;
-      gint32                *layers = NULL;
-      gint32                 n_layers;
 
       if (run_mode == GIMP_RUN_INTERACTIVE ||
           run_mode == GIMP_RUN_WITH_LAST_VALS)
@@ -188,50 +186,45 @@ run (const gchar      *name,
       image_ID    = param[1].data.d_int32;
       drawable_ID = param[2].data.d_int32;
 
+      /* Default settings */
+      params.preset        = WEBP_PRESET_DEFAULT;
+      params.lossless      = FALSE;
+      params.animation     = FALSE;
+      params.loop          = TRUE;
+      params.minimize_size = TRUE;
+      params.kf_distance   = 50;
+      params.quality       = 90.0f;
+      params.alpha_quality = 100.0f;
+      params.exif          = FALSE;
+      params.iptc          = FALSE;
+      params.xmp           = FALSE;
+      params.delay         = 200;
+      params.force_delay   = FALSE;
+
+      /* Override the defaults with preferences. */
+      metadata = gimp_image_metadata_save_prepare (image_ID,
+                                                   "image/webp",
+                                                   &metadata_flags);
+      params.exif    = (metadata_flags & GIMP_METADATA_SAVE_EXIF) != 0;
+      params.xmp     = (metadata_flags & GIMP_METADATA_SAVE_XMP) != 0;
+      params.iptc    = (metadata_flags & GIMP_METADATA_SAVE_IPTC) != 0;
+      params.profile = (metadata_flags & GIMP_METADATA_SAVE_COLOR_PROFILE) != 0;
+
       switch (run_mode)
         {
         case GIMP_RUN_WITH_LAST_VALS:
-        case GIMP_RUN_INTERACTIVE:
-          /* Default settings */
-          params.preset        = WEBP_PRESET_DEFAULT;
-          params.lossless      = FALSE;
-          params.animation     = FALSE;
-          params.loop          = TRUE;
-          params.minimize_size = TRUE;
-          params.kf_distance   = 50;
-          params.quality       = 90.0f;
-          params.alpha_quality = 100.0f;
-          params.exif          = FALSE;
-          params.iptc          = FALSE;
-          params.xmp           = FALSE;
-          params.delay         = 200;
-          params.force_delay   = FALSE;
-
-          /* Override the defaults with preferences. */
-          metadata = gimp_image_metadata_save_prepare (image_ID,
-                                                       "image/webp",
-                                                       &metadata_flags);
-          params.exif    = (metadata_flags & GIMP_METADATA_SAVE_EXIF) != 0;
-          params.xmp     = (metadata_flags & GIMP_METADATA_SAVE_XMP) != 0;
-          params.iptc    = (metadata_flags & GIMP_METADATA_SAVE_IPTC) != 0;
-          params.profile = (metadata_flags & GIMP_METADATA_SAVE_COLOR_PROFILE) != 0;
-
           /*  Possibly override with session data  */
           gimp_get_data (SAVE_PROC, &params);
+          break;
 
-          export = gimp_export_image (&image_ID, &drawable_ID, "WebP",
-                                      GIMP_EXPORT_CAN_HANDLE_RGB     |
-                                      GIMP_EXPORT_CAN_HANDLE_GRAY    |
-                                      GIMP_EXPORT_CAN_HANDLE_INDEXED |
-                                      GIMP_EXPORT_CAN_HANDLE_ALPHA   |
-                                      GIMP_EXPORT_CAN_HANDLE_LAYERS_AS_ANIMATION);
+        case GIMP_RUN_INTERACTIVE:
+          /*  Possibly override with session data  */
+          gimp_get_data (SAVE_PROC, &params);
 
-          if (export == GIMP_EXPORT_CANCEL)
+          if (! save_dialog (&params, image_ID))
             {
-              values[0].data.d_status = GIMP_PDB_CANCEL;
               status = GIMP_PDB_CANCEL;
             }
-
           break;
 
         case GIMP_RUN_NONINTERACTIVE:
@@ -266,24 +259,31 @@ run (const gchar      *name,
           break;
         }
 
-
-      if (status == GIMP_PDB_SUCCESS)
+      if (status == GIMP_PDB_SUCCESS && (run_mode == GIMP_RUN_INTERACTIVE ||
+                                         run_mode == GIMP_RUN_WITH_LAST_VALS))
         {
-          layers = gimp_image_get_layers (image_ID, &n_layers);
+          GimpExportCapabilities capabilities =
+            GIMP_EXPORT_CAN_HANDLE_RGB     |
+            GIMP_EXPORT_CAN_HANDLE_GRAY    |
+            GIMP_EXPORT_CAN_HANDLE_INDEXED |
+            GIMP_EXPORT_CAN_HANDLE_ALPHA;
+
+          if (params.animation)
+            capabilities |= GIMP_EXPORT_CAN_HANDLE_LAYERS_AS_ANIMATION;
+
+          export = gimp_export_image (&image_ID, &drawable_ID, "WebP",
+                                      capabilities);
 
-          if (run_mode == GIMP_RUN_INTERACTIVE)
+          if (export == GIMP_EXPORT_CANCEL)
             {
-              if (! save_dialog (&params, image_ID, n_layers))
-                {
-                  status = GIMP_PDB_CANCEL;
-                }
+              values[0].data.d_status = GIMP_PDB_CANCEL;
+              status = GIMP_PDB_CANCEL;
             }
         }
 
       if (status == GIMP_PDB_SUCCESS)
         {
           if (! save_image (param[3].data.d_string,
-                            n_layers, layers,
                             image_ID,
                             drawable_ID,
                             metadata, metadata_flags,
@@ -295,8 +295,6 @@ run (const gchar      *name,
         }
 
 
-      g_free (layers);
-
       if (export == GIMP_EXPORT_EXPORT)
         gimp_image_delete (image_ID);
 


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