You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary Lucas (Jira)" <ji...@apache.org> on 2021/09/03 15:32:00 UTC

[jira] [Created] (IMAGING-312) Alpha-channel setting not interpreted from ExtraSamples tag

Gary Lucas created IMAGING-312:
----------------------------------

             Summary: Alpha-channel setting not interpreted from ExtraSamples tag
                 Key: IMAGING-312
                 URL: https://issues.apache.org/jira/browse/IMAGING-312
             Project: Commons Imaging
          Issue Type: Bug
          Components: Format: TIFF
    Affects Versions: 1.0-alpha2
         Environment:  
            Reporter: Gary Lucas


Commons Imaging sometimes misinterprets TIFF files that have 4-byte RGB samples but do not define alpha.   In some cases, these images are treated as semi-transparent when they should be opaque.   Commons Imaging is not unique in this regard...  Windows Photo Viewer does the same thing.

The TIFF specification allows RGB images to be encoded with 4-bytes per pixel.  It would be natural to assume (as Commons Imaging does) that the 4th byte is the alpha channel and that it would have values of 0xff in the case where pixels were opaque. However, the interpretation of the 4th byte depends on information in the TIFF "ExtraSamples" tag. 

It turns out that there are images in-the-wild that use 4 bytes, but populate the 4th byte with junk values. For example, there are a number of older aerial photographs from the US Geological Survey (USGS) that do this.  These images give an ExtraSamples tag with a value of zero.  But the TIFF specification calls for images to be treated as having alpha channels only if the ExtraSamples field carries a value of either 1 or 2.   When ExtraSamples has a value of 0, the 4th byte is to be ignored. 

There are many examples of this phenomenon on the USGS Earth Explorer website. One specific example: 

* High Resolution Orthoimagery
* Dataset: 201203_connecticut_state_lot1_ct_0x3000m_utm_cnir
* Entity: 2818289_18TYL425825
* File: 18tyl425825.tif 




*Proposed Fix*
I propose to do the following:
* Extend the TiffImageParser logic for detecting alpha to assume hasAlpha is true if and only if the ExtraSamples tag is supplied and contains values 1 or 2. 
* Provide a hasAlpha accessor for the ImageBuilder class (is should really have one anyway)
* Enhance the DataReaderStrips and DataReaderTiles classes to check hasAlpha when processing RGB images that have 4 samples per pixel samples. 


*Concerns*
At this time, I am not sure what to do if an RGB TIFF image uses 4-samples per pixel but the ExtraSamples tag is not provided.  At this time, I have not seen an example of this, but my collection of sample TIFF files is rather narrow and I would not rule it out.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)