-
Hello, I am trying to understand why PNG files with alpha are not giving us the expected results. The issue seems to be down to how OpenImageIO premultiplies the alpha when loading this texture. Is it done in the texture color space or the linear color space? Our results seem to indicate the former. I have attached a single-pixel texture, cropped from the original texture, which shows this very clearly. This texture contains the pixel color (1, 1, 1, 0.5). We get that value correctly when checking with "oiiotool --dumpdata -no-autopremult", but when we take out the "-no-autopremult" option, we get "55 55 55 127 (0.21568629 0.21568629 0.21568629 0.49803925)". Notice how this value is suspiciously close to the expected value in linear space with gamma 2.2 applied (0.5 ^ 2.2 = 0.2176). After reading https://www.realtimerendering.com/blog/a-png-puzzle/, I think we should be getting something like (187, 187, 187, 128). Am I correct? Is there anything else I should be doing? Maybe I am missing an option to change this behaviour? Thanks in advance. Regards, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
I know sRGB is not pure 2.2 gamma, but let's use that here because it's close enough and simpler to do. So the various values OIIO could be returning for the linear space premultiplied R channel I think are (G and B would be the same):
OIIO Looks to be returning 0.217, but I think the proper value is 0.5. The 187 value Angel refers to above is I believe the value you get if you composite against black and re-apply the sRGB display transform: So assuming OIIO is wrong, how do we handle this? As Eric's blog post points out, many image viewers do the png color space transform at the wrong point. Fixing this might break what some people expect. But we also definitely want OIIO to be doing the right thing. Do we support both with a switch? Drop support for the wrong way of doing this? |
Beta Was this translation helpful? Give feedback.
-
I have finally gotten to the bottom of this. Stupid mistake on my part. Will have a patch in the morning. |
Beta Was this translation helpful? Give feedback.
-
You were right that this was egregiously wrong. It turns out we did the linearize-associate-delinearize sequence right, and it wasn't the case that we were associating in the nonlinear case. BUT... the truth was even more embarrassing. We applied gamma, associated, and then applied 1/gamma to bring it back, when of course it should have been 1/gamma, associate, gamma. |
Beta Was this translation helpful? Give feedback.
-
lg fixed this in #4315. |
Beta Was this translation helpful? Give feedback.
You were right that this was egregiously wrong.
It turns out we did the linearize-associate-delinearize sequence right, and it wasn't the case that we were associating in the nonlinear case.
BUT... the truth was even more embarrassing. We applied gamma, associated, and then applied 1/gamma to bring it back, when of course it should have been 1/gamma, associate, gamma.