Struct lab::Lab[][src]

pub struct Lab {
    pub l: f32,
    pub a: f32,
    pub b: f32,
}
Expand description

Struct representing a color in CIALab, a.k.a. L*a*b*, color space

Fields

l: f32a: f32b: f32

Implementations

Constructs a new Lab from a three-element array of u8s

Examples

let lab = lab::Lab::from_rgb(&[240, 33, 95]);
assert_eq!(lab::Lab { l: 52.334686, a: 75.55157, b: 19.995684 }, lab);

Constructs a new Lab from a four-element array of u8s

The Lab struct does not store alpha channel information, so the last u8 representing alpha is discarded. This convenience method exists in order to easily measure colors already stored in an RGBA array.

Examples

let lab = lab::Lab::from_rgba(&[240, 33, 95, 255]);
assert_eq!(lab::Lab { l: 52.334686, a: 75.55157, b: 19.995684 }, lab);

Returns the Lab’s color in RGB, in a 3-element array.

Examples

let lab = lab::Lab { l: 52.330193, a: 75.56704, b: 19.989174 };
let rgb = lab.to_rgb();
assert_eq!([240, 33, 95], rgb);

Measures the perceptual distance between the colors of one Lab and an other.

Examples

let pink = Lab { l: 66.6348, a: 52.260696, b: 14.850557 };
let websafe_pink = Lab { l: 64.2116, a: 62.519463, b: 2.8871894 };
assert_eq!(254.23636, pink.squared_distance(&websafe_pink));

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

Returns the “default value” for a type. 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.