Skip to content

Color lerping could be improved

I noticed the colors lerping was not implemented "properly".
RGB values should be lerped in linear space, that is after raising the RGB value by a gamma power. If you don't do it this way you get less appealing muddy colors between the gradient pivot points.

Here are some examples of lerps using the "proper" method on top, and the current method on bottom.
image

This is the function that could be improved:
https://gitlab.com/OpenRGBDevelopers/OpenRGBHardwareSyncPlugin/-/blob/master/ColorUtils.h#L221

The following code is just a suggestion, but I think it would work without needing to change much:

static unsigned char InterpolateChanel(unsigned char a, unsigned char b, float x)
{
 const float gamma = 2.2f;
 float a2 = pow((float)a, gamma);
 float b2 = pow((float)b, gamma);
 float lerped = ((b2 - a2) * x + a2);
 return (unsigned char)pow(lerped, 1f/gamma);
}

You can read more about properly handling gamma and color in this helpful blog post.

Edited by romen-h