Thanks for quickly reply. :-)
I load an png in imageview in IrfanView or Photoshop SE. And both show the
image is 24bpp. So I assume the image itself is premultiplied or there is
no alpha channel info.
However, when I use imagecache to open the png and then load it into
opencv. It gives me 4 channel, which alpha channel seems contain
transparency info.
But at the same time, I load it using Qt's QImage, it gives me 4 channel,
but the alpha channel is simply a binary mask.
So I am wondering what I can do to let OpenImageIO give me the same result
like QImage.
For my purpose, the QImage gives me correct result, while OpenImageIO seems
not correct. I use eariler version of 1.6. I am not sure it is known issue
or just I use it wrong.
Larry, If I use imagecache->attribute ("oiio::UnassociatedAlpha", 1), the
rgb chanel will not premultiplied, and 0 means it will premultiplied.
Is this correct?
I set it both before and after call get_imagespec (I don't know it should
happen before or after it), and then call get_pixels.
I tried both ways, seems no impact on end result.
Thanks.
Yang
2016-04-13 19:09 GMT-05:00 Larry Gritz <[email protected]>:
> Yes, though there are some subtleties.
>
> PNG spec is clear that PNG files store alpha as unassociated. (Bad.)
>
> OIIO is clear that the values delivered to the app should be associated
> alpha, and so file format readers that encounter unassociated alpha are
> expected to multiply the color channels by alpha in the process of copying
> the values to the app's buffer.
>
> Every once in a while, you want to bypass this conversion (usually to
> prevent loss of precision), and the way you can do that for an ImageCache
> is:
>
> imagecache->attribute ("unassociatedalpha", 1);
>
> (You must do this BEFORE reading anything from the file.)
>
> That will help you get the unassociated alpha when you want it. But Yang
> didn't describe that -- he said he wanted premultiplied, and that should be
> what OIIO is giving him. Maybe he described it backwards, and he wanted the
> original unassociated? If so, see the above advice. The other possibility
> is that the data is stored in the file already associated (in violation of
> the PNG spec), and he's complaining about the fact that it's being
> double-corrected, and in that case the answer also is to set the above
> attribute, and just know that the value you're getting is the (unchanged)
> associated alpha.
>
> The one thing we can't do is distinguish between unassociated alpha
> correctly stored in the PNG, and associated alpha incorrectly stored in the
> PNG. Because PNG stipulates that alpha is always unassociated (i.e. colors
> not "premultiplied"), there is no PNG header field that indicates whether
> the alpha is associated or not, because the spec says it always must be.
>
>
>
> On Apr 13, 2016, at 4:36 PM, Troy Sobotka <[email protected]> wrote:
>
> PNG, by specification, can only use unassociated alpha.
>
> With respect,
> TJS
>
> On Wed, Apr 13, 2016, 3:17 PM Yang Yang <[email protected]> wrote:
>
>> HI All,
>>
>> I am trying to read a bunch of png images supposed to have premultiplied
>> alpha.
>> However, it always give me unpremultiplied alpha.
>>
>> I don't know how can i configure Image cache to give me correct result.
>>
>> Could anyone give me suggestion?
>>
>> Thanks,
>>
>> Yang
>> _______________________________________________
>> 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
>
>
> --
> 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