[gimp] Issue #3553: Cannot export TIF as G3/G4 fax compression.



commit f9fd818c3deb89b1d792edc7762c86617157dbcd
Author: Jehan <jehan girinstud io>
Date:   Fri Jun 28 22:33:12 2019 +0200

    Issue #3553: Cannot export TIF as G3/G4 fax compression.
    
    G3/G4 compression does not support transparency, yet in multi-layer
    export, gimp_export_image() capability GIMP_EXPORT_CAN_HANDLE_LAYERS
    implied GIMP_EXPORT_CAN_HANDLE_ALPHA. I guess multi-layer TIFF is more
    for multi-page (at least with G3/G4 which is apparently a fax format, so
    it makes sense) than actual multi-layer.
    
    So I use the new GIMP_EXPORT_NEEDS_OPAQUE_LAYERS capability from
    previous commit for this particular use case of export layers + G3/G4
    compression.
    
    Also it is better to run gimp_export_image() *after* the option dialog,
    as we do for other formats, with variable capabilities depending on
    which options was chosen, instead of running it before then after
    merging layers when user chose not to export layers. This is duplicating
    the purpose of gimp_export_image().

 plug-ins/file-tiff/file-tiff.c | 72 +++++++++++++++++++-----------------------
 1 file changed, 32 insertions(+), 40 deletions(-)
---
diff --git a/plug-ins/file-tiff/file-tiff.c b/plug-ins/file-tiff/file-tiff.c
index 6ca94e3c17..e1a80e8c5b 100644
--- a/plug-ins/file-tiff/file-tiff.c
+++ b/plug-ins/file-tiff/file-tiff.c
@@ -271,19 +271,6 @@ run (const gchar      *name,
         case GIMP_RUN_INTERACTIVE:
         case GIMP_RUN_WITH_LAST_VALS:
           gimp_ui_init (PLUG_IN_BINARY, FALSE);
-
-          export = gimp_export_image (&image, &drawable, "TIFF",
-                                      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);
-
-          if (export == GIMP_EXPORT_CANCEL)
-            {
-              values[0].data.d_status = GIMP_PDB_CANCEL;
-              return;
-            }
           break;
         default:
           break;
@@ -385,40 +372,45 @@ run (const gchar      *name,
           break;
         }
 
-      if (status == GIMP_PDB_SUCCESS)
+      switch (run_mode)
         {
-          GFile *file;
-          gint   saved_bpp;
+        case GIMP_RUN_INTERACTIVE:
+        case GIMP_RUN_WITH_LAST_VALS:
+            {
+              GimpExportCapabilities capabilities;
 
-          file = g_file_new_for_uri (param[3].data.d_string);
+              if (tsvals.compression == COMPRESSION_CCITTFAX3 ||
+                  tsvals.compression == COMPRESSION_CCITTFAX4)
+                capabilities = GIMP_EXPORT_CAN_HANDLE_INDEXED |
+                               GIMP_EXPORT_NEEDS_OPAQUE_LAYERS;
+              else
+                capabilities = GIMP_EXPORT_CAN_HANDLE_RGB     |
+                               GIMP_EXPORT_CAN_HANDLE_GRAY    |
+                               GIMP_EXPORT_CAN_HANDLE_INDEXED |
+                               GIMP_EXPORT_CAN_HANDLE_ALPHA;
 
-          /* saving with layers is not supporting blend modes, so people might
-           * prefer to save a flat copy. */
-          if (! tsvals.save_layers)
-            {
-              gint32 transp;
+              if (tsvals.save_layers)
+                capabilities |= GIMP_EXPORT_CAN_HANDLE_LAYERS;
 
-              if (export != GIMP_EXPORT_EXPORT)
-                {
-                  image    = gimp_image_duplicate (image);
-                  drawable = gimp_image_get_active_layer (image);
+              export = gimp_export_image (&image, &drawable, "TIFF", capabilities);
 
-                  export = GIMP_EXPORT_EXPORT;
+              if (export == GIMP_EXPORT_CANCEL)
+                {
+                  values[0].data.d_status = GIMP_PDB_CANCEL;
+                  return;
                 }
-
-              /* borrowed from ./libgimp/gimpexport.c:export_merge()
-               * this makes sure that the exported file size is correct. */
-              transp = gimp_layer_new (image, "-",
-                                       gimp_image_width (image),
-                                       gimp_image_height (image),
-                                       gimp_drawable_type (drawable) | 1,
-                                       100.0, GIMP_LAYER_MODE_NORMAL);
-              gimp_image_insert_layer (image, transp, -1, 1);
-              gimp_selection_none (image);
-              gimp_drawable_edit_clear (transp);
-
-              gimp_image_merge_visible_layers (image, GIMP_CLIP_TO_IMAGE);
             }
+          break;
+        default:
+          break;
+        }
+
+      if (status == GIMP_PDB_SUCCESS)
+        {
+          GFile *file;
+          gint   saved_bpp;
+
+          file = g_file_new_for_uri (param[3].data.d_string);
 
           if (save_image (file, &tsvals, image, orig_image, image_comment,
                           &saved_bpp, metadata, metadata_flags, &error))


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