[][src]Struct color_processing::Color

pub struct Color {
    pub red: u8,
    pub green: u8,
    pub blue: u8,
    pub alpha: u8,
}

Fields

red: u8green: u8blue: u8alpha: u8

Methods

impl Color[src]

pub fn new() -> Color[src]

Gets a new Color struct, that represents the "black"-color.

Example

use color_processing::Color;
 
let black = Color::new();
 
assert_eq!(0, black.red);
assert_eq!(0, black.green);
assert_eq!(0, black.blue);
assert_eq!(255, black.alpha);

pub fn new_cmyk(cyan: f64, magenta: f64, yellow: f64, key: f64) -> Color[src]

Gets a new Color struct, that represents a color with the given cyan, magenta, yellow and key (black) values.

  • The value range of cyan, magenta, yellow and key (black) is from 0.0 to 1.0 represents the intensity from 0% to 100%.
  • If a value is out of this range, it will be automatically clipped, e.g.: -0.123 becomes 0.0 and 231.31 becomes 1.0!

Example

use color_processing::Color;
 
let red = Color::new_cmyk(0.0, 1.0, 1.0, 0.0);
 
assert_eq!(255, red.red);
assert_eq!(0, red.green);
assert_eq!(0, red.blue);
assert_eq!(255, red.alpha);

pub fn new_enum(known_color: KnownColors) -> Color[src]

Gets a new Color struct, that represents a color with the given KnownColors-enum values.

  • The names and values are equal from the www.w3.org Website for the css named colors.

Example

use color_processing::{Color, KnownColors};
 
let red = Color::new_enum(KnownColors::Red);
 
assert_eq!(255, red.red);
assert_eq!(0, red.green);
assert_eq!(0, red.blue);
assert_eq!(255, red.alpha);

pub fn new_gray(gray: u8) -> Color[src]

Gets a new Color struct, that represents a color with a gray value.

  • The value range of gray is from 0 to 255.

Example

use color_processing::Color;
 
let gray = Color::new_gray(100);
 
assert_eq!(100, gray.red);
assert_eq!(100, gray.green);
assert_eq!(100, gray.blue);
assert_eq!(255, gray.alpha);

pub fn new_hsl(hue: f64, saturation: f64, lightness: f64) -> Color[src]

Gets a new Color struct, that represents a color with the hue, saturation and lightness values.

  • The value range of hue is from 0.0 to 360.0 in degrees.
  • If the value of the hue is out of range, it will be normalized. e.g.: 420.0 becomes 60.0 and -40.0 becomes 320.0.
  • The value range of saturation and lightness is from 0.0 to 1.0 represents the intensity from 0% to 100%.
  • If the value of the saturation or lightness is out of range, it will be automatically clipped, e.g.: -0.123 becomes 0.0 and 231.31 becomes 1.0!

Example

use color_processing::Color;
 
let red = Color::new_hsl(0.0, 1.0, 0.5);
 
assert_eq!(255, red.red);
assert_eq!(0, red.green);
assert_eq!(0, red.blue);
assert_eq!(255, red.alpha);

pub fn new_hsla(hue: f64, saturation: f64, lightness: f64, alpha: f64) -> Color[src]

Gets a new Color struct, that represents a color with the hue, saturation, lightness and alpha values.

  • The value range of hue is from 0.0 to 360.0 in degrees.
  • If the value of the hue is out of range, it will be normalized. e.g.: 420.0 becomes 60.0 and -40.0 becomes 320.0.
  • The value range of saturation, lightness and alpha is from 0.0 to 1.0 represents the intensity from 0% to 100%.
  • If the value of the saturation, lightness or alpha is out of range, it will be automatically clipped, e.g.: -0.123 becomes 0.0 and 231.31 becomes 1.0!

Example

use color_processing::Color;
 
let red = Color::new_hsla(0.0, 1.0, 0.5, 0.5);
 
assert_eq!(255, red.red);
assert_eq!(0, red.green);
assert_eq!(0, red.blue);
assert_eq!(128, red.alpha);

pub fn new_hsv(hue: f64, saturation: f64, value: f64) -> Color[src]

Gets a new Color struct, that represents a color with the hue, saturation and value values.

  • The value range of hue is from 0.0 to 360.0 in degrees.
  • If the value of the hue is out of range, it will be normalized. e.g.: 420.0 becomes 60.0 and -40.0 becomes 320.0.
  • The value range of saturation and value is from 0.0 to 1.0 represents the intensity from 0% to 100%.
  • If the value of the saturation or value is out of range, it will be automatically clipped, e.g.: -0.123 becomes 0.0 and 231.31 becomes 1.0!

Example

use color_processing::Color;
 
let red = Color::new_hsv(0.0, 1.0, 1.0);
 
