Struct DecoderOptions

pub struct DecoderOptions { /* private fields */ }

Decoder options

Not all options are respected by decoders all decoders

Implementations

impl DecoderOptions

const fn hvec_use_apple_videotoolbox(&self) -> bool

Whether the decoder should use apple hardware decoding (videotoolbox) to decode heif/heic images.

const fn hvec_set_use_videotoolbox(self, yes: bool) -> Self

Set whether to use hardware decoding in heif/heic on apple devices

NB: This only affects decoding in macos its not considered for other os

const fn hevc_max_mdat_size(&self) -> usize

Return the size in bytes the maximum allowed size of the MDAT section in HEIC images, the section is read to memory so a cap is important

Default is 16 MB

fn set_hevc_max_mdat_size(self, max_size: usize) -> Self

Set the maximum size in bytes for the MDAT section for HEIC images.

The section is read into memory so important to have it with an upper limit

impl DecoderOptions

const fn max_width(&self) -> usize

Get maximum width configured for which the decoder should not try to decode images greater than this width

const fn max_height(&self) -> usize

Get maximum height configured for which the decoder should not try to decode images greater than this height

fn strict_mode(&self) -> bool

Return true whether the decoder should be in strict mode And reject most errors

const fn use_unsafe(&self) -> bool

Return true if the decoder should use unsafe routines where possible

fn set_max_width(self, width: usize) -> Self

Set maximum width for which the decoder should not try decoding images greater than that width

Arguments

  • width: The maximum width allowed

returns: DecoderOptions

fn set_max_height(self, height: usize) -> Self

Set maximum height for which the decoder should not try decoding images greater than that height

Arguments

  • height: The maximum height allowed

returns: DecoderOptions

fn set_use_unsafe(self, yes: bool) -> Self

Whether the routines can use unsafe platform specific intrinsics when necessary

Platform intrinsics are implemented for operations which the compiler can't auto-vectorize, or we can do a marginably better job at it

All decoders with unsafe routines respect it.

Treat this with caution, disabling it will cause slowdowns but it's provided for mainly for debugging use.

  • Respected by: png and jpeg(decoders with unsafe routines)
fn set_strict_mode(self, yes: bool) -> Self

Set whether the decoder should be in standards conforming/ strict mode

This reduces the error tolerance level for the decoders and invalid samples will be rejected by the decoder

Arguments

  • yes:

returns: DecoderOptions

fn set_byte_endian(self, endian: ByteEndian) -> Self

Set the byte endian for which raw samples will be stored in in case a single pixel sample spans more than a byte.

The default is usually native endian hence big endian values will be converted to little endian on little endian systems,

and little endian values will be converted to big endian on big endian systems

Arguments

  • endian: The endianness to which to set the bytes to

returns: DecoderOptions

const fn byte_endian(&self) -> ByteEndian

Get the byte endian for which samples that span more than one byte will be treated

fn set_num_threads(self, num_threads: u8) -> Self

Set the number of threads used to decode images

This can be used e.g to implement threads used in heic tile decoding

const fn num_threads(&self) -> u8

Get the number of threads used to decode images

This can be used e.g to tell you how many threads the heic decoder will used when decoding tiles

impl DecoderOptions

fn use_sse2(&self) -> bool

Use SSE 2 code paths where possible

This checks for existence of SSE2 first and returns false if it's not present

fn use_sse3(&self) -> bool

Use SSE 3 paths where possible

This also checks for SSE3 support and returns false if it's not present

fn use_sse41(&self) -> bool

Use SSE4 paths where possible

This also checks for sse 4.1 support and returns false if it is not present

fn use_avx(&self) -> bool

Use AVX paths where possible

This also checks for AVX support and returns false if it's not present

fn use_avx2(&self) -> bool

Use avx2 paths where possible

This also checks for AVX2 support and returns false if it's not present

fn use_neon(&self) -> bool

impl DecoderOptions

const fn inflate_get_confirm_adler(&self) -> bool

Whether the inflate decoder should confirm adler checksums

fn inflate_set_confirm_adler(self, yes: bool) -> Self

Set whether the inflate decoder should confirm adler checksums

const fn inflate_get_limit(&self) -> usize

Get default inflate limit for which the decoder will not try to decompress further

fn inflate_set_limit(self, limit: usize) -> Self

Set the default inflate limit for which decompressors relying on inflate won't surpass this limit

const fn png_get_confirm_crc(&self) -> bool

Whether the inflate decoder should confirm crc 32 checksums

fn png_set_confirm_crc(self, yes: bool) -> Self

