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

color_space

library for converting between color spaces and comparing colors

12 releases (4 breaking)

0.5.3 Oct 28, 2020
0.5.2 Sep 12, 2020
0.4.3 Sep 11, 2020
0.3.2 Sep 11, 2020
0.1.0 Sep 11, 2020

#609 in Algorithms

Download history 73/week @ 2023-12-17 69/week @ 2023-12-24 58/week @ 2023-12-31 110/week @ 2024-01-07 99/week @ 2024-01-14 182/week @ 2024-01-21 206/week @ 2024-01-28 119/week @ 2024-02-04 116/week @ 2024-02-11 137/week @ 2024-02-18 190/week @ 2024-02-25 182/week @ 2024-03-03 210/week @ 2024-03-10 280/week @ 2024-03-17 220/week @ 2024-03-24 249/week @ 2024-03-31

988 downloads per month
Used in 3 crates

MIT license

30KB
785 lines

A Rust 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

Currently Supported Color Spaces

  • CMY
  • CMYK
  • HSL
  • HSB
  • HSV
  • CIE L*AB
  • Hunter LAB
  • LCH
  • LUV
  • RGB
  • XYZ
  • YXY

Currently Supported Comparisons

  • Euclidean
  • CIE1976
  • CIE2000
  • CMC

Contibutions

I'm happy to take feedback and improvements on the API if there's ways it can be improved. I need to write more tests to check the quality of the conversion outputs as well, but they are tedious to write so I'm currently procrastinating on that.

No runtime deps