Enum piet::Color[][src]

#[non_exhaustive]
pub enum Color {
    // some variants omitted
}
Expand description

A datatype representing color.

Currently this is only a 32 bit RGBA value, but it will likely extend to some form of wide-gamut colorspace, and in the meantime is useful for giving programs proper type.

Implementations

Create a color from 8 bit per sample RGB values.

Create a color from 8 bit per sample RGBA values.

Create a color from a 32-bit rgba value (alpha as least significant byte).

Attempt to create a color from a CSS-style hex string.

This will accept strings in the following formats, with or without the leading #:

  • rrggbb
  • rrggbbaa
  • rbg
  • rbga

This method returns a ColorParseError if the color cannot be parsed.

Create a color from a grey value.

use piet::Color;

let grey_val = 0x55;

let one = Color::grey8(grey_val);
// is shorthand for
let two = Color::rgb8(grey_val, grey_val, grey_val);

assert_eq!(one.as_rgba_u32(), two.as_rgba_u32());

Create a color with a grey value in the range 0.0..=1.0.

Create a color from four floating point values, each in the range 0.0 to 1.0.

The interpretation is the same as rgba32, and no greater precision is (currently) assumed.

Create a color from three floating point values, each in the range 0.0 to 1.0.

The interpretation is the same as rgb8, and no greater precision is (currently) assumed.

Create a color from a CIEL*a*b* polar (also known as CIE HCL) specification.

The h parameter is an angle in degrees, with 0 roughly magenta, 90 roughly yellow, 180 roughly cyan, and 270 roughly blue. The l parameter is perceptual luminance, with 0 black and 100 white. The c parameter is a chrominance concentration, with 0 grayscale and a nominal maximum of 127 (in the future, higher values might be useful, for high gamut contexts).

Currently this is just converted into sRGB, but in the future as we support high-gamut colorspaces, it can be used to specify more colors or existing colors with a higher accuracy.

Currently out-of-gamut values are clipped to the nearest sRGB color, which is perhaps not ideal (the clipping might change the hue). See https://github.com/d3/d3-color/issues/33 for discussion.

Create a color from a CIEL*a*b* polar specification and alpha.

The a value represents alpha in the range 0.0 to 1.0.

Change just the alpha value of a color.

The a value represents alpha in the range 0.0 to 1.0.

Convert a color value to a 32-bit rgba value.

Convert a color value to four 8-bit rgba values.

Convert a color value to four f64 values, each in the range 0.0 to 1.0.

Opaque aqua (or cyan).

Opaque black.

Opaque blue.

Opaque fuchsia (or magenta).

Opaque gray.

Opaque green.

Opaque lime.

Opaque maroon.

Opaque navy.

Opaque olive.

Opaque purple.

Opaque red.

Opaque silver.

Opaque teal.

Fully transparent

Opaque white.

Opaque yellow.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

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

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.