Crate png [] [src]

PNG encoder and decoder

This crate contains a PNG decoder. It supports reading of single lines or whole frames.

The decoder

The most important types for decoding purposes are Decoder and Reader. They both wrap a std::io::Read. Decoder serves as a builder for Reader. Calling Decoder::read_info reads from the Read until the image data is reached.

Using the decoder

use std::fs::File;

// The decoder is a build for reader and can be used to set various decoding options
// via `Transformations`. The default output transformation is `TRANSFORM_EXPAND
// | TRANSFORM_STRIP_ALPHA`.
let decoder = png::Decoder::new(File::open("tests/pngsuite/basi0g01.png").unwrap());
let (info, mut reader) = decoder.read_info().unwrap();
// Allocate the output buffer.
let mut buf = vec![0; info.buffer_size()];
// Read the next frame. Currently this function should only called once.
// The default options
reader.next_frame(&mut buf).unwrap();

Encoder

Not available yet

Modules

chunk

Chunk types and functions

Structs

AnimationControl

Animation control information

Decoder

PNG Decoder

Encoder
FrameControl

Frame control information

Info

PNG info struct

OutputInfo

Output info

Reader

PNG reader (mostly high-level interface)

StreamingDecoder

PNG StreamingDecoder (low-level interface)

Transformations
Writer

Enums

BitDepth

Bit depth of the png file

ColorType
Decoded

Result of the decoding process

DecodingError
EncodingError

Constants

TRANSFORM_BGR

Flip RGB to BGR, RGBA to BGRA

TRANSFORM_EXPAND

Expand paletted images to RGB, expand grayscale images of less than 8-bit depth to 8-bit depth, and expand tRNS chunks to alpha channels.

TRANSFORM_EXPAND_16
TRANSFORM_GRAY_TO_RGB
TRANSFORM_IDENTITY

No transformation

TRANSFORM_INVERT_ALPHA

Change alpha from opacity to transparency

TRANSFORM_INVERT_MONO

Invert monochrome images

TRANSFORM_PACKING

Expand 1, 2 and 4-bit samples to bytes

TRANSFORM_PACKSWAP

Change order of packed pixels to LSB first

TRANSFORM_SCALE_16
TRANSFORM_SHIFT

Normalize pixels to the sBIT depth

TRANSFORM_STRIP_16

Strip 16-bit samples to 8 bits

TRANSFORM_STRIP_ALPHA

Discard the alpha channel

TRANSFORM_STRIP_FILLER
TRANSFORM_STRIP_FILLER_AFTER
TRANSFORM_STRIP_FILLER_BEFORE
TRANSFORM_SWAP_ALPHA

Flip RGBA to ARGB or GA to AG

TRANSFORM_SWAP_ENDIAN

Byte-swap 16-bit samples

Traits

HasParameters

Object has parameters

Parameter

Configuration parameter trait