1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//! Core gain map math for Ultra HDR.
//!
//! This crate provides the pure computational components for Ultra HDR:
//! - Pixel math for applying/computing gain maps
//! - Tone mapping (HDR → SDR)
//! - Color space conversions and transfer functions
//!
//! JPEG-container metadata (MPF, XMP, ISO 21496-1 APP2 envelope) previously
//! lived here in `ultrahdr_core::metadata`; it has moved to
//! `zenjpeg::container` (JPEG-specific parsing) and `zencodec::gainmap`
//! (codec-agnostic payload). See issue #8.
//!
//! This crate has **no JPEG codec dependency**. For full Ultra HDR encode/decode,
//! use the `ultrahdr` crate which provides codec integration.
//!
//! # Production HDR→SDR (audited)
//!
//! The 2026-06-22 audited shootout established `Bt2446A` as the
//! production-recommended HDR→SDR tone curve (wins mean ΔE2000 by 2-5× over
//! every channel-independent curve) and `CllMeasure::measure_max` as the
//! production-recommended peak measurement (wins 3 of 6 ranking criteria).
//! Both are exposed through `color::audited` / re-exported at the crate
//! root behind the `tonemap-bt2446a` Cargo feature:
//!
//! ```toml
//! ultrahdr-core = { version = "0.6", features = ["tonemap-bt2446a"] }
//! ```
//!
//! See `zen/zentone/benchmarks/shootout_2026-06-22_findings_v2.md` for the
//! full empirical citation.
//!
//! # no_std Support
//!
//! This crate is `no_std` compatible with alloc. Disable default features:
//! ```toml
//! ultrahdr-core = { version = "0.6", default-features = false }
//! ```
//!
//! # Cooperative Cancellation
//!
//! Long-running operations accept an `impl Stop` parameter from the `enough` crate
//! for cooperative cancellation. Use `Unstoppable` when cancellation is not needed.
//!
//! # Example — compute a gain map from an HDR/SDR pair
//!
//! ```
//! use ultrahdr_core::{
//! ColorPrimaries, TransferFunction, PixelFormat, new_pixel_buffer, Unstoppable,
//! gainmap::{apply_gainmap, compute_gainmap, GainMapConfig, HdrOutputFormat},
//! };
//!
//! // Minimal 8x8 matching HDR + SDR surfaces. In practice these come from
//! // your image decoder — this example just shows the call shape.
//! let hdr = new_pixel_buffer(
//! 8, 8, PixelFormat::Rgba8, ColorPrimaries::Bt709, TransferFunction::Srgb,
//! )?;
//! let sdr = new_pixel_buffer(
//! 8, 8, PixelFormat::Rgba8, ColorPrimaries::Bt709, TransferFunction::Srgb,
//! )?;
//!
//! // Derive gain map + metadata.
//! let config = GainMapConfig::default();
//! let (gainmap, metadata) = compute_gainmap(&hdr, &sdr, &config, Unstoppable)?;
//!
//! // For XMP / ISO 21496-1 APP2 serialization, use `zenjpeg::container::xmp`
//! // and `zencodec::gainmap`.
//!
//! // Reconstruct HDR at 4× boost.
//! let _hdr_out = apply_gainmap(
//! &sdr, &gainmap, &metadata,
//! 4.0, HdrOutputFormat::LinearFloat, Unstoppable,
//! )?;
//! # Ok::<(), ultrahdr_core::Error>(())
//! ```
extern crate alloc;
// Crate-info getter required by `whereat::at!()` for server-side error stack
// traces (the `At<Error>` pattern). Generates `crate::at_crate_info()`, which
// every `at!()` invocation resolves at the crate root regardless of module.
define_at_crate_info!;
// Re-export core types (local)
pub use ;
// Re-export from zencodec (canonical gain map metadata types)
pub use ;
pub use GainMapParams;
pub use ;
// Re-export enough for convenience
pub use ;
// Re-export gain map types
pub use ;
// Re-export Apple MakerNote HDR extraction (HEIC/JPEG gain-map headroom)
pub use ;
// Splitter API lives in zentone — re-export at crate root for back-compat
// with `ultrahdr_core::LumaToneMap` etc. Gated behind the `tonemap` feature
// (default-on) so decoder-only consumers can build without pulling in zentone.
pub use ;
// Production-recommended HDR→SDR primitives (audited 2026-06-22 shootout).
// `Bt2446A` won by 2-5× mean ΔE2000 over every channel-independent curve;
// `measure_max` won 3 of 6 ranking criteria for peak measurement
// (including `pct_above_de5` by 11 %). See [`color::audited`] for the
// full citation. Gated behind `tonemap-bt2446a` (default-off — pulls
// archmage/magetypes/garb/libm via zenpixels-convert).
pub use ;
/// Safety limits for parsing and allocation.