Skip to main content

ColorSpace

Enum ColorSpace 

Source
#[non_exhaustive]
pub enum ColorSpace { DeviceGray, DeviceRgb, DeviceCmyk, CalGray(Box<CalGray>), CalRgb(Box<CalRgb>), Lab(Box<Lab>), IccBased(Box<IccBased>), Indexed(Box<Indexed>), Separation(Box<Separation>), DeviceN(Box<DeviceN>), Pattern(Box<PatternSpace>), }
Expand description

A loaded colour space.

Cheap to clone: the heavy members — ICC profiles, tint transforms — are behind Arc, and palettes are boxed slices.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

DeviceGray

One component: a grey level.

§

DeviceRgb

Three components: red, green, blue.

§

DeviceCmyk

Four components: cyan, magenta, yellow, black.

§

CalGray(Box<CalGray>)

A calibrated grey space whose calibration is parsed and then ignored.

§

CalRgb(Box<CalRgb>)

A calibrated RGB space.

§

Lab(Box<Lab>)

A CIE 1976 L*a*b* space.

§

IccBased(Box<IccBased>)

A space defined by an embedded ICC profile.

§

Indexed(Box<Indexed>)

A palette over some base space.

§

Separation(Box<Separation>)

One colorant driving an alternate space through a tint transform.

§

DeviceN(Box<DeviceN>)

Several colorants driving an alternate space.

§

Pattern(Box<PatternSpace>)

Colour supplied by a pattern rather than by components.

Implementations§

Source§

impl ColorSpace

Source

pub fn family(&self) -> Family

Which family this is.

Source

pub fn n_components(&self) -> usize

How many components a colour in this space carries.

Separation and Indexed always report 1; ICCBased reports its /N rather than whatever the profile says; DeviceN reports its colorant count with no cap.

Source

pub fn is_special(&self) -> bool

Whether the space’s components are indices or tints rather than colour: Separation, DeviceN, Indexed, Pattern.

Several validation paths refuse a special space where a colour is required — a shading’s alternate, an ICCBased’s /Alternate.

Source

pub fn is_normal(&self) -> bool

Whether the space is a plain additive or subtractive colour space, which decides whether a soft mask may take its backdrop from it.

Source

pub fn to_rgb(&self, comps: &[f32]) -> Rgb

Convert components to RGB, taking the vector-fill path.

A space that cannot produce a colour for these components — an out of range Indexed entry, a /None Separation — paints black, which is what every caller of the C++’s GetRGBOrZerosOnError sees. Use Self::try_to_rgb when the distinction matters.

Source

pub fn try_to_rgb(&self, comps: &[f32]) -> Option<Rgb>

Convert components, distinguishing “black” from “no colour at all”.

Source

pub fn default_value(&self, index: usize) -> (f32, f32, f32)

The initial value and legal interval of component index.

The initial colour of a space is these values for each component: zero everywhere except Separation and DeviceN, which start at full colorant.

Source

pub fn default_color(&self) -> Vec<f32>

The space’s initial colour: one Self::default_value per component.

Source

pub fn translate_image_line( &self, dest: &mut [u8], samples: &[u8], pixels: usize, trans_mask: bool, )

Convert a run of image samples to B, G, R triples.

This is the bulk path, and it is not to_rgb in a loop for every family — see the module docs. samples holds pixels * n_components() bytes; dest receives pixels * 3.

trans_mask selects DeviceCMYK’s second formula, the one that is unreachable from the scalar path; every other family ignores it.

Trait Implementations§

Source§

impl Clone for ColorSpace

Source§

fn clone(&self) -> ColorSpace

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ColorSpace

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ColorSpace

Source§

fn eq(&self, other: &ColorSpace) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ColorSpace

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.