Skip to main content

Header

Struct Header 

Source
#[non_exhaustive]
pub struct Header { pub width: u32, pub height: u32, pub bit_depth: u8, pub color_type: ColorType, pub interlaced: bool, }
Expand description

A parsed IHDR chunk (§11.2.2).

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§width: u32

Image width in pixels.

§height: u32

Image height in pixels.

§bit_depth: u8

Bits per channel: 1, 2, 4, 8 or 16.

§color_type: ColorType

How samples are interpreted.

§interlaced: bool

Whether the image is Adam7 interlaced.

Implementations§

Source§

impl Header

Source

pub fn parse(payload: &[u8], limits: &Limits) -> Result<Self>

Parse a 13-byte IHDR payload, validating it against limits.

Dimension limits are enforced here, before any pixel buffer exists (SPEC §Safety), so a header claiming 4 billion pixels costs nothing.

§Errors

Returns PixelsError::Malformed for an invalid header, or PixelsError::LimitExceeded if the dimensions exceed limits.

Source

pub const fn bits_per_pixel(&self) -> usize

Bits per pixel in the encoded stream.

Source

pub const fn row_bytes(&self, width: u32) -> usize

Bytes in one filtered scanline of width pixels, excluding the filter byte. Sub-byte depths round up.

Source

pub const fn filter_stride(&self) -> usize

Bytes per pixel, rounded up — the filter offset (§9.2).

For depths below 8 this is 1, which is what the filters require.

Source

pub const fn output_format(&self, has_transparency: bool) -> PixelFormat

The pixel format this header decodes into.

The mapping is constrained by SPEC §Pixel formats, which has no 16-bit grey-with-alpha type. Rather than silently truncating those to 8 bits, they widen to Rgba16: more memory, but no data thrown away by a decoder the caller did not ask to be lossy.

Sub-byte greyscale expands to Gray8 and palettes expand to RGB or RGBA, because the engine’s formats are byte-aligned and unpalettised.

Source

pub fn descriptor( &self, has_transparency: bool, limits: &Limits, ) -> Result<ImageDescriptor>

The engine descriptor for this header.

§Errors

Propagates ImageDescriptor::with_limits.

Source

pub fn filtered_size(&self) -> usize

Total filtered bytes the whole image decompresses to.

This is the exact output limit handed to inflate, which is what turns a decompression bomb into a malformed-input error (SPEC §Safety).

Trait Implementations§

Source§

impl Clone for Header

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Header

Source§

impl Debug for Header

Source§

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

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

impl Eq for Header

Source§

impl PartialEq for Header

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Header

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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.