Skip to main content

gamut_icc/
header.rs

1//! The 128-byte ICC profile header.
2
3/// The fixed 128-byte header that opens every ICC profile (ICC.1:2022 §7.2).
4///
5/// The header records the profile's size, the device/connection color spaces it relates, the
6/// profile version, the default rendering intent, and an MD5 identifier. Only the most
7/// load-bearing fields are modelled here; the reserved and date/platform fields are added in the
8/// implementation phase.
9pub struct ProfileHeader {
10    /// Total profile size in bytes (`size` field).
11    pub size: u32,
12    /// Preferred CMM signature (e.g. `'appl'`, `'lcms'`), or zero.
13    pub preferred_cmm: u32,
14    /// Profile format version (the `major.minor.bugfix` of the spec it conforms to).
15    pub version: ProfileVersion,
16    /// What kind of device or transform the profile describes.
17    pub device_class: DeviceClass,
18    /// The device color space the profile's data side uses (the `A` side).
19    pub data_color_space: ColorSpace,
20    /// The profile connection space (the `B` side) — always `XYZ` or `Lab`.
21    pub pcs: ColorSpace,
22    /// The default rendering intent.
23    pub rendering_intent: RenderingIntent,
24    /// Profile creator signature, or zero.
25    pub creator: u32,
26    /// The 16-byte profile ID (an MD5 of the profile with certain fields zeroed), or all-zero if
27    /// unset.
28    pub profile_id: [u8; 16],
29}
30
31/// An ICC profile format version, e.g. 4.4.0 or 2.4.0.
32pub struct ProfileVersion {
33    /// Major version (`2` or `4` in practice).
34    pub major: u8,
35    /// Minor version (the high nibble of the second version byte).
36    pub minor: u8,
37    /// Bug-fix version (the low nibble of the second version byte).
38    pub bugfix: u8,
39}
40
41/// The profile/device class, stored in the header's `deviceClass` field (ICC.1:2022 §7.2.5).
42pub enum DeviceClass {
43    /// `'scnr'` — input device (scanner, camera).
44    Input,
45    /// `'mntr'` — display device (monitor).
46    Display,
47    /// `'prtr'` — output device (printer).
48    Output,
49    /// `'link'` — a device link (a fused device-to-device transform).
50    DeviceLink,
51    /// `'spac'` — a color-space conversion profile.
52    ColorSpace,
53    /// `'abst'` — an abstract profile (color-space to color-space, not device-bound).
54    Abstract,
55    /// `'nmcl'` — a named-color profile.
56    NamedColor,
57}
58
59/// A color space signature, used for both the data color space and the profile connection space
60/// (ICC.1:2022 §7.2.6–7.2.7). Only the common spaces are listed; the multi-channel `nCLR` spaces
61/// are added in the implementation phase.
62pub enum ColorSpace {
63    /// `'XYZ '` — CIE XYZ (a valid PCS).
64    Xyz,
65    /// `'Lab '` — CIE L\*a\*b\* (a valid PCS).
66    Lab,
67    /// `'Luv '` — CIE L\*u\*v\*.
68    Luv,
69    /// `'YCbr'` — YCbCr.
70    YCbCr,
71    /// `'Yxy '` — CIE Yxy.
72    Yxy,
73    /// `'RGB '` — RGB.
74    Rgb,
75    /// `'GRAY'` — grayscale.
76    Gray,
77    /// `'HSV '` — HSV.
78    Hsv,
79    /// `'HLS '` — HLS.
80    Hls,
81    /// `'CMYK'` — CMYK.
82    Cmyk,
83    /// `'CMY '` — CMY.
84    Cmy,
85}
86
87/// The rendering intent, stored in the header's `renderingIntent` field (ICC.1:2022 §7.2.15).
88pub enum RenderingIntent {
89    /// `0` — perceptual.
90    Perceptual,
91    /// `1` — media-relative colorimetric.
92    MediaRelativeColorimetric,
93    /// `2` — saturation.
94    Saturation,
95    /// `3` — ICC-absolute colorimetric.
96    IccAbsoluteColorimetric,
97}