png/lib.rs
1//! # PNG encoder and decoder
2//! This crate contains a PNG encoder and decoder. It supports reading of single lines or whole frames.
3//! ## The decoder
4//! The most important types for decoding purposes are [`Decoder`](struct.Decoder.html) and
5//! [`Reader`](struct.Reader.html). They both wrap a `std::io::Read`.
6//! `Decoder` serves as a builder for `Reader`. Calling `Decoder::read_info` reads from the `Read` until the
7//! image data is reached.
8//! ### Using the decoder
9//! use std::fs::File;
10//!
11//! // The decoder is a build for reader and can be used to set various decoding options
12//! // via `Transformations`. The default output transformation is `Transformations::EXPAND
13//! // | Transformations::STRIP_ALPHA`.
14//! let decoder = png::Decoder::new(File::open("tests/pngsuite/basi0g01.png").unwrap());
15//! let (info, mut reader) = decoder.read_info().unwrap();
16//! // Allocate the output buffer.
17//! let mut buf = vec![0; info.buffer_size()];
18//! // Read the next frame. Currently this function should only called once.
19//! // The default options
20//! reader.next_frame(&mut buf).unwrap();
21//! ## Encoder
22//! ### Using the encoder
23//! ```ignore
24//! // For reading and opening files
25//! use std::path::Path;
26//! use std::fs::File;
27//! use std::io::BufWriter;
28//! // To use encoder.set()
29//! use png::HasParameters;
30//!
31//! let path = Path::new(r"/path/to/image.png");
32//! let file = File::create(path).unwrap();
33//! let ref mut w = BufWriter::new(file);
34//!
35//! let mut encoder = png::Encoder::new(w, 2, 1); // Width is 2 pixels and height is 1.
36//! encoder.set(png::ColorType::RGBA).set(png::BitDepth::Eight);
37//! let mut writer = encoder.write_header().unwrap();
38//!
39//! let data = [255, 0, 0, 255, 0, 0, 0, 255]; // An array containing a RGBA sequence. First pixel is red and second pixel is black.
40//! writer.write_image_data(&data).unwrap(); // Save
41//! ```
42//!
43//#![cfg_attr(test, feature(test))]
44
45#[macro_use] extern crate bitflags;
46
47extern crate num_iter;
48
49pub mod chunk;
50mod crc;
51mod decoder;
52#[cfg(feature = "png-encoding")]
53mod encoder;
54mod filter;
55mod traits;
56mod common;
57mod utils;
58
59pub use common::*;
60pub use decoder::{Decoder, Reader, OutputInfo, StreamingDecoder, Decoded, DecodingError, Limits};
61#[cfg(feature = "png-encoding")]
62pub use encoder::{Encoder, Writer, EncodingError};
63pub use filter::FilterType;
64
65pub use traits::{Parameter, HasParameters};