Skip to content

Commit

Permalink
Add new_with_limits
Browse files Browse the repository at this point in the history
  • Loading branch information
zealousidealroll authored Sep 5, 2018
1 parent 919a2bf commit 8382e9a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,14 @@ pub struct Decoder<R: Read> {

impl<R: Read> Decoder<R> {
pub fn new(r: R) -> Decoder<R> {
Decoder::new_with_limits(r, Limits::default())
}

pub fn new_with_limits(r: R, l: Limits) -> Decoder<R> {
Decoder {
r: r,
transform: ::Transformations::EXPAND | ::Transformations::SCALE_16 | ::Transformations::STRIP_16,
limits: Limits::default(),
limits: l,
}
}

Expand All @@ -94,14 +98,12 @@ impl<R: Read> Decoder<R> {
/// // This image is 32x32 pixels, so it's more than four pixels in size.
/// let mut limits = Limits::default();
/// limits.pixels = 4;
/// let mut decoder = Decoder::new(File::open("tests/pngsuite/basi0g01.png").unwrap());
/// decoder.set_limits(limits);
/// let mut decoder = Decoder::new_with_limits(File::open("tests/pngsuite/basi0g01.png", limits).unwrap());
/// assert!(decoder.read_info().is_err());
/// // This image is 32x32 pixels, so it's exactly 1024 pixels in size.
/// let mut limits = Limits::default();
/// limits.pixels = 1024;
/// let mut decoder = Decoder::new(File::open("tests/pngsuite/basi0g01.png").unwrap());
/// decoder.set_limits(limits);
/// let mut decoder = Decoder::new_with_limits(File::open("tests/pngsuite/basi0g01.png", limits).unwrap());
/// assert!(decoder.read_info().is_ok());
/// ```
pub fn set_limits(&mut self, limits: Limits) {
Expand Down

0 comments on commit 8382e9a

Please sign in to comment.