Warning, always convert your colors to from sRGB to Linear RGB before doing any math on them, then convert them back to sRGB afterwards for displaying them.

sRGB is the familiar color space you all know and love, it's what your display uses, and it's what has those RGB numbers between 0 and 255. But it's not a linear color space.

First think of values as being between 0 and 1 instead of 0 and 255. To change sRGB to Linear, do X^2.2 (close to squaring the value). To change Linear back to sRGB, do X^(1/2.2) (close to a square root).

In Linear RGB, a value of 0.5 is halfway between black and white. You can put a stripe or checkerboard pattern next to the color value, and it will appear to be the same brightness. But in sRGB, a value of 0.5 is much darker. Linear RGB of 0.5 is roughly equivalent to sRGB of 0.73.

The actual method of conversion involves a complicated curve that isn't continuous, using X^2.2 is still an approximation.

Even better, convert to HSL or CieLAB. RGB is not at all how our eyes see things.

For the purpose of blurring, there's nothing wrong with linear RGB.

HSL has the angle discontinuity which is really annoying to deal with and sometimes even impossible to work around.

CIELAB should be fine in theory, but it's not what people actually use on their screens, so I've had some problems with it in practice.

CIEXYZ (CIE 1931) had the best brightness axis ever. But the hunt for the best color-axis seems to be ongoing. CIE 1960, CIE 1964, CIELAB/CIELUV 1976...

CIECAM02 CIECAM16 seem to be new iterations. Maybe those are good now?

For blending, linear RGB is a much better choice than HSL. In HSL, a slightly cool gray (230°, 5%, 50%) mixed with an intense warm yellow (40°, 100%, 50%) might create a hot pink (315°, 52.5%, 50%). Not what your eyes expect.

When I was trying to find how close colors are to each other (such as when mapping an image to an existing palette), comparing color distance in YCbCr worked far better than comparing color distance in RGB.

There are also color science packages like this one that let you do conversions to various spaces - https://www.colour-science.org/

Pretty flawed also really.

Basically, anyone that paints knows that the more colours are mixed, the more they tend to brown. Yet because of that misunderstanding in the 1960s in Caltech, in CS more colors = white.

Crazy stuff. A great example of technical debt in systems design where we have all this jazz like sRGB, HSL, HSV, etc, trying to reset that basic mistake in physics from 60 years ago.

When you start from a black screen (eg. a monitor) your primary colors that can form all others are literally red, green and blue. Those are the subpixels that every monitor must have as a minimum. These colors will add to white and mixtures of them can make every color humans can perceive (provided your rgb are at the maximum extremes of each color, otherwise your color triangle is slightly smaller than what rgb can actually do). This is called additive color mixing. Start from black and add color.

When you mix paints your are subtracting from white. The primary colors are 45degrees around the color wheel, namely cyan, magenta, yellow. From those you can make alm other colors by subtracting various amounts of the above three colors from white.

Btw do you know what color model matches your eyes the most? It’s additive color mixing. Your eyes literally start by seeing black and as your eyes let in light the cones and rods that are focused around detecting red, green and blue are triggered in various amounts and you see color that way. You don't see color the same way color is formed from mixing paints. You don’t see cyan, magenta, yellow at all. You see in RGB.

So your painting example is really flawed. Subtractive color models are inly useful for paints.

Displays are not made of paint, though - they use light.

There are two models of combination:

- subtractive, which applies to paint, since the more you mix in the more frequencies are absorbed

- additive, which applies to light, as mixing an extra light adds the frequencies in it

So additive, where more colour tends to white, is correct.

There's been no mistakes here. Additive mixing is the most intuitive way to represent color, just add primaries. Mixing paint is super complicated!

Additive vs substractive approach to color Displays use the former, so it is natural this is mirrored in software.

If you don't believe the people telling you about additive vs subtractive mixing, ask yourself this: How does a prism separate a rainbow of colors out of white sunlight? Shouldn't the sunlight be brown for that to work?

> The actual method of conversion involves a complicated curve that isn't continuous

Isn't continuous? Really? That seems surprising to me; tell me more.

it's complicated for appropriate values of complicated.

more specifically it's defined piecewise and the standard then rounds some constants in the definition, which results in a slight discontinuity around the transition from one piece to the other.

https://en.wikipedia.org/wiki/SRGB#Deriving_the_transfer_fun...

A piecewise function is definitely not what I'd call "complicated".

It's an implementation detail. In theory, it should be continuous.