devela/media/color/rgb/
definitions.rs

1// devela::media::color::rgb::definitions
2//
3//! Defines the [`Rgb`] and [`Rgba`] types.
4//
5
6/// RGB color with 3 components.
7#[repr(C)]
8#[must_use]
9#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
10pub struct Rgb<T, const LINEAR: bool = false> {
11    /// Color channels in order: [red, green, blue].
12    ///
13    /// - **Red/Green/Blue**: Gamma-encoded luminosity (0..=255).
14    pub c: [T; 3],
15}
16/// RGB+A color with 4 components.
17#[repr(C)]
18#[must_use]
19#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
20pub struct Rgba<T, const LINEAR: bool = false, const PREMUL: bool = false> {
21    /// Color channels in order: [red, green, blue, alpha].
22    ///
23    /// - **Red/Green/Blue**: Gamma-encoded luminosity (0..=255).
24    /// - **Alpha**: Linear opacity (0 = transparent, 255 = opaque).
25    pub c: [T; 4],
26}
27
28/* aliases */
29
30/// RGB color with 8-bit integer components (sRGB gamma space).
31pub type Rgb8 = Rgb<u8>;
32/// RGB+A color with 8-bit integer components (sRGB gamma space, straight alpha).
33pub type Rgba8 = Rgba<u8>;
34/// RGB+A color with 8-bit integer components (sRGB gamma space, premultiplied alpha).
35pub type RgbaPre8 = Rgba<u8, false, true>;
36
37/// RGB color with 16-bit integer components (sRGB gamma space).
38pub type Rgb16 = Rgb<u16>;
39/// RGB+A color with 16-bit integer components (sRGB gamma space, straight alpha).
40pub type Rgba16 = Rgba<u16>;
41/// RGB+A color with 16-bit integer components (sRGB gamma space, premultiplied alpha).
42pub type RgbaPre16 = Rgba<u16, false, true>;
43
44#[cfg(feature = "_float_f32")]
45crate::items! {
46    /// RGB color with 32-bit float components (sRGB gamma space).
47    pub type RgbF32 = Rgb<f32>;
48    /// RGB+A color with 32-bit float components (sRGB gamma space, straight alpha).
49    pub type RgbaF32 = Rgba<f32>;
50    /// RGB+A color with 32-bit float components (sRGB gamma space, premultiplied alpha).
51    pub type RgbaPreF32 = Rgba<f32, false, true>;
52
53    /// RGB color with 32-bit float components (linear space).
54    pub type RgbLinF32 = Rgb<f32, true>;
55    /// RGB+A color with 32-bit float components (linear space, straight alpha).
56    pub type RgbaLinF32 = Rgba<f32, true>;
57    /// RGB+A color with 32-bit float components (linear space, premultiplied alpha).
58    pub type RgbaLinPreF32 = Rgba<f32, true, true>;
59}
60#[cfg(feature = "_float_f64")]
61crate::items! {
62    /// RGB color with 64-bit float components (sRGB gamma space).
63    pub type RgbF64 = Rgb<f64>;
64    /// RGB+A color with 64-bit float components (sRGB gamma space, straight alpha).
65    pub type RgbaF64 = Rgba<f64>;
66    /// RGB+A color with 64-bit float components (sRGB gamma space, premultiplied alpha).
67    pub type RgbaPreF64 = Rgba<f64, false, true>;
68
69    /// RGB color with 64-bit float components (linear space).
70    pub type RgbLinF64 = Rgb<f64, true>;
71    /// RGB+A color with 64-bit float components (linear space, straight alpha).
72    pub type RgbaLinF64 = Rgba<f64, true>;
73    /// RGB+A color with 64-bit float components (linear space, premultiplied alpha).
74    pub type RgbaLinPreF64 = Rgba<f64, true, true>;
75}