I was wondering how premultiplied alpha and gamma work together. Particularly if the alpha might be influencing the outcome of the sRGBToLinear function.
I was thinking that the outcome might not be correctly linear when not undoing the alpha premultiplication before the sRGBToLinear part. But maybe this is not a problem for some reason that I might be aware of?
I see it like this: c is color, a is alpha
1 2 | c' = a*c sRGBToLinear(c') = c' * c' = (a*c) * (a*c) = a*a * c*c |
So a color with 1.0 red and alpha 0.5 would be r'=a*r = 1.0*0.5 = 0.5
Doing the sRGBToLinear would then get 0.5*0.5 = 0.25
But you might want
1 | sRGBToLinear(c, a) = a * c*c |
or
1 | sRGBToLinear(c', a) = c'*c' / a |
Which would still give you 0.5, which in my eyes is the expected representation of 50% transparent red in linear space. Or should the alpha component already have effect on the color? Casey kept the alpha the same in the sRGBToLinear function, so that gives me the idea that alpha should already be linear.
LinearTosRGB would probably also need to involve unpremultiplying.
Premultiplied alpha already had my head hurting, so gamma on top of this really makes my world spin. Anybody have any thoughts on this?
Mox