pub struct Header { /* private fields */ }
Expand description
PNG header representation.
You must create one of these with image metadata when encoding, and can reuse the header for multiple encodings if desired.
Implementations§
source§impl Header
impl Header
sourcepub fn new() -> Header
pub fn new() -> Header
Create a new Header struct with default settings.
This will be 1x1 pixels, TruecolorAlpha 8-bit, with the standard compression, filter, and interlace methods. You can mutate the state using the set_* methods.
sourcepub fn color_type(&self) -> ColorType
pub fn color_type(&self) -> ColorType
Get the color type of the image.
sourcepub fn compression_method(&self) -> CompressionMethod
pub fn compression_method(&self) -> CompressionMethod
Get the compression method defined for the image.
sourcepub fn filter_method(&self) -> FilterMethod
pub fn filter_method(&self) -> FilterMethod
Get the filter method defined for the image.
sourcepub fn interlace_method(&self) -> InterlaceMethod
pub fn interlace_method(&self) -> InterlaceMethod
Get the interlace method defined for the image.
sourcepub fn bytes_per_pixel(&self) -> usize
pub fn bytes_per_pixel(&self) -> usize
Calculate the bytes per pixel, for PNG filtering purposes.
If the bit depth is < 8, this will clamp at 1.
sourcepub fn stride(&self) -> usize
pub fn stride(&self) -> usize
Calculate the stride in bytes for the encoded pixel rows.
Will panic on arithmetic overflow if given pathologically long rows.
sourcepub fn set_size(&mut self, width: u32, height: u32) -> Result<()>
pub fn set_size(&mut self, width: u32, height: u32) -> Result<()>
Set the pixel dimensions of the image.
Returns error if width or height are 0.
Warning: it’s possible to make combinations of width and color type that cannot fit in memory on 32-bit systems. These are not detected here, but will panic when stride() is called.
sourcepub fn set_color(&mut self, color_type: ColorType, depth: u8) -> Result<()>
pub fn set_color(&mut self, color_type: ColorType, depth: u8) -> Result<()>
Set the color type and depth of the image.
Returns error if depth is invalid for the given color type.
Warning: it’s possible to make combinations of width and color type that cannot fit in memory on 32-bit systems. These are not detected here, but will panic when stride() is called.
sourcepub fn set_compression_method(
&mut self,
compression_method: CompressionMethod
) -> Result<()>
pub fn set_compression_method( &mut self, compression_method: CompressionMethod ) -> Result<()>
Set the compression method.
This is not very useful, as only deflate is supported.
sourcepub fn set_filter_method(&mut self, filter_method: FilterMethod) -> Result<()>
pub fn set_filter_method(&mut self, filter_method: FilterMethod) -> Result<()>
Set the filter method.
Currently only Standard is supported.
sourcepub fn set_interlace_method(
&mut self,
interlace_method: InterlaceMethod
) -> Result<()>
pub fn set_interlace_method( &mut self, interlace_method: InterlaceMethod ) -> Result<()>
Set the interlace method.
Currently only Standard is supported; requesting Adam7 will return an error.