colr-types 0.3.0

Color model ZSTs and marker traits for colr.
Documentation
//! Oklab and Oklch color models.

use crate::{BackingStore, ChannelMap};

/// Oklab perceptual color space by Björn Ottosson, 2020.
///
/// Better hue linearity than CIELab. L is lightness [0, 1], a and b are
/// opponent axes. D65 adaptation is baked into the specification.
/// Adopted in CSS Color Level 4.
///
/// `OFFSET` is the storage index of the first color channel. `0` (default)
/// places color channels at [0, 1, 2] with alpha at 3. `1` places color
/// channels at [1, 2, 3] with alpha at 0, matching alpha-first texture layouts.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Oklab<const OFFSET: usize = 0>;

/// Oklch, the polar form of Oklab.
///
/// L is lightness [0, 1], C is chroma, h is hue angle in radians [0, 2pi).
///
/// `OFFSET` is the storage index of the first color channel. `0` (default)
/// places color channels at [0, 1, 2] with alpha at 3. `1` places color
/// channels at [1, 2, 3] with alpha at 0, matching alpha-first texture layouts.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Oklch<const OFFSET: usize = 0>;

impl<const OFFSET: usize> BackingStore<[f32; 3]> for Oklab<OFFSET> {}
impl<const OFFSET: usize> BackingStore<[f32; 4]> for Oklab<OFFSET> {}
impl<const OFFSET: usize> BackingStore<[f32; 3]> for Oklch<OFFSET> {}
impl<const OFFSET: usize> BackingStore<[f32; 4]> for Oklch<OFFSET> {}

impl<const OFFSET: usize> ChannelMap<4> for Oklab<OFFSET> {
    const INDICES: [usize; 4] = [OFFSET, OFFSET + 1, OFFSET + 2, 3 - OFFSET * 3];
}

impl<const OFFSET: usize> ChannelMap<4> for Oklch<OFFSET> {
    const INDICES: [usize; 4] = [OFFSET, OFFSET + 1, OFFSET + 2, 3 - OFFSET * 3];
}

#[cfg(feature = "glam")]
mod glam_impls {
    use super::*;
    impl<const OFFSET: usize> BackingStore<glam::Vec3> for Oklab<OFFSET> {}
    impl<const OFFSET: usize> BackingStore<glam::Vec3A> for Oklab<OFFSET> {}
    impl<const OFFSET: usize> BackingStore<glam::Vec4> for Oklab<OFFSET> {}
    impl<const OFFSET: usize> BackingStore<glam::Vec3> for Oklch<OFFSET> {}
    impl<const OFFSET: usize> BackingStore<glam::Vec3A> for Oklch<OFFSET> {}
    impl<const OFFSET: usize> BackingStore<glam::Vec4> for Oklch<OFFSET> {}
}