[gimp/gimp-2-10] plug-ins: fix #3740 Impossible to delete multi page tiff with thumbnail



commit 843d99802892f230f318d46cac99a21fb36432da
Author: Jacob Boerema <jgboerema gmail com>
Date:   Fri Aug 27 15:34:26 2021 -0400

    plug-ins: fix #3740 Impossible to delete multi page tiff with thumbnail
    
    On Windows there is a long standing issue in its File Explorer. When
    GIMP exported as a multi page (multi-layer) TIFF with thumbnail saving
    enabled, then the Windows thumbnailer apparently gets stuck and does not
    close the TIFF file when browsing a folder. Because those files are not
    closed it is impossible to delete them. This issue has been reported
    many times over the years to Microsoft without any reaction.
    
    Investigation showed us that this lock up only happens when we save the
    thumbnail as a subifd. To resolve this issue we change this and now let
    exiv2 handle our thumbnail saving, just as for other image formats. For
    TIFF this means the thumbnail is saved as the second page of a TIFF.
    
    Previous commits have made sure that it is now easier to recognize a TIFF
    page as a thumbnail and to make sure we don't load thumbnail TIFF pages.
    
    Since saving as a subifd is what made TIFF thumbnail saving different
    from other formats, this commit consists of only removal of code.
    
    (cherry picked from commit 42e61104d71a37f15cbc64d09b54e367db570afd)
    
    # Conflicts:
    #       plug-ins/file-tiff/file-tiff-save.c

 plug-ins/file-tiff/file-tiff-save.c | 102 ++----------------------------------
 1 file changed, 4 insertions(+), 98 deletions(-)
---
diff --git a/plug-ins/file-tiff/file-tiff-save.c b/plug-ins/file-tiff/file-tiff-save.c
index 555ae013f3..e9bbe3b3f9 100644
--- a/plug-ins/file-tiff/file-tiff-save.c
+++ b/plug-ins/file-tiff/file-tiff-save.c
@@ -77,10 +77,6 @@ static void      byte2bit               (const guchar  *byteline,
                                          guchar        *bitline,
                                          gboolean       invert);
 
-static void      save_thumbnail         (TiffSaveVals  *tsvals,
-                                         gint32         image,
-                                         TIFF          *tif);
-
 
 static void
 double_to_psd_fixed (gdouble  value,
@@ -836,88 +832,6 @@ out:
   return status;
 }
 
-static void
-save_thumbnail (TiffSaveVals *tsvals,
-                gint32        image,
-                TIFF         *tif)
-{
-  /* now switch IFD and write thumbnail
-   *
-   * the thumbnail must be saved in a subimage of the image.
-   * otherwise the thumbnail will be saved in a second page of the
-   * same image.
-   *
-   * Exif saves the thumbnail as a second page. To avoid this, the
-   * thumbnail must be saved with the functions of libtiff.
-   */
-  if (tsvals->save_thumbnail)
-    {
-      GdkPixbuf *thumb_pixbuf;
-      guchar    *thumb_pixels;
-      guchar    *buf;
-      gint       image_width;
-      gint       image_height;
-      gint       thumbw;
-      gint       thumbh;
-      gint       x, y;
-
-#define EXIF_THUMBNAIL_SIZE 256
-
-      image_width  = gimp_image_width  (image);
-      image_height = gimp_image_height (image);
-
-      if (image_width > image_height)
-        {
-          thumbw = EXIF_THUMBNAIL_SIZE;
-          thumbh = EXIF_THUMBNAIL_SIZE * image_height / image_width;
-        }
-      else
-        {
-          thumbh = EXIF_THUMBNAIL_SIZE;
-          thumbw = EXIF_THUMBNAIL_SIZE * image_width / image_height;
-        }
-
-      thumb_pixbuf = gimp_image_get_thumbnail (image, thumbw, thumbh,
-                                               GIMP_PIXBUF_KEEP_ALPHA);
-
-      thumb_pixels = gdk_pixbuf_get_pixels (thumb_pixbuf);
-
-      TIFFSetField (tif, TIFFTAG_SUBFILETYPE, FILETYPE_REDUCEDIMAGE);
-      TIFFSetField (tif, TIFFTAG_IMAGEWIDTH, thumbw);
-      TIFFSetField (tif, TIFFTAG_IMAGELENGTH, thumbh);
-      TIFFSetField (tif, TIFFTAG_BITSPERSAMPLE, 8);
-      TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
-      TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, thumbh);
-      TIFFSetField (tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
-      TIFFSetField (tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
-      TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
-      TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, 3);
-
-      buf = _TIFFmalloc (thumbw * 3);
-
-      for (y = 0; y < thumbh; y++)
-        {
-          guchar *p = buf;
-
-          for (x = 0; x < thumbw; x++)
-            {
-              *p++ = *thumb_pixels++; /* r */
-              *p++ = *thumb_pixels++; /* g */
-              *p++ = *thumb_pixels++; /* b */
-              thumb_pixels++;
-            }
-
-          TIFFWriteScanline (tif, buf, y, 0);
-        }
-
-      _TIFFfree (buf);
-
-      TIFFWriteDirectory (tif);
-
-      g_object_unref (thumb_pixbuf);
-    }
-}
-
 /* FIXME Most of the stuff in save_metadata except the
  * thumbnail saving should probably be moved to
  * gimpmetadata.c and gimpmetadata-save.c.
@@ -994,8 +908,10 @@ save_metadata (GFile                 *file,
   else
     metadata_flags &= ~GIMP_METADATA_SAVE_IPTC;
 
-  /* never save metadata thumbnails for TIFF, see bug #729952 */
-  metadata_flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
+  if (tsvals->save_thumbnail)
+    metadata_flags |= GIMP_METADATA_SAVE_THUMBNAIL;
+  else
+    metadata_flags &= ~GIMP_METADATA_SAVE_THUMBNAIL;
 
   if (tsvals->save_profile)
     metadata_flags |= GIMP_METADATA_SAVE_COLOR_PROFILE;
@@ -1024,8 +940,6 @@ save_image (GFile                  *file,
   TIFF     *tif = NULL;
   gboolean  status              = FALSE;
   gboolean  out_linear          = FALSE;
-  gint      number_of_sub_IFDs  = 1;
-  toff_t    sub_IFDs_offsets[1] = { 0UL };
   gint32    num_layers, *layers, current_layer = 0;
   gint      origin_x = 0, origin_y = 0;
   gint32    i;
@@ -1103,10 +1017,6 @@ save_image (GFile                  *file,
     }
 #endif
 
-  /* we put the whole file's thumbnail into the first IFD (i.e., page) */
-  if (tsvals->save_thumbnail)
-    TIFFSetField (tif, TIFFTAG_SUBIFD, number_of_sub_IFDs, sub_IFDs_offsets);
-
   /* calculate the top-left coordinates */
   for (i = 0; i < num_layers; i++)
     {
@@ -1129,10 +1039,6 @@ save_image (GFile                  *file,
     }
   current_layer++;
 
-  /* write thumbnail */
-  if (tsvals->save_thumbnail)
-    save_thumbnail (tsvals, image, tif);
-
   /* close file so we can safely let exiv2 work on it to write metadata.
    * this can be simplified once multi page TIFF is supported by exiv2
    */


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