Expand description
Ultra HDR - Pure Rust encoder/decoder for HDR images with gain maps.
Ultra HDR is an image format that stores HDR (High Dynamic Range) content in a backwards-compatible JPEG file. Legacy viewers see the SDR (Standard Dynamic Range) base image, while HDR-capable displays can reconstruct the full HDR content using an embedded gain map.
§Crate Structure
ultrahdr_core- Core gain map math and metadata (no codec dependency)ultrahdr(this crate) - Full encoder/decoder (bring your own JPEG codec)
§Format Overview
An Ultra HDR JPEG contains:
- Primary JPEG: SDR base image (8-bit, sRGB)
- Gain map JPEG: Compressed ratio of HDR/SDR luminance
- XMP metadata: Describes how to apply the gain map
- MPF header: Multi-Picture Format container
§Example
ⓘ
use ultrahdr::{encode_ultrahdr, Decoder, GainMapMetadata, ColorGamut};
use ultrahdr::gainmap::compute::{compute_gainmap, GainMapConfig};
// 1. Prepare your images (using your own JPEG codec)
let sdr_jpeg = my_encoder.encode_rgb(&sdr_pixels)?;
// 2. Compute gain map from HDR and SDR
let config = GainMapConfig::default();
let (gainmap, metadata) = compute_gainmap(&hdr, &sdr, &config, Unstoppable)?;
let gainmap_jpeg = my_encoder.encode_grayscale(&gainmap.data)?;
// 3. Assemble Ultra HDR file
let ultrahdr = encode_ultrahdr(&sdr_jpeg, &gainmap_jpeg, &metadata, ColorGamut::Bt709)?;
// 4. Decode: get raw JPEG bytes and decode with your codec
let decoder = Decoder::new(&ultrahdr)?;
let sdr_jpeg = decoder.primary_jpeg().unwrap();
let gainmap_jpeg = decoder.gainmap_jpeg().unwrap();
let metadata = decoder.metadata().unwrap();§Standards
This implementation follows:
- Ultra HDR Image Format v1.1
- ISO 21496-1 (gain map metadata)
- Adobe XMP (hdrgm namespace)
Modules§
- color
- Color space handling: transfer functions, gamut matrices, conversions.
- container
- JPEG container utilities for codec-agnostic Ultra HDR support.
- gainmap
- Gain map computation and application.
- jpeg
- JPEG handling utilities.
- limits
- Safety limits for parsing and allocation.
- luminance
- Reference display luminance values (in nits).
- metadata
- Metadata handling for Ultra HDR and multi-image JPEG formats.
Structs§
- Decoder
- Ultra HDR decoder.
- Encoder
- Ultra HDR encoder.
- Fraction
- A fraction for ISO 21496-1 metadata encoding.
- GainMap
- A gain map image (8-bit grayscale or per-channel).
- Gain
MapConfig - Configuration for gain map computation.
- Gain
MapMetadata - ISO 21496-1 gain map metadata.
- RawImage
- A raw (uncompressed) image.
- Unstoppable
- A
Stopimplementation that never stops (no cooperative cancellation).
Enums§
- Color
Gamut - Color gamut / color space primaries.
- Color
Transfer - Electro-optical transfer function (EOTF/OETF).
- Error
- Errors that can occur during Ultra HDR operations.
- Gain
MapEncoding Format - Controls which metadata format(s) to embed in Ultra HDR output.
- HdrOutput
Format - Output format for HDR reconstruction.
- Pixel
Format - Pixel format for raw images.
- Stop
Reason - Why an operation was stopped.
Traits§
- Stop
- Cooperative cancellation check.
Functions§
- encode_
ultrahdr - Assemble an Ultra HDR JPEG from pre-encoded components.
- encode_
ultrahdr_ with_ format - Assemble an Ultra HDR JPEG from pre-encoded components with format control.
Type Aliases§
- Result
- Result type for Ultra HDR operations.