assert_eq!(255, red.red);
assert_eq!(0, red.green);
assert_eq!(0, red.blue);
assert_eq!(255, red.alpha);

pub fn new_hsva(hue: f64, saturation: f64, value: f64, alpha: f64) -> Color[src]

Gets a new Color struct, that represents a color with the hue, saturation, value and alpha values.

  • The value range of hue is from 0.0 to 360.0 in degrees.
  • If the value of the hue is out of range, it will be normalized. e.g.: 420.0 becomes 60.0 and -40.0 becomes 320.0.
  • The value range of saturation, value and alpha is from 0.0 to 1.0 represents the intensity from 0% to 100%.
  • If the value of the saturation, value or alpha is out of range, it will be automatically clipped, e.g.: -0.123 becomes 0.0 and 231.31 becomes 1.0!

Example

use color_processing::Color;
 
let red = Color::new_hsva(0.0, 1.0, 1.0, 0.5);
 
assert_eq!(255, red.red);
assert_eq!(0, red.green);
assert_eq!(0, red.blue);
assert_eq!(128, red.alpha);

pub fn new_hwb(hue: f64, whiteness: f64, blackness: f64) -> Color[src]

Gets a new Color struct, that represents a color with the hue, whiteness and blackness values.

  • The value range of hue is from 0.0 to 360.0 in degrees.
  • If the value of the hue is out of range, it will be normalized. e.g.: 420.0 becomes 60.0 and -40.0 becomes 320.0.
  • The value range of whiteness and blackness is from 0.0 to 1.0 represents the intensity from 0% to 100%.
  • If the value of the whiteness or blackness is out of range, it will be automatically clipped, e.g.: -0.123 becomes 0.0 and 231.31 becomes 1.0!

Example

use color_processing::Color;
 
let red = Color::new_hwb(0.0, 0.0, 0.0);
 
assert_eq!(255, red.red);
assert_eq!(0, red.green);
assert_eq!(0, red.blue);
assert_eq!(255, red.alpha);

pub fn new_hwba(hue: f64, whiteness: f64, blackness: f64, alpha: f64) -> Color[src]

Gets a new Color struct, that represents a color with the hue, whiteness, blackness and alpha values.

  • The value range of hue is from 0.0 to 360.0 in degrees.
  • If the value of the hue is out of range, it will be normalized. e.g.: 420.0 becomes 60.0 and -40.0 becomes 320.0.
  • The value range of whiteness, blackness and alpha is from 0.0 to 1.0 represents the intensity from 0% to 100%.
  • If the value of the whiteness, blackness or alpha is out of range, it will be automatically clipped, e.g.: -0.123 becomes 0.0 and 231.31 becomes 1.0!

Example

use color_processing::Color;
 
let red = Color::new_hwba(0.0, 0.0, 0.0, 0.5);
 
assert_eq!(255, red.red);
assert_eq!(0, red.green);
assert_eq!(0, red.blue);
assert_eq!(128, red.alpha);

pub fn new_lab(l: f64, a: f64, b: f64) -> Color[src]

Gets a new Color struct, that represents a color with the lightness, a and b values.

Example

use color_processing::Color;
 
let black_lab = Color::new_lab(0.0, 0.0, 0.0);
assert_eq!(black_lab.to_hex_string(), "#000000");
 
let white_lab = Color::new_lab(100.0, 0.0, 0.0);
assert_eq!(white_lab.to_hex_string(), "#FFFFFF");
 
let gray_lab = Color::new_lab(53.59, 0.0, 0.0);
assert_eq!(gray_lab.to_hex_string(), "#808080");
 
let red_lab = Color::new_lab(53.24, 80.09, 67.2);
assert_eq!(red_lab.to_hex_string(), "#FF0000");
 
let yellow_lab = Color::new_lab(97.14, -21.55, 94.48);
assert_eq!(yellow_lab.to_hex_string(), "#FFFF00");
 
let green_lab = Color::new_lab(87.73, -86.18, 83.18);
assert_eq!(green_lab.to_hex_string(), "#00FF00");
 
let cyan_lab = Color::new_lab(91.11, -48.09, -14.13);
assert_eq!(cyan_lab.to_hex_string(), "#00FFFF");
 
let blue_lab = Color::new_lab(32.3, 79.19, -107.86);
assert_eq!(blue_lab.to_hex_string(), "#0000FF");

pub fn new_laba(l: f64, a: f64, b: f64, alpha: f64) -> Color[src]

Gets a new Color struct, that represents a color with the lightness, a, b and alpha values.

Example

use color_processing::Color;
 
let black_lab = Color::new_laba(0.0, 0.0, 0.0, 1.0);
assert_eq!(black_lab.to_hex_string(), "#000000");
 
