color-names-csharp
1.0.3
This package has been renamed and modified to better fit C# coding conventions.
dotnet add package color-names-csharp --version 1.0.3
NuGet\Install-Package color-names-csharp -Version 1.0.3
<PackageReference Include="color-names-csharp" Version="1.0.3" />
<PackageVersion Include="color-names-csharp" Version="1.0.3" />
<PackageReference Include="color-names-csharp" />
paket add color-names-csharp --version 1.0.3
#r "nuget: color-names-csharp, 1.0.3"
#addin nuget:?package=color-names-csharp&version=1.0.3
#tool nuget:?package=color-names-csharp&version=1.0.3
Color names
This library's primary purpose is to be able to specify a color and end up with a fitting name for that color 🌈
Examples:<br>
"#ffffff"
→ White
<br>
"#facfea"
→ Classic Rose
<br>
#abcdef
→ Alphabet Blue
<br>
#123456
→ Incremental Blue
<br>
#c1b2a3
→ Balanced Beige
<br>
...and so on
Where do the names come from?!
Color Names is meant to act as an easy drop-in dependency you can import and start using, meaning it's already bundled with a list of color names, a list that is maintained by another awesome open-sourced project: meodai/color-names. There's around 16.7 million sRGB colors, obviously not all of these are named, but this list provides plenty to work with, we can just extrapolate the closest color from the list. <br>
Ermm actually I don't like the bundled color list 🤓🤓
Color Names remain customisable for those who'd like the extra control: you can use the ColorNameBuilder
(usage outlined below) to fully customize the color names used, enabling you to add your own colors and even bypass the default list entirely. Alternatively, you could fork this project yourself and replace/modify the list in src/main/resources/colornames.csv
with whatever you'd like. If you'd like to make changes to the default list, consider reviewing the naming rules of the open sourced list mentioned above and contributing there.
How about performance, and how accurate is the "nearest" color?
The default colour list has over 30,000 names (that's a lot). Trying to find the closest color by comparing distance in the 3D color space can be pretty computationally expensive. <br><br> Other libraries with similar functionality seem to often approach this by iterating over all the colors, plotting the sRGB values and calculating Euclidian distance and whatever has the lowest distance is the "closest" color. This has 2 notable concerns: <br>
- The sRGB color space isn't all that accurate in terms of visual similarity, ie: 3 sRGB values that are equally apart in terms of raw numerical value are unlikely to be visually "different" by the same factor. Okay... so, how do we put a number on the visual similarity of colors? Fortunately, that's not my job. The CIELAB Color Space has us covered! This color space precisely revolves around positioning colors with uniform visual perception and for this reason, its used for all sorts of color correction work, and is exactly what we need. Perfect, we convert our values from the sRGB color space to the CIELAB color space, problem one solved!
- Iterating through >30,000 vectors in a 3D space and finding the distance between all of them to a point is... a lot of calculations. But it's exactly what we need, since that's how we find the Delta-E variance between all our CIELAB colours to see whats the closest. So, we should really try to optimise this. For this we cache our colors in a K-D Tree with 3 dimensions, providing us with fast nearest neighbour searches. This takes the time complexity for searches from O(n) to O(logn). In practice, this makes a pretty substantial difference.
Benchmarks:
This section is a work in progress. If you'd like to contribute to the benchmarks, feel free to open a PR with your results.
<br>
Pretty notes ✨
While researching K-D trees, I put together some visuals to help me understand, and I figured why not make them pretty and provide it here. Hopfully these prove to be helpful for anyone interested in learning about K-D trees. And remember, there are plenty of other great resources out there (YouTube videos did it for me!).
You can open that image in a new tab for a nicer, full-resolution view.
<br>
Usage
You can find the nuget package here: https://www.nuget.org/packages/color-names-csharp
This section is a work in progress. If you'd like to contribute to the usage guide, feel free to open a PR with your changes.
Other
This library is a C# implementation of the original color names library by meodai and it takes inspiration from UwUAroze's implementation in Kotlin.. Huge thanks to both of them for their work!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|