Struct zune_hdr::HdrDecoder

source ·
pub struct HdrDecoder<T: ZReaderTrait> { /* private fields */ }
Expand description

A simple radiance HDR decoder

Accessing metadata

Radiance files may contain metadata in it’s headers as key value pairs, we save the metadata in a hashmap and provide a way to inspect that metadata by exposing the map as an API access method.

For sophisticated algorithms, they may use the metadata to further understand the data.

Implementations§

source§

impl<T> HdrDecoder<T>where T: ZReaderTrait,

source

pub fn new(data: T) -> HdrDecoder<T>

Create a new HDR decoder

Arguments
  • data: Raw HDR file contents

returns: HdrDecoder

Examples
use zune_hdr::HdrDecoder;
// read hdr file to memory
let file_data = std::fs::read("sample.hdr").unwrap();
let decoder = HdrDecoder::new(&file_data);
source

pub fn new_with_options(data: T, options: DecoderOptions) -> HdrDecoder<T>

Create a new HDR decoder with the specified options

Arguments
  • data: Raw HDR file contents already in memory
  • options: Decoder options that influence how decoding occurs

returns: HdrDecoder

Examples
use zune_core::options::DecoderOptions;
use zune_hdr::HdrDecoder;
// read hdr file to memory
let file_data = std::fs::read("sample.hdr").unwrap();
// set that the decoder does not decode images greater than
// 50 px width
let options = DecoderOptions::default().set_max_width(50);
// use the options set
let decoder = HdrDecoder::new_with_options(&file_data,options);
source

pub const fn get_metadata(&self) -> &BTreeMap<String, String>

Get key value metadata found in the header

In case the key or value contains non-valid UTF-8, the characters are replaced with REPLACEMENT_CHARACTER

source

pub fn decode_headers(&mut self) -> Result<(), HdrDecodeErrors>

Decode headers for the HDR image

The struct is modified in place and data can be extracted from appropriate getters.

source

pub const fn get_dimensions(&self) -> Option<(usize, usize)>

Get image dimensions as a tuple of width and height or None if the image hasn’t been decoded.

Returns
  • Some(width,height): Image dimensions
  • None : The image headers haven’t been decoded
source

pub fn get_colorspace(&self) -> Option<ColorSpace>

Return the input colorspace of the image

Returns

-Some(Colorspace): Input colorspace

  • None : Indicates the headers weren’t decoded
source

pub fn decode(&mut self) -> Result<Vec<f32>, HdrDecodeErrors>

Decode HDR file return a vector containing decoded coefficients

Returns
  • Ok(Vec<f32>): The actual decoded coefficients
  • Err(HdrDecodeErrors): Indicates an unrecoverable error occurred during decoding.
source

pub fn output_buffer_size(&self) -> Option<usize>

decoded using the given input transformations

Returns
  • Some(usize): Minimum size for a buffer needed to decode the image
  • None: Indicates the image was not decoded or width*height*colorspace calculation overflows a usize
source

pub fn decode_into(&mut self, buffer: &mut [f32]) -> Result<(), HdrDecodeErrors>

Decode into a pre-allocated buffer

It is an error if the buffer size is smaller than output_buffer_size()

If the buffer is bigger than expected, we ignore the end padding bytes

Example
  • Read headers and then alloc a buffer big enough to hold the image
use zune_hdr::HdrDecoder;
let mut decoder = HdrDecoder::new(&[]);
// before we get output, we must decode the headers to get width
// height, and input colorspace
decoder.decode_headers().unwrap();

let mut out = vec![0.0;decoder.output_buffer_size().unwrap()];
// write into out
decoder.decode_into(&mut out).unwrap();

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for HdrDecoder<T>where T: RefUnwindSafe,

§

impl<T> Send for HdrDecoder<T>where T: Send,

§

impl<T> Sync for HdrDecoder<T>where T: Sync,

§

impl<T> Unpin for HdrDecoder<T>where T: Unpin,

§

impl<T> UnwindSafe for HdrDecoder<T>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.