let white_lab = Color::new_laba(100.0, 0.0, 0.0, 0.5);
assert_eq!(white_lab.to_hex_string(), "#FFFFFF80");
 
let gray_lab = Color::new_laba(53.59, 0.0, 0.0, 0.5);
assert_eq!(gray_lab.to_hex_string(), "#80808080");
 
let red_lab = Color::new_laba(53.24, 80.09, 67.2, 1.0);
assert_eq!(red_lab.to_hex_string(), "#FF0000");
 
let yellow_lab = Color::new_laba(97.14, -21.55, 94.48, 0.0);
assert_eq!(yellow_lab.to_hex_string(), "#FFFF0000");
 
let green_lab = Color::new_laba(87.73, -86.18, 83.18, 1.0);
assert_eq!(green_lab.to_hex_string(), "#00FF00");
 
let cyan_lab = Color::new_laba(91.11, -48.09, -14.13, 1.0);
assert_eq!(cyan_lab.to_hex_string(), "#00FFFF");
 
let blue_lab = Color::new_laba(32.3, 79.19, -107.86, 1.0);
assert_eq!(blue_lab.to_hex_string(), "#0000FF");

pub fn new_lch(lightness: f64, chroma: f64, hue: f64) -> Color[src]

Gets a new Color struct, that represents a color with the lightness, chroma and hue values.

Example

use color_processing::Color;

let black_lch = Color::new_lch(0.0, 0.0, std::f64::NAN);
assert_eq!(black_lch.to_rgb_string(), "rgb(0, 0, 0)");
 
let white_lch = Color::new_lch(100.0, 0.0, std::f64::NAN);
assert_eq!(white_lch.to_rgb_string(), "rgb(255, 255, 255)");
 
let gray_lch = Color::new_lch(53.59, 0.0, std::f64::NAN);
assert_eq!(gray_lch.to_rgb_string(), "rgb(128, 128, 128)");
 
let red_lch = Color::new_lch(53.24, 104.55, 40.0);
assert_eq!(red_lch.to_rgb_string(), "rgb(255, 0, 0)");
 
let yellow_lch = Color::new_lch(97.14, 96.91, 102.85);
assert_eq!(yellow_lch.to_rgb_string(), "rgb(255, 255, 0)");
 
let green_lch = Color::new_lch(87.73, 119.78, 136.02);
assert_eq!(green_lch.to_rgb_string(), "rgb(0, 255, 0)");
 
let cyan_lch = Color::new_lch(91.11, 50.12, 196.38);
assert_eq!(cyan_lch.to_rgb_string(), "rgb(0, 255, 255)");
 
let blue_lch = Color::new_lch(32.3, 133.81, 306.28);
assert_eq!(blue_lch.to_rgb_string(), "rgb(0, 0, 255)");
 
let magenta_lch = Color::new_lch(60.32, 115.54, 328.23);
assert_eq!(magenta_lch.to_rgb_string(), "rgb(255, 0, 255)");

pub fn new_lcha(lightness: f64, chroma: f64, hue: f64, alpha: f64) -> Color[src]

Gets a new Color struct, that represents a color with the lightness, chroma, hue and alpha values.

Example

use color_processing::Color;

let black_lch = Color::new_lcha(0.0, 0.0, std::f64::NAN, 1.0);
assert_eq!(black_lch.to_rgb_string(), "rgb(0, 0, 0)");
 
let white_lch = Color::new_lcha(100.0, 0.0, std::f64::NAN, 0.0);
assert_eq!(white_lch.to_rgb_string(), "rgba(255, 255, 255, 0)");
 
let gray_lch = Color::new_lcha(53.59, 0.0, std::f64::NAN, 0.5);
assert_eq!(gray_lch.to_rgb_string(), "rgba(128, 128, 128, 0.5)");
 
let red_lch = Color::new_lcha(53.24, 104.55, 40.0, 0.5);
assert_eq!(red_lch.to_rgb_string(), "rgba(255, 0, 0, 0.5)");
 
let yellow_lch = Color::new_lcha(97.14, 96.91, 102.8, 1.0);
assert_eq!(yellow_lch.to_rgb_string(), "rgb(255, 255, 0)");
 
let green_lch = Color::new_lcha(87.73, 119.78, 136.02, 1.0);
assert_eq!(green_lch.to_rgb_string(), "rgb(0, 255, 0)");
 
let cyan_lch = Color::new_lcha(91.11, 50.12, 196.38, 1.0);
assert_eq!(cyan_lch.to_rgb_string(), "rgb(0, 255, 255)");
 
let blue_lch = Color::new_lcha(32.3, 133.81, 306.28, 1.0);
assert_eq!(blue_lch.to_rgb_string(), "rgb(0, 0, 255)");
 
