#[non_exhaustive]
pub enum BitDepth { Eight, Sixteen, Float32, Unknown, }
Expand description

The image bit depth.

The library successfully supports depths up to 16 bits, as the underlying storage is usually a u16.

This allows us to comfortably support a wide variety of images e.g 10 bit av1, 16 bit png and ppm.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Eight

U8 bit depth.

Images with such bit depth use u8 to store pixels and use the whole range from 0-255.

It is currently the smallest supported bit depth by the library.

For images with bit depths lower than this, they will be scaled to this bit depth

§

Sixteen

U16 bit depth

Images with such bit depths use u16 to store values and use the whole range i.e 0-65535

Data is stored and processed in native endian.

§

Float32

Floating point 32 bit data, range is 0.0 to 1.0

Uses f32 to store data

§

Unknown

Bit depth information is unknown

Implementations§

source§

impl BitDepth

source

pub const fn max_value(self) -> u16

Get the max value supported by the bit depth

During conversion from one bit depth to another

larger values should be clamped to this bit depth

source

pub const fn bit_type(self) -> BitType

Return the minimum number of bits that can be used to represent each pixel in the image

All bit depths below 8 return a bit type of BitType::U8. and all those above 8 and below 16 return a bit type of BitType::SixTeen

Returns

An enum whose variants represent the minimum size for an unsigned integer which can store the image pixels without overflow

Example
use zune_core::bit_depth::{BitDepth, BitType};
assert_eq!(BitDepth::Eight.bit_type(),BitType::U8);

assert_eq!(BitDepth::Sixteen.bit_type(),BitType::U16);

See also size_of

source

pub const fn size_of(self) -> usize

Get the number of bytes needed to store a specific bit depth

Example

For images less than or equal to 8 bits(1 byte), we can use a u8 to store the pixels, and a size_of u8 is 1

For images greater than 8 bits and less than 16 bits(2 bytes), we can use a u16 to store the pixels, a size_of u16 is 2.

use zune_core::bit_depth::BitDepth;
let depth = BitDepth::Sixteen;
// greater 12 bits is greater than 8 and less than 16
assert_eq!(depth.size_of(),2);
source

pub const fn bit_size(&self) -> usize

Trait Implementations§

source§

impl Clone for BitDepth

source§

fn clone(&self) -> BitDepth

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for BitDepth

source§

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

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

impl Default for BitDepth

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl PartialEq for BitDepth

source§

fn eq(&self, other: &BitDepth) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for BitDepth

source§

impl Eq for BitDepth

source§

impl StructuralEq for BitDepth

source§

impl StructuralPartialEq for BitDepth

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

§

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>,

§

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>,

§

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.