Encoder

Struct Encoder 

Source
pub struct Encoder { /* private fields */ }
Expand description

Ultra HDR encoder.

Supports multiple input modes:

  • HDR only: Automatically generates SDR via tone mapping
  • HDR + SDR: Uses provided SDR image
  • HDR + compressed SDR: Uses pre-encoded JPEG for base image
  • HDR + SDR + existing gain map: Reuses pre-computed gain map (for lossless round-trips)

Implementations§

Source§

impl Encoder

Source

pub fn new() -> Self

Create a new encoder with default settings.

Source

pub fn set_hdr_image(&mut self, image: RawImage) -> &mut Self

Set the HDR input image (required).

Source

pub fn set_sdr_image(&mut self, image: RawImage) -> &mut Self

Set the SDR input image (optional).

If not provided, SDR will be generated via tone mapping.

Source

pub fn set_compressed_sdr(&mut self, jpeg: Vec<u8>) -> &mut Self

Set a pre-compressed SDR JPEG (optional).

If provided, this JPEG will be used as the base image instead of compressing the SDR image.

Source

pub fn set_existing_gainmap( &mut self, gainmap: GainMap, metadata: GainMapMetadata, ) -> &mut Self

Set an existing gain map and metadata (optional).

If provided, this gain map will be used instead of computing a new one. This enables lossless UltraHDR round-trips (decode → process → encode) when the SDR dimensions haven’t changed.

Note: The caller is responsible for ensuring the gain map is appropriate for the SDR image. If the SDR dimensions have changed (e.g., after resize), the gain map should be invalidated and recomputed.

Source

pub fn clear_existing_gainmap(&mut self) -> &mut Self

Clear any existing gain map, forcing recomputation.

Source

pub fn set_existing_gainmap_jpeg( &mut self, jpeg: Vec<u8>, metadata: GainMapMetadata, ) -> &mut Self

Set an existing gain map as raw JPEG bytes and metadata (optional).

This is an alternative to set_existing_gainmap that skips the JPEG re-encoding step entirely. Useful when the original gain map JPEG is available (e.g., from a decoded UltraHDR image).

When set, this takes precedence over existing_gainmap.

Source

pub fn has_existing_gainmap(&self) -> bool

Check if an existing gain map is set.

Source

pub fn set_quality(&mut self, base: u8, gainmap: u8) -> &mut Self

Set JPEG quality for base and gain map images.

Quality ranges from 1-100. Default: base=90, gainmap=85.

Source

pub fn set_gainmap_scale(&mut self, scale: u8) -> &mut Self

Set gain map downscale factor.

The gain map is typically smaller than the base image. Factor of 4 means gain map is 1/4 the width and height. Default: 4. Range: 1-128.

Source

pub fn set_target_display_peak(&mut self, nits: f32) -> &mut Self

Set target display peak brightness in nits.

Default: 10000.0 (HDR10 max).

Source

pub fn set_min_content_boost(&mut self, boost: f32) -> &mut Self

Set minimum content boost.

Default: 1.0 (no boost at minimum).

Source

pub fn set_use_iso_metadata(&mut self, use_iso: bool) -> &mut Self

Enable or disable ISO 21496-1 metadata.

Default: true (include both XMP and ISO metadata).

Source

pub fn encode(&self) -> Result<Vec<u8>>

Encode to Ultra HDR JPEG.

Trait Implementations§

Source§

impl Default for Encoder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.