let magenta_lch = Color::new_lcha(60.32, 115.54, 328.23, 1.0);
assert_eq!(magenta_lch.to_rgb_string(), "rgb(255, 0, 255)");

pub fn new_rgb(red: u8, green: u8, blue: u8) -> Color[src]

Gets a new Color struct, that represents a color with the given red, green and blue values.

  • The value range of red, green and blue is from 0 to 255.

Example

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);
assert_eq!(255, red.alpha);

pub fn new_rgba(red: u8, green: u8, blue: u8, alpha: u8) -> Color[src]

Gets a new Color struct, that represents a color with the given red, green, blue and alpha values.

  • The value range of red, green, blue and alpha (opacity) is from 0 to 255.

Example

use color_processing::Color;
 
let red = Color::new_rgba(255, 0, 0, 128);
 
assert_eq!(255, red.red);
assert_eq!(0, red.green);
assert_eq!(0, red.blue);
assert_eq!(128, red.alpha);

pub fn new_string(string: &str) -> Option<Color>[src]

Gets a new Option<Color>, that represents a color by a string.

Example (known color names)

use color_processing::Color;
 
let red = Color::new_string("red").unwrap();
 
assert_eq!(255, red.red);
assert_eq!(0, red.green);
assert_eq!(0, red.blue);
assert_eq!(255, red.alpha);

Example (abbreviated names)

use color_processing::Color;
 
let green = Color::new_string("GN").unwrap();
 
assert_eq!(0, green.red);
assert_eq!(128, green.green);
assert_eq!(0, green.blue);
assert_eq!(255, green.alpha);

Example (hex-notation)

use color_processing::Color;
 
let blue = Color::new_string("#0000ff").unwrap();
 
assert_eq!(0, blue.red);
assert_eq!(0, blue.green);
assert_eq!(255, blue.blue);
assert_eq!(255, blue.alpha);
 
let transparent_blue = Color::new_string("#0000ff80").unwrap();
 
assert_eq!(0, transparent_blue.red);
assert_eq!(0, transparent_blue.green);
assert_eq!(255, transparent_blue.blue);
assert_eq!(128, transparent_blue.alpha);
 
let yellow = Color::new_string("#ff0").unwrap();
 
assert_eq!(255, yellow.red);
assert_eq!(255, yellow.green);
assert_eq!(0, yellow.blue);
assert_eq!(255, yellow.alpha);
 
let transparent_yellow = Color::new_string("#ff07").unwrap();
 
assert_eq!(255, transparent_yellow.red);
assert_eq!(255, transparent_yellow.green);
assert_eq!(0, transparent_yellow.blue);
assert_eq!(119, transparent_yellow.alpha);

Example (rgb(a) notation)

use color_processing::Color;
 
let red = Color::new_string("rgb(255, 0, 0)").unwrap();
 
assert_eq!(255, red.red);
assert_eq!(0, red.green);
assert_eq!(0, red.blue);
assert_eq!(255, red.alpha);
 
let green = Color::new_string("rgb(0%, 100%, 0%)").unwrap();
 
assert_eq!(0, green.red);
assert_eq!(255, green.green);
assert_eq!(0, green.blue);
assert_eq!(255, green.alpha);
 
let blue = Color::new_string("rgba(0, 0, 255, 0.5)").unwrap();
 
assert_eq!(0, blue.red);
assert_eq!(0, blue.green);
assert_eq!(255, blue.blue);
assert_eq!(128, blue.alpha);
 
let yellow = Color::new_string("rgba(100%, 100%, 0%, 0.5)").unwrap();
 
assert_eq!(255, yellow.red);
assert_eq!(255, yellow.green);
assert_eq!(0, yellow.blue);
assert_eq!(128, yellow.alpha);

Example (gray notation)

use color_processing::Color;
 
let gray = Color::new_string("gray(128)").unwrap();
assert_eq!(128, gray.red);
assert_eq!(128, gray.green);
assert_eq!(128, gray.blue);
assert_eq!(255, gray.alpha);
 
let gray = Color::new_string("gray(50%)").unwrap();
assert_eq!(128, gray.red);
assert_eq!(128, gray.green);
assert_eq!(128, gray.blue);
assert_eq!(255, gray.alpha);
 
let transparent_light_gray = Color::new_string("gray(50, 0.75)").unwrap();
assert_eq!(50, transparent_light_gray.red);
assert_eq!(50, transparent_light_gray.green);
assert_eq!(50, transparent_light_gray.blue);
assert_eq!(191, transparent_light_gray.alpha);
 
