Expand description
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.
§no_std Support
This crate is no_std compatible with alloc. Disable default features:
ultrahdr-core = { version = "0.1", 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,
)?;Re-exports§
pub use gainmap::apply::HdrOutputFormat;pub use gainmap::compute::GainMapConfig;pub use gainmap::compute::compute_gain_row;
Modules§
- color
- Color space handling: transfer functions, gamut matrices, HDR→SDR tone mapping.
- gainmap
- Gain map computation and application.
- limits
- Safety limits for parsing and allocation.
- luminance
- Reference display luminance values (in nits).
Structs§
- Bt2408
Yrgb - Newtype guaranteeing a
Bt2408Tonemapperis inYrgb(luma) mode. - Extended
Reinhard Luma - Wraps a
ToneMapCurve::ExtendedReinhardfor use as a luma curve. - GainMap
- A gain map image (8-bit grayscale or per-channel).
- Gain
MapChannel - Per-channel gain map parameters.
- Gain
MapParams - ISO 21496-1 gain map parameters. Canonical cross-codec representation.
- Hable
Filmic - John Hable’s filmic curve from GDC 2010 (“Uncharted 2”). Identical math to libultrahdr’s reference implementation and the original GDC 2010 paper.
- LumaFn
- Adapt a closure as a
LumaToneMap. Caller is responsible for monotonicity and[0, 1]output range. - Luma
Gain MapSplitter - Splits HDR rows into (SDR, log2-gain) pairs around a
LumaToneMap. - Pixel
Buffer - Owning pixel container. Re-exported from
zenpixels::PixelBuffer. - Pixel
Slice - Borrowed pixel view. Re-exported from
zenpixels::PixelSlice. Borrowed view of pixel data. - Pixel
Slice Mut - Mutably borrowed pixel view. Re-exported from
zenpixels::PixelSliceMut. Mutable borrowed view of pixel data. - Split
Config - Splitter configuration.
- Split
Stats - Per-row statistics. Accumulate across rows; pass into
GainMapParamsmetadata or use to tightenmin_log2/max_log2on a second pass. - Unstoppable
- A
Stopimplementation that never stops (no cooperative cancellation).
Enums§
- Color
Primaries - Color primaries. Re-exported from
zenpixels::ColorPrimaries. Color primaries (CIE xy chromaticities of R, G, B) and white point. - Error
- Errors that can occur during Ultra HDR operations.
- Gain
MapEncoding Format - Controls which metadata format(s) to embed in Ultra HDR output.
- Iso21496
Format - Wire format variant for ISO 21496-1 gain map metadata serialization.
- Pixel
Format - Pixel format for raw images. Re-exported from
zenpixels::PixelFormat. - Stop
Reason - Why an operation was stopped.
- Transfer
Function - Electro-optical transfer function. Re-exported from
zenpixels::TransferFunction. Encoding transfer function (OETF).
Traits§
- Luma
Tone Map - A scalar luma tone curve:
Y_HDR(linear, ≥0) →Y_SDR(linear). - Stop
- Cooperative cancellation check.
Functions§
- clone_
pixel_ buffer - Deep-copy a
PixelBuffer.zenpixels::PixelBufferintentionally does not implementCloneto discourage silent large-pixel copies; this helper gives ultrahdr-core callers a single owned duplicate (tightly packed, same descriptor) when they genuinely need one. - descriptor_
for - Build a
zenpixels::PixelDescriptorwith the given format, primaries, and transfer function. Convenience for the common pattern used by ultrahdr-core’s tests and examples. - new_
pixel_ buffer - Allocate a
PixelBufferfor ultrahdr-core’s kernels. - parse_
iso21496_ fmt - Parse ISO 21496-1 binary gain map metadata with explicit format selection.
- pixel_
buffer_ from_ vec - Wrap an existing
Vec<u8>as aPixelBuffer, validating ultrahdr-core’s dimension caps and format subset. - require_
supported_ format - Reject pixel formats the kernels don’t understand.
- serialize_
iso21496_ fmt - Serialize
GainMapParamsto ISO 21496-1 binary format with explicit format selection. - validate_
gainmap_ metadata - Validate gain map metadata with ultrahdr-core’s stricter checks.
- validate_
ultrahdr_ dimensions - Validate image dimensions against ultrahdr-core’s stricter caps.
- validate_
ultrahdr_ image - Validate a
PixelBufferagainst ultrahdr-core’s dimension caps and the kernels’ format subset. Used at public entry points. - validate_
ultrahdr_ slice - Validate a
PixelSliceagainst ultrahdr-core’s dimension caps and the kernels’ format subset.
Type Aliases§
- Fraction
- Signed fraction for ISO 21496-1 metadata encoding.
- Gain
MapMetadata - ISO 21496-1 gain map metadata.
- Result
- Result type for Ultra HDR operations.
- Unsigned
Fraction - Unsigned fraction for ISO 21496-1 metadata encoding.