#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.width: u32Image width in pixels.
height: u32Image height in pixels.
bit_depth: u8Bits per channel: 1, 2, 4, 8 or 16.
color_type: ColorTypeHow samples are interpreted.
interlaced: boolWhether the image is Adam7 interlaced.
Implementations§
Source§impl Header
impl Header
Sourcepub fn parse(payload: &[u8], limits: &Limits) -> Result<Self>
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.
Sourcepub const fn bits_per_pixel(&self) -> usize
pub const fn bits_per_pixel(&self) -> usize
Bits per pixel in the encoded stream.
Sourcepub const fn row_bytes(&self, width: u32) -> usize
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.
Sourcepub const fn filter_stride(&self) -> usize
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.
Sourcepub const fn output_format(&self, has_transparency: bool) -> PixelFormat
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.
Sourcepub fn descriptor(
&self,
has_transparency: bool,
limits: &Limits,
) -> Result<ImageDescriptor>
pub fn descriptor( &self, has_transparency: bool, limits: &Limits, ) -> Result<ImageDescriptor>
Sourcepub fn filtered_size(&self) -> usize
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).