let transparent_dark_gray = Color::new_string("gray(200, 50%)").unwrap();
assert_eq!(200, transparent_dark_gray.red);
assert_eq!(200, transparent_dark_gray.green);
assert_eq!(200, transparent_dark_gray.blue);
assert_eq!(128, transparent_dark_gray.alpha);

Example (cmyk notation)

use color_processing::Color;
 
let red = Color::new_string("cmyk(0%, 100%, 100%, 0%)").unwrap();
 
assert_eq!(255, red.red);
assert_eq!(0, red.green);
assert_eq!(0, red.blue);
assert_eq!(255, red.alpha);

Example (hsl(a) notation)

use color_processing::Color;
 
let red = Color::new_string("hsl(0, 100%, 50%)").unwrap();
assert_eq!(red.red, 255);
assert_eq!(red.green, 0);
assert_eq!(red.blue, 0);
assert_eq!(red.alpha, 255);
 
let green = Color::new_string("hsl(120°, 100%, 50%)").unwrap();
assert_eq!(green.red, 0);
assert_eq!(green.green, 255);
assert_eq!(green.blue, 0);
assert_eq!(green.alpha, 255);
 
let transparent_green = Color::new_string("hsla(120°, 100%, 50%, 0.5)").unwrap();
assert_eq!(transparent_green.red, 0);
assert_eq!(transparent_green.green, 255);
assert_eq!(transparent_green.blue, 0);
assert_eq!(transparent_green.alpha, 128);

Example (hsv(a) notation)

use color_processing::Color;
 
let red = Color::new_string("hsv(0, 100%, 100%)").unwrap();
assert_eq!(red.red, 255);
assert_eq!(red.green, 0);
assert_eq!(red.blue, 0);
assert_eq!(red.alpha, 255);
 
let green = Color::new_string("hsv(120°, 100%, 100%)").unwrap();
assert_eq!(green.red, 0);
assert_eq!(green.green, 255);
assert_eq!(green.blue, 0);
assert_eq!(green.alpha, 255);
 
let transparent_green = Color::new_string("hsva(120°, 100%, 100%, 0.5)").unwrap();
assert_eq!(transparent_green.red, 0);
assert_eq!(transparent_green.green, 255);
assert_eq!(transparent_green.blue, 0);
assert_eq!(transparent_green.alpha, 128);

Example (hwb(a) notation)

use color_processing::Color;
 
let red = Color::new_string("hwb(0, 0%, 0%)").unwrap();
assert_eq!(red.red, 255);
assert_eq!(red.green, 0);
assert_eq!(red.blue, 0);
assert_eq!(red.alpha, 255);
 
let green = Color::new_string("hwb(120°, 0%, 0%)").unwrap();
assert_eq!(green.red, 0);
assert_eq!(green.green, 255);
assert_eq!(green.blue, 0);
assert_eq!(green.alpha, 255);
 
let transparent_green = Color::new_string("hwba(120°, 0%, 0%, 0.5)").unwrap();
assert_eq!(transparent_green.red, 0);
assert_eq!(transparent_green.green, 255);
assert_eq!(transparent_green.blue, 0);
assert_eq!(transparent_green.alpha, 128);

pub fn get_cmyk(&self) -> (f64, f64, f64, f64)[src]

Gets a cmyk tuple of the color.

This method returns a tuple of the cmyk-components (cyan, magenta, yellow, key) of the color.
The range of each component is from 0.0 to 1.0, representing the intensity from 0% to 100%.

Example

use color_processing::Color;
 
let red = Color::new_string("red").unwrap();
let red_cmyk = red.get_cmyk();
 
assert_eq!(0.0, red_cmyk.0);
assert_eq!(1.0, red_cmyk.1);
assert_eq!(1.0, red_cmyk.2);
assert_eq!(0.0, red_cmyk.3);

pub fn get_hsla(&self) -> (f64, f64, f64, f64)[src]

Gets a hsla tuple of the color.

This method returns a tuple of hue, saturation, lightness and alpha of the color.
The range for hue goes from 0.0 to 360.0 degrees.
The range for saturation, lightness and alpha goes from 0.0 to 1.0, representing the intensity from 0% to 100%.

Example

use color_processing::Color;
 
let transparent_green = Color::new_string("rgba(0, 255, 0, 0.5)").unwrap();
let transparent_green_hsla = transparent_green.get_hsla();
 
assert_eq!(120.0, transparent_green_hsla.0);
assert_eq!(1.0, transparent_green_hsla.1);
assert_eq!(0.5, transparent_green_hsla.2);
assert_eq!(0.5, transparent_green_hsla.3);

pub fn get_hsva(&self) -> (f64, f64, f64, f64)[src]

Gets a hsva tuple of the color.

This method returns a tuple of hue, saturation, value and alpha of the color.
The range for hue goes from 0.0 to 360.0 degrees.
The range for saturation, value and alpha goes from 0.0 to 1.0, representing the intensity from 0% to 100%.

