Yes, it's clear now, thanks for that detailed answer.
So my guess is that Photoshop writes data in a tag OIIO doesn't recognize, to know this extra channel is alpha. (and hopefully Gimp can read it, so he decides to use it as well.)

On 07/20/2015 09:33 PM, Larry Gritz wrote:
OK, so here's the deal:

TIFF (unlike OpenEXR) doesn't have any header field or other information that stores 
channel names. So it is meaningless to talk about the channel names "in a TIFF 
file." No such thing. All OIIO can do for TIFF is make up names that we think 
correspond to what's there, based on other header fields.

For a file with >= 3 channels and whose PHOTOMETRIC tag is PHOTOMETRIC_RGB, we make the reasonable guess that 
the channel names for the first three channels should be "R", "G", and "B".

But what if there's a fourth channel? What is it, and what is its name? TIFF 
files contain a tag called EXTRASAMPLES describing the meaning of extra 
samples. There are three choices:

1. ASSOCIATED -- it's an alpha channel, with the assumption that the color channels are 
"premultiplied". We pass this along and call it "A".

2. UNASSOCIATED -- it's a mask, and the color channels are not premultiplied. We pass this on as channel 
"A", and premultiply the color channels so we always present "associated alpha" (unless 
the user has set the configuration to include "oiio:UnassociatedAlpha" set to 1, in which case we 
do not premultiply and leave the alpha unassociated).

3. UNSPECIFIED -- this means that the extra channel is something else, not an alpha (associated or 
unassociated). In that case, it seems wrong to call the channel "A", since the TIFF file 
*** explicitly says that it's not alpha ***. So we call it "channelN", since the TIFF 
file, as we said, specifies no name. (Examples of an extra channel that is not alpha would include 
depth, unlit diffuse color, surface normal, etc.)

So, bottom line, the file you attached says in the TIFF header that the EXTRASAMPLES 
value is UNSPECIFIED, meaning that it's not alpha. So we don't call it "A". I 
don't really know what else to say.

You can rename channels with oiiotool:

        oiiotool testalpha_olds.tif -chnames R,G,B,A -o out.tif

Although TIFF won't store the channel names you give it, the OIIO tiff output module will 
recognize that since it's named "A", it's meant to be alpha, so the 
EXTRASAMPLES value it writes should be ASSOCIATED. So this effectively just copies the 
file and corrects the EXTRASAMPLES. I don't know how it got to have the UNSPECIFIED value 
to being with.

Does this clarify?

        -- lg


On Jul 6, 2015, at 8:39 AM, Michel Lerenard <[email protected]> wrote:

Hi,

I've stumbled on an issue I haven't been able to understand. I've attached a 
file sent to our support team, which cannot be loaded properly. The file comes 
from Photoshop.

While trying to understand what was happening, I noticed that in the ImageSpec channel names list, I get "R", 
"G", "B" and "channel3". If I open the file in GIMP and resave it using another name, everything is 
fine: the fourth channel is named "A".

I've looked at the TIFF plugin code, and I don't understand the part of the readspec 
function that is renaming the fourth channel I have. From what I understand, at first the 
function reads that there are four channels in the file, initializes the spec with 
default names (R,G,B,A), then renames the channel "channel3" when it decides 
that the extra channel is not alpha.

====>>>>>
// This extra channel is not alpha at all.  Undo any
                // assumptions we previously made about this channel.
                if (m_spec.alpha_channel == c) {
                    m_spec.channelnames[c] = Strutil::format("channel%d", c);
                    m_spec.alpha_channel = -1;
                }

====<<<<<

Could anyone explain to me how this works ? I'm completely lost with all the 
EXTRASAMPLE stuff that is used to decide what to do with the last channel.

Thanks.

Michel
<testalpha_olds.tif>_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
--
Larry Gritz
[email protected]


_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org


_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to