[gimp/gimp-2-10] plug-ins: Issue #6753 Add toggle for metadata



commit 8ac561458fe9df5339539d6fb3c4e2da7dfdffaf
Author: Nikc <nikcdc gmail com>
Date:   Sat Feb 19 04:02:44 2022 +0000

    plug-ins: Issue #6753 Add toggle for metadata
    
    Backports option from master to toggle whether IPTC and thumbnails
    are saved on export. Note that in webp format, IPTC data is saved
    via XMP, so if XMP is not saved, IPTC option is deactivated.

 plug-ins/file-webp/file-webp-dialog.c | 27 ++++++++++
 plug-ins/file-webp/file-webp-save.c   | 10 +++-
 plug-ins/file-webp/file-webp-save.h   |  1 +
 plug-ins/file-webp/file-webp.c        | 98 +++++++++++++++++++++++++++++------
 plug-ins/file-webp/file-webp.h        |  1 +
 5 files changed, 119 insertions(+), 18 deletions(-)
---
diff --git a/plug-ins/file-webp/file-webp-dialog.c b/plug-ins/file-webp/file-webp-dialog.c
index fb4f97f0b3..782c072088 100644
--- a/plug-ins/file-webp/file-webp-dialog.c
+++ b/plug-ins/file-webp/file-webp-dialog.c
@@ -92,6 +92,7 @@ save_dialog (WebPSaveParams *params,
   GtkWidget *label;
   GtkWidget *toggle;
   GtkWidget *toggle_minsize;
+  GtkWidget *toggle_iptc;
   GtkWidget *combo;
   GtkObject *quality_scale;
   GtkObject *alpha_quality_scale;
@@ -373,6 +374,18 @@ save_dialog (WebPSaveParams *params,
                     G_CALLBACK (gimp_toggle_button_update),
                     &params->exif);
 
+  /* IPTC metadata */
+  toggle_iptc = gtk_check_button_new_with_mnemonic (_("Save _IPTC"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle_iptc), params->iptc);
+  gtk_box_pack_start (GTK_BOX (vbox), toggle_iptc, FALSE, FALSE, 0);
+  gtk_widget_show (toggle_iptc);
+
+  g_signal_connect (toggle_iptc, "toggled",
+                    G_CALLBACK (gimp_toggle_button_update),
+                    &params->iptc);
+
+  gtk_widget_set_sensitive (toggle_iptc, params->xmp);
+
   /* XMP metadata */
   toggle = gtk_check_button_new_with_mnemonic (_("Save _XMP data"));
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), params->xmp);
@@ -383,6 +396,10 @@ save_dialog (WebPSaveParams *params,
                     G_CALLBACK (gimp_toggle_button_update),
                     &params->xmp);
 
+  g_object_bind_property (toggle, "active",
+                          toggle_iptc, "sensitive",
+                          G_BINDING_SYNC_CREATE);
+
   /* Color profile */
   toggle = gtk_check_button_new_with_mnemonic (_("Save color _profile"));
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), params->profile);
@@ -393,6 +410,16 @@ save_dialog (WebPSaveParams *params,
                     G_CALLBACK (gimp_toggle_button_update),
                     &params->profile);
 
+  /* Save Thumbnail */
+  toggle = gtk_check_button_new_with_mnemonic (_("Save _thumbnail"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), params->thumbnail);
+  gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
+  gtk_widget_show (toggle);
+
+  g_signal_connect (toggle, "toggled",
+                    G_CALLBACK (gimp_toggle_button_update),
+                    &params->thumbnail);
+
   gtk_widget_show (dialog);
 
   run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