Example

use color_processing::Color;
 
let transparent_green = Color::new_string("rgba(0, 255, 0, 0.5)").unwrap();
let transparent_green_hsva = transparent_green.get_hsva();
 
assert_eq!(120.0, transparent_green_hsva.0);
assert_eq!(1.0, transparent_green_hsva.1);
assert_eq!(1.0, transparent_green_hsva.2);
assert_eq!(0.5, transparent_green_hsva.3);

pub fn get_hwba(&self) -> (f64, f64, f64, f64)[src]

Gets a hwba tuple of the color.

This method returns a tuple of hue, whiteness, blackness and alpha of the color.
The range for hue goes from 0.0 to 360.0 degrees.
The range for whiteness, blackness and alpha goes from 0.0 to 1.0, representing the intensity from 0% to 100%.

Example

use color_processing::Color;
 
let transparent_green = Color::new_string("rgba(0, 255, 0, 0.5)").unwrap();
let transparent_green_hwba = transparent_green.get_hwba();
 
assert_eq!(120.0, transparent_green_hwba.0);
assert_eq!(0.0, transparent_green_hwba.1);
assert_eq!(0.0, transparent_green_hwba.2);
assert_eq!(0.5, transparent_green_hwba.3);

pub fn get_rgba(&self) -> (f64, f64, f64, f64)[src]

Gets a rgba tuple of the color.

This method returns a tuple of red, green, blue and alpha of the color.
The range for red, green, blue and alpha goes from 0.0 to 1.0, representing the intensity from 0% to 100%.

Example

use color_processing::Color;
 
let transparent_green = Color::new_string("rgba(0, 255, 0, 0.5)").unwrap();
let transparent_green_rgba = transparent_green.get_rgba();
 
assert_eq!(0.0, transparent_green_rgba.0);
assert_eq!(1.0, transparent_green_rgba.1);
assert_eq!(0.0, transparent_green_rgba.2);
assert_eq!(0.5, transparent_green_rgba.3);

pub fn get_laba(&self) -> (f64, f64, f64, f64)[src]

Gets a laba tuple of the color.

This method returns a tuple of lightness, a, b and alpha of the color.

Example

use color_processing::Color;
 
let transparent_green = Color::new_string("rgba(0, 255, 0, 0.5)").unwrap();
let transparent_green_laba = transparent_green.get_laba();
 
assert_eq!(87.73, transparent_green_laba.0);
assert_eq!(-86.18, transparent_green_laba.1);
assert_eq!(83.18, transparent_green_laba.2);
assert_eq!(0.5, transparent_green_laba.3);

pub fn get_lcha(&self) -> (f64, f64, f64, f64)[src]

Gets a laba tuple of the color.

This method returns a tuple of lightness, chroma, hue and alpha of the color.

Example

use color_processing::Color;
 
let transparent_green = Color::new_string("rgba(0, 255, 0, 0.5)").unwrap();
let transparent_green_lcha = transparent_green.get_lcha();
 
assert_eq!(87.73, transparent_green_lcha.0);
assert_eq!(119.77, transparent_green_lcha.1);
assert_eq!(136.01, transparent_green_lcha.2);
assert_eq!(0.5, transparent_green_lcha.3);

pub fn colorize(&self, color: Color) -> Color[src]

Colorizes this color with another color.

Example

use color_processing::Color;
 
let white = Color::new_string("white").unwrap();
let black = Color::new_string("black").unwrap();
let red = Color::new_string("red").unwrap();
let colorized_red_over_white = white.colorize(red);
let colorized_red_over_black = black.colorize(red);
 
assert_eq!("#FF0000", colorized_red_over_white.to_hex_string());
assert_eq!("#000000", colorized_red_over_black.to_hex_string());

pub fn colorize_string(&self, color: &str) -> Result<Color, &str>[src]

Colorizes this color with another color.

Example

use color_processing::Color;
 
let white = Color::new_string("white").unwrap();
let black = Color::new_string("black").unwrap();
let colorized_red_over_white = white.colorize_string("red").unwrap();
let colorized_red_over_black = black.colorize_string("red").unwrap();
 
assert_eq!("#FF0000", colorized_red_over_white.to_hex_string());
assert_eq!("#000000", colorized_red_over_black.to_hex_string());

pub fn brighten(&self, amount: f64) -> Color[src]

Gets a brightened color by a specified amount.

Example

use color_processing::Color;
 
let red = Color::new_string("#ff0000").unwrap();
let red_brightened_1 = red.brighten(1.0);
let red_brightened_10 = red.brighten(10.0);
 
