Struct mtpng::Header

source ·
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

source

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.

source

pub fn width(&self) -> u32

Get the pixel width of the image.

source

pub fn height(&self) -> u32

Get the pixel height of the image.

source

pub fn depth(&self) -> u8

Get the color depth of the image in bits.

source

pub fn color_type(&self) -> ColorType

Get the color type of the image.

source

pub fn compression_method(&self) -> CompressionMethod

Get the compression method defined for the image.

source

pub fn filter_method(&self) -> FilterMethod

Get the filter method defined for the image.

source

pub fn interlace_method(&self) -> InterlaceMethod

Get the interlace method defined for the image.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn set_filter_method(&mut self, filter_method: FilterMethod) -> Result<()>

Set the filter method.

Currently only Standard is supported.

source

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.

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 Default for Header

source§

fn default() -> Self

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

impl Copy 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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

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,

§

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.