diff --git a/plug-ins/file-webp/file-webp-save.c b/plug-ins/file-webp/file-webp-save.c
index d3bc64793e..5aaa383735 100644
--- a/plug-ins/file-webp/file-webp-save.c
+++ b/plug-ins/file-webp/file-webp-save.c
@@ -812,7 +812,10 @@ save_image (const gchar            *filename,
       if (params->xmp)
         {
           metadata_flags |= GIMP_METADATA_SAVE_XMP;
-          metadata_flags |= GIMP_METADATA_SAVE_IPTC;
+          if (params->iptc)
+            metadata_flags |= GIMP_METADATA_SAVE_IPTC;
+          else
+            metadata_flags &= ~GIMP_METADATA_SAVE_IPTC;
         }
       else
         {
@@ -825,6 +828,11 @@ save_image (const gchar            *filename,
       else
         metadata_flags &= ~GIMP_METADATA_SAVE_COLOR_PROFILE;
 
+      if (params->thumbnail)
+        metadata_flags |= GIMP_METADATA_SAVE_THUMBNAIL;
+      else
+        metadata_flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
+
       file = g_file_new_for_path (filename);
       gimp_image_metadata_save_finish (image_ID,
                                        "image/webp",
diff --git a/plug-ins/file-webp/file-webp-save.h b/plug-ins/file-webp/file-webp-save.h
index 3d4b425197..ddb2afb3d3 100644
--- a/plug-ins/file-webp/file-webp-save.h
+++ b/plug-ins/file-webp/file-webp-save.h
@@ -37,6 +37,7 @@ typedef struct
   gboolean   iptc;
   gboolean   xmp;
   gboolean   profile;
+  gboolean   thumbnail;
   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 a734c92c37..219e6a6344 100644
--- a/plug-ins/file-webp/file-webp.c
+++ b/plug-ins/file-webp/file-webp.c
@@ -92,6 +92,29 @@ query (void)
     { GIMP_PDB_INT32,    "force-delay",   "Force delay on all frames" }
   };
 
+  static const GimpParamDef save_arguments2[] =
+  {
+    { 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",        "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)" 
},
+    { GIMP_PDB_INT32,    "animation",     "Use layers for animation (0/1)" },
+    { GIMP_PDB_INT32,    "anim-loop",     "Loop animation infinitely (0/1)" },
+    { GIMP_PDB_INT32,    "minimize-size", "Minimize animation size (0/1)" },
+    { GIMP_PDB_INT32,    "kf-distance",   "Maximum distance between key-frames (>=0)" },
+    { GIMP_PDB_INT32,    "exif",          "Toggle saving exif data (0/1)" },
+    { GIMP_PDB_INT32,    "iptc",          "Toggle saving iptc data (0/1)" },
+    { GIMP_PDB_INT32,    "xmp",           "Toggle saving xmp data (0/1)" },
+    { GIMP_PDB_INT32,    "thumbnail",     "Toggle saving thumbnail (0/1)" },
+    { GIMP_PDB_INT32,    "delay",         "Delay to use when timestamps are not available or forced" },
+    { GIMP_PDB_INT32,    "force-delay",   "Force delay on all frames" }
+  };
+
   gimp_install_procedure (LOAD_PROC,
                           "Loads images in the WebP file format",
                           "Loads images in the WebP file format",
@@ -129,6 +152,24 @@ query (void)
 
   gimp_register_file_handler_mime (SAVE_PROC, "image/webp");
   gimp_register_save_handler (SAVE_PROC, "webp", "");
+
+  gimp_install_procedure (SAVE_PROC2,
+                          "Saves files in the WebP image format",
+                          "Saves files in the WebP image format "
+                          "with additional metadata control",
+                          "Nathan Osman, Ben Touchette",
+                          "(C) 2015-2016 Nathan Osman, (C) 2016 Ben Touchette",
+                          "2015,2016",
+                          N_("WebP image"),
+                          "RGB*, GRAY*, INDEXED*",
+                          GIMP_PLUGIN,
+                          G_N_ELEMENTS (save_arguments2),
+                          0,
+                          save_arguments2,
+                          NULL);
+
+  gimp_register_file_handler_mime (SAVE_PROC2, "image/webp");
+  gimp_register_save_handler (SAVE_PROC2, "webp", "");
 }
 
 static void
@@ -172,7 +213,8 @@ run (const gchar      *name,
           status = GIMP_PDB_EXECUTION_ERROR;
         }
     }
-  else if (! strcmp (name, SAVE_PROC))
+  else if (! strcmp (name, SAVE_PROC) ||
+           ! strcmp (name, SAVE_PROC2))
     {
       GimpMetadata          *metadata = NULL;
       GimpMetadataSaveFlags  metadata_flags;
@@ -200,6 +242,7 @@ run (const gchar      *name,
       params.xmp           = FALSE;
       params.delay         = 200;
       params.force_delay   = FALSE;
+      params.thumbnail     = FALSE;
 
       /* Override the defaults with preferences. */
       metadata = gimp_image_metadata_save_prepare (image_ID,
@@ -209,17 +252,25 @@ run (const gchar      *name,
       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;
+      if (! strcmp (name, SAVE_PROC2))
+        params.thumbnail = (metadata_flags & GIMP_METADATA_SAVE_THUMBNAIL) != 0;
 
       switch (run_mode)
         {
         case GIMP_RUN_WITH_LAST_VALS:
           /*  Possibly override with session data  */
-          gimp_get_data (SAVE_PROC, &params);
+          if (! strcmp (name, SAVE_PROC))
+            gimp_get_data (SAVE_PROC, &params);
+          else if (! strcmp (name, SAVE_PROC2))
+            gimp_get_data (SAVE_PROC2, &params);
           break;
 
         case GIMP_RUN_INTERACTIVE:
           /*  Possibly override with session data  */
-          gimp_get_data (SAVE_PROC, &params);
+          if (! strcmp (name, SAVE_PROC))
+            gimp_get_data (SAVE_PROC, &params);
+          else if (! strcmp (name, SAVE_PROC2))
+            gimp_get_data (SAVE_PROC2, &params);
 
           if (! save_dialog (&params, image_ID))
             {
@@ -228,7 +279,8 @@ run (const gchar      *name,
           break;
 
         case GIMP_RUN_NONINTERACTIVE:
-          if (nparams != 18)
+          if ((! strcmp (name, SAVE_PROC) && nparams != 18) ||
+              (! strcmp (name, SAVE_PROC2) && nparams != 19))
             {
               status = GIMP_PDB_CALLING_ERROR;
             }
@@ -240,18 +292,27 @@ run (const gchar      *name,
               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;
-              params.animation     = param[9].data.d_int32;
-              params.loop          = param[10].data.d_int32;
-              params.minimize_size = param[11].data.d_int32;
-              params.kf_distance   = param[12].data.d_int32;
-              params.exif          = param[13].data.d_int32;
-              params.iptc          = param[14].data.d_int32;
-              params.xmp           = param[15].data.d_int32;
-              params.delay         = param[16].data.d_int32;
-              params.force_delay   = param[17].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;
+              params.animation         = param[9].data.d_int32;
+              params.loop              = param[10].data.d_int32;
+              params.minimize_size     = param[11].data.d_int32;
+              params.kf_distance       = param[12].data.d_int32;
+              params.exif              = param[13].data.d_int32;
+              params.iptc              = param[14].data.d_int32;
+              params.xmp               = param[15].data.d_int32;
+              if (! strcmp (name, SAVE_PROC))
+                {
+                  params.delay         = param[16].data.d_int32;
+                  params.force_delay   = param[17].data.d_int32;
+                }
+              else
+                {
+                  params.thumbnail     = param[16].data.d_int32;
+                  params.delay         = param[17].data.d_int32;
+                  params.force_delay   = param[18].data.d_int32;
+                }
             }
           break;
 
@@ -304,7 +365,10 @@ run (const gchar      *name,
       if (status == GIMP_PDB_SUCCESS)
         {
           /* save parameters for later */
-          gimp_set_data (SAVE_PROC, &params, sizeof (params));
+          if (! strcmp (name, SAVE_PROC))
+            gimp_set_data (SAVE_PROC, &params, sizeof (params));
+          else if (! strcmp (name, SAVE_PROC2))
+            gimp_set_data (SAVE_PROC2, &params, sizeof (params));
         }
     }
 
diff --git a/plug-ins/file-webp/file-webp.h b/plug-ins/file-webp/file-webp.h
index a64ff96fa1..6d77e3b828 100644
--- a/plug-ins/file-webp/file-webp.h
+++ b/plug-ins/file-webp/file-webp.h
@@ -25,6 +25,7 @@
 
 #define LOAD_PROC      "file-webp-load"
 #define SAVE_PROC      "file-webp-save"
+#define SAVE_PROC2     "file-webp-save2"
 #define PLUG_IN_BINARY "file-webp"
 #define PLUG_IN_ROLE   "gimp-file-webp"
 


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