4 ms·
So, what is the right way to deal with gamma in a graphics application?
by HexDecOctBin 3y ago
So, what is the right way to deal with gamma in a graphics application?
- AndriyKunitsyn 3y agoMost of the time, you convert the image from gamma space to linear space, you do whatever you want to do, and then convert back.
- corysama 3y agoRecognize when you are doing linear algebra and don’t do linear algebra on non-linear representations. Gamma encoding is only really necessary to optimize around the limitations of 8-bit color channels. So, load sRGB888 convert to linear 32-bit floats, do linear algebra, convert back to sRGB888, store the results.
- pixelpoet 3y agoNice to see the usual suspects in graphics programming HN discussion :) Good succinct answer.
- Dylan16807 3y agoAnd 8 bit channels are really bad for generation loss, so try to delay or avoid converting back as much as possible. And 16 bit floats are plenty, so that's a good option as long as the hardware won't do something dumb with them that makes them slower.
- Asooka 3y agoYou can even get away with 16 bit fixed point math, like what Imagemagick does.
- contravariant 3y agoIn most cases I'd even prefer the 16 bit fixed point, with 11 significant bits the rounding errors become visible fast.
- Dylan16807 3y agoOn the other hand fixed point can oversaturate easily and also the dark areas end up with less than 11 significant bits. I guess ideally you'd reallocate the sign bit to the mantissa, and maybe an exponent bit too.
- Asooka 3y agoI've honestly started questioning if the gamma representation was even worth it. Does using 8 bit linear really lose out on so much fidelity? I guess to test that you would need a display capable of showing 10 bit colour or maybe a CRT with adjustable gamma down to 1.
- Dylan16807 3y agoConsider a test page like this: https://web.archive.org/web/20230323033128im_/http://www.lagom.nl/lcd-test/img/blacktest.png https://web.archive.org/web/20230323033128im_/http://www.lag... A gamma of 2.2 puts that '15' at 0.2% brightness, and the '20' at 0.4% brightness. An 8 bit linear representation would make that '20' square the minimum brightness above zero. The next step up would be roughly the '30' square. So yes, the gamma curve is very necessary. Even 12 bit linear would be a bad idea. So 14 or 16 minimum. And adding HDR is something like 2 bits with gamma and 8 bits without.
- ancientworldnow 3y agoThis is how color workflows work in film and tv. I imagine the issue is his television (despite him blaming the stream and his follow-up Netflix anecdote). Netflix has delivery specs that specifically outline these issues and require you to go through a workflow that prevents them (though people make mistakes and QC misses things).