Struct qoi::Header

source ·
pub struct Header {
    pub width: u32,
    pub height: u32,
    pub channels: Channels,
    pub colorspace: ColorSpace,
}
Expand description

Image header: dimensions, channels, color space.

§Notes

A valid image header must satisfy the following conditions:

  • Both width and height must be non-zero.
  • Maximum number of pixels is 400Mp (=4e8 pixels).

Fields§

§width: u32

Image width in pixels

§height: u32

Image height in pixels

§channels: Channels

Number of 8-bit channels per pixel

§colorspace: ColorSpace

Color space (informative field, doesn’t affect encoding)

Implementations§

source§

impl Header

source

pub const fn try_new( width: u32, height: u32, channels: Channels, colorspace: ColorSpace, ) -> Result<Self>

Creates a new header and validates image dimensions.

source

pub const fn with_channels(self, channels: Channels) -> Self

Creates a new header with modified channels.

source

pub const fn with_colorspace(self, colorspace: ColorSpace) -> Self

Creates a new header with modified color space.

source

pub(crate) fn encode(&self) -> [u8; 14]

Serializes the header into a bytes array.

source

pub(crate) fn decode(data: impl AsRef<[u8]>) -> Result<Self>

Deserializes the header from a byte array.

source

pub const fn n_pixels(&self) -> usize

Returns a number of pixels in the image.

source

pub const fn n_bytes(&self) -> usize

Returns the total number of bytes in the raw pixel array.

This may come useful when pre-allocating a buffer to decode the image into.

source

pub fn encode_max_len(&self) -> usize

The maximum number of bytes the encoded image will take.

Can be used to pre-allocate the buffer to encode the image into.

Trait Implementations§

source§

impl Clone for Header

source§

fn clone(&self) -> Header

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 Header

source§

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

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

impl Default for Header

source§

fn default() -> Self

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

impl Hash for Header

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for Header

source§

fn eq(&self, other: &Header) -> 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 Header

source§

impl Eq for Header

source§

impl StructuralPartialEq for Header

Auto Trait Implementations§

§

impl Freeze for Header

§

impl RefUnwindSafe for Header

§

impl Send for Header

§

impl Sync for Header

§

impl Unpin for Header

§

impl UnwindSafe for Header

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.