Skip to main content

colr_types/
lib.rs

1#![no_std]
2#![warn(missing_docs)]
3
4//! Color model ZSTs, marker traits, and type aliases for colr.
5
6#[cfg(feature = "std")]
7extern crate std;
8
9pub mod chromatic_adaptation;
10pub mod decode;
11pub mod device;
12pub mod encode;
13pub mod illuminant;
14pub mod layout;
15pub mod math;
16pub mod model;
17pub mod observer;
18pub mod primaries;
19pub mod tonemap;
20pub mod transfer;
21
22pub use model::{LCh, Lab, Oklab, Oklch, Xyz};
23
24/// sRGB color space per IEC 61966-2-1:1999. Layout defaults to `Rgba`.
25pub type Srgb<L = layout::Rgba> = model::Rgb<primaries::Srgb, transfer::Srgb, L>;
26/// Linear-light sRGB. Layout defaults to `Rgba`.
27pub type LinearSrgb<L = layout::Rgba> = model::Rgb<primaries::Srgb, transfer::Linear, L>;
28/// Rec. 709 color space per ITU-R BT.709-6. Layout defaults to `Rgba`.
29pub type Rec709<L = layout::Rgba> = model::Rgb<primaries::Srgb, transfer::Rec709, L>;
30/// Display P3 with sRGB transfer function. Layout defaults to `Rgba`.
31pub type DisplayP3<L = layout::Rgba> = model::Rgb<primaries::P3, transfer::Srgb, L>;
32/// Linear-light Display P3. Layout defaults to `Rgba`.
33pub type LinearP3<L = layout::Rgba> = model::Rgb<primaries::P3, transfer::Linear, L>;
34/// Rec. 2020 with PQ transfer function for HDR10. Layout defaults to `Rgba`.
35pub type Hdr10<L = layout::Rgba> = model::Rgb<primaries::Rec2020, transfer::Pq, L>;
36/// Rec. 2020 with HLG transfer function. Layout defaults to `Rgba`.
37pub type Hlg<L = layout::Rgba> = model::Rgb<primaries::Rec2020, transfer::Hlg, L>;
38/// Linear-light Rec. 2020. Layout defaults to `Rgba`.
39pub type LinearRec2020<L = layout::Rgba> = model::Rgb<primaries::Rec2020, transfer::Linear, L>;
40/// ACEScg working space, linear AP1 under the ACES white point. Layout defaults to `Rgba`.
41pub type AcesCg<L = layout::Rgba> = model::Rgb<primaries::AcesAp1, transfer::Linear, L>;
42/// ACES 2065-1 archival space, linear AP0 under the ACES white point. Layout defaults to `Rgba`.
43pub type Aces2065<L = layout::Rgba> = model::Rgb<primaries::AcesAp0, transfer::Linear, L>;
44/// ACEScc logarithmic encoding of AP1. Layout defaults to `Rgba`.
45pub type AcesCc<L = layout::Rgba> = model::Rgb<primaries::AcesAp1, transfer::AcesCc, L>;
46/// ACEScct quasi-logarithmic encoding of AP1. Layout defaults to `Rgba`.
47pub type AcesCct<L = layout::Rgba> = model::Rgb<primaries::AcesAp1, transfer::AcesCct, L>;
48/// ProPhoto ROMM RGB. Layout defaults to `Rgba`.
49pub type ProPhoto<L = layout::Rgba> = model::Rgb<primaries::ProPhoto, transfer::ProPhoto, L>;
50/// Linear-light ProPhoto. Layout defaults to `Rgba`.
51pub type LinearProPhoto<L = layout::Rgba> = model::Rgb<primaries::ProPhoto, transfer::Linear, L>;
52/// DCI-P3 for theatrical projection. Layout defaults to `Rgba`.
53pub type DciP3<L = layout::Rgba> = model::Rgb<primaries::DciP3, transfer::DciP3, L>;
54
55/// A marker trait which implies `S` can act as storage for a model.
56///
57/// A model or layout implements `BackingStore<S>` for each raw type S it can
58/// be carried by. This is the sole gate on `Color<S, M>` construction.
59pub trait BackingStore<S> {}
60
61/// Marks how the alpha channel relates to the color channels.
62pub trait AlphaState: 'static {}
63
64/// Alpha channel is independent of the color channels.
65#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
66pub struct Straight;
67
68/// Color channels have been multiplied by alpha.
69#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
70pub struct Premultiplied;
71
72impl AlphaState for Straight {}
73impl AlphaState for Premultiplied {}
74
75/// Maps all N channels to their storage indices.
76///
77/// INDICES contains the storage position of each logical channel in logical order.
78/// For RGB layouts the first three are R, G, B. For perceptual spaces with an
79/// OFFSET the color channels begin at `OFFSET` and alpha occupies the remaining slot.
80pub trait ChannelMap<const N: usize>: 'static {
81    /// BackingStore positions of all N channels in logical order.
82    const INDICES: [usize; N];
83}