server icon indicating copy to clipboard operation
server copied to clipboard

Mixer is not gamma-correct

Open sesse opened this issue 10 years ago • 4 comments

Hi,

It looks like the basic operations in the mixer (like scaling) are not working in linear light as they should; in particular, see http://www.4p8.com/eric.brasseur/gamma.html. In particular, this matters when doing crossfades between light and dark media.

Simple test: Download http://www.4p8.com/eric.brasseur/gamma-1.0-or-2.2.png as media/gamma.png, set up a 720p consumer and do

LOAD 1 gamma PLAY 1 gamma MIXER 1 FILL 0 0 0.2 0.1777777

Result included, if maybe a bit offensive. :-)

The right way to fix this is to convert all data from sRGB (or whatever colorspace you assume) on the way in, do operations in floating-point and then convert back on the way out.

casparcg-gammacorrect

sesse avatar Jul 17 '15 10:07 sesse

Simply using SRGB texture format in OpenGL for both input texture and the frame buffer instead of RGB should solve the problem.

ronag avatar Sep 09 '15 09:09 ronag

I noticed today that this also makes CasparCG output incorrect premultiplied alpha. If you have a white (255,255,255) at 50% alpha, it should be (188,188,188) after premultiplication, not (128,128,128), since all blending, and thus also the premultiplication of alpha, should happen in linear gamma and only be converted to sRGB for final storage. This causes out-of-gamut values and halos when fed into a processing pipeline that actually understands sRGB correctly.

Using straight alpha is a workaround, although perhaps not a very satisfying one. Note that alpha is always linear (never gamma-corrected, since it wouldn't make any sense), so storing 50% alpha as 128 is completely fine.

sesse avatar Apr 21 '17 16:04 sesse

@5opr4ni can you analyze this? i.e. make it reproducible so we can fix it at some point.

ronag avatar Feb 15 '18 09:02 ronag

I think this is best solved in GLSL.

ronag avatar Feb 16 '18 14:02 ronag