[gil new_io] tiff alpha channel support

Briefly: gil new_io does not support tiff alpha channel. Is support planned? If not, I'll attempt to add it and submit a patch if successful. Details: I am using the latest code from the gil-contributions googlecode SVN repository. The following causes a crash when "tifffile.tif" is interleaved 32-bit rgba (ie 8*4 bits, including the alpha channel): argb8_image_t image; read_and_convert_image("tifffile.tif", image, tiff_tag()); If "tifffile.tif" is planar instead of interleaved, no crash occurs. However, the image is not loaded correctly - all channels are filled with the same values, causing the image to apparently be grayscale. "tifffile.tif" stored without an alpha channel loads correctly, but the alpha channel is essential for my application. Around line 237 of io_new/formats/tiff/read.hpp, I see that we are reading into an rgb8_view_t for 8 bit per sample images, so we're obviously not going to retain alpha channel data even if it is read correctly. Additionally, TIFFTAG_SAMPLES_PER_PIXEL is read but not respected. To avoid crashes for tiff images with extra channels, row_buffer_helper must be aware of TIFFTAG_SAMPLES_PER_PIXEL. So that the alpha channel is retained for RGBA images, in the PHOTOMETRIC_RGB case near line 237, if TIFFTAG_SAMPLES_PER_PIXEL is 4, we should read into an rgba*_view_t.

Hi Erik, thanks for using the new gil::io. Sorry for not getting back to you sooner. On Sun, Apr 17, 2011 at 6:36 PM, Erik Hvatum <ice.rikh@gmail.com> wrote:
Briefly:
gil new_io does not support tiff alpha channel. Is support planned? If not, I'll attempt to add it and submit a patch if successful.
Before going into details can you tell what your PhotometricInterpretation value is? See here: http://www.awaresystems.be/imaging/tiff/tifftags/photometricinterpretation.h... Using this value will decide what color space an image is in.
Details:
I am using the latest code from the gil-contributions googlecode SVN repository. The following causes a crash when "tifffile.tif" is interleaved 32-bit rgba (ie 8*4 bits, including the alpha channel):
Could you send me the tifffile.tif or something of similar format? That would help me hugely. Regards, Christian

You're responsive by my standards. On Tue, Apr 19, 2011 at 10:27 AM, Christian Henning <chhenning@gmail.com>wrote:
Hi Erik, thanks for using the new gil::io. Sorry for not getting back to you sooner.
On Sun, Apr 17, 2011 at 6:36 PM, Erik Hvatum <ice.rikh@gmail.com> wrote:
Briefly:
gil new_io does not support tiff alpha channel. Is support planned? If not, I'll attempt to add it and submit a patch if successful.
Before going into details can you tell what your PhotometricInterpretation value is? See here:
http://www.awaresystems.be/imaging/tiff/tifftags/photometricinterpretation.h...
Using this value will decide what color space an image is in.
PHOTOMETRIC_RGB
Details:
I am using the latest code from the gil-contributions googlecode SVN
repository. The following causes a crash when "tifffile.tif" is interleaved 32-bit rgba (ie 8*4 bits, including the alpha channel):
Could you send me the tifffile.tif or something of similar format? That would help me hugely.
It's tiny; hopefully I'm not breaking anything by sending it to the list. Thanks, Erik

Hi Erik, thanks for the sample image. Do you mind when I add it to my test cases?
I am using the latest code from the gil-contributions googlecode SVN repository. The following causes a crash when "tifffile.tif" is interleaved 32-bit rgba (ie 8*4 bits, including the alpha channel):
Could you send me the tifffile.tif or something of similar format? That would help me hugely.
I did try to run and it work for me the first time. But then I realized I was using read_image() instead of read_image_and_convert(). Is there any reason you use read_image_and_convert()? I did add a fix to read.hpp. Please try if you have time. Thanks for the report, Christian

Hi Christian,
thanks for the sample image. Do you mind when I add it to my test cases?
You're welcome, and thanks for your help. I release tifffile.tif into the public domain; you may use it as you wish.
I did try to run and it work for me the first time. But then I realized I was using read_image() instead of read_image_and_convert(). Is there any reason you use read_image_and_convert()?
I use read_image_and_convert() in case the user supplies a tiff that is not exactly what I want (8 bits per sample, 4 sample per pixel RGBA). To load a grayscale file directly into an rgb8_image_t, read_image_and_convert() is required, correct? Is the same true for loading a 24-bit RGB image (8 bits per sample, 3 samples per pixel) into an argb8_image_t?
I did add a fix to read.hpp. Please try if you have time.
This fix seems to do the trick - the crash does not occur and I verified that the alpha channels for a number of tiffs are loaded correctly. Thanks again, Erik
participants (3)
-
Christian Henning
-
Erik
-
Erik Hvatum