#color #rgb #color-conversion #hsl #hsv #lab #graphics

color_space

library for converting between color spaces and comparing colors

13 releases

0.5.4 Jun 28, 2024
0.5.3 Oct 28, 2020
0.5.2 Sep 12, 2020
0.4.3 Sep 11, 2020
0.1.0 Sep 11, 2020

#228 in Algorithms

Download history 194/week @ 2024-03-30 258/week @ 2024-04-06 393/week @ 2024-04-13 235/week @ 2024-04-20 229/week @ 2024-04-27 260/week @ 2024-05-04 312/week @ 2024-05-11 407/week @ 2024-05-18 446/week @ 2024-05-25 465/week @ 2024-06-01 416/week @ 2024-06-08 490/week @ 2024-06-15 396/week @ 2024-06-22 374/week @ 2024-06-29 241/week @ 2024-07-06 182/week @ 2024-07-13

1,305 downloads per month
Used in 3 crates

MIT license

29KB
785 lines

UPDATE

This crate is no longer supported, nor recommended for use. If you want a great crate for color management and conversations, I recommend checking out the palette crate!

https://crates.io/crates/palette

It achieves what this crate set out to do, has all the same features and more, but does so with a much nicer, more flexible codebase.


lib.rs:

A library for converting between color spaces and comparing colors, ported from https://github.com/berendeanicolae/ColorSpace.

Color Conversion

You can convert between any supported color spaces using the from trait method:

use color_space::{Rgb, Hsv};
let rgb = Rgb::new(0.0, 255.0, 0.0);
let hsv = Hsv::from(rgb);
assert_eq!(hsv, Hsv::new(120.0, 1.0, 1.0));

You can also do this generically with the from_color method:

use color_space::{Rgb, Hsv, FromColor};
let rgb = Rgb::new(0.0, 0.0, 255.0);
let hsv = Hsv::from_color(&rgb);
assert_eq!(hsv, Hsv::new(240.0, 1.0, 1.0));

Comparing Colors

You can compare colors by using the compare_* methods:

use color_space::{Rgb, Hsv, CompareCie2000};
let rgb = Rgb::new(255.0, 0.0, 0.0);
let hsv = Hsv::new(0.0, 1.0, 1.0);
let diff = rgb.compare_cie2000(&hsv);
assert_eq!(diff, 0.0);
// these two colors are the same, so the difference is zero

No runtime deps