Skip to content

Highlight color name#110

Open
42plat0 wants to merge 3 commits into0xabu:mainfrom
42plat0:highlight-color-name
Open

Highlight color name#110
42plat0 wants to merge 3 commits into0xabu:mainfrom
42plat0:highlight-color-name

Conversation

@42plat0
Copy link
Copy Markdown

@42plat0 42plat0 commented Mar 9, 2025

Issue #109

Simple way of getting the names of colors. Tested on iOS and Firefox highlights.

What do you think?

@0xabu
Copy link
Copy Markdown
Owner

0xabu commented Mar 10, 2025

Sorry, I'm no expert on colour spaces, but this looks really arbitrary and fragile. Why is the test for "red and green dominate" inconsistent with "red and blue dominate"? Why the choice of these five colours (red / green / blue / yellow / purple)? The last series of nested ifs is also oddly unbalanced (e.g., if red and green are exactly the same it's yellow, otherwise it could flip to any of purple, red, or green depending on a 1 bit change in any of the R/G/B values).

I think this approach would cause more confusion than it helps anyone. Colour names are inherently subjective anyway, so I suspect a better approach would be:

  • a database of known colour names (ideally borrowed from some standard, or just common colours available in PDF annotations programs like Adobe reader etc.)
  • if the colour is close (TBD how exactly "close" is defined) to one of the known names, use it
  • otherwise the colour has no name

@42plat0
Copy link
Copy Markdown
Author

42plat0 commented Mar 10, 2025

This code is arbitrary, I agree. The reason I chose this approach was mainly for simplicity (that's why there are only 5 colors, in my experience those are the most common). Other, was that databases produced answers that sometimes were not clear (eg. " khaki", "turquoise", "misty rose", "tomato") in contrast to basic ones.

I've noticed that purple has a lot more "room" to stay purple, but in yellow's case at same values it would be regarded more as green than yellow. I'd agree that it's fragile, as this enhancement as I've come to understand, would be unnecessary hard to implement and I tried my best to keep it simple without external libraries.

Your suggestion has merit as there are databases (webcolors) that provide a database of colors. Closeness of colors could be calculated based on distance between them (it'd depend if RGB, HSL or other ways of representation would produce best results). I still hold onto conviction that it'd be better to represent colors in as simple way as possible. For example, there could be a .csv table of PDF annotation program colors that would share color we could display in final document.

color-name,    hex,     r,   g,   b,  color-family
saffron-mango, F9CD59, 249, 205,  89, yellow
pale-canary,   FFFF99, 255, 255, 153, yellow
mantis,        7CC867, 124, 200, 103, green
aquamarine,    54FFBC,  84, 255, 188, green
etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants