jpegxl_sys\color/
color_encoding.rs

1/*
2This file is part of jpegxl-sys.
3
4jpegxl-sys is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 3 of the License, or
7(at your option) any later version.
8
9jpegxl-sys is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with jpegxl-sys.  If not, see <https://www.gnu.org/licenses/>.
16*/
17
18//! Color Encoding definitions used by JPEG XL.
19//! All CIE units are for the standard 1931 2 degree observer.
20
21#[cfg(doc)]
22use crate::metadata::codestream_header::JxlBasicInfo;
23
24/// Color space of the image data.
25#[repr(C)]
26#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
27pub enum JxlColorSpace {
28    /// Tristimulus RGB
29    Rgb = 0,
30    /// Luminance based, the primaries in [`JxlColorEncoding`] must be ignored.
31    /// This value implies that [`JxlBasicInfo::num_color_channels`] is `1`, any
32    /// other value implies `num_color_channels` is `3`.
33    Gray,
34    /// XYB (opsin) color space
35    Xyb,
36    /// None of the other table entries describe the color space appropriately
37    Unknown,
38}
39
40/// Built-in white points for color encoding. When decoding, the numerical xy
41/// white point value can be read from the [`JxlColorEncoding::white_point`]
42/// field regardless of the enum value. When encoding, enum values except
43/// [`JxlWhitePoint::Custom`] override the numerical fields. Some enum values
44/// match a subset of CICP (Rec. ITU-T H.273 | ISO/IEC 23091-2:2019(E)), however
45/// the white point and RGB primaries are separate enums here.
46#[repr(C)]
47#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
48pub enum JxlWhitePoint {
49    /// CIE Standard Illuminant D65: 0.3127, 0.3290
50    D65 = 1,
51    /// White point must be read from the [`JxlColorEncoding::white_point`] field,
52    /// or as ICC profile. This enum value is not an exact match of the
53    /// corresponding CICP value.
54    Custom = 2,
55    /// CIE Standard Illuminant E (equal-energy): 1/3, 1/3
56    E = 10,
57    /// DCI-P3 from SMPTE RP 431-2: 0.314, 0.351
58    Dci = 11,
59}
60
61/// Built-in primaries for color encoding. When decoding, the primaries can be
62/// read from the [`JxlColorEncoding::primaries_red_xy`], [`JxlColorEncoding::primaries_green_xy`],
63/// and [`JxlColorEncoding::primaries_blue_xy`] fields regardless of the enum value. When encoding,
64/// the enum values except [`JxlPrimaries::Custom`] override the numerical fields. Some enum values
65/// match a subset of CICP (Rec. ITU-T H.273 | ISO/IEC 23091-2:2019(E)), however the white point
66/// and RGB primaries are separate enums here.
67#[repr(C)]
68#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
69pub enum JxlPrimaries {
70    /// The CIE xy values of the red, green and blue primaries are: 0.639998686,
71    /// 0.330010138; 0.300003784, 0.600003357; 0.150002046, 0.059997204
72    SRgb = 1,
73    /// Primaries must be read from the [`JxlColorEncoding::primaries_red_xy`],
74    /// [`JxlColorEncoding::primaries_green_xy`] and [`JxlColorEncoding::primaries_blue_xy`] fields,
75    /// or as ICC profile. This enum value is not an exact match of the corresponding CICP value.
76    Custom = 2,
77    /// As specified in Rec. ITU-R BT.2100-1
78    Rec2100 = 9,
79    /// As specified in SMPTE RP 431-2
80    P3 = 11,
81}
82
83/// Built-in transfer functions for color encoding. Enum values match a subset
84/// of CICP (Rec. ITU-T H.273 | ISO/IEC 23091-2:2019(E)) unless specified
85/// otherwise.
86#[repr(C)]
87#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
88pub enum JxlTransferFunction {
89    /// As specified in ITU-R BT.709-6
90    BT709 = 1,
91    /// None of the other table entries describe the transfer function.
92    Unknown = 2,
93    /// The gamma exponent is 1
94    Linear = 8,
95    /// As specified in IEC 61966-2-1 sRGB
96    SRGB = 13,
97    /// As specified in SMPTE ST 2084
98    PQ = 16,
99    /// As specified in SMPTE ST 428-1
100    DCI = 17,
101    /// As specified in Rec. ITU-R BT.2100-1
102    HLG = 18,
103    /// Transfer function follows power law given by the gamma value in [`JxlColorEncoding`].
104    /// Not a CICP value.
105    Gamma = 65535,
106}
107
108/// Rendering intent for color encoding, as specified in ISO 15076-1:2010
109#[repr(C)]
110#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
111pub enum JxlRenderingIntent {
112    /// vendor-specific
113    Perceptual = 0,
114    /// media-relative
115    Relative,
116    /// vendor-specific
117    Saturation,
118    /// ICC-absolute
119    Absolute,
120}
121
122/// Color encoding of the image as structured information.
123#[repr(C)]
124#[derive(Clone, Debug)]
125pub struct JxlColorEncoding {
126    /// Color space of the image data.
127    pub color_space: JxlColorSpace,
128
129    /// Built-in white point. If this value is [`JxlWhitePoint::Custom`], must
130    /// use the numerical white point values from [`Self::white_point_xy`].
131    pub white_point: JxlWhitePoint,
132
133    /// Numerical whitepoint values in CIE xy space.
134    pub white_point_xy: [f64; 2],
135
136    /// Built-in RGB primaries. If this value is [`JxlPrimaries::Custom`], must
137    /// use the numerical primaries values below. This field and the custom values
138    /// below are unused and must be ignored if the color space is
139    /// [`JxlColorSpace::Gray`] or [`JxlColorSpace::Xyb`].
140    pub primaries: JxlPrimaries,
141
142    /// Numerical red primary values in CIE xy space.
143    pub primaries_red_xy: [f64; 2],
144
145    /// Numerical green primary values in CIE xy space.
146    pub primaries_green_xy: [f64; 2],
147
148    /// Numerical blue primary values in CIE xy space.
149    pub primaries_blue_xy: [f64; 2],
150
151    /// Transfer function if `have_gamma` is 0.
152    pub transfer_function: JxlTransferFunction,
153
154    /// Gamma value used when [`Self::transfer_function`] is [`JxlTransferFunction::Gamma`].
155    pub gamma: f64,
156
157    /// Rendering intent defined for the color profile.
158    pub rendering_intent: JxlRenderingIntent,
159}