J
John Novak
blog.johnnovak.net · Personal blog · on HN since 2016
John Novak writes technical posts on graphics, gamma correction, the Nim language, GUI toolkits and emulator graphics.
What HN saysHN commenters link "What every coder should know about gamma" as a go-to explainer, especially for color mixing and its helpful gradient examples.
30HN people shared it
16linked it in comments
24stories submitted
1.2Kstory points
5 months agolast shared
2016people per year2026
Most-shared posts
- 1What every coder should know about gamma19 people · 723 points · first shared 2016 · 183 comments on HN
- 2Cross-Platform GUI Toolkit Trainwreck (2016)7 people · 277 points · first shared 2016 · 170 comments on HN
- 3Nim Apocrypha, Vol. I2 people · 120 points · first shared 2020 · 56 comments on HN
- 4Period-Correct Graphics in PC Emulators: Part 1 – The Amiga2 people · 33 points · first shared 2022 · discussion on HN
- 5Nim performance tuning for the uninitiated2 people · 12 points · first shared 2017 · discussion on HN
- 6A minimalist Openbox desktop for Vim freaks1 people · 6 points · first shared 2016 · discussion on HN
- 7The Nim Ray Tracer Project – Part 4: Calculating Box Normals1 people · 6 points · first shared 2016 · discussion on HN
- 8Ao Resists the Forces of Darkness (pbrt Meets Nim)1 people · 3 points · first shared 2017 · discussion on HN
- 9The Nim Ray Tracer Project – Part 3: Lighting and Vector Maths1 people · 2 points · first shared 2016 · discussion on HN
- 10Cross-Platform GUI Toolkit Trainwreck, 2016 Edition1 people · 2 points · first shared 2018 · discussion on HN
- 11Cross platform gui trai..1 people · first shared 2018
- 12Ray%20tracing1 people · first shared 2016
- 13The nim raytracer project part11 people · first shared 2016
What HN people wrote when they linked it
meindnoch · 2023-05-06
John Novak proposes a different hypothesis for Photoshop's choice of gamma=1.42 in text antialiasing:
"Photoshop antialiases text using γ=1.42 by default, and this indeed seems to yield the best looking results (middle image). The reason for this is that most fonts have been designed for gamma-incorrect font rasterizers, hence if you use linear space (correctly), then the fonts will look thinner than they should."
https://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-abo…
boustrophedon · 2021-07-14
There was a great post about gamma and sRGB from 2016 on HN a couple weeks ago[0] with some discussion[1]
[0] http://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-abou…
[1] https://news.ycombinator.com/item?id=27721094
srikz · 2018-06-06
I will soon start working on a IDE / developer tool for a niche industry. I am actively looking for desktop gui frameworks to build performant desktop apps. There will be lot of trees and mind-map style diagrams with traced signals. So, I have currently ruled out Electron and looking at building a native tool as cross platform is not a priority.
I recently came across this excellent article comparing GUI frameworks [1]. It is definitely worth a read for anyone looking at building a serious desktop app.
I have put my particular requirement in a longer format here if anyone is curious and has some suggestions [2].
[1]: http://blog.johnnovak.net/2016/05/29/cross-platform-gui-trainwreck-201…
[2]: https://pastebin.com/8SUpcgWJ
java-man · 2022-02-17
When mixing colors, gamma value is important, see for example [0]. A naive implementation would produce darker, and generally incorrect colors.
[0] http://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-abou…
omegabravo · 2021-07-10
I learnt about gamma the other day from this article. Don't have to read it, just scroll down until you see the colour gradients, and maybe the swiggly lines over colours.
https://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-abo…
Nice work on the css tool Retroid
scq · 2021-07-03
This article covers things really well: http://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-abou…
nickpsecurity · 2019-08-22
You might find this article interesting:
http://blog.johnnovak.net/2016/05/29/cross-platform-gui-trainwreck-201…
arcameron · 2017-02-07
This page[1] documents some effects of gamma-incorrect resizing. Specifically, check out Figure 12.
[1] http://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-abou…
ThatOtherPerson · 2017-02-03
I thought about that, but some of the results I found on Google suggest that output from WebGL shaders is supposed to be in a linear color space [0] [1]. Then again, some of the comments here [2] suggest that you do have to do gamma correction manually.
Incidentally, I didn't know to do gamma correction until I came across [3], which explained why the output from my raytracers always looked a little off ;)
[0] http://stackoverflow.com/questions/10843321/should-webgl-shader-output…
[1] https://www.khronos.org/webgl/public-mailing-list/archives/1009/msg000…
[2] https://www.shadertoy.com/view/Xdl3WM
[3] http://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-abou…
petters · 2017-01-10
"What every coder should know about gamma" may be of interest here. http://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-abou…
vanderZwan · 2017-01-09
Bit of a jump in topic, but I'm kind of curious: I don't use instagram myself, bugt I'm sure it resizes images for online viewing, saving bandwidth ans such. Does it do so with correct gamma[0]? Since that's a thing many image-related applications get wrong.
[0] http://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-abou…
tomjakubowski · 2016-09-22
Another one: "ray racer" is probably meant to be "ray tracer" (that, or my imagination is far too small) - and links to another broken page here http://blog.johnnovak.net/tags/ray%20tracing
johnnovak · 2016-09-22
I'd say scanline rendering is "more of a hack" than ray tracing, but both can produce useful looking results, of course. They are both crude approximations of reality, but ray tracing is a closer model and it makes non-local phenomena easier to model (especially if you do things in a physically-correct way, respecting the law of conservation of energy etc.) Arguably, you would end up writing a "Universe simulator" if you wanted to accurately model absolutely everything that's happening in the real world :)
By the way, I've written about this exact same topic in my initial ray tracing post:
http://blog.johnnovak.net/2016/04/28/the-nim-raytracer-project-part1/
jpap · 2021-02-13
This post covers a topic I've spent some time with in the past, and is generally a good overview but unfortunately gets the idea of "linear RGB" wrong. That means all of the results need some attention, including the Go implementation. Maybe for a part II post?
Each color value (e.g. red) is represented by a value from zero to full intensity. It's easiest to think of it as a number between 0 and 1 in a linear space. You could use a floating point number for that, or a quantized/fixed point value. For example the 10-bit quantized value round(r_linear*1023) in the range 0 to 0x3ff.
8-bit RGB color components are "encoded" from their linear version with a transfer curve (aka gamma compression). For sRGB, the curve is a piecewise linear and exponential combination. A good overview is [1]. There are many different encodings, including sRGB, BT.601, BT.709, etc. Then there's "full range" vs. "video range"... it can get complex pretty quickly.
Because of gamma encoding, an 8-bit R_sRGB red value is not equal to round(r_linear*255). You have to first compress r_linear via the gamma curve, then quantize that 0..1 value to 8-bits. When going in reverse (expanding an 8-bit sRGB value to linear), you generally take R_sRGB/255 to produce a value in the 0..1 range and then use the inverse gamma curve to get the linear value. These computations can be done in floating point, fixed point, or using lookup tables.
The takeaway is that you can't represent 8-bit sRGB color…
fireattack · 2021-01-05
I misunderstood what you mean. Please ignore. On a side note, by colorspace I mainly meant that we can just stick with one with ultra-wide gamut. There are indeed other reasons to have different color spaces.
(Below is my original comment for transparency.)
-------------
Gamma isn't really about CRT; or I should say, they're two different things. The fact CRT has a somewhat physical "gamma" (light intensity varies nonlinearly with the voltage) is likely just a coincidence with the gamma we're talking here.
The reason gamma is used in sRGB is because human eyes are more sensitive to changes in darker area, i.e. if the light intensity changes linearly, it feels more "jumpy" in darker end (which causes perceptible bandings). This is especially an issue with lower color depth. To solve this, we invented gamma space to give darker end more bits/intensity intervals to smooth the perceptive brightness.
>it's not needed to understand the difference between linear and non-linear colorspaces
It absolutely should, since any gamma space would have problem with "averaging", as explained by the GP. Actually, it's so bad that almost all the image editing/representing tasks we have today are doing it wrong (resizing, blurring, mixing..).
This topic has been discussed extensively on Internet, so I'm not going to go into detail too much. A good start point is [1][2].
[1] https://www.youtube.com/watch?v=LKnqECcg6Gw
[2]…
lioeters · 2026-02-22
Quoting the list here for visibility and archival purpose.
* [Euclidean Vector - Properties and Operations](https://en.wikipedia.org/wiki/Euclidean_vector#Properties_and_operatio… - I assume you know all this already since it's pretty fundamental, but just in case, you'll want to be really comfortable with 2D vector math, and the [dot product](https://en.wikipedia.org/wiki/Dot_product) especially. In 2D graphics, I also find uses for the ["perp dot" product](http://cas.xav.free.fr/Graphics%20Gems%204%20-%20Paul%20S.%20Heckbert.… all the time. (I maintain that in graphics, if you're calling trig functions too much, you're probably doing it wrong!)
* [W3C HTML5 2D canvas specification](https://www.w3.org/TR/2015/REC-2dcontext-20151119/) - Obviously, this provides the basis that I was trying to adapt closely to a C++ API. There's a lot of detail in here, including some abstract descriptions of how the implementations are supposed to work.
* [ISO Open Font Format spec](http://wikil.lwwhome.cn:28080/wp-content/uploads/2018/06/ISO_IEC_14496… [Apple TrueType Reference Manual](https://developer.apple.com/fonts/TrueType-Reference-Manual/), [Microsoft OpenType Spec](https://learn.microsoft.com/en-us/typography/opentype/spec/) - These are the references that I consulted when it came to adding font and text support. In particular, the descriptions of the internal tables where useful when I was writing the code to parse TrueType font files.
* [Circles…