Set whether the png decoder should confirm CRC 32 checksums

fn png_set_add_alpha_channel(self, yes: bool) -> Self

Set whether the png decoder should add an alpha channel to images where possible.

For Luma images, it converts it to Luma+Alpha

For RGB images it converts it to RGB+Alpha

const fn png_get_add_alpha_channel(&self) -> bool

Return true whether the png decoder should add an alpha channel to images where possible

fn png_set_strip_to_8bit(self, yes: bool) -> Self

Whether the png decoder should reduce 16 bit images to 8 bit images implicitly.

Equivalent to png::Transformations::STRIP_16

const fn png_get_strip_to_8bit(&self) -> bool

Return a boolean indicating whether the png decoder should reduce 16 bit images to 8 bit images implicitly

const fn png_decode_animated(&self) -> bool

Return whether zune-image should decode animated images or whether we should just decode the first frame only

const fn png_set_decode_animated(self, yes: bool) -> Self

Set whether zune-image should decode animated images or whether we should just decode the first frame only

impl DecoderOptions

const fn jxl_decode_animated(&self) -> bool

Return whether zune-image should decode animated images or whether we should just decode the first frame only

const fn jxl_set_decode_animated(self, yes: bool) -> Self

Set whether zune-image should decode animated images or whether we should just decode the first frame only

impl DecoderOptions

const fn jpeg_get_max_scans(&self) -> usize

Get maximum scans for which the jpeg decoder should not go above for progressive images

fn jpeg_set_max_scans(self, max_scans: usize) -> Self

Set maximum scans for which the jpeg decoder should not exceed when reconstructing images.

const fn jpeg_get_out_colorspace(&self) -> ColorSpace

Get expected output colorspace set by the user for which the image is expected to be reconstructed into.

This may be different from the

fn jpeg_set_out_colorspace(self, colorspace: ColorSpace) -> Self

Set expected colorspace for which the jpeg output is expected to be in

This is mainly provided as is, we do not guarantee the decoder can convert to all colorspaces and the decoder can change it internally when it sees fit.

impl DecoderOptions

fn new_safe() -> DecoderOptions

Create the decoder with options setting most configurable options to be their safe counterparts

This is the same as default option as default initializes options to the safe variant.

Note, decoders running on this will be slower as it disables platform specific intrinsics

fn new_fast() -> DecoderOptions

Create the decoder with options setting the configurable options to the fast counterparts

This enables platform specific code paths and enable use of unsafe

fn new_cmd() -> DecoderOptions

Create the decoder options with the following characteristics

  • Use unsafe paths.
  • Ignore error checksuming, e.g in png we do not confirm adler and crc in this mode
  • Enable fast intrinsics paths

Trait Implementations

impl Clone for DecoderOptions

fn clone(&self) -> DecoderOptions

impl Copy for DecoderOptions

impl Debug for DecoderOptions

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Default for DecoderOptions

fn default() -> Self

Create a default and sane option for decoders

The following are the defaults

  • All decoders

    • max_width: 16536
    • max_height: 16535
    • use_unsafe: Use unsafe intrinsics where possible.
  • JPEG

    • max_scans: 100 (progressive images only, artificial cap to prevent a specific DOS)
    • error_on_non_conformance: False (slightly corrupt images will be allowed)
  • DEFLATE

    • deflate_limit: 1GB (will not continue decoding deflate archives larger than this)
  • PNG

    • endianness: Default endianess is Big Endian when decoding 16 bit images to be viewed as 8 byte images
    • confirm_crc: False (CRC will not be confirmed to be safe)
    • strip_16_bit_to_8: False, 16 bit images are handled as 16 bit images
    • add alpha: False, alpha channel is not added where it isn't present
    • decode_animated: True: All frames in an animated image are decoded
  • JXL

    • decode_animated: True: All frames in an animated image are decoded
  • HEVC

    • max_hevc_mdat_size: Maximum MDAT size, the value is read to memory so it prevents OOM value is 16 MB, which is valid for almost 99.999999% of HEIC images there

Auto Trait Implementations

impl Freeze for DecoderOptions

impl RefUnwindSafe for DecoderOptions

impl Send for DecoderOptions

impl Sync for DecoderOptions

impl Unpin for DecoderOptions

impl UnsafeUnpin for DecoderOptions

impl UnwindSafe for DecoderOptions

Blanket Implementations

impl<T> Any for DecoderOptions where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for DecoderOptions where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for DecoderOptions where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for DecoderOptions where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for DecoderOptions

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for DecoderOptions where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for DecoderOptions where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for DecoderOptions where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for DecoderOptions where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>