assert_eq!(red_brightened_1.to_hex_string(), "#FF5A36");
assert_eq!(red_brightened_10.to_hex_string(), "#FFFFFF");

pub fn darken(&self, amount: f64) -> Color[src]

Gets a darkened color by a specified amount.

Example

use color_processing::Color;
 
let red = Color::new_string("#ff0000").unwrap();
let red_darkened_1 = red.darken(1.0);
let red_darkened_10 = red.darken(10.0);
 
assert_eq!(red_darkened_1.to_hex_string(), "#C20000");
assert_eq!(red_darkened_10.to_hex_string(), "#000000");

pub fn grayscale(&self) -> Color[src]

Gets a grayscaled color from the color.

This method uses the default formula used by PAL and NTSC systems.
Y = 0.299 * R + 0.587 * G + 0.114 * B

Example

use color_processing::Color;
 
let red = Color::new_string("rgb(255, 0, 0)").unwrap();
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!(255, grayscaled_red.alpha);

pub fn grayscale_hdtv(&self) -> Color[src]

Gets a grayscaled color from the color.

This method uses the default formula used by HDTV systems.
Y = 0.2126 * R + 0.7152 * G + 0.0722 * B

Example

use color_processing::Color;
 
let red = Color::new_string("rgb(255, 0, 0)").unwrap();
let grayscaled_red = red.grayscale_hdtv();
 
assert_eq!(54, grayscaled_red.red);
assert_eq!(54, grayscaled_red.green);
assert_eq!(54, grayscaled_red.blue);
assert_eq!(255, grayscaled_red.alpha);

pub fn grayscale_hdr(&self) -> Color[src]

Gets a grayscaled color from the color.

This method uses the default formula used by HDTV systems.
Y = 0.2627 * R + 0.678 * G + 0.0593 * B

Example

use color_processing::Color;
 
let red = Color::new_string("rgb(255, 0, 0)").unwrap();
let grayscaled_red = red.grayscale_hdr();
 
assert_eq!(67, grayscaled_red.red);
assert_eq!(67, grayscaled_red.green);
assert_eq!(67, grayscaled_red.blue);
assert_eq!(255, grayscaled_red.alpha);

pub fn monochrome(&self) -> Color[src]

Gets a monochromed (black or white) color from the color.

Example

use color_processing::Color;
 
let darker_gray = Color::new_string("rgb(100, 100, 100)").unwrap();
let lighter_gray = Color::new_string("rgb(200, 200, 200)").unwrap();
let black = darker_gray.monochrome();
let white = lighter_gray.monochrome();
 
assert_eq!(0, black.red);
assert_eq!(0, black.green);
assert_eq!(0, black.blue);
assert_eq!(255, black.alpha);
 
assert_eq!(255, white.red);
assert_eq!(255, white.green);
assert_eq!(255, white.blue);
assert_eq!(255, white.alpha);

pub fn invert(&self) -> Color[src]

Gets the inverted color of a color.

Example

use color_processing::Color;
 
let black = Color::new_string("#000000").unwrap();
let black_inverted = black.invert();
 
assert_eq!("#FFFFFF", black_inverted.to_hex_string());

pub fn invert_luminescence(&self) -> Color[src]

Gets the inverted luminescenced color of a color.

Example

use color_processing::Color;
 
let dark_green = Color::new_hsla(120.0, 1.0, 0.3, 1.0);
let light_green = dark_green.invert_luminescence();
 
assert_eq!("#009900", dark_green.to_hex_string());
assert_eq!("#66FF66", light_green.to_hex_string());

pub fn to_cmyk_string(&self) -> String[src]

Gets a formatted cmyk String of the color as used in css.

Example

use color_processing::Color;
 
let red = Color::new_string("red").unwrap();
 
assert_eq!("cmyk(0%, 100%, 100%, 0%)", red.to_cmyk_string());

pub fn to_gray_string(&self) -> String[src]

Gets a formatted hex String of the color as used in css.

Example

use color_processing::Color;
 
let red = Color::new_string("red").unwrap();
 
assert_eq!("gray(76)", red.to_gray_string());

pub fn to_hex_string(&self) -> String[src]

Gets a formatted hex String of the color as used in css.

Example

use color_processing::Color;
 
let red = Color::new_string("red").unwrap();
let transparent_green = Color::new_string("rgba(0, 255, 0, 0.5)").unwrap();
 
assert_eq!("#FF0000", red.to_hex_string());
assert_eq!("#00FF0080", transparent_green.to_hex_string());

pub fn to_hsl_string(&self) -> String[src]

Gets a formatted hsl String of the color as used in css.

Example

use color_processing::Color;
 
let red = Color::new_string("red").unwrap();
let transparent_green = Color::new_string("rgba(0, 255, 0, 0.5)").unwrap();
 
