Struct HdrEncoder

Source
pub struct HdrEncoder<'a> { /* private fields */ }
Expand description

A simple HDR encoder

Implementations§

Source§

impl<'a> HdrEncoder<'a>

Source

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 encode
  • options: Contains metadata for data, including width and height
Source

pub fn add_headers(&mut self, headers: &'a HashMap<String, String>)

Add extra headers to be encoded with the image

This must be called before you call encode otherwise it will have no effect.

§Arguments:
  • headers: A hashmap containing keys and values, the values will be encoded as key=value in the hdr header before encoding
Source

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

Source

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
Source

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);

Auto Trait Implementations§

§

impl<'a> Freeze for HdrEncoder<'a>

§

impl<'a> RefUnwindSafe for HdrEncoder<'a>

§

impl<'a> Send for HdrEncoder<'a>

§

impl<'a> Sync for HdrEncoder<'a>

§

impl<'a> Unpin for HdrEncoder<'a>

§

impl<'a> UnwindSafe for HdrEncoder<'a>

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.