In the past I used to build this stuff in silicon .... just a quick note it's quite common in the real world to get incoming values that are out of gamut (the results of compressing and decompressing data for example) - you need to pin your final values to 0-255 in the cases where they are < 0 or > 255 otherwise they tend to wrap, you also need to carry that extra bit of precision through your math (not such an issue with FP) to make sure you can detect this
This is mostly a port of the code on <a href="https://www.easyrgb.com/en/math.php" rel="nofollow">https://www.easyrgb.com/en/math.php</a> but I have added a few extras.<p>What I use it for is:<p>* RGB - easy to guess what values to use to make a color<p>* HSL - easy to change the hue of a color<p>* Lab - lets you compare colors<p>* Named color - lets you know the name of a color
The builtin System.Drawing.Color namespace already contains much of what you have in regards to colors to and from names.<p>There are a lot of helpful methods available.<p>Color foo = Color.FromArgb(int);
int foo = Color.ToArgb();
Color foo = Color.FromName("CornflowerBlue");<p>Color itself also exposes
.IsKnownColor and .IsNamedColor
Lab has the cool effect that you can smoothly change the luminance of a particular color in steps (usually scale is 0-100), where each step has an equal perception of change to the user.<p>Very useful when making gradients.<p>I used this for my MSc thesis project :)
For more advanced needs there is Colourful .NET [1].<p>[1] <a href="https://github.com/tompazourek/Colourful" rel="nofollow">https://github.com/tompazourek/Colourful</a>