Struct zune_farbfeld::FarbFeldDecoder
source · pub struct FarbFeldDecoder<T: ZReaderTrait> { /* private fields */ }
Expand description
A simple Farbfeld lossless decoder.
One can modify the decoder accepted dimensions
via DecoderOptions
Implementations§
source§impl<T> FarbFeldDecoder<T>where
T: ZReaderTrait,
impl<T> FarbFeldDecoder<T>where T: ZReaderTrait,
sourcepub fn new(data: T) -> FarbFeldDecoder<T>
pub fn new(data: T) -> FarbFeldDecoder<T>
Create a new decoder.
Data is the raw compressed farbfeld data
sourcepub fn new_with_options(data: T, option: DecoderOptions) -> FarbFeldDecoder<T>
pub fn new_with_options(data: T, option: DecoderOptions) -> FarbFeldDecoder<T>
Create a new decoder with non default options as opposed to
new
sourcepub fn decode_headers(&mut self) -> Result<(), &'static str>
pub fn decode_headers(&mut self) -> Result<(), &'static str>
Decode a header for this specific image
sourcepub fn output_buffer_size(&self) -> Option<usize>
pub fn output_buffer_size(&self) -> Option<usize>
Return the minimum buffer size for which the buffer provided must be in order to store decoded bytes into
Returns
- Some(usize) - The size expected for a buffer of
&[u8]
which can hold the whole decoded bytes without overflow - None: Indicates the headers weren’t decoded or widthheight8 would overflow a usize
sourcepub fn decode_into(&mut self, sink: &mut [u16]) -> Result<(), &'static str>
pub fn decode_into(&mut self, sink: &mut [u16]) -> Result<(), &'static str>
Decode data writing it into the buffer as native endian
It is an error if the sink buffer is smaller than
output_buffer_size()
Arguments
sink
: The output buffer which we will fill with bytes
Endianness
Since Farbfeld uses 16 bit big endian samples, each two bytes represent a single pixel.
The endianness of these is converted to native endian which means each two consecutive bytes represents the two bytes that make the u16
sourcepub fn decode(&mut self) -> Result<Vec<u16>, &'static str>
pub fn decode(&mut self) -> Result<Vec<u16>, &'static str>
Decode a farbfeld data returning raw pixels or an error
Example
use zune_farbfeld::FarbFeldDecoder;
let mut decoder = FarbFeldDecoder::new(b"NOT A VALID FILE".as_slice());
assert!(decoder.decode().is_err());
sourcepub const fn get_colorspace(&self) -> ColorSpace
pub const fn get_colorspace(&self) -> ColorSpace
Returns farbfeld default image colorspace.
This is always RGBA
sourcepub const fn get_bit_depth(&self) -> BitDepth
pub const fn get_bit_depth(&self) -> BitDepth
Return farbfeld default bit depth
This is always 16
sourcepub const fn get_dimensions(&self) -> Option<(usize, usize)>
pub const fn get_dimensions(&self) -> Option<(usize, usize)>
Return the width and height of the image
Or none if the headers haven’t been decoded
use zune_farbfeld::FarbFeldDecoder;
let mut decoder = FarbFeldDecoder::new([].as_slice());
decoder.decode_headers().unwrap();
// get dimensions now.
let (w,h)=decoder.get_dimensions().unwrap();