[][src]Crate png_pong

PNG Pong - A pure Rust PNG encoder & decoder

This is a pure Rust PNG image decoder and encoder based on lodepng. This crate allows easy reading and writing of PNG files without any system dependencies.

Goals

  • Forbid unsafe.
  • APNG support as iterator.
  • Fast.
  • Compatible with pix / gift-style API.
  • Load all PNG files crushed with pngcrush.
  • Save crushed PNG files.
  • Clean, well-documented, concise code.

Examples

  • Say you want to read a PNG file into a raster:
let mut decoder_builder = png_pong::DecoderBuilder::new();
let data = std::fs::read("graphic.png").expect("Failed to open PNG");
let data = std::io::Cursor::new(data);
let decoder = decoder_builder.decode_rasters(data);
let (raster, _nanos) = decoder
    .last()
    .expect("No frames in PNG")
    .expect("PNG parsing error");
  • Say you want to save a raster as a PNG file.
let raster = png_pong::RasterBuilder::new().with_pixels(1, 1, &[
    pix::Rgba8::with_alpha(
        pix::Ch8::new(0),
        pix::Ch8::new(0),
        pix::Ch8::new(0),
        pix::Ch8::new(0),
    )][..]
);
let mut out_data = Vec::new();
let mut encoder = png_pong::EncoderBuilder::new();
let mut encoder = encoder.encode_rasters(&mut out_data);
encoder.add_frame(&raster, 0).expect("Failed to add frame");
std::fs::write("graphic.png", out_data).expect("Failed to save image");

TODO

  • Implement APNG reading.
  • Implement Chunk reading (with all the different chunk structs).
  • RasterDecoder should wrap ChunkDecoder & RasterEncoder should wrap ChunkEncoder
  • Replace ParseError with Rust-style enum instead of having a C integer.
  • More test cases to test against.

Modules

chunk

Low-level chunk control.

prelude

Prelude.

Structs

ChunkDecoder

Decoder for iterating Chunks within a PNG file.

ChunkEncoder

Encoder for writing Chunks into a PNG file.

DecoderBuilder

Builder for PNG decoders.

EncoderBuilder

Builder for PNG encoders.

Meta

Metadata for raster.

ParseError

A lame error code.

Raster

Raster image representing a two-dimensional array of pixels.

RasterBuilder

Builder for Raster images.

RasterDecoder

Decoder for iterating Rasters within a PNG file.

RasterEncoder

Encoder for writing Rasters into a PNG file.

Enums

DecodeError

Decoding Errors.

EncodeError

Encoding Errors.