pub trait ToneMapper:
Send
+ Sync
+ UnwindSafe
+ RefUnwindSafe
+ Debug {
// Required methods
fn requirements(&self) -> Requirements;
fn prepare(
&self,
ctx: &ToneMapContext,
pulse: Option<&dyn Pulse>,
) -> Result<PreparedMapper, At<ConvertError>>;
fn name(&self) -> &'static str;
// Provided methods
fn working_primaries_for(&self, _target: Primaries) -> Primaries { ... }
fn baked_peaks(&self) -> Option<(f32, f32)> { ... }
}Expand description
Pluggable HDR→SDR tone mapper for RowPlan and ImagePlan.
Implementations declare their analysis needs via
requirements, then receive the gathered
ToneMapContext in prepare and produce a
PreparedMapper — typically a StripMapper with image-specific
coefficients precomputed.
The trait is object-safe: ConvertPolicy
stores Arc<dyn ToneMapper> internally, so the dispatch table never
has to know the concrete mapper type.
§Invariants
- Pure and deterministic. Given
&selfand aToneMapContext, every method must be a pure function of its inputs. Interior mutability that perturbs output is forbidden. Send + Sync + UnwindSafe + RefUnwindSafe + Debug. The supertrait bounds are required so plans (which areClone + Debug) keep their auto-traits across theArc<dyn ToneMapper>field stored onConvertStep::ToneMap. Mappers are pure functions of their inputs and pose no panic-safety hazard; concrete implementations virtually always satisfy this without thought (any#[derive(Debug)]struct of plain numeric /Arcfields does).- Stable
name. The string is consumed by diagnostics, trace recorders, and estimate / oracle cache keys. Treat it as part of the implementation’s public contract: once shipped, do not rename across releases.
§Working space
The strip handed to StripMapper::map_strip is linear-light RGB
in the primaries declared by
working_primaries_for (BT.2020 by
default — the canonical HDR working space). Mappers that operate in a
different gamut (a few Filmic variants prefer DCI-P3) override
working_primaries_for; the pipeline inserts an extra gamut matrix
on each side of the strip to honor that.
Required Methods§
Sourcefn requirements(&self) -> Requirements
fn requirements(&self) -> Requirements
What pipeline-gathered context does this mapper need before it
can produce a PreparedMapper?
Examples:
- A pointwise curve with peaks pre-baked at construction returns
Requirements::NONE— no analysis needed. - A pointwise curve that wants the pipeline to manage peaks
returns
Requirements::SOURCE_PEAK_ONLY. - A local operator (Mantiuk, Fattal, bilateral) returns
Requirements { full_image: true, ..Requirements::NONE }— currently rejected by the builder (reserved for a future release; seePreparedMapper::Streaming).
Sourcefn prepare(
&self,
ctx: &ToneMapContext,
pulse: Option<&dyn Pulse>,
) -> Result<PreparedMapper, At<ConvertError>>
fn prepare( &self, ctx: &ToneMapContext, pulse: Option<&dyn Pulse>, ) -> Result<PreparedMapper, At<ConvertError>>
Build a per-image strip executor from the gathered context.
Called once by the pipeline after the analysis pass.
Implementations should precompute curve coefficients / LUTs /
adaptation fields here, then return a PreparedMapper that the
pipeline applies strip-by-strip during row dispatch.
ctx carries every field the mapper declared in
requirements, plus the always-populated
source_peak_nits / target_peak_nits / working_primaries.
pulse carries optional cooperative cancellation and progress reporting
from how_far::Pulse. Callers pass None when cancellation and
progress reporting are not needed, or Some(pulse) (e.g.
Some(&StopOnly::borrowed(stop)) for cancellation alone).
Implementations doing non-trivial preparation work (such as building 3D
LUTs or running a local spatial pass) should call pulse.check() before
and during that work and map StopReason into
ConvertError::Cancelled. Per
how-far’s contract, implementations borrow pulse and never finish
it.
Provided Methods§
Sourcefn working_primaries_for(&self, _target: Primaries) -> Primaries
fn working_primaries_for(&self, _target: Primaries) -> Primaries
The working color primaries this mapper expects on its input strip, given a target primaries hint.
Default: Primaries::Bt2020 — the canonical HDR working space.
Sourcefn baked_peaks(&self) -> Option<(f32, f32)>
fn baked_peaks(&self) -> Option<(f32, f32)>
Pre-baked (source_peak_nits, target_peak_nits) when this mapper ignores
pipeline-supplied peaks (e.g., Bt2446A::with_peaks(Nits::new_positive_or_panic(4000.0), Nits::new_positive_or_panic(100.0))).
When Some((src_peak, dst_peak)), the pipeline normalizes input/output
strips to those exact peaks and skips redundant peak scanning.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".