[gimp] plug-ins: add option to crop layers to image bounds when exporting TIFF



commit 7f39be86dea167ac9c462cea45849cd2879fddf4
Author: Ell <ell_se yahoo com>
Date:   Thu Jun 25 17:56:41 2020 +0300

    plug-ins: add option to crop layers to image bounds when exporting TIFF
    
    In file-tiff, add an option to crop the layers to the image bounds
    when exporting individual layers (using GIMP_EXPORT_NEEDS_CROP
    added in the previous commit), since TIFF has no concept of global
    image bounds otherwise.  Cropping is enabled by default.

 plug-ins/file-tiff/file-tiff-save.c | 29 ++++++++++++++++++++++++++++-
 plug-ins/file-tiff/file-tiff.c      | 15 ++++++++++++++-
 2 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/plug-ins/file-tiff/file-tiff-save.c b/plug-ins/file-tiff/file-tiff-save.c
index fca3f8847e..e287256ef9 100644
--- a/plug-ins/file-tiff/file-tiff-save.c
+++ b/plug-ins/file-tiff/file-tiff-save.c
@@ -1286,7 +1286,7 @@ save_dialog (GimpImage     *image,
   else
     {
       /* If single-layer TIFF, set the toggle insensitive and show it as
-       * unchecked though I don't actually change the tsvals value to
+       * unchecked though I don't actually change the config value to
        * keep storing previously chosen value.
        */
       button = gtk_check_button_new_with_mnemonic (_("Save layers"));
@@ -1296,6 +1296,33 @@ save_dialog (GimpImage     *image,
 
   gtk_grid_attach (GTK_GRID (grid), button, 0, row++, 2, 1);
 
+  frame = gimp_frame_new (NULL);
+  gtk_grid_attach (GTK_GRID (grid), frame, 0, row++, 2, 1);
+  gtk_widget_show (frame);
+
+  if (is_multi_layer)
+    {
+      g_object_bind_property (config, "save-layers",
+                              frame,  "sensitive",
+                              G_BINDING_SYNC_CREATE);
+
+      button = gimp_prop_check_button_new (config, "crop-layers",
+                                           _("Crop layers to image bounds"));
+      gtk_container_add (GTK_CONTAINER (frame), button);
+    }
+  else
+    {
+      /* If single-layer TIFF, set the layers frame insensitive and
+       * show its toggles as unchecked though I don't actually change
+       * the config value to keep storing previously chosen values.
+       */
+      gtk_widget_set_sensitive (frame, FALSE);
+
+      button = gtk_check_button_new_with_mnemonic (_("Crop layers"));
+      gtk_container_add (GTK_CONTAINER (frame), button);
+      gtk_widget_show (button);
+    }
+
   if (has_alpha && ! is_indexed)
     {
       button = gimp_prop_check_button_new (config, "save-transparent-pixels",
diff --git a/plug-ins/file-tiff/file-tiff.c b/plug-ins/file-tiff/file-tiff.c
index 40ba7f2220..53d59d3aea 100644
--- a/plug-ins/file-tiff/file-tiff.c
+++ b/plug-ins/file-tiff/file-tiff.c
@@ -223,6 +223,12 @@ tiff_create_procedure (GimpPlugIn  *plug_in,
                                  TRUE,
                                  G_PARAM_READWRITE);
 
+      GIMP_PROC_AUX_ARG_BOOLEAN (procedure, "crop-layers",
+                                 "Crop Layers",
+                                 "Crop Layers",
+                                 TRUE,
+                                 G_PARAM_READWRITE);
+
       GIMP_PROC_AUX_ARG_BOOLEAN (procedure, "save-exif",
                                  "Save Exif",
                                  "Save Exif",
@@ -373,10 +379,12 @@ tiff_save (GimpProcedure        *procedure,
         GimpExportCapabilities capabilities;
         GimpCompression        compression;
         gboolean               save_layers;
+        gboolean               crop_layers;
 
         g_object_get (config,
                       "compression", &compression,
                       "save-layers", &save_layers,
+                      "crop-layers", &crop_layers,
                       NULL);
 
         if (compression == GIMP_COMPRESSION_CCITTFAX3 ||
@@ -396,7 +404,12 @@ tiff_save (GimpProcedure        *procedure,
           }
 
         if (save_layers && image_is_multi_layer (image))
-          capabilities |= GIMP_EXPORT_CAN_HANDLE_LAYERS;
+          {
+            capabilities |= GIMP_EXPORT_CAN_HANDLE_LAYERS;
+
+            if (crop_layers)
+              capabilities |= GIMP_EXPORT_NEEDS_CROP;
+          }
 
         export = gimp_export_image (&image, &n_drawables, &drawables, "TIFF",
                                     capabilities);


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