assert_eq!("hsl(0, 100%, 50%)", red.to_hsl_string());
assert_eq!("hsla(120, 100%, 50%, 0.5)", transparent_green.to_hsl_string());

pub fn to_hsv_string(&self) -> String[src]

Gets a formatted hsv String of the color as used in css.

Example

use color_processing::Color;
 
let red = Color::new_string("red").unwrap();
let transparent_green = Color::new_string("rgba(0, 255, 0, 0.5)").unwrap();
 
assert_eq!("hsv(0, 100%, 100%)", red.to_hsv_string());
assert_eq!("hsva(120, 100%, 100%, 0.5)", transparent_green.to_hsv_string());

pub fn to_hwb_string(&self) -> String[src]

Gets a formatted hwb String of the color as used in css.

Example

use color_processing::Color;
 
let red = Color::new_string("red").unwrap();
let transparent_green = Color::new_string("rgba(0, 255, 0, 0.5)").unwrap();
 
assert_eq!("hwb(0, 0%, 0%)", red.to_hwb_string());
assert_eq!("hwba(120, 0%, 0%, 0.5)", transparent_green.to_hwb_string());

pub fn to_rgb_string(&self) -> String[src]

Gets a formatted rgb String of the color as used in css.

Example

use color_processing::Color;
 
let red = Color::new_string("red").unwrap();
let transparent_green = Color::new_string("rgba(0, 255, 0, 0.5)").unwrap();
 
assert_eq!("rgb(255, 0, 0)", red.to_rgb_string());
assert_eq!("rgba(0, 255, 0, 0.5)", transparent_green.to_rgb_string());

pub fn interpolate(&self, color: Color, interpolation: f64) -> Color[src]

Gets an interpolated Color-struct from the current to the final color by an interpolation factor. The interpolation is made by the rgb values.

Example

use color_processing::Color;
 
let white = Color::new_string("white").unwrap();
let black = Color::new_string("black").unwrap();
let gray = white.interpolate(black, 0.5);
 
assert_eq!("rgb(128, 128, 128)", gray.to_rgb_string());

pub fn interpolate_hsv(&self, color: Color, interpolation: f64) -> Color[src]

Gets an interpolated Color-struct from the current to the final color by an interpolation factor. The interpolation is made by the hsv values.

Example

use color_processing::Color;
 
let white = Color::new_string("white").unwrap();
let black = Color::new_string("black").unwrap();
let gray = white.interpolate_hsv(black, 0.5);
 
assert_eq!("rgb(128, 128, 128)", gray.to_rgb_string());

pub fn interpolate_hsl(&self, color: Color, interpolation: f64) -> Color[src]

Gets an interpolated Color-struct from the current to the final color by an interpolation factor. The interpolation is made by the hsl values.

Example

use color_processing::Color;
 
let white = Color::new_string("white").unwrap();
let black = Color::new_string("black").unwrap();
let gray = white.interpolate_hsl(black, 0.5);
 
assert_eq!("rgb(128, 128, 128)", gray.to_rgb_string());

pub fn interpolate_hwb(&self, color: Color, interpolation: f64) -> Color[src]

Gets an interpolated Color-struct from the current to the final color by an interpolation factor. The interpolation is made by the hwb values.

Example

use color_processing::Color;
 
let white = Color::new_string("white").unwrap();
let black = Color::new_string("black").unwrap();
let gray = white.interpolate_hwb(black, 0.5);
 
assert_eq!("rgb(128, 128, 128)", gray.to_rgb_string());

pub fn interpolate_lch(&self, color: Color, interpolation: f64) -> Color[src]

Gets an interpolated Color-struct from the current to the final color by an interpolation factor. The interpolation is made by the lch values.

Example

use color_processing::Color;
 
let white = Color::new_string("white").unwrap();
let black = Color::new_string("black").unwrap();
let gray = white.interpolate_lch(black, 0.5);
 
assert_eq!("rgb(119, 119, 119)", gray.to_rgb_string());

Trait Implementations

impl Clone for Color[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Copy for Color[src]

impl FromStr for Color[src]

type Err = &'static str

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Self, Self::Err>[src]

Parses a string into a Color-struct.

Example

use color_processing::Color;
 
let red: Color = "red".parse().unwrap();
 
assert_eq!(255, red.red);
assert_eq!(0, red.green);
assert_eq!(0, red.blue);
assert_eq!(255, red.alpha);
 
// alternative:
let green = "green".parse::<Color>().unwrap();
 
assert_eq!(0, green.red);
assert_eq!(128, green.green);
assert_eq!(0, green.blue);
assert_eq!(255, green.alpha);

Auto Trait Implementations

impl Send for Color

impl Sync for Color

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]