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,
impl<T> HdrDecoder<T>where T: ZReaderTrait,
sourcepub fn new(data: T) -> HdrDecoder<T>
pub fn new(data: T) -> HdrDecoder<T>
sourcepub fn new_with_options(data: T, options: DecoderOptions) -> HdrDecoder<T>
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 memoryoptions
: 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);
sourcepub const fn get_metadata(&self) -> &BTreeMap<String, String>
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
sourcepub fn decode_headers(&mut self) -> Result<(), HdrDecodeErrors>
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.
sourcepub const fn get_dimensions(&self) -> Option<(usize, usize)>
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
sourcepub fn get_colorspace(&self) -> Option<ColorSpace>
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
sourcepub fn decode(&mut self) -> Result<Vec<f32>, HdrDecodeErrors>
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 coefficientsErr(HdrDecodeErrors)
: Indicates an unrecoverable error occurred during decoding.
sourcepub fn output_buffer_size(&self) -> Option<usize>
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 imageNone
: Indicates the image was not decoded orwidth*height*colorspace
calculation overflows a usize
sourcepub fn decode_into(&mut self, buffer: &mut [f32]) -> Result<(), HdrDecodeErrors>
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();