From 4adcc5e14ac4c7ff6905ba9cc91890e4ac667579 Mon Sep 17 00:00:00 2001 From: Felix Hanau Date: Wed, 24 Jul 2019 14:16:13 +0100 Subject: [PATCH] Interlacing fixes (#182) * Fix decoding interlaced images with height or width <= 2 * Add Issue 175 test case * Deinterlace tiny images correctly --- src/interlace.rs | 13 +++++++++++++ tests/regression.rs | 18 +++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/interlace.rs b/src/interlace.rs index 5f2daccf..2d391934 100644 --- a/src/interlace.rs +++ b/src/interlace.rs @@ -135,6 +135,19 @@ pub fn deinterlace_image(png: &PngImage) -> PngImage { if current_pass == 3 && png.ihdr.height <= 4 { current_pass += 1; } + if current_pass == 4 && png.ihdr.width <= 2 { + current_pass += 1; + } + if current_pass == 5 && png.ihdr.height <= 2 { + current_pass += 1; + } + if current_pass == 6 && png.ihdr.width == 1 { + current_pass += 1; + } + if current_pass == 7 && png.ihdr.height == 1 { + break; + } + pass_constants = interlaced_constants(current_pass); current_y = pass_constants.y_shift as usize; } diff --git a/tests/regression.rs b/tests/regression.rs index a5d8bd39..867902ab 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -634,4 +634,20 @@ fn issue_175() { ColorType::Grayscale, BitDepth::One, ); -} \ No newline at end of file +} + +#[test] +fn issue_182() { + let input = "tests/files/issue-175.png"; + let (output, mut opts) = get_opts(Path::new(input)); + opts.interlace = Some(0); + + test_it_converts( + input, + Some((output, opts)), + ColorType::Grayscale, + BitDepth::One, + ColorType::Grayscale, + BitDepth::One, + ); +}