Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs on encoder/writer and added example code for encoding #44

Merged
merged 1 commit into from
Jan 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl From<EncodingError> for io::Error {
}
}

/// PNG Encoder
pub struct Encoder<W: Write> {
w: W,
info: Info,
Expand Down Expand Up @@ -88,6 +89,7 @@ impl<W: Write> Parameter<Encoder<W>> for BitDepth {
}
}

/// PNG writer
pub struct Writer<W: Write> {
w: W,
info: Info,
Expand Down
23 changes: 21 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! # PNG encoder and decoder
//! This crate contains a PNG decoder. It supports reading of single lines or whole frames.
//! This crate contains a PNG encoder and decoder. It supports reading of single lines or whole frames.
//! ## The decoder
//! The most important types for decoding purposes are [`Decoder`](struct.Decoder.html) and
//! [`Reader`](struct.Reader.html). They both wrap a `std::io::Read`.
Expand All @@ -19,7 +19,26 @@
//! // The default options
//! reader.next_frame(&mut buf).unwrap();
//! ## Encoder
//! Not available yet
//! ### Using the encoder
//! // For reading and opening files
//! use std::path::Path;
//! use std::fs::File;
//! use std::io::BufWriter;
//! // To use encoder.set()
//! use png::HasParameters;
//!
//! let path = Path::new(r"/path/to/image.png");
//! let file = File::create(path).unwrap();
//! let ref mut w = BufWriter::new(file);
//!
//! let mut encoder = png::Encoder::new(w, 2, 1); // Width is 2 pixels and height is 1.
//! encoder.set(png::ColorType::RGBA).set(png::BitDepth::Eight);
//! let mut writer = encoder.write_header().unwrap();
//!
//! 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.
//! writer.write_image_data(&data).unwrap(); // Save
//!
//!
//#![cfg_attr(test, feature(test))]

#[macro_use] extern crate bitflags;
Expand Down