Struct EncodingSupport

Source
pub struct EncodingSupport { /* private fields */ }
Expand description

Describes the extent of support for encoding a format.

Implementations§

Source§

impl EncodingSupport

Source

pub const fn dithering(&self) -> Dithering

Whether and what type of dithering is supported.

Source

pub const fn split_height(&self) -> Option<NonZeroU8>

The split height for the image format.

Encoding most formats is trivially parallelizable, by splitting the image into chunks by lines, encoding each chunk separately, and writing the encoded chunks to the output stream in order.

This value specifies how many lines need to be grouped together for correct encoding. E.g. BC1_UNORM requires 4 lines to be grouped together, meaning that all chunks (except the last one) must have a height that is a multiple of 4. So e.g. an image with a height of 10 pixels can split into chunks with heights of 4-4-2, 8-2, 4-6, or 10.

crate::SplitSurface will automatically split the image into chunks of the correct height, so this value is only relevant if you are implementing your own encoder/splitter.

Note that most dithering will produce different (but not necessarily incorrect) results if the image is split into chunks. However, all BCn formats implement block-based local dithering, meaning that the dithering is the same whether the image is split or not. See EncodingSupport::local_dithering().

Source

pub const fn local_dithering(&self) -> bool

Whether the format supports local dithering.

Most formats implement global error diffusing dithering for best quality. However, this prevents parallel encoding of the image, as the dithering error of one chunk depends on the dithering error of the previous chunk. It’s still possible to encode the image in parallel, but the dither pattern may reveal the chunk seams.

Local dithering on the other hand will attempt to diffuse the error within a small region of the image. E.g. BC1_UNORM will dither within a 4x4 block. This allows the image to be split into chunks and encoded in parallel without revealing the chunk seams.

self.dithering() == Dithering::None implies self.local_dithering() == false.

Source

pub const fn size_multiple(&self) -> Option<(NonZeroU32, NonZeroU32)>

The size multiple of the encoded image, if any.

Some formats require the image to be a multiple of a certain size. E.g. NV12 requires the image to be a multiple of 2x2 pixels, meaning that the width and height of the image must be even.

Formats that can encode images of any size will return None.

If Some is returned, the width and height of the returned value are both non-zero, and at least one of them is greater than 1.

Use EncodingSupport::supports_size() to check if a given image size is supported by the format.

§Example
let format = Format::NV12;
let encoding = format.encoding_support().unwrap();

assert_eq!(
    encoding.size_multiple(),
    Some((NonZeroU32::new(2).unwrap(), NonZeroU32::new(2).unwrap()))
);
assert_eq!(encoding.supports_size(Size::new(2, 2)), true);
assert_eq!(encoding.supports_size(Size::new(3, 2)), false);
Source

pub const fn supports_size(&self, size: Size) -> bool

Whether the given image size is supported for encoding.

This will always return true if EncodingSupport::size_multiple() is None.

Trait Implementations§

Source§

impl Clone for EncodingSupport

Source§

fn clone(&self) -> EncodingSupport

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EncodingSupport

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Copy for EncodingSupport

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.