libpano13 writes TIFF files with an alpha channel, but without the required 
ExtraSamples 
<https://www.awaresystems.be/imaging/tiff/tifftags/extrasamples.html> TIFF 
metadata tag indicating that the 4th channel is alpha.

With the incorrect metadata, applications based on libtiff (e.g. tiffinfo) 
print a warning when opening a file created by PTUncrop:
TIFFReadDirectory: Warning, Sum of Photometric type-related color channels 
and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels 
as ExtraSamples.. 

Pillow 9.1.0 (Python library) fails to load these images 
<https://github.com/python-pillow/Pillow/issues/6266>, though this has been 
fixed.

I couldn't figure out where libpano13's authoritative source repository is, 
or how to submit a pull request or equivalent, so I've attached the patch 
against libpano13 v2.9.21 here.

-- 
A list of frequently asked questions is available at: 
http://wiki.panotools.org/Hugin_FAQ
--- 
You received this message because you are subscribed to the Google Groups 
"hugin and other free panoramic software" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to hugin-ptx+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/hugin-ptx/bd8e7f18-4e89-4ddf-8a06-c52847ac2673n%40googlegroups.com.
diff --git a/tiff.c b/tiff.c
index 218069b..c4baa01 100644
--- a/tiff.c
+++ b/tiff.c
@@ -385,6 +385,7 @@ int writeCroppedTIFF(Image * im, fullPath * sfile, CropInfo * crop_info)
     case 32:
         TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
         TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
+        TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, 1, &(uint16_t){EXTRASAMPLE_UNASSALPHA});
         break;
     case 48:
         TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16);
@@ -393,6 +394,7 @@ int writeCroppedTIFF(Image * im, fullPath * sfile, CropInfo * crop_info)
     case 64:
         TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16);
         TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
+        TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, 1, &(uint16_t){EXTRASAMPLE_UNASSALPHA});
         break;
     case 96:
         TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 32);
@@ -402,6 +404,7 @@ int writeCroppedTIFF(Image * im, fullPath * sfile, CropInfo * crop_info)
     case 128:
         TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 32);
         TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
+        TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, 1, &(uint16_t){EXTRASAMPLE_UNASSALPHA});
         TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
         break;
     }
@@ -1077,6 +1080,9 @@ int panoTiffSetImageProperties(pano_Tiff * file)
 			metadata->imageTotalNumber);
 
 
+    if (returnValue && metadata->samplesPerPixel == 4) {
+        returnValue = TIFFSetField(tiffFile, TIFFTAG_EXTRASAMPLES, 1, &(uint16_t){EXTRASAMPLE_UNASSALPHA});
+    }
 
 
     if (returnValue && metadata->bitsPerSample == 32)

Reply via email to