colr-types 0.3.1

Color model ZSTs and marker traits for colr.
Documentation
#![no_std]
#![warn(missing_docs)]

//! Color model ZSTs, marker traits, and type aliases for colr.

#[cfg(feature = "std")]
extern crate std;

pub mod chromatic_adaptation;
pub mod decode;
pub mod device;
pub mod encode;
pub mod illuminant;
pub mod layout;
pub mod math;
pub mod model;
pub mod observer;
pub mod primaries;
pub mod tonemap;
pub mod transfer;

pub use model::{LCh, Lab, Oklab, Oklch, Xyz};

/// sRGB color space per IEC 61966-2-1:1999. Layout defaults to `Rgba`.
pub type Srgb<L = layout::Rgba> = model::Rgb<primaries::Srgb, transfer::Srgb, L>;
/// Linear-light sRGB. Layout defaults to `Rgba`.
pub type LinearSrgb<L = layout::Rgba> = model::Rgb<primaries::Srgb, transfer::Linear, L>;
/// Rec. 709 color space per ITU-R BT.709-6. Layout defaults to `Rgba`.
pub type Rec709<L = layout::Rgba> = model::Rgb<primaries::Srgb, transfer::Rec709, L>;
/// Display P3 with sRGB transfer function. Layout defaults to `Rgba`.
pub type DisplayP3<L = layout::Rgba> = model::Rgb<primaries::P3, transfer::Srgb, L>;
/// Linear-light Display P3. Layout defaults to `Rgba`.
pub type LinearP3<L = layout::Rgba> = model::Rgb<primaries::P3, transfer::Linear, L>;
/// Rec. 2020 with PQ transfer function for HDR10. Layout defaults to `Rgba`.
pub type Hdr10<L = layout::Rgba> = model::Rgb<primaries::Rec2020, transfer::Pq, L>;
/// Rec. 2020 with HLG transfer function. Layout defaults to `Rgba`.
pub type Hlg<L = layout::Rgba> = model::Rgb<primaries::Rec2020, transfer::Hlg, L>;
/// Linear-light Rec. 2020. Layout defaults to `Rgba`.
pub type LinearRec2020<L = layout::Rgba> = model::Rgb<primaries::Rec2020, transfer::Linear, L>;
/// ACEScg working space, linear AP1 under the ACES white point. Layout defaults to `Rgba`.
pub type AcesCg<L = layout::Rgba> = model::Rgb<primaries::AcesAp1, transfer::Linear, L>;
/// ACES 2065-1 archival space, linear AP0 under the ACES white point. Layout defaults to `Rgba`.
pub type Aces2065<L = layout::Rgba> = model::Rgb<primaries::AcesAp0, transfer::Linear, L>;
/// ACEScc logarithmic encoding of AP1. Layout defaults to `Rgba`.
pub type AcesCc<L = layout::Rgba> = model::Rgb<primaries::AcesAp1, transfer::AcesCc, L>;
/// ACEScct quasi-logarithmic encoding of AP1. Layout defaults to `Rgba`.
pub type AcesCct<L = layout::Rgba> = model::Rgb<primaries::AcesAp1, transfer::AcesCct, L>;
/// ProPhoto ROMM RGB. Layout defaults to `Rgba`.
pub type ProPhoto<L = layout::Rgba> = model::Rgb<primaries::ProPhoto, transfer::ProPhoto, L>;
/// Linear-light ProPhoto. Layout defaults to `Rgba`.
pub type LinearProPhoto<L = layout::Rgba> = model::Rgb<primaries::ProPhoto, transfer::Linear, L>;
/// DCI-P3 for theatrical projection. Layout defaults to `Rgba`.
pub type DciP3<L = layout::Rgba> = model::Rgb<primaries::DciP3, transfer::DciP3, L>;

/// A marker trait which implies `S` can act as storage for a model.
///
/// A model or layout implements `BackingStore<S>` for each raw type S it can
/// be carried by. This is the sole gate on `Color<S, M>` construction.
pub trait BackingStore<S> {}

/// Marks how the alpha channel relates to the color channels.
pub trait AlphaState: 'static {}

/// Alpha channel is independent of the color channels.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Straight;

/// Color channels have been multiplied by alpha.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Premultiplied;

impl AlphaState for Straight {}
impl AlphaState for Premultiplied {}

/// Maps all N channels to their storage indices.
///
/// INDICES contains the storage position of each logical channel in logical order.
/// For RGB layouts the first three are R, G, B. For perceptual spaces with an
/// OFFSET the color channels begin at `OFFSET` and alpha occupies the remaining slot.
pub trait ChannelMap<const N: usize>: 'static {
    /// BackingStore positions of all N channels in logical order.
    const INDICES: [usize; N];
}