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,

source

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

Create a new decoder.

Data is the raw compressed farbfeld data

source

pub fn new_with_options(data: T, option: DecoderOptions) -> FarbFeldDecoder<T>

Create a new decoder with non default options as opposed to new

source

pub fn decode_headers(&mut self) -> Result<(), &'static str>

Decode a header for this specific image

source

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
source

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

source

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

pub const fn get_colorspace(&self) -> ColorSpace

Returns farbfeld default image colorspace.

This is always RGBA

source

pub const fn get_bit_depth(&self) -> BitDepth

Return farbfeld default bit depth

This is always 16

source

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for FarbFeldDecoder<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.