pub struct HdrEncoder<'a> { /* private fields */ }
Expand description
A simple HDR encoder
Implementations§
Source§impl<'a> HdrEncoder<'a>
impl<'a> HdrEncoder<'a>
Sourcepub fn new(data: &'a [f32], options: EncoderOptions) -> HdrEncoder<'a>
pub fn new(data: &'a [f32], options: EncoderOptions) -> HdrEncoder<'a>
Create a new HDR encoder context that can encode the provided data
§Arguments
data
: Data to encodeoptions
: Contains metadata for data, including width and height
Sourcepub fn add_headers(&mut self, headers: &'a HashMap<String, String>)
pub fn add_headers(&mut self, headers: &'a HashMap<String, String>)
Sourcepub fn expected_buffer_size(&self) -> Option<usize>
pub fn expected_buffer_size(&self) -> Option<usize>
Calculate buffer with padding size needed for encoding this into a vec
This is a given upper limit and doesn’t specifically mean that your buffer should exactly be that size.
The size of the output will depend on the nature of your data
Sourcepub fn encode(&self) -> Result<Vec<u8>, HdrEncodeErrors>
pub fn encode(&self) -> Result<Vec<u8>, HdrEncodeErrors>
Encode data in HDR format
The encoder expects colorspace to be in RGB and the length to match
otherwise it’s an error to try and encode
The floating point data is expected to be normalized between 0.0 and 1.0, it will not be clipped if not in this range
§Returns
The encoded data in case of no errors in case of errors returns error
§See also
- encode_into: Encodes into a pre-allocated buffer
Sourcepub fn encode_into(&self, out: &mut [u8]) -> Result<usize, HdrEncodeErrors>
pub fn encode_into(&self, out: &mut [u8]) -> Result<usize, HdrEncodeErrors>
Encode into a pre-allocated buffer
The size of output cannot be determined up until compression is over hence we cannot be sure if the output buffer will be enough.
The library provides expected_buffer_size which guarantees that if your buffer is that big, encoding will always succeed
§Arguments:
- out: The output buffer to write bytes into
§Returns
- Ok(usize): The number of bytes written into out
- Err(HdrEncodeErrors): An error if something occurred
§Examples
Encode a black image of 10x10
use zune_core::bit_depth::BitDepth;
use zune_core::colorspace::ColorSpace;
use zune_core::options::EncoderOptions;
use zune_hdr::HdrEncoder;
let w = 10;
let h = 10;
let comp = 3;
let data = vec![0.0_f32;w*h*comp];
let opts = EncoderOptions::new(w,h,ColorSpace::RGB,BitDepth::Float32);
let encoder = HdrEncoder::new(&data,opts);
// create output buffer , this is the upper limit on it
let mut output = vec![0;encoder.expected_buffer_size().unwrap()];
let size = encoder.encode_into(&mut output).unwrap();
// trim it so that the buffer only contains encoded hdr
output.truncate(size);