Hacker News new | ask | show | jobs
by dosshell 1531 days ago
directly when reading this code I cannot help myself but to get into review-mode. It is an awesome example, which i will probably use myself one day.

However...

inc.cpp:27

Gray is not the average of RGB, it is usally approximated with `Y = 0.299 R + 0.587 G + 0.114 B`.

3 comments

For future readers, this is the code that is being referred:

https://github.com/ern0/howto-wasm-minimal/blob/master/inc.c...

It should be:

    uint32_t gray = 0.299 * ptr[i] + 0.587 * ptr[i+1] + 0.114 * ptr[i+2];
    ptr[i] = gray;
    ptr[i+1] = gray;
    ptr[i+2] = gray;
I know it (see: https://github.com/ern0/kolorwheel.js ), but I did not wanted use floats.
Also, you must work in linear colour space. In OP's case you would have to apply the inverse sRGB transform, do the calculation, then apply the forward sRGB transform. Best if you just work with linear colour end to end, if you have the memory to spare.
Well, it's certainly traditional to get that wrong. Technically nothing's wrong in graphics as long as you get some kind of image out of it, it's just different :)
Marvelous example of the bikeshed effect
That doesn't seem applicable unless there are bigger problems to solve that are being ignored.