[−][src]Crate color_processing
Color crate
This color_processing
crate contains functions/methods to handle color values,
like converting a rgb color to another colorspace (cmyk, hsl, hwb, ...),
parse different kinds of color-strings or
modifying colors (inverting, grayscale, colorize, ...).
It's not intended for image manipulation, just for parsing and processing single colors.
Examples
use color_processing::Color; let red = Color::new_rgb(255, 0, 0); assert_eq!(255, red.red); assert_eq!(0, red.green); assert_eq!(0, red.blue); let grayscaled_red = red.grayscale(); assert_eq!(76, grayscaled_red.red); assert_eq!(76, grayscaled_red.green); assert_eq!(76, grayscaled_red.blue); assert_eq!("#4C4C4C", grayscaled_red.to_hex_string()); assert_eq!("rgb(76, 76, 76)", grayscaled_red.to_rgb_string()); assert_eq!("cmyk(0%, 0%, 0%, 70%)", grayscaled_red.to_cmyk_string()); assert_eq!("hsl(0, 0%, 29.8%)", grayscaled_red.to_hsl_string()); // for colorizing: let colorized_blue = grayscaled_red.colorize_string("blue").unwrap(); assert_eq!("rgb(0, 0, 76)", colorized_blue.to_rgb_string()); // To get the raw values of a specific colorspace: // The ranges go from 0.0 (0%) to 1.0 (100%). let raw_rgba = red.get_rgba(); assert_eq!(1.0, raw_rgba.0); // red value assert_eq!(0.0, raw_rgba.1); // green value assert_eq!(0.0, raw_rgba.2); // blue value assert_eq!(1.0, raw_rgba.3); // alpha value let raw_cmyk = red.get_cmyk(); assert_eq!(0.0, raw_cmyk.0); // cyan value assert_eq!(1.0, raw_cmyk.1); // magenta value assert_eq!(1.0, raw_cmyk.2); // yellow value assert_eq!(0.0, raw_cmyk.3); // key (black) value // several ways of parsing strings is also possible: let green = Color::new_string("green").unwrap(); let blue = Color::new_string("rgb(0, 0, 255)").unwrap(); let cyan = Color::new_string("cmyk(100%, 0%, 0%, 0%)").unwrap(); let yellow: Color = "yellow".parse().unwrap(); let magenta = "yellow".parse::<Color>().unwrap();
Now, you should have a notion of what this library can do and if it is the right thing for you!
For all the available functionality, please lookout for the Color-struct.
Structs
Color |
Enums
KnownColors |