Convert RGB to the closest representation with name #2813
RFC 7986 New Properties for iCalendar introduces a COLOR property and according to my reading the value can only be a color name, hence no RGB.
A possible UI would be, rathat than offering a mega big box of distinct possible colorus, to let the user choose any RGB colour and then convert the choice to the nearest colour that has text representation.
The question is how to calculate the nearest RGB with a text representation to a given RGB.
At first I thought that the colours listed at https://drafts.csswg.org/css-color/#named-colors have equal distance, so it is just a matter of converting each color component to the closest value that can be divided by e.g. 8. But the list contains only two values starting with #3:
limegreen #32CD32 | 50 205 50
but with #2 more colours start:
So the jumps in the colours are not normed.
Isn't it better to adjust the text representations for have equal distances between each other? E.g. each R-G-B component can have distinct values: 0, 4, 8, C or alike?
What would be the current procedure to convert arbitraty RGB to the closest colour representable as text?
You mean, keeping the names but changing the colors they represent? No, that would not be web compatible at all.
Also, even spacing in RGB space is not the same as evenly spaced visually.
If RFC 7986 is not finalized yet, perhaps you could recommend that they accept a more flexible color definition, such as hex code. As @svgeesus notes, the named colors in CSS do not represent any kind of consistent color system, and there are many regions of the RGB cube (or any other color space) which aren't well represented.
Otherwise, your best approach for a usable UI might be to create a subset of the named colors which represent an attractive and well-balanced palette. But of course, for interoperability, you'd still need to support the full set of names.
The RFC is finalized, but I am going to propose errata to it: