phaneron_plugin/
colour.rs

1//! This module contains colour space transformation definitions.
2//! Some built-in colour spaces are provided, but custom spaces may be
3//! defined using the [`ColourSpec`] struct.
4
5use abi_stable::StableAbi;
6
7pub use self::{
8    bt_2020::COLOUR_SPEC_BT_2020, bt_601_525::COLOUR_SPEC_BT_601_525,
9    bt_601_625::COLOUR_SPEC_BT_601_625, bt_709::COLOUR_SPEC_BT_709, srgb::COLOUR_SPEC_SRGB,
10};
11
12mod bt_2020;
13mod bt_601_525;
14mod bt_601_625;
15mod bt_709;
16mod srgb;
17
18/// Built-in colour space definitions.
19#[repr(C)]
20#[derive(Debug, Clone, PartialEq, Eq, Hash, StableAbi)]
21pub enum ColourSpace {
22    #[allow(non_camel_case_types)]
23    sRGB,
24    #[allow(non_camel_case_types)]
25    BT_601_625,
26    #[allow(non_camel_case_types)]
27    BT_601_525,
28    #[allow(non_camel_case_types)]
29    BT_709,
30    #[allow(non_camel_case_types)]
31    BT_2020,
32}
33
34/// Defines the transformation function for a colourspace.
35/// May be used to define custom colour spaces.
36#[repr(C)]
37#[derive(StableAbi)]
38#[allow(non_snake_case)]
39pub struct ColourSpec {
40    pub kR: f32,
41    pub kB: f32,
42    pub rx: f32,
43    pub ry: f32,
44    pub gx: f32,
45    pub gy: f32,
46    pub bx: f32,
47    pub by: f32,
48    pub wx: f32,
49    pub wy: f32,
50    pub alpha: f32,
51    pub beta: f32,
52    pub gamma: f32,
53    pub delta: f32,
54}
55
56impl ColourSpace {
57    pub fn colour_spec(&self) -> ColourSpec {
58        match self {
59            ColourSpace::BT_2020 => COLOUR_SPEC_BT_2020,
60            ColourSpace::BT_601_525 => COLOUR_SPEC_BT_601_525,
61            ColourSpace::BT_601_625 => COLOUR_SPEC_BT_601_625,
62            ColourSpace::BT_709 => COLOUR_SPEC_BT_709,
63            ColourSpace::sRGB => COLOUR_SPEC_SRGB,
64        }
65    }
66}