diff --git a/src/lib.rs b/src/lib.rs index 3f054a51..c248f702 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -187,9 +187,6 @@ pub fn optimize(filepath: &Path, opts: &Options) -> Result<(), String> { if let Some(interlacing) = opts.interlace { if png.change_interlacing(interlacing) { something_changed = true; - if opts.verbosity == Some(1) { - report_reduction(&png); - } } } diff --git a/src/png.rs b/src/png.rs index 76dd27b5..febf325e 100644 --- a/src/png.rs +++ b/src/png.rs @@ -123,6 +123,8 @@ pub struct ScanLines<'a> { pub png: &'a PngData, start: usize, end: usize, + /// Current pass number, and 0-indexed row within the pass + pass: Option<(u8, u32)>, } impl<'a> Iterator for ScanLines<'a> { @@ -130,7 +132,99 @@ impl<'a> Iterator for ScanLines<'a> { fn next(&mut self) -> Option { if self.end == self.png.raw_data.len() { None + } else if self.png.ihdr_data.interlaced == 1 { + // Scanlines for interlaced PNG files + if self.pass.is_none() { + self.pass = Some((1, 0)); + } + // Handle edge cases for images smaller than 5 pixels in either direction + if self.png.ihdr_data.width < 5 && self.pass.unwrap().0 == 2 { + if let Some(pass) = self.pass.as_mut() { + pass.0 = 3; + pass.1 = 4; + } + } + // Intentionally keep these separate so that they can be applied one after another + if self.png.ihdr_data.height < 5 && self.pass.unwrap().0 == 3 { + if let Some(pass) = self.pass.as_mut() { + pass.0 = 4; + pass.1 = 0; + } + } + let bits_per_pixel = self.png.ihdr_data.bit_depth.as_u8() as usize * + self.png.channels_per_pixel() as usize; + let mut bits_per_line = self.png.ihdr_data.width as usize * bits_per_pixel; + let y_steps; + match self.pass { + Some((1, _)) => { + bits_per_line >>= 3; + y_steps = 8; + } + Some((2, _)) => { + bits_per_line >>= 3; + y_steps = 8; + } + Some((3, _)) => { + bits_per_line >>= 2; + y_steps = 8; + } + Some((4, _)) => { + bits_per_line >>= 2; + y_steps = 4; + } + Some((5, _)) => { + bits_per_line >>= 1; + y_steps = 4; + } + Some((6, _)) => { + bits_per_line >>= 1; + y_steps = 2; + } + Some((7, _)) => { + y_steps = 2; + } + _ => unreachable!(), + } + // Determine whether to trim the last (overflow) pixel for rows on this pass + let gap = bits_per_line % bits_per_pixel; + if gap != 0 { + let x_start = bits_per_pixel * + match self.pass.unwrap().0 { + 2 => 4, + 4 => 2, + 6 => 1, + _ => 0, + }; + if gap >= x_start { + bits_per_line += bits_per_pixel - gap; + } else { + bits_per_line -= gap; + } + } + // Round up without converting to float + let bytes_per_line = (bits_per_line + bits_per_line % 8) >> 3; + self.start = self.end; + self.end = self.start + bytes_per_line + 1; + // TODO: Handle 4x4 pixel images + if let Some(pass) = self.pass.as_mut() { + if pass.1 + y_steps >= self.png.ihdr_data.height { + pass.0 += 1; + pass.1 = match pass.0 { + 3 => 4, + 5 => 2, + 7 => 1, + _ => 0, + }; + } else { + pass.1 += y_steps; + } + } + Some(ScanLine { + filter: self.png.raw_data[self.start], + data: self.png.raw_data[(self.start + 1)..self.end].to_owned(), + }) } else { + // Standard, non-interlaced PNG scanlines let bits_per_line = self.png.ihdr_data.width as usize * self.png.ihdr_data.bit_depth.as_u8() as usize * self.png.channels_per_pixel() as usize; @@ -338,6 +432,7 @@ impl PngData { png: &self, start: 0, end: 0, + pass: None, } } /// Reverse all filters applied on the image, returning an unfiltered IDAT bytestream @@ -543,11 +638,15 @@ impl PngData { /// Convert the image to the specified interlacing type /// Returns true if the interlacing was changed, false otherwise pub fn change_interlacing(&mut self, interlace: u8) -> bool { - // TODO: Implement - if interlace != self.ihdr_data.interlaced { + if interlace == self.ihdr_data.interlaced { return false; } + if interlace == 1 { + // TODO: Interlace + } else { + // TODO: Deinterlace + } false } } diff --git a/tests/files/generate.sh b/tests/files/generate.sh new file mode 100755 index 00000000..7e63cb1a --- /dev/null +++ b/tests/files/generate.sh @@ -0,0 +1,157 @@ +#/bin/bash +cp rgba_16_should_be_rgba_16.png interlaced_rgba_16_should_be_rgba_16.png +cp rgba_16_should_be_rgba_8.png interlaced_rgba_16_should_be_rgba_8.png +cp rgba_8_should_be_rgba_8.png interlaced_rgba_8_should_be_rgba_8.png +cp rgba_16_should_be_rgb_16.png interlaced_rgba_16_should_be_rgb_16.png +cp rgba_16_should_be_rgb_8.png interlaced_rgba_16_should_be_rgb_8.png +cp rgba_8_should_be_rgb_8.png interlaced_rgba_8_should_be_rgb_8.png +cp rgba_16_should_be_palette_8.png interlaced_rgba_16_should_be_palette_8.png +cp rgba_8_should_be_palette_8.png interlaced_rgba_8_should_be_palette_8.png +cp rgba_16_should_be_palette_4.png interlaced_rgba_16_should_be_palette_4.png +cp rgba_8_should_be_palette_4.png interlaced_rgba_8_should_be_palette_4.png +cp rgba_16_should_be_palette_2.png interlaced_rgba_16_should_be_palette_2.png +cp rgba_8_should_be_palette_2.png interlaced_rgba_8_should_be_palette_2.png +cp rgba_16_should_be_palette_1.png interlaced_rgba_16_should_be_palette_1.png +cp rgba_8_should_be_palette_1.png interlaced_rgba_8_should_be_palette_1.png +cp rgba_16_should_be_grayscale_alpha_16.png interlaced_rgba_16_should_be_grayscale_alpha_16.png +cp rgba_16_should_be_grayscale_alpha_8.png interlaced_rgba_16_should_be_grayscale_alpha_8.png +cp rgba_8_should_be_grayscale_alpha_8.png interlaced_rgba_8_should_be_grayscale_alpha_8.png +cp rgba_16_should_be_grayscale_16.png interlaced_rgba_16_should_be_grayscale_16.png +cp rgba_16_should_be_grayscale_8.png interlaced_rgba_16_should_be_grayscale_8.png +cp rgba_8_should_be_grayscale_8.png interlaced_rgba_8_should_be_grayscale_8.png +cp rgba_16_should_be_palette_4_grayscale.png interlaced_rgba_16_should_be_palette_4_grayscale.png +cp rgba_8_should_be_palette_4_grayscale.png interlaced_rgba_8_should_be_palette_4_grayscale.png +cp rgba_16_should_be_palette_2_grayscale.png interlaced_rgba_16_should_be_palette_2_grayscale.png +cp rgba_8_should_be_palette_2_grayscale.png interlaced_rgba_8_should_be_palette_2_grayscale.png +cp rgba_16_should_be_palette_1_grayscale.png interlaced_rgba_16_should_be_palette_1_grayscale.png +cp rgba_8_should_be_palette_1_grayscale.png interlaced_rgba_8_should_be_palette_1_grayscale.png +cp rgb_16_should_be_rgb_16.png interlaced_rgb_16_should_be_rgb_16.png +cp rgb_16_should_be_rgb_8.png interlaced_rgb_16_should_be_rgb_8.png +cp rgb_8_should_be_rgb_8.png interlaced_rgb_8_should_be_rgb_8.png +cp rgb_16_should_be_palette_8.png interlaced_rgb_16_should_be_palette_8.png +cp rgb_8_should_be_palette_8.png interlaced_rgb_8_should_be_palette_8.png +cp rgb_16_should_be_palette_4.png interlaced_rgb_16_should_be_palette_4.png +cp rgb_8_should_be_palette_4.png interlaced_rgb_8_should_be_palette_4.png +cp rgb_16_should_be_palette_2.png interlaced_rgb_16_should_be_palette_2.png +cp rgb_8_should_be_palette_2.png interlaced_rgb_8_should_be_palette_2.png +cp rgb_16_should_be_palette_1.png interlaced_rgb_16_should_be_palette_1.png +cp rgb_8_should_be_palette_1.png interlaced_rgb_8_should_be_palette_1.png +cp rgb_16_should_be_grayscale_16.png interlaced_rgb_16_should_be_grayscale_16.png +cp rgb_16_should_be_grayscale_8.png interlaced_rgb_16_should_be_grayscale_8.png +cp rgb_8_should_be_grayscale_8.png interlaced_rgb_8_should_be_grayscale_8.png +cp rgb_16_should_be_palette_4_grayscale.png interlaced_rgb_16_should_be_palette_4_grayscale.png +cp rgb_8_should_be_palette_4_grayscale.png interlaced_rgb_8_should_be_palette_4_grayscale.png +cp rgb_16_should_be_palette_2_grayscale.png interlaced_rgb_16_should_be_palette_2_grayscale.png +cp rgb_8_should_be_palette_2_grayscale.png interlaced_rgb_8_should_be_palette_2_grayscale.png +cp rgb_16_should_be_palette_1_grayscale.png interlaced_rgb_16_should_be_palette_1_grayscale.png +cp rgb_8_should_be_palette_1_grayscale.png interlaced_rgb_8_should_be_palette_1_grayscale.png +cp palette_8_should_be_grayscale_8.png interlaced_palette_8_should_be_grayscale_8.png +cp palette_8_should_be_palette_8.png interlaced_palette_8_should_be_palette_8.png +cp palette_8_should_be_palette_4.png interlaced_palette_8_should_be_palette_4.png +cp palette_4_should_be_palette_4.png interlaced_palette_4_should_be_palette_4.png +cp palette_8_should_be_palette_2.png interlaced_palette_8_should_be_palette_2.png +cp palette_4_should_be_palette_2.png interlaced_palette_4_should_be_palette_2.png +cp palette_2_should_be_palette_2.png interlaced_palette_2_should_be_palette_2.png +cp palette_8_should_be_palette_1.png interlaced_palette_8_should_be_palette_1.png +cp palette_4_should_be_palette_1.png interlaced_palette_4_should_be_palette_1.png +cp palette_2_should_be_palette_1.png interlaced_palette_2_should_be_palette_1.png +cp palette_1_should_be_palette_1.png interlaced_palette_1_should_be_palette_1.png +cp grayscale_alpha_16_should_be_grayscale_alpha_16.png interlaced_grayscale_alpha_16_should_be_grayscale_alpha_16.png +cp grayscale_alpha_16_should_be_grayscale_alpha_8.png interlaced_grayscale_alpha_16_should_be_grayscale_alpha_8.png +cp grayscale_alpha_8_should_be_grayscale_alpha_8.png interlaced_grayscale_alpha_8_should_be_grayscale_alpha_8.png +cp grayscale_alpha_16_should_be_grayscale_16.png interlaced_grayscale_alpha_16_should_be_grayscale_16.png +cp grayscale_alpha_16_should_be_grayscale_8.png interlaced_grayscale_alpha_16_should_be_grayscale_8.png +cp grayscale_alpha_8_should_be_grayscale_8.png interlaced_grayscale_alpha_8_should_be_grayscale_8.png +cp grayscale_alpha_16_should_be_palette_4.png interlaced_grayscale_alpha_16_should_be_palette_4.png +cp grayscale_alpha_8_should_be_palette_4.png interlaced_grayscale_alpha_8_should_be_palette_4.png +cp grayscale_alpha_16_should_be_palette_2.png interlaced_grayscale_alpha_16_should_be_palette_2.png +cp grayscale_alpha_8_should_be_palette_2.png interlaced_grayscale_alpha_8_should_be_palette_2.png +cp grayscale_alpha_16_should_be_palette_1.png interlaced_grayscale_alpha_16_should_be_palette_1.png +cp grayscale_alpha_8_should_be_palette_1.png interlaced_grayscale_alpha_8_should_be_palette_1.png +cp grayscale_16_should_be_grayscale_16.png interlaced_grayscale_16_should_be_grayscale_16.png +cp grayscale_16_should_be_grayscale_8.png interlaced_grayscale_16_should_be_grayscale_8.png +cp grayscale_16_should_be_palette_4.png interlaced_grayscale_16_should_be_palette_4.png +cp grayscale_16_should_be_palette_2.png interlaced_grayscale_16_should_be_palette_2.png +cp grayscale_16_should_be_palette_1.png interlaced_grayscale_16_should_be_palette_1.png +cp grayscale_8_should_be_grayscale_8.png interlaced_grayscale_8_should_be_grayscale_8.png +cp grayscale_8_should_be_palette_4.png interlaced_grayscale_8_should_be_palette_4.png +cp grayscale_8_should_be_palette_2.png interlaced_grayscale_8_should_be_palette_2.png +cp grayscale_8_should_be_palette_1.png interlaced_grayscale_8_should_be_palette_1.png +optipng -nx -i 1 interlaced_rgba_16_should_be_rgba_16.png +optipng -nx -i 1 interlaced_rgba_16_should_be_rgba_8.png +optipng -nx -i 1 interlaced_rgba_8_should_be_rgba_8.png +optipng -nx -i 1 interlaced_rgba_16_should_be_rgb_16.png +optipng -nx -i 1 interlaced_rgba_16_should_be_rgb_8.png +optipng -nx -i 1 interlaced_rgba_8_should_be_rgb_8.png +optipng -nx -i 1 interlaced_rgba_16_should_be_palette_8.png +optipng -nx -i 1 interlaced_rgba_8_should_be_palette_8.png +optipng -nx -i 1 interlaced_rgba_16_should_be_palette_4.png +optipng -nx -i 1 interlaced_rgba_8_should_be_palette_4.png +optipng -nx -i 1 interlaced_rgba_16_should_be_palette_2.png +optipng -nx -i 1 interlaced_rgba_8_should_be_palette_2.png +optipng -nx -i 1 interlaced_rgba_16_should_be_palette_1.png +optipng -nx -i 1 interlaced_rgba_8_should_be_palette_1.png +optipng -nx -i 1 interlaced_rgba_16_should_be_grayscale_alpha_16.png +optipng -nx -i 1 interlaced_rgba_16_should_be_grayscale_alpha_8.png +optipng -nx -i 1 interlaced_rgba_8_should_be_grayscale_alpha_8.png +optipng -nx -i 1 interlaced_rgba_16_should_be_grayscale_16.png +optipng -nx -i 1 interlaced_rgba_16_should_be_grayscale_8.png +optipng -nx -i 1 interlaced_rgba_8_should_be_grayscale_8.png +optipng -nx -i 1 interlaced_rgba_16_should_be_palette_4_grayscale.png +optipng -nx -i 1 interlaced_rgba_8_should_be_palette_4_grayscale.png +optipng -nx -i 1 interlaced_rgba_16_should_be_palette_2_grayscale.png +optipng -nx -i 1 interlaced_rgba_8_should_be_palette_2_grayscale.png +optipng -nx -i 1 interlaced_rgba_16_should_be_palette_1_grayscale.png +optipng -nx -i 1 interlaced_rgba_8_should_be_palette_1_grayscale.png +optipng -nx -i 1 interlaced_rgb_16_should_be_rgb_16.png +optipng -nx -i 1 interlaced_rgb_16_should_be_rgb_8.png +optipng -nx -i 1 interlaced_rgb_8_should_be_rgb_8.png +optipng -nx -i 1 interlaced_rgb_16_should_be_palette_8.png +optipng -nx -i 1 interlaced_rgb_8_should_be_palette_8.png +optipng -nx -i 1 interlaced_rgb_16_should_be_palette_4.png +optipng -nx -i 1 interlaced_rgb_8_should_be_palette_4.png +optipng -nx -i 1 interlaced_rgb_16_should_be_palette_2.png +optipng -nx -i 1 interlaced_rgb_8_should_be_palette_2.png +optipng -nx -i 1 interlaced_rgb_16_should_be_palette_1.png +optipng -nx -i 1 interlaced_rgb_8_should_be_palette_1.png +optipng -nx -i 1 interlaced_rgb_16_should_be_grayscale_16.png +optipng -nx -i 1 interlaced_rgb_16_should_be_grayscale_8.png +optipng -nx -i 1 interlaced_rgb_8_should_be_grayscale_8.png +optipng -nx -i 1 interlaced_rgb_16_should_be_palette_4_grayscale.png +optipng -nx -i 1 interlaced_rgb_8_should_be_palette_4_grayscale.png +optipng -nx -i 1 interlaced_rgb_16_should_be_palette_2_grayscale.png +optipng -nx -i 1 interlaced_rgb_8_should_be_palette_2_grayscale.png +optipng -nx -i 1 interlaced_rgb_16_should_be_palette_1_grayscale.png +optipng -nx -i 1 interlaced_rgb_8_should_be_palette_1_grayscale.png +optipng -nx -i 1 interlaced_palette_8_should_be_grayscale_8.png +optipng -nx -i 1 interlaced_palette_8_should_be_palette_8.png +optipng -nx -i 1 interlaced_palette_8_should_be_palette_4.png +optipng -nx -i 1 interlaced_palette_4_should_be_palette_4.png +optipng -nx -i 1 interlaced_palette_8_should_be_palette_2.png +optipng -nx -i 1 interlaced_palette_4_should_be_palette_2.png +optipng -nx -i 1 interlaced_palette_2_should_be_palette_2.png +optipng -nx -i 1 interlaced_palette_8_should_be_palette_1.png +optipng -nx -i 1 interlaced_palette_4_should_be_palette_1.png +optipng -nx -i 1 interlaced_palette_2_should_be_palette_1.png +optipng -nx -i 1 interlaced_palette_1_should_be_palette_1.png +optipng -nx -i 1 interlaced_grayscale_alpha_16_should_be_grayscale_alpha_16.png +optipng -nx -i 1 interlaced_grayscale_alpha_16_should_be_grayscale_alpha_8.png +optipng -nx -i 1 interlaced_grayscale_alpha_8_should_be_grayscale_alpha_8.png +optipng -nx -i 1 interlaced_grayscale_alpha_16_should_be_grayscale_16.png +optipng -nx -i 1 interlaced_grayscale_alpha_16_should_be_grayscale_8.png +optipng -nx -i 1 interlaced_grayscale_alpha_8_should_be_grayscale_8.png +optipng -nx -i 1 interlaced_grayscale_alpha_16_should_be_palette_4.png +optipng -nx -i 1 interlaced_grayscale_alpha_8_should_be_palette_4.png +optipng -nx -i 1 interlaced_grayscale_alpha_16_should_be_palette_2.png +optipng -nx -i 1 interlaced_grayscale_alpha_8_should_be_palette_2.png +optipng -nx -i 1 interlaced_grayscale_alpha_16_should_be_palette_1.png +optipng -nx -i 1 interlaced_grayscale_alpha_8_should_be_palette_1.png +optipng -nx -i 1 interlaced_grayscale_16_should_be_grayscale_16.png +optipng -nx -i 1 interlaced_grayscale_16_should_be_grayscale_8.png +optipng -nx -i 1 interlaced_grayscale_16_should_be_palette_4.png +optipng -nx -i 1 interlaced_grayscale_16_should_be_palette_2.png +optipng -nx -i 1 interlaced_grayscale_16_should_be_palette_1.png +optipng -nx -i 1 interlaced_grayscale_8_should_be_grayscale_8.png +optipng -nx -i 1 interlaced_grayscale_8_should_be_palette_4.png +optipng -nx -i 1 interlaced_grayscale_8_should_be_palette_2.png +optipng -nx -i 1 interlaced_grayscale_8_should_be_palette_1.png diff --git a/tests/files/interlaced_grayscale_16_should_be_grayscale_16.png b/tests/files/interlaced_grayscale_16_should_be_grayscale_16.png new file mode 100644 index 00000000..ede03fa8 Binary files /dev/null and b/tests/files/interlaced_grayscale_16_should_be_grayscale_16.png differ diff --git a/tests/files/interlaced_grayscale_16_should_be_grayscale_8.png b/tests/files/interlaced_grayscale_16_should_be_grayscale_8.png new file mode 100644 index 00000000..399e5dc2 Binary files /dev/null and b/tests/files/interlaced_grayscale_16_should_be_grayscale_8.png differ diff --git a/tests/files/interlaced_grayscale_16_should_be_palette_1.png b/tests/files/interlaced_grayscale_16_should_be_palette_1.png new file mode 100644 index 00000000..c83dd280 Binary files /dev/null and b/tests/files/interlaced_grayscale_16_should_be_palette_1.png differ diff --git a/tests/files/interlaced_grayscale_16_should_be_palette_2.png b/tests/files/interlaced_grayscale_16_should_be_palette_2.png new file mode 100644 index 00000000..bbe611c1 Binary files /dev/null and b/tests/files/interlaced_grayscale_16_should_be_palette_2.png differ diff --git a/tests/files/interlaced_grayscale_16_should_be_palette_4.png b/tests/files/interlaced_grayscale_16_should_be_palette_4.png new file mode 100644 index 00000000..5469aa39 Binary files /dev/null and b/tests/files/interlaced_grayscale_16_should_be_palette_4.png differ diff --git a/tests/files/interlaced_grayscale_8_should_be_grayscale_8.png b/tests/files/interlaced_grayscale_8_should_be_grayscale_8.png new file mode 100644 index 00000000..8384c4cb Binary files /dev/null and b/tests/files/interlaced_grayscale_8_should_be_grayscale_8.png differ diff --git a/tests/files/interlaced_grayscale_8_should_be_palette_1.png b/tests/files/interlaced_grayscale_8_should_be_palette_1.png new file mode 100644 index 00000000..68362afe Binary files /dev/null and b/tests/files/interlaced_grayscale_8_should_be_palette_1.png differ diff --git a/tests/files/interlaced_grayscale_8_should_be_palette_2.png b/tests/files/interlaced_grayscale_8_should_be_palette_2.png new file mode 100644 index 00000000..aa3aa0d5 Binary files /dev/null and b/tests/files/interlaced_grayscale_8_should_be_palette_2.png differ diff --git a/tests/files/interlaced_grayscale_8_should_be_palette_4.png b/tests/files/interlaced_grayscale_8_should_be_palette_4.png new file mode 100644 index 00000000..7786bf3a Binary files /dev/null and b/tests/files/interlaced_grayscale_8_should_be_palette_4.png differ diff --git a/tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_16.png b/tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_16.png new file mode 100644 index 00000000..dbaeb043 Binary files /dev/null and b/tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_16.png differ diff --git a/tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_8.png b/tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_8.png new file mode 100644 index 00000000..f55ed716 Binary files /dev/null and b/tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_8.png differ diff --git a/tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_alpha_16.png b/tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_alpha_16.png new file mode 100644 index 00000000..f7388809 Binary files /dev/null and b/tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_alpha_16.png differ diff --git a/tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_alpha_8.png b/tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_alpha_8.png new file mode 100644 index 00000000..5b06dd76 Binary files /dev/null and b/tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_alpha_8.png differ diff --git a/tests/files/interlaced_grayscale_alpha_16_should_be_palette_1.png b/tests/files/interlaced_grayscale_alpha_16_should_be_palette_1.png new file mode 100644 index 00000000..7f88db48 Binary files /dev/null and b/tests/files/interlaced_grayscale_alpha_16_should_be_palette_1.png differ diff --git a/tests/files/interlaced_grayscale_alpha_16_should_be_palette_2.png b/tests/files/interlaced_grayscale_alpha_16_should_be_palette_2.png new file mode 100644 index 00000000..b7e01d3d Binary files /dev/null and b/tests/files/interlaced_grayscale_alpha_16_should_be_palette_2.png differ diff --git a/tests/files/interlaced_grayscale_alpha_16_should_be_palette_4.png b/tests/files/interlaced_grayscale_alpha_16_should_be_palette_4.png new file mode 100644 index 00000000..4cfdf1c4 Binary files /dev/null and b/tests/files/interlaced_grayscale_alpha_16_should_be_palette_4.png differ diff --git a/tests/files/interlaced_grayscale_alpha_8_should_be_grayscale_8.png b/tests/files/interlaced_grayscale_alpha_8_should_be_grayscale_8.png new file mode 100644 index 00000000..da52e91a Binary files /dev/null and b/tests/files/interlaced_grayscale_alpha_8_should_be_grayscale_8.png differ diff --git a/tests/files/interlaced_grayscale_alpha_8_should_be_grayscale_alpha_8.png b/tests/files/interlaced_grayscale_alpha_8_should_be_grayscale_alpha_8.png new file mode 100644 index 00000000..cba55fcf Binary files /dev/null and b/tests/files/interlaced_grayscale_alpha_8_should_be_grayscale_alpha_8.png differ diff --git a/tests/files/interlaced_grayscale_alpha_8_should_be_palette_1.png b/tests/files/interlaced_grayscale_alpha_8_should_be_palette_1.png new file mode 100644 index 00000000..3b1e0c7d Binary files /dev/null and b/tests/files/interlaced_grayscale_alpha_8_should_be_palette_1.png differ diff --git a/tests/files/interlaced_grayscale_alpha_8_should_be_palette_2.png b/tests/files/interlaced_grayscale_alpha_8_should_be_palette_2.png new file mode 100644 index 00000000..5cfc04b9 Binary files /dev/null and b/tests/files/interlaced_grayscale_alpha_8_should_be_palette_2.png differ diff --git a/tests/files/interlaced_grayscale_alpha_8_should_be_palette_4.png b/tests/files/interlaced_grayscale_alpha_8_should_be_palette_4.png new file mode 100644 index 00000000..bddc76ae Binary files /dev/null and b/tests/files/interlaced_grayscale_alpha_8_should_be_palette_4.png differ diff --git a/tests/files/interlaced_palette_1_should_be_palette_1.png b/tests/files/interlaced_palette_1_should_be_palette_1.png new file mode 100644 index 00000000..8fad7ec4 Binary files /dev/null and b/tests/files/interlaced_palette_1_should_be_palette_1.png differ diff --git a/tests/files/interlaced_palette_2_should_be_palette_1.png b/tests/files/interlaced_palette_2_should_be_palette_1.png new file mode 100644 index 00000000..2ae2c18f Binary files /dev/null and b/tests/files/interlaced_palette_2_should_be_palette_1.png differ diff --git a/tests/files/interlaced_palette_2_should_be_palette_2.png b/tests/files/interlaced_palette_2_should_be_palette_2.png new file mode 100644 index 00000000..d762bf9c Binary files /dev/null and b/tests/files/interlaced_palette_2_should_be_palette_2.png differ diff --git a/tests/files/interlaced_palette_4_should_be_palette_1.png b/tests/files/interlaced_palette_4_should_be_palette_1.png new file mode 100644 index 00000000..d752f06b Binary files /dev/null and b/tests/files/interlaced_palette_4_should_be_palette_1.png differ diff --git a/tests/files/interlaced_palette_4_should_be_palette_2.png b/tests/files/interlaced_palette_4_should_be_palette_2.png new file mode 100644 index 00000000..2604e434 Binary files /dev/null and b/tests/files/interlaced_palette_4_should_be_palette_2.png differ diff --git a/tests/files/interlaced_palette_4_should_be_palette_4.png b/tests/files/interlaced_palette_4_should_be_palette_4.png new file mode 100644 index 00000000..ad7906bb Binary files /dev/null and b/tests/files/interlaced_palette_4_should_be_palette_4.png differ diff --git a/tests/files/interlaced_palette_8_should_be_grayscale_8.png b/tests/files/interlaced_palette_8_should_be_grayscale_8.png new file mode 100644 index 00000000..bdb188fd Binary files /dev/null and b/tests/files/interlaced_palette_8_should_be_grayscale_8.png differ diff --git a/tests/files/interlaced_palette_8_should_be_palette_1.png b/tests/files/interlaced_palette_8_should_be_palette_1.png new file mode 100644 index 00000000..3b00238f Binary files /dev/null and b/tests/files/interlaced_palette_8_should_be_palette_1.png differ diff --git a/tests/files/interlaced_palette_8_should_be_palette_2.png b/tests/files/interlaced_palette_8_should_be_palette_2.png new file mode 100644 index 00000000..c694bfc0 Binary files /dev/null and b/tests/files/interlaced_palette_8_should_be_palette_2.png differ diff --git a/tests/files/interlaced_palette_8_should_be_palette_4.png b/tests/files/interlaced_palette_8_should_be_palette_4.png new file mode 100644 index 00000000..46088e1c Binary files /dev/null and b/tests/files/interlaced_palette_8_should_be_palette_4.png differ diff --git a/tests/files/interlaced_palette_8_should_be_palette_8.png b/tests/files/interlaced_palette_8_should_be_palette_8.png new file mode 100644 index 00000000..bf8dfa92 Binary files /dev/null and b/tests/files/interlaced_palette_8_should_be_palette_8.png differ diff --git a/tests/files/interlaced_rgb_16_should_be_grayscale_16.png b/tests/files/interlaced_rgb_16_should_be_grayscale_16.png new file mode 100644 index 00000000..67ed56d0 Binary files /dev/null and b/tests/files/interlaced_rgb_16_should_be_grayscale_16.png differ diff --git a/tests/files/interlaced_rgb_16_should_be_grayscale_8.png b/tests/files/interlaced_rgb_16_should_be_grayscale_8.png new file mode 100644 index 00000000..a769e131 Binary files /dev/null and b/tests/files/interlaced_rgb_16_should_be_grayscale_8.png differ diff --git a/tests/files/interlaced_rgb_16_should_be_palette_1.png b/tests/files/interlaced_rgb_16_should_be_palette_1.png new file mode 100644 index 00000000..f0fb5a56 Binary files /dev/null and b/tests/files/interlaced_rgb_16_should_be_palette_1.png differ diff --git a/tests/files/interlaced_rgb_16_should_be_palette_1_grayscale.png b/tests/files/interlaced_rgb_16_should_be_palette_1_grayscale.png new file mode 100644 index 00000000..031593e3 Binary files /dev/null and b/tests/files/interlaced_rgb_16_should_be_palette_1_grayscale.png differ diff --git a/tests/files/interlaced_rgb_16_should_be_palette_2.png b/tests/files/interlaced_rgb_16_should_be_palette_2.png new file mode 100644 index 00000000..7242fac1 Binary files /dev/null and b/tests/files/interlaced_rgb_16_should_be_palette_2.png differ diff --git a/tests/files/interlaced_rgb_16_should_be_palette_2_grayscale.png b/tests/files/interlaced_rgb_16_should_be_palette_2_grayscale.png new file mode 100644 index 00000000..7ddc0525 Binary files /dev/null and b/tests/files/interlaced_rgb_16_should_be_palette_2_grayscale.png differ diff --git a/tests/files/interlaced_rgb_16_should_be_palette_4.png b/tests/files/interlaced_rgb_16_should_be_palette_4.png new file mode 100644 index 00000000..702ac8f4 Binary files /dev/null and b/tests/files/interlaced_rgb_16_should_be_palette_4.png differ diff --git a/tests/files/interlaced_rgb_16_should_be_palette_4_grayscale.png b/tests/files/interlaced_rgb_16_should_be_palette_4_grayscale.png new file mode 100644 index 00000000..bd09b398 Binary files /dev/null and b/tests/files/interlaced_rgb_16_should_be_palette_4_grayscale.png differ diff --git a/tests/files/interlaced_rgb_16_should_be_palette_8.png b/tests/files/interlaced_rgb_16_should_be_palette_8.png new file mode 100644 index 00000000..45444185 Binary files /dev/null and b/tests/files/interlaced_rgb_16_should_be_palette_8.png differ diff --git a/tests/files/interlaced_rgb_16_should_be_rgb_16.png b/tests/files/interlaced_rgb_16_should_be_rgb_16.png new file mode 100644 index 00000000..3be3b01f Binary files /dev/null and b/tests/files/interlaced_rgb_16_should_be_rgb_16.png differ diff --git a/tests/files/interlaced_rgb_16_should_be_rgb_8.png b/tests/files/interlaced_rgb_16_should_be_rgb_8.png new file mode 100644 index 00000000..aa3768d4 Binary files /dev/null and b/tests/files/interlaced_rgb_16_should_be_rgb_8.png differ diff --git a/tests/files/interlaced_rgb_8_should_be_grayscale_8.png b/tests/files/interlaced_rgb_8_should_be_grayscale_8.png new file mode 100644 index 00000000..53550a14 Binary files /dev/null and b/tests/files/interlaced_rgb_8_should_be_grayscale_8.png differ diff --git a/tests/files/interlaced_rgb_8_should_be_palette_1.png b/tests/files/interlaced_rgb_8_should_be_palette_1.png new file mode 100644 index 00000000..4f77419e Binary files /dev/null and b/tests/files/interlaced_rgb_8_should_be_palette_1.png differ diff --git a/tests/files/interlaced_rgb_8_should_be_palette_1_grayscale.png b/tests/files/interlaced_rgb_8_should_be_palette_1_grayscale.png new file mode 100644 index 00000000..3792e688 Binary files /dev/null and b/tests/files/interlaced_rgb_8_should_be_palette_1_grayscale.png differ diff --git a/tests/files/interlaced_rgb_8_should_be_palette_2.png b/tests/files/interlaced_rgb_8_should_be_palette_2.png new file mode 100644 index 00000000..88d72a01 Binary files /dev/null and b/tests/files/interlaced_rgb_8_should_be_palette_2.png differ diff --git a/tests/files/interlaced_rgb_8_should_be_palette_2_grayscale.png b/tests/files/interlaced_rgb_8_should_be_palette_2_grayscale.png new file mode 100644 index 00000000..89008e12 Binary files /dev/null and b/tests/files/interlaced_rgb_8_should_be_palette_2_grayscale.png differ diff --git a/tests/files/interlaced_rgb_8_should_be_palette_4.png b/tests/files/interlaced_rgb_8_should_be_palette_4.png new file mode 100644 index 00000000..23be3225 Binary files /dev/null and b/tests/files/interlaced_rgb_8_should_be_palette_4.png differ diff --git a/tests/files/interlaced_rgb_8_should_be_palette_4_grayscale.png b/tests/files/interlaced_rgb_8_should_be_palette_4_grayscale.png new file mode 100644 index 00000000..d842ddbd Binary files /dev/null and b/tests/files/interlaced_rgb_8_should_be_palette_4_grayscale.png differ diff --git a/tests/files/interlaced_rgb_8_should_be_palette_8.png b/tests/files/interlaced_rgb_8_should_be_palette_8.png new file mode 100644 index 00000000..464c6cdc Binary files /dev/null and b/tests/files/interlaced_rgb_8_should_be_palette_8.png differ diff --git a/tests/files/interlaced_rgb_8_should_be_rgb_8.png b/tests/files/interlaced_rgb_8_should_be_rgb_8.png new file mode 100644 index 00000000..23375db0 Binary files /dev/null and b/tests/files/interlaced_rgb_8_should_be_rgb_8.png differ diff --git a/tests/files/interlaced_rgba_16_should_be_grayscale_16.png b/tests/files/interlaced_rgba_16_should_be_grayscale_16.png new file mode 100644 index 00000000..f2f349f6 Binary files /dev/null and b/tests/files/interlaced_rgba_16_should_be_grayscale_16.png differ diff --git a/tests/files/interlaced_rgba_16_should_be_grayscale_8.png b/tests/files/interlaced_rgba_16_should_be_grayscale_8.png new file mode 100644 index 00000000..ee0245e1 Binary files /dev/null and b/tests/files/interlaced_rgba_16_should_be_grayscale_8.png differ diff --git a/tests/files/interlaced_rgba_16_should_be_grayscale_alpha_16.png b/tests/files/interlaced_rgba_16_should_be_grayscale_alpha_16.png new file mode 100644 index 00000000..f11382a1 Binary files /dev/null and b/tests/files/interlaced_rgba_16_should_be_grayscale_alpha_16.png differ diff --git a/tests/files/interlaced_rgba_16_should_be_grayscale_alpha_8.png b/tests/files/interlaced_rgba_16_should_be_grayscale_alpha_8.png new file mode 100644 index 00000000..8131ae79 Binary files /dev/null and b/tests/files/interlaced_rgba_16_should_be_grayscale_alpha_8.png differ diff --git a/tests/files/interlaced_rgba_16_should_be_palette_1.png b/tests/files/interlaced_rgba_16_should_be_palette_1.png new file mode 100644 index 00000000..8ccb3117 Binary files /dev/null and b/tests/files/interlaced_rgba_16_should_be_palette_1.png differ diff --git a/tests/files/interlaced_rgba_16_should_be_palette_1_grayscale.png b/tests/files/interlaced_rgba_16_should_be_palette_1_grayscale.png new file mode 100644 index 00000000..d7b2ad9e Binary files /dev/null and b/tests/files/interlaced_rgba_16_should_be_palette_1_grayscale.png differ diff --git a/tests/files/interlaced_rgba_16_should_be_palette_2.png b/tests/files/interlaced_rgba_16_should_be_palette_2.png new file mode 100644 index 00000000..8dfee69a Binary files /dev/null and b/tests/files/interlaced_rgba_16_should_be_palette_2.png differ diff --git a/tests/files/interlaced_rgba_16_should_be_palette_2_grayscale.png b/tests/files/interlaced_rgba_16_should_be_palette_2_grayscale.png new file mode 100644 index 00000000..15623587 Binary files /dev/null and b/tests/files/interlaced_rgba_16_should_be_palette_2_grayscale.png differ diff --git a/tests/files/interlaced_rgba_16_should_be_palette_4.png b/tests/files/interlaced_rgba_16_should_be_palette_4.png new file mode 100644 index 00000000..ce414935 Binary files /dev/null and b/tests/files/interlaced_rgba_16_should_be_palette_4.png differ diff --git a/tests/files/interlaced_rgba_16_should_be_palette_4_grayscale.png b/tests/files/interlaced_rgba_16_should_be_palette_4_grayscale.png new file mode 100644 index 00000000..7bbf3d70 Binary files /dev/null and b/tests/files/interlaced_rgba_16_should_be_palette_4_grayscale.png differ diff --git a/tests/files/interlaced_rgba_16_should_be_palette_8.png b/tests/files/interlaced_rgba_16_should_be_palette_8.png new file mode 100644 index 00000000..d5114b21 Binary files /dev/null and b/tests/files/interlaced_rgba_16_should_be_palette_8.png differ diff --git a/tests/files/interlaced_rgba_16_should_be_rgb_16.png b/tests/files/interlaced_rgba_16_should_be_rgb_16.png new file mode 100644 index 00000000..9b54dded Binary files /dev/null and b/tests/files/interlaced_rgba_16_should_be_rgb_16.png differ diff --git a/tests/files/interlaced_rgba_16_should_be_rgb_8.png b/tests/files/interlaced_rgba_16_should_be_rgb_8.png new file mode 100644 index 00000000..408bbcdc Binary files /dev/null and b/tests/files/interlaced_rgba_16_should_be_rgb_8.png differ diff --git a/tests/files/interlaced_rgba_16_should_be_rgba_16.png b/tests/files/interlaced_rgba_16_should_be_rgba_16.png new file mode 100644 index 00000000..87a04b62 Binary files /dev/null and b/tests/files/interlaced_rgba_16_should_be_rgba_16.png differ diff --git a/tests/files/interlaced_rgba_16_should_be_rgba_8.png b/tests/files/interlaced_rgba_16_should_be_rgba_8.png new file mode 100644 index 00000000..d90811b0 Binary files /dev/null and b/tests/files/interlaced_rgba_16_should_be_rgba_8.png differ diff --git a/tests/files/interlaced_rgba_8_should_be_grayscale_8.png b/tests/files/interlaced_rgba_8_should_be_grayscale_8.png new file mode 100644 index 00000000..fa906f8a Binary files /dev/null and b/tests/files/interlaced_rgba_8_should_be_grayscale_8.png differ diff --git a/tests/files/interlaced_rgba_8_should_be_grayscale_alpha_8.png b/tests/files/interlaced_rgba_8_should_be_grayscale_alpha_8.png new file mode 100644 index 00000000..f0484f29 Binary files /dev/null and b/tests/files/interlaced_rgba_8_should_be_grayscale_alpha_8.png differ diff --git a/tests/files/interlaced_rgba_8_should_be_palette_1.png b/tests/files/interlaced_rgba_8_should_be_palette_1.png new file mode 100644 index 00000000..5a2092a2 Binary files /dev/null and b/tests/files/interlaced_rgba_8_should_be_palette_1.png differ diff --git a/tests/files/interlaced_rgba_8_should_be_palette_1_grayscale.png b/tests/files/interlaced_rgba_8_should_be_palette_1_grayscale.png new file mode 100644 index 00000000..fcf91970 Binary files /dev/null and b/tests/files/interlaced_rgba_8_should_be_palette_1_grayscale.png differ diff --git a/tests/files/interlaced_rgba_8_should_be_palette_2.png b/tests/files/interlaced_rgba_8_should_be_palette_2.png new file mode 100644 index 00000000..1280eaba Binary files /dev/null and b/tests/files/interlaced_rgba_8_should_be_palette_2.png differ diff --git a/tests/files/interlaced_rgba_8_should_be_palette_2_grayscale.png b/tests/files/interlaced_rgba_8_should_be_palette_2_grayscale.png new file mode 100644 index 00000000..045ba467 Binary files /dev/null and b/tests/files/interlaced_rgba_8_should_be_palette_2_grayscale.png differ diff --git a/tests/files/interlaced_rgba_8_should_be_palette_4.png b/tests/files/interlaced_rgba_8_should_be_palette_4.png new file mode 100644 index 00000000..16836c5e Binary files /dev/null and b/tests/files/interlaced_rgba_8_should_be_palette_4.png differ diff --git a/tests/files/interlaced_rgba_8_should_be_palette_4_grayscale.png b/tests/files/interlaced_rgba_8_should_be_palette_4_grayscale.png new file mode 100644 index 00000000..7ee30fb9 Binary files /dev/null and b/tests/files/interlaced_rgba_8_should_be_palette_4_grayscale.png differ diff --git a/tests/files/interlaced_rgba_8_should_be_palette_8.png b/tests/files/interlaced_rgba_8_should_be_palette_8.png new file mode 100644 index 00000000..ad7cbb55 Binary files /dev/null and b/tests/files/interlaced_rgba_8_should_be_palette_8.png differ diff --git a/tests/files/interlaced_rgba_8_should_be_rgb_8.png b/tests/files/interlaced_rgba_8_should_be_rgb_8.png new file mode 100644 index 00000000..7d784854 Binary files /dev/null and b/tests/files/interlaced_rgba_8_should_be_rgb_8.png differ diff --git a/tests/files/interlaced_rgba_8_should_be_rgba_8.png b/tests/files/interlaced_rgba_8_should_be_rgba_8.png new file mode 100644 index 00000000..ecef7322 Binary files /dev/null and b/tests/files/interlaced_rgba_8_should_be_rgba_8.png differ diff --git a/tests/files/interlaced_small_files.png b/tests/files/interlaced_small_files.png new file mode 100644 index 00000000..91af6176 Binary files /dev/null and b/tests/files/interlaced_small_files.png differ diff --git a/tests/files/interlacing_0_to_1.png b/tests/files/interlacing_0_to_1.png new file mode 100644 index 00000000..3f9bdb1a Binary files /dev/null and b/tests/files/interlacing_0_to_1.png differ diff --git a/tests/files/interlacing_1_to_0.png b/tests/files/interlacing_1_to_0.png new file mode 100644 index 00000000..23375db0 Binary files /dev/null and b/tests/files/interlacing_1_to_0.png differ diff --git a/tests/flags.rs b/tests/flags.rs index cc71450b..782e9d0d 100644 --- a/tests/flags.rs +++ b/tests/flags.rs @@ -267,3 +267,77 @@ fn strip_headers_none() { remove_file(output).ok(); } + +#[test] +fn interlacing_0_to_1() { + let input = PathBuf::from("tests/files/interlacing_0_to_1.png"); + let mut opts = get_opts(&input); + opts.interlace = Some(1); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.interlaced == 0); + + match oxipng::optimize(&input, &opts) { + Ok(_) => (), + Err(x) => panic!(x.to_owned()), + }; + assert!(output.exists()); + + let png = match png::PngData::new(&output) { + Ok(x) => x, + Err(x) => { + remove_file(output).ok(); + panic!(x.to_owned()) + } + }; + + assert!(png.ihdr_data.interlaced == 1); + + let old_png = image::open(&input).unwrap(); + let new_png = image::open(&output).unwrap(); + + // Conversion should be lossless + assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + + remove_file(output).ok(); +} + +#[test] +fn interlacing_1_to_0() { + let input = PathBuf::from("tests/files/interlacing_1_to_0.png"); + let mut opts = get_opts(&input); + opts.interlace = Some(0); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.interlaced == 1); + + match oxipng::optimize(&input, &opts) { + Ok(_) => (), + Err(x) => panic!(x.to_owned()), + }; + assert!(output.exists()); + + let png = match png::PngData::new(&output) { + Ok(x) => x, + Err(x) => { + remove_file(output).ok(); + panic!(x.to_owned()) + } + }; + + assert!(png.ihdr_data.interlaced == 0); + + let old_png = image::open(&input).unwrap(); + let new_png = image::open(&output).unwrap(); + + // Conversion should be lossless + assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + + remove_file(output).ok(); +} diff --git a/tests/interlaced.rs b/tests/interlaced.rs new file mode 100644 index 00000000..5c24cad6 --- /dev/null +++ b/tests/interlaced.rs @@ -0,0 +1,1276 @@ +extern crate image; +extern crate oxipng; + +use image::GenericImage; +use image::Pixel; +use oxipng::png; +use std::collections::HashSet; +use std::fs::remove_file; +use std::path::Path; +use std::path::PathBuf; + +fn get_opts(input: &Path) -> oxipng::Options { + let mut filter = HashSet::new(); + filter.insert(0); + let mut compression = HashSet::new(); + compression.insert(9); + let mut memory = HashSet::new(); + memory.insert(9); + let mut strategies = HashSet::new(); + for i in 0..4 { + strategies.insert(i); + } + + oxipng::Options { + backup: false, + out_file: input.with_extension("out.png").to_owned(), + out_dir: None, + stdout: false, + pretend: false, + recursive: false, + fix_errors: false, + force: true, + clobber: true, + create: true, + preserve_attrs: false, + verbosity: None, + filter: filter, + interlace: None, + compression: compression, + memory: memory, + strategies: strategies, + window: 15, + bit_depth_reduction: true, + color_type_reduction: true, + palette_reduction: true, + idat_recoding: true, + strip: png::Headers::None, + use_heuristics: false, + } +} + +fn test_it_converts(input: &Path, + output: &Path, + opts: &oxipng::Options, + color_type_in: png::ColorType, + bit_depth_in: png::BitDepth, + color_type_out: png::ColorType, + bit_depth_out: png::BitDepth) { + let png = png::PngData::new(input).unwrap(); + + assert!(png.ihdr_data.color_type == color_type_in); + assert!(png.ihdr_data.bit_depth == bit_depth_in); + assert!(png.ihdr_data.interlaced == 1); + + match oxipng::optimize(input, opts) { + Ok(_) => (), + Err(x) => panic!(x.to_owned()), + }; + assert!(output.exists()); + + let png = match png::PngData::new(output) { + Ok(x) => x, + Err(x) => { + remove_file(output).ok(); + panic!(x.to_owned()) + } + }; + + assert!(png.ihdr_data.color_type == color_type_out); + assert!(png.ihdr_data.bit_depth == bit_depth_out); + + let old_png = image::open(input).unwrap(); + let new_png = image::open(output).unwrap(); + + // Conversion should be lossless + assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + + remove_file(output).ok(); +} + + +#[test] +fn interlaced_rgba_16_should_be_rgba_16() { + let input = PathBuf::from("tests/files/interlaced_rgba_16_should_be_rgba_16.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::RGBA, + png::BitDepth::Sixteen); +} + +#[test] +fn interlaced_rgba_16_should_be_rgba_8() { + let input = PathBuf::from("tests/files/interlaced_rgba_16_should_be_rgba_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::RGBA, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgba_8_should_be_rgba_8() { + let input = PathBuf::from("tests/files/interlaced_rgba_8_should_be_rgba_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::RGBA, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgba_16_should_be_rgb_16() { + let input = PathBuf::from("tests/files/interlaced_rgba_16_should_be_rgb_16.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::RGB, + png::BitDepth::Sixteen); +} + +#[test] +fn interlaced_rgba_16_should_be_rgb_8() { + let input = PathBuf::from("tests/files/interlaced_rgba_16_should_be_rgb_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::RGB, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgba_8_should_be_rgb_8() { + let input = PathBuf::from("tests/files/interlaced_rgba_8_should_be_rgb_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::RGB, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgba_16_should_be_palette_8() { + let input = PathBuf::from("tests/files/interlaced_rgba_16_should_be_palette_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgba_8_should_be_palette_8() { + let input = PathBuf::from("tests/files/interlaced_rgba_8_should_be_palette_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgba_16_should_be_palette_4() { + let input = PathBuf::from("tests/files/interlaced_rgba_16_should_be_palette_4.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Four); +} + +#[test] +fn interlaced_rgba_8_should_be_palette_4() { + let input = PathBuf::from("tests/files/interlaced_rgba_8_should_be_palette_4.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Four); +} + +#[test] +fn interlaced_rgba_16_should_be_palette_2() { + let input = PathBuf::from("tests/files/interlaced_rgba_16_should_be_palette_2.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Two); +} + +#[test] +fn interlaced_rgba_8_should_be_palette_2() { + let input = PathBuf::from("tests/files/interlaced_rgba_8_should_be_palette_2.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Two); +} + +#[test] +fn interlaced_rgba_16_should_be_palette_1() { + let input = PathBuf::from("tests/files/interlaced_rgba_16_should_be_palette_1.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_rgba_8_should_be_palette_1() { + let input = PathBuf::from("tests/files/interlaced_rgba_8_should_be_palette_1.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_rgba_16_should_be_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/interlaced_rgba_16_should_be_grayscale_alpha_16.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen); +} + +#[test] +fn interlaced_rgba_16_should_be_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/interlaced_rgba_16_should_be_grayscale_alpha_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgba_8_should_be_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/interlaced_rgba_8_should_be_grayscale_alpha_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgba_16_should_be_grayscale_16() { + let input = PathBuf::from("tests/files/interlaced_rgba_16_should_be_grayscale_16.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Sixteen); +} + +#[test] +fn interlaced_rgba_16_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/interlaced_rgba_16_should_be_grayscale_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgba_8_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/interlaced_rgba_8_should_be_grayscale_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgba_16_should_be_palette_4_grayscale() { + let input = PathBuf::from("tests/files/interlaced_rgba_16_should_be_palette_4_grayscale.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Four); +} + +#[test] +fn interlaced_rgba_8_should_be_palette_4_grayscale() { + let input = PathBuf::from("tests/files/interlaced_rgba_8_should_be_palette_4_grayscale.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Four); +} + +#[test] +fn interlaced_rgba_16_should_be_palette_2_grayscale() { + let input = PathBuf::from("tests/files/interlaced_rgba_16_should_be_palette_2_grayscale.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Two); +} + +#[test] +fn interlaced_rgba_8_should_be_palette_2_grayscale() { + let input = PathBuf::from("tests/files/interlaced_rgba_8_should_be_palette_2_grayscale.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Two); +} + +#[test] +fn interlaced_rgba_16_should_be_palette_1_grayscale() { + let input = PathBuf::from("tests/files/interlaced_rgba_16_should_be_palette_1_grayscale.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_rgba_8_should_be_palette_1_grayscale() { + let input = PathBuf::from("tests/files/interlaced_rgba_8_should_be_palette_1_grayscale.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_rgb_16_should_be_rgb_16() { + let input = PathBuf::from("tests/files/interlaced_rgb_16_should_be_rgb_16.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::RGB, + png::BitDepth::Sixteen); +} + +#[test] +fn interlaced_rgb_16_should_be_rgb_8() { + let input = PathBuf::from("tests/files/interlaced_rgb_16_should_be_rgb_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::RGB, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgb_8_should_be_rgb_8() { + let input = PathBuf::from("tests/files/interlaced_rgb_8_should_be_rgb_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::RGB, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgb_16_should_be_palette_8() { + let input = PathBuf::from("tests/files/interlaced_rgb_16_should_be_palette_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgb_8_should_be_palette_8() { + let input = PathBuf::from("tests/files/interlaced_rgb_8_should_be_palette_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgb_16_should_be_palette_4() { + let input = PathBuf::from("tests/files/interlaced_rgb_16_should_be_palette_4.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Four); +} + +#[test] +fn interlaced_rgb_8_should_be_palette_4() { + let input = PathBuf::from("tests/files/interlaced_rgb_8_should_be_palette_4.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Four); +} + +#[test] +fn interlaced_rgb_16_should_be_palette_2() { + let input = PathBuf::from("tests/files/interlaced_rgb_16_should_be_palette_2.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Two); +} + +#[test] +fn interlaced_rgb_8_should_be_palette_2() { + let input = PathBuf::from("tests/files/interlaced_rgb_8_should_be_palette_2.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Two); +} + +#[test] +fn interlaced_rgb_16_should_be_palette_1() { + let input = PathBuf::from("tests/files/interlaced_rgb_16_should_be_palette_1.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_rgb_8_should_be_palette_1() { + let input = PathBuf::from("tests/files/interlaced_rgb_8_should_be_palette_1.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_rgb_16_should_be_grayscale_16() { + let input = PathBuf::from("tests/files/interlaced_rgb_16_should_be_grayscale_16.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Sixteen); +} + +#[test] +fn interlaced_rgb_16_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/interlaced_rgb_16_should_be_grayscale_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgb_8_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/interlaced_rgb_8_should_be_grayscale_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_rgb_16_should_be_palette_4_grayscale() { + let input = PathBuf::from("tests/files/interlaced_rgb_16_should_be_palette_4_grayscale.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Four); +} + +#[test] +fn interlaced_rgb_8_should_be_palette_4_grayscale() { + let input = PathBuf::from("tests/files/interlaced_rgb_8_should_be_palette_4_grayscale.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Four); +} + +#[test] +fn interlaced_rgb_16_should_be_palette_2_grayscale() { + let input = PathBuf::from("tests/files/interlaced_rgb_16_should_be_palette_2_grayscale.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Two); +} + +#[test] +fn interlaced_rgb_8_should_be_palette_2_grayscale() { + let input = PathBuf::from("tests/files/interlaced_rgb_8_should_be_palette_2_grayscale.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Two); +} + +#[test] +fn interlaced_rgb_16_should_be_palette_1_grayscale() { + let input = PathBuf::from("tests/files/interlaced_rgb_16_should_be_palette_1_grayscale.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_rgb_8_should_be_palette_1_grayscale() { + let input = PathBuf::from("tests/files/interlaced_rgb_8_should_be_palette_1_grayscale.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_palette_8_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/interlaced_palette_8_should_be_grayscale_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_palette_8_should_be_palette_8() { + let input = PathBuf::from("tests/files/interlaced_palette_8_should_be_palette_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_palette_8_should_be_palette_4() { + let input = PathBuf::from("tests/files/interlaced_palette_8_should_be_palette_4.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Four); +} + +#[test] +fn interlaced_palette_4_should_be_palette_4() { + let input = PathBuf::from("tests/files/interlaced_palette_4_should_be_palette_4.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Four, + png::ColorType::Indexed, + png::BitDepth::Four); +} + +#[test] +fn interlaced_palette_8_should_be_palette_2() { + let input = PathBuf::from("tests/files/interlaced_palette_8_should_be_palette_2.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Two); +} + +#[test] +fn interlaced_palette_4_should_be_palette_2() { + let input = PathBuf::from("tests/files/interlaced_palette_4_should_be_palette_2.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Four, + png::ColorType::Indexed, + png::BitDepth::Two); +} + +#[test] +fn interlaced_palette_2_should_be_palette_2() { + let input = PathBuf::from("tests/files/interlaced_palette_2_should_be_palette_2.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Two, + png::ColorType::Indexed, + png::BitDepth::Two); +} + +#[test] +fn interlaced_palette_8_should_be_palette_1() { + let input = PathBuf::from("tests/files/interlaced_palette_8_should_be_palette_1.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_palette_4_should_be_palette_1() { + let input = PathBuf::from("tests/files/interlaced_palette_4_should_be_palette_1.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Four, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_palette_2_should_be_palette_1() { + let input = PathBuf::from("tests/files/interlaced_palette_2_should_be_palette_1.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Two, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_palette_1_should_be_palette_1() { + let input = PathBuf::from("tests/files/interlaced_palette_1_should_be_palette_1.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::One, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_grayscale_alpha_16_should_be_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_alpha_16.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen); +} + +#[test] +fn interlaced_grayscale_alpha_16_should_be_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_alpha_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_grayscale_alpha_8_should_be_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/interlaced_grayscale_alpha_8_should_be_grayscale_alpha_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_grayscale_alpha_16_should_be_grayscale_16() { + let input = PathBuf::from("tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_16.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Sixteen); +} + +#[test] +fn interlaced_grayscale_alpha_16_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/interlaced_grayscale_alpha_16_should_be_grayscale_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_grayscale_alpha_8_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/interlaced_grayscale_alpha_8_should_be_grayscale_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_grayscale_alpha_16_should_be_palette_4() { + let input = PathBuf::from("tests/files/interlaced_grayscale_alpha_16_should_be_palette_4.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Four); +} + +#[test] +fn interlaced_grayscale_alpha_8_should_be_palette_4() { + let input = PathBuf::from("tests/files/interlaced_grayscale_alpha_8_should_be_palette_4.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Four); +} + +#[test] +fn interlaced_grayscale_alpha_16_should_be_palette_2() { + let input = PathBuf::from("tests/files/interlaced_grayscale_alpha_16_should_be_palette_2.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Two); +} + +#[test] +fn interlaced_grayscale_alpha_8_should_be_palette_2() { + let input = PathBuf::from("tests/files/interlaced_grayscale_alpha_8_should_be_palette_2.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Two); +} + +#[test] +fn interlaced_grayscale_alpha_16_should_be_palette_1() { + let input = PathBuf::from("tests/files/interlaced_grayscale_alpha_16_should_be_palette_1.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_grayscale_alpha_8_should_be_palette_1() { + let input = PathBuf::from("tests/files/interlaced_grayscale_alpha_8_should_be_palette_1.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_grayscale_16_should_be_grayscale_16() { + let input = PathBuf::from("tests/files/interlaced_grayscale_16_should_be_grayscale_16.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Sixteen); +} + +#[test] +fn interlaced_grayscale_16_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/interlaced_grayscale_16_should_be_grayscale_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_grayscale_16_should_be_palette_4() { + let input = PathBuf::from("tests/files/interlaced_grayscale_16_should_be_palette_4.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Four); +} + +#[test] +fn interlaced_grayscale_16_should_be_palette_2() { + let input = PathBuf::from("tests/files/interlaced_grayscale_16_should_be_palette_2.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Two); +} + +#[test] +fn interlaced_grayscale_16_should_be_palette_1() { + let input = PathBuf::from("tests/files/interlaced_grayscale_16_should_be_palette_1.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_grayscale_8_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/interlaced_grayscale_8_should_be_grayscale_8.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); +} + +#[test] +fn interlaced_grayscale_8_should_be_palette_4() { + let input = PathBuf::from("tests/files/interlaced_grayscale_8_should_be_palette_4.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Four); +} + +#[test] +fn interlaced_grayscale_8_should_be_palette_2() { + let input = PathBuf::from("tests/files/interlaced_grayscale_8_should_be_palette_2.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Two); +} + +#[test] +fn interlaced_grayscale_8_should_be_palette_1() { + let input = PathBuf::from("tests/files/interlaced_grayscale_8_should_be_palette_1.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::One); +} + +#[test] +fn interlaced_small_files() { + let input = PathBuf::from("tests/files/interlaced_small_files.png"); + let opts = get_opts(&input); + let output = opts.out_file.clone(); + + test_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Two); +} diff --git a/tests/reduction.rs b/tests/reduction.rs index 6c0cafde..d7a35033 100644 --- a/tests/reduction.rs +++ b/tests/reduction.rs @@ -60,6 +60,7 @@ fn test_it_converts(input: &Path, assert!(png.ihdr_data.color_type == color_type_in); assert!(png.ihdr_data.bit_depth == bit_depth_in); + assert!(png.ihdr_data.interlaced == 0); match oxipng::optimize(input, opts) { Ok(_) => (),