Crate color_space

Source
Expand description

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

Structs§

Cmy
A CMY color (cyan, magenta, yellow).
Cmyk
A CMYK color (cyan, magenta, yellow, key).
Hsl
An HSL color (hue, saturation, light).
Hsv
An HSV color (hue, saturation, value).
HunterLab
A Hunter Lab color.
Lab
A CIELAB color.
Lch
An LCH color (luminance, chroma, hue).
Luv
A CIELUV color (luminance, )
Rgb
An RGB color (red, green, blue).
Xyz
A CIE 1931 XYZ color.
Yxy
A CIE YXY color.

Traits§

CompareCie1976
CompareCie2000
CompareCmc
CompareEuclidean
FromColor
FromRgb
ToRgb