From 90ae9df0e988eeae6a905495cbddab2d885b825f Mon Sep 17 00:00:00 2001 From: Joshua Holmer Date: Wed, 2 Mar 2016 22:26:13 -0500 Subject: [PATCH 1/4] Filter tests with some failing --- tests/oxipng.rs | 2640 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2640 insertions(+) diff --git a/tests/oxipng.rs b/tests/oxipng.rs index 6bef3c28..0ab49b61 100644 --- a/tests/oxipng.rs +++ b/tests/oxipng.rs @@ -3010,3 +3010,2643 @@ fn strip_headers() { remove_file(output).ok(); } + +#[test] +fn filter_0_for_rgba_16() { + let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_1_for_rgba_16() { + let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_2_for_rgba_16() { + let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_3_for_rgba_16() { + let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_4_for_rgba_16() { + let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_5_for_rgba_16() { + let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_0_for_rgba_8() { + let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_1_for_rgba_8() { + let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_2_for_rgba_8() { + let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_3_for_rgba_8() { + let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_4_for_rgba_8() { + let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_5_for_rgba_8() { + let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::RGBA); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_0_for_rgb_16() { + let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_1_for_rgb_16() { + let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_2_for_rgb_16() { + let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_3_for_rgb_16() { + let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_4_for_rgb_16() { + let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_5_for_rgb_16() { + let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_0_for_rgb_8() { + let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_1_for_rgb_8() { + let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_2_for_rgb_8() { + let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_3_for_rgb_8() { + let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_4_for_rgb_8() { + let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_5_for_rgb_8() { + let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::RGB); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_0_for_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_1_for_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_2_for_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_3_for_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_4_for_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_5_for_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_0_for_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_1_for_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_2_for_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_3_for_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_4_for_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_5_for_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::GrayscaleAlpha); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_0_for_grayscale_16() { + let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_1_for_grayscale_16() { + let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_2_for_grayscale_16() { + let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_3_for_grayscale_16() { + let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_4_for_grayscale_16() { + let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_5_for_grayscale_16() { + let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); + + 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 filter_0_for_grayscale_8() { + let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_1_for_grayscale_8() { + let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_2_for_grayscale_8() { + let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_3_for_grayscale_8() { + let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_4_for_grayscale_8() { + let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_5_for_grayscale_8() { + let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 == png::ColorType::Grayscale); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + + 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 filter_0_for_palette_4() { + let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); + + 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 filter_1_for_palette_4() { + let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); + + 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 filter_2_for_palette_4() { + let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); + + 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 filter_3_for_palette_4() { + let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); + + 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 filter_4_for_palette_4() { + let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); + + 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 filter_5_for_palette_4() { + let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); + + 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 filter_0_for_palette_2() { + let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); + + 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 filter_1_for_palette_2() { + let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); + + 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 filter_2_for_palette_2() { + let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); + + 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 filter_3_for_palette_2() { + let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); + + 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 filter_4_for_palette_2() { + let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); + + 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 filter_5_for_palette_2() { + let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); + + 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 filter_0_for_palette_1() { + let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::One); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::One); + + 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 filter_1_for_palette_1() { + let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::One); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::One); + + 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 filter_2_for_palette_1() { + let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::One); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::One); + + 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 filter_3_for_palette_1() { + let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::One); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::One); + + 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 filter_4_for_palette_1() { + let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::One); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::One); + + 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 filter_5_for_palette_1() { + let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.ihdr_data.color_type == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::One); + + 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 == png::ColorType::Indexed); + assert!(png.ihdr_data.bit_depth == png::BitDepth::One); + + 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(); +} From 3506d57c7b5a761d44058759d4cbc8dc98527c64 Mon Sep 17 00:00:00 2001 From: Joshua Holmer Date: Thu, 3 Mar 2016 12:39:18 -0500 Subject: [PATCH 2/4] Move tests into separate modules More or less fixes #13. We have some repeat util code that I still want to eliminate though. --- tests/filters.rs | 808 +++++++ tests/flags.rs | 86 + tests/oxipng.rs | 5652 -------------------------------------------- tests/reduction.rs | 785 ++++++ 4 files changed, 1679 insertions(+), 5652 deletions(-) create mode 100644 tests/filters.rs create mode 100644 tests/flags.rs delete mode 100644 tests/oxipng.rs create mode 100644 tests/reduction.rs diff --git a/tests/filters.rs b/tests/filters.rs new file mode 100644 index 00000000..201e334f --- /dev/null +++ b/tests/filters.rs @@ -0,0 +1,808 @@ +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: Some(0), + 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: 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); + + 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 filter_0_for_rgba_16() { + let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + 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 filter_1_for_rgba_16() { + let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + 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 filter_2_for_rgba_16() { + let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + 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 filter_3_for_rgba_16() { + let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + 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 filter_4_for_rgba_16() { + let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + 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 filter_5_for_rgba_16() { + let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + 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 filter_0_for_rgba_8() { + let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + 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 filter_1_for_rgba_8() { + let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + 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 filter_2_for_rgba_8() { + let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + 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 filter_3_for_rgba_8() { + let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + 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 filter_4_for_rgba_8() { + let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + 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 filter_5_for_rgba_8() { + let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + 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 filter_0_for_rgb_16() { + let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + 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 filter_1_for_rgb_16() { + let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + 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 filter_2_for_rgb_16() { + let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + 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 filter_3_for_rgb_16() { + let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + 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 filter_4_for_rgb_16() { + let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + 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 filter_5_for_rgb_16() { + let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + 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 filter_0_for_rgb_8() { + let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + 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 filter_1_for_rgb_8() { + let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + 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 filter_2_for_rgb_8() { + let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + 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 filter_3_for_rgb_8() { + let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + 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 filter_4_for_rgb_8() { + let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + 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 filter_5_for_rgb_8() { + let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + 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 filter_0_for_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + 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 filter_1_for_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + 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 filter_2_for_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + 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 filter_3_for_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + 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 filter_4_for_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + 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 filter_5_for_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + 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 filter_0_for_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + 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 filter_1_for_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + 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 filter_2_for_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + 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 filter_3_for_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + 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 filter_4_for_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + 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 filter_5_for_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + 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 filter_0_for_grayscale_16() { + let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + 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 filter_1_for_grayscale_16() { + let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + 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 filter_2_for_grayscale_16() { + let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + 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 filter_3_for_grayscale_16() { + let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + 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 filter_4_for_grayscale_16() { + let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + 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 filter_5_for_grayscale_16() { + let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + 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 filter_0_for_grayscale_8() { + let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + 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 filter_1_for_grayscale_8() { + let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + 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 filter_2_for_grayscale_8() { + let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + 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 filter_3_for_grayscale_8() { + let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + 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 filter_4_for_grayscale_8() { + let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + 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 filter_5_for_grayscale_8() { + let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + 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 filter_0_for_palette_4() { + let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + 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 filter_1_for_palette_4() { + let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + 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 filter_2_for_palette_4() { + let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + 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 filter_3_for_palette_4() { + let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + 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 filter_4_for_palette_4() { + let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + 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 filter_5_for_palette_4() { + let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + 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 filter_0_for_palette_2() { + let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + 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 filter_1_for_palette_2() { + let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + 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 filter_2_for_palette_2() { + let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + 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 filter_3_for_palette_2() { + let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + 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 filter_4_for_palette_2() { + let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + 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 filter_5_for_palette_2() { + let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + 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 filter_0_for_palette_1() { + let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(0); + 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 filter_1_for_palette_1() { + let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(1); + 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 filter_2_for_palette_1() { + let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(2); + 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 filter_3_for_palette_1() { + let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(3); + 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 filter_4_for_palette_1() { + let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(4); + 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 filter_5_for_palette_1() { + let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); + let mut opts = get_opts(&input); + opts.filter = HashSet::new(); + opts.filter.insert(5); + let output = opts.out_file.clone(); + + test_it_converts(&input, &output, &opts, png::ColorType::Indexed, png::BitDepth::One, png::ColorType::Indexed, png::BitDepth::One); +} diff --git a/tests/flags.rs b/tests/flags.rs new file mode 100644 index 00000000..9d99839e --- /dev/null +++ b/tests/flags.rs @@ -0,0 +1,86 @@ +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: Some(0), + 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: false, + } +} + +#[test] +fn strip_headers() { + let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); + let mut opts = get_opts(&input); + opts.strip = true; + let output = opts.out_file.clone(); + + let png = png::PngData::new(&input).unwrap(); + + assert!(png.aux_headers.contains_key("tEXt")); + + 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.aux_headers.contains_key("tEXt")); + + 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/oxipng.rs b/tests/oxipng.rs deleted file mode 100644 index 0ab49b61..00000000 --- a/tests/oxipng.rs +++ /dev/null @@ -1,5652 +0,0 @@ -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: Some(0), - 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: false, - } -} - -#[test] -fn rgba_16_should_be_rgba_16() { - let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 rgba_16_should_be_rgba_8() { - let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgba_8_should_be_rgba_8() { - let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgba_16_should_be_rgb_16() { - let input = PathBuf::from("tests/files/rgba_16_should_be_rgb_16.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 rgba_16_should_be_rgb_8() { - let input = PathBuf::from("tests/files/rgba_16_should_be_rgb_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgba_8_should_be_rgb_8() { - let input = PathBuf::from("tests/files/rgba_8_should_be_rgb_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgba_16_should_be_palette_8() { - let input = PathBuf::from("tests/files/rgba_16_should_be_palette_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgba_8_should_be_palette_8() { - let input = PathBuf::from("tests/files/rgba_8_should_be_palette_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgba_16_should_be_palette_4() { - let input = PathBuf::from("tests/files/rgba_16_should_be_palette_4.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 rgba_8_should_be_palette_4() { - let input = PathBuf::from("tests/files/rgba_8_should_be_palette_4.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 rgba_16_should_be_palette_2() { - let input = PathBuf::from("tests/files/rgba_16_should_be_palette_2.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 rgba_8_should_be_palette_2() { - let input = PathBuf::from("tests/files/rgba_8_should_be_palette_2.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 rgba_16_should_be_palette_1() { - let input = PathBuf::from("tests/files/rgba_16_should_be_palette_1.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 rgba_8_should_be_palette_1() { - let input = PathBuf::from("tests/files/rgba_8_should_be_palette_1.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 rgba_16_should_be_grayscale_alpha_16() { - let input = PathBuf::from("tests/files/rgba_16_should_be_grayscale_alpha_16.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 rgba_16_should_be_grayscale_alpha_8() { - let input = PathBuf::from("tests/files/rgba_16_should_be_grayscale_alpha_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgba_8_should_be_grayscale_alpha_8() { - let input = PathBuf::from("tests/files/rgba_8_should_be_grayscale_alpha_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgba_16_should_be_grayscale_16() { - let input = PathBuf::from("tests/files/rgba_16_should_be_grayscale_16.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 rgba_16_should_be_grayscale_8() { - let input = PathBuf::from("tests/files/rgba_16_should_be_grayscale_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgba_8_should_be_grayscale_8() { - let input = PathBuf::from("tests/files/rgba_8_should_be_grayscale_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgba_16_should_be_palette_4_grayscale() { - let input = PathBuf::from("tests/files/rgba_16_should_be_palette_4_grayscale.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 rgba_8_should_be_palette_4_grayscale() { - let input = PathBuf::from("tests/files/rgba_8_should_be_palette_4_grayscale.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 rgba_16_should_be_palette_2_grayscale() { - let input = PathBuf::from("tests/files/rgba_16_should_be_palette_2_grayscale.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 rgba_8_should_be_palette_2_grayscale() { - let input = PathBuf::from("tests/files/rgba_8_should_be_palette_2_grayscale.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 rgba_16_should_be_palette_1_grayscale() { - let input = PathBuf::from("tests/files/rgba_16_should_be_palette_1_grayscale.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 rgba_8_should_be_palette_1_grayscale() { - let input = PathBuf::from("tests/files/rgba_8_should_be_palette_1_grayscale.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 rgb_16_should_be_rgb_16() { - let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 rgb_16_should_be_rgb_8() { - let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgb_8_should_be_rgb_8() { - let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgb_16_should_be_palette_8() { - let input = PathBuf::from("tests/files/rgb_16_should_be_palette_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgb_8_should_be_palette_8() { - let input = PathBuf::from("tests/files/rgb_8_should_be_palette_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgb_16_should_be_palette_4() { - let input = PathBuf::from("tests/files/rgb_16_should_be_palette_4.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 rgb_8_should_be_palette_4() { - let input = PathBuf::from("tests/files/rgb_8_should_be_palette_4.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 rgb_16_should_be_palette_2() { - let input = PathBuf::from("tests/files/rgb_16_should_be_palette_2.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 rgb_8_should_be_palette_2() { - let input = PathBuf::from("tests/files/rgb_8_should_be_palette_2.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 rgb_16_should_be_palette_1() { - let input = PathBuf::from("tests/files/rgb_16_should_be_palette_1.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 rgb_8_should_be_palette_1() { - let input = PathBuf::from("tests/files/rgb_8_should_be_palette_1.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 rgb_16_should_be_grayscale_16() { - let input = PathBuf::from("tests/files/rgb_16_should_be_grayscale_16.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 rgb_16_should_be_grayscale_8() { - let input = PathBuf::from("tests/files/rgb_16_should_be_grayscale_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgb_8_should_be_grayscale_8() { - let input = PathBuf::from("tests/files/rgb_8_should_be_grayscale_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 rgb_16_should_be_palette_4_grayscale() { - let input = PathBuf::from("tests/files/rgb_16_should_be_palette_4_grayscale.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 rgb_8_should_be_palette_4_grayscale() { - let input = PathBuf::from("tests/files/rgb_8_should_be_palette_4_grayscale.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 rgb_16_should_be_palette_2_grayscale() { - let input = PathBuf::from("tests/files/rgb_16_should_be_palette_2_grayscale.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 rgb_8_should_be_palette_2_grayscale() { - let input = PathBuf::from("tests/files/rgb_8_should_be_palette_2_grayscale.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 rgb_16_should_be_palette_1_grayscale() { - let input = PathBuf::from("tests/files/rgb_16_should_be_palette_1_grayscale.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 rgb_8_should_be_palette_1_grayscale() { - let input = PathBuf::from("tests/files/rgb_8_should_be_palette_1_grayscale.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 palette_8_should_be_grayscale_8() { - let input = PathBuf::from("tests/files/palette_8_should_be_grayscale_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 palette_8_should_be_palette_8() { - let input = PathBuf::from("tests/files/palette_8_should_be_palette_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 palette_8_should_be_palette_4() { - let input = PathBuf::from("tests/files/palette_8_should_be_palette_4.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 palette_4_should_be_palette_4() { - let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 palette_8_should_be_palette_2() { - let input = PathBuf::from("tests/files/palette_8_should_be_palette_2.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 palette_4_should_be_palette_2() { - let input = PathBuf::from("tests/files/palette_4_should_be_palette_2.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 palette_2_should_be_palette_2() { - let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 palette_8_should_be_palette_1() { - let input = PathBuf::from("tests/files/palette_8_should_be_palette_1.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 palette_4_should_be_palette_1() { - let input = PathBuf::from("tests/files/palette_4_should_be_palette_1.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 palette_2_should_be_palette_1() { - let input = PathBuf::from("tests/files/palette_2_should_be_palette_1.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 palette_1_should_be_palette_1() { - let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 grayscale_alpha_16_should_be_grayscale_alpha_16() { - let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 grayscale_alpha_16_should_be_grayscale_alpha_8() { - let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 grayscale_alpha_8_should_be_grayscale_alpha_8() { - let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 grayscale_alpha_16_should_be_grayscale_16() { - let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_16.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 grayscale_alpha_16_should_be_grayscale_8() { - let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 grayscale_alpha_8_should_be_grayscale_8() { - let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 grayscale_alpha_16_should_be_palette_4() { - let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_palette_4.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 grayscale_alpha_8_should_be_palette_4() { - let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_palette_4.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 grayscale_alpha_16_should_be_palette_2() { - let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_palette_2.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 grayscale_alpha_8_should_be_palette_2() { - let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_palette_2.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 grayscale_alpha_16_should_be_palette_1() { - let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_palette_1.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 grayscale_alpha_8_should_be_palette_1() { - let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_palette_1.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 grayscale_16_should_be_grayscale_8() { - let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 grayscale_16_should_be_palette_4() { - let input = PathBuf::from("tests/files/grayscale_16_should_be_palette_4.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 grayscale_16_should_be_palette_2() { - let input = PathBuf::from("tests/files/grayscale_16_should_be_palette_2.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 grayscale_16_should_be_palette_1() { - let input = PathBuf::from("tests/files/grayscale_16_should_be_palette_1.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 grayscale_8_should_be_grayscale_8() { - let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 grayscale_8_should_be_palette_4() { - let input = PathBuf::from("tests/files/grayscale_8_should_be_palette_4.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 grayscale_8_should_be_palette_2() { - let input = PathBuf::from("tests/files/grayscale_8_should_be_palette_2.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 grayscale_8_should_be_palette_1() { - let input = PathBuf::from("tests/files/grayscale_8_should_be_palette_1.png"); - let opts = get_opts(&input); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 strip_headers() { - let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); - let mut opts = get_opts(&input); - opts.strip = true; - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.aux_headers.contains_key("tEXt")); - - 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.aux_headers.contains_key("tEXt")); - - 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 filter_0_for_rgba_16() { - let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(0); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_1_for_rgba_16() { - let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(1); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_2_for_rgba_16() { - let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(2); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_3_for_rgba_16() { - let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(3); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_4_for_rgba_16() { - let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(4); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_5_for_rgba_16() { - let input = PathBuf::from("tests/files/rgba_16_should_be_rgba_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(5); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_0_for_rgba_8() { - let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(0); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_1_for_rgba_8() { - let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(1); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_2_for_rgba_8() { - let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(2); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_3_for_rgba_8() { - let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(3); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_4_for_rgba_8() { - let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(4); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_5_for_rgba_8() { - let input = PathBuf::from("tests/files/rgba_8_should_be_rgba_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(5); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_0_for_rgb_16() { - let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(0); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_1_for_rgb_16() { - let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(1); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_2_for_rgb_16() { - let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(2); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_3_for_rgb_16() { - let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(3); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_4_for_rgb_16() { - let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(4); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_5_for_rgb_16() { - let input = PathBuf::from("tests/files/rgb_16_should_be_rgb_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(5); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_0_for_rgb_8() { - let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(0); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_1_for_rgb_8() { - let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(1); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_2_for_rgb_8() { - let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(2); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_3_for_rgb_8() { - let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(3); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_4_for_rgb_8() { - let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(4); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_5_for_rgb_8() { - let input = PathBuf::from("tests/files/rgb_8_should_be_rgb_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(5); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::RGB); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_0_for_grayscale_alpha_16() { - let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(0); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_1_for_grayscale_alpha_16() { - let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(1); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_2_for_grayscale_alpha_16() { - let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(2); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_3_for_grayscale_alpha_16() { - let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(3); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_4_for_grayscale_alpha_16() { - let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(4); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_5_for_grayscale_alpha_16() { - let input = PathBuf::from("tests/files/grayscale_alpha_16_should_be_grayscale_alpha_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(5); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_0_for_grayscale_alpha_8() { - let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(0); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_1_for_grayscale_alpha_8() { - let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(1); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_2_for_grayscale_alpha_8() { - let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(2); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_3_for_grayscale_alpha_8() { - let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(3); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_4_for_grayscale_alpha_8() { - let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(4); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_5_for_grayscale_alpha_8() { - let input = PathBuf::from("tests/files/grayscale_alpha_8_should_be_grayscale_alpha_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(5); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::GrayscaleAlpha); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_0_for_grayscale_16() { - let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(0); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_1_for_grayscale_16() { - let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(1); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_2_for_grayscale_16() { - let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(2); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_3_for_grayscale_16() { - let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(3); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_4_for_grayscale_16() { - let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(4); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_5_for_grayscale_16() { - let input = PathBuf::from("tests/files/grayscale_16_should_be_grayscale_16.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(5); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Sixteen); - - 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 filter_0_for_grayscale_8() { - let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(0); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_1_for_grayscale_8() { - let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(1); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_2_for_grayscale_8() { - let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(2); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_3_for_grayscale_8() { - let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(3); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_4_for_grayscale_8() { - let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(4); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_5_for_grayscale_8() { - let input = PathBuf::from("tests/files/grayscale_8_should_be_grayscale_8.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(5); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - - 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 filter_0_for_palette_4() { - let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(0); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 filter_1_for_palette_4() { - let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(1); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 filter_2_for_palette_4() { - let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(2); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 filter_3_for_palette_4() { - let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(3); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 filter_4_for_palette_4() { - let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(4); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 filter_5_for_palette_4() { - let input = PathBuf::from("tests/files/palette_4_should_be_palette_4.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(5); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Four); - - 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 filter_0_for_palette_2() { - let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(0); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 filter_1_for_palette_2() { - let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(1); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 filter_2_for_palette_2() { - let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(2); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 filter_3_for_palette_2() { - let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(3); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 filter_4_for_palette_2() { - let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(4); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 filter_5_for_palette_2() { - let input = PathBuf::from("tests/files/palette_2_should_be_palette_2.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(5); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Two); - - 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 filter_0_for_palette_1() { - let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(0); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 filter_1_for_palette_1() { - let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(1); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 filter_2_for_palette_1() { - let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(2); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 filter_3_for_palette_1() { - let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(3); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 filter_4_for_palette_1() { - let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(4); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 filter_5_for_palette_1() { - let input = PathBuf::from("tests/files/palette_1_should_be_palette_1.png"); - let mut opts = get_opts(&input); - opts.filter = HashSet::new(); - opts.filter.insert(5); - let output = opts.out_file.clone(); - - let png = png::PngData::new(&input).unwrap(); - - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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 == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); - - 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/reduction.rs b/tests/reduction.rs new file mode 100644 index 00000000..8e8e8c8c --- /dev/null +++ b/tests/reduction.rs @@ -0,0 +1,785 @@ +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: Some(0), + 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: 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); + + 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 rgba_16_should_be_rgba_16() { + let input = PathBuf::from("tests/files/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 rgba_16_should_be_rgba_8() { + let input = PathBuf::from("tests/files/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 rgba_8_should_be_rgba_8() { + let input = PathBuf::from("tests/files/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 rgba_16_should_be_rgb_16() { + let input = PathBuf::from("tests/files/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 rgba_16_should_be_rgb_8() { + let input = PathBuf::from("tests/files/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 rgba_8_should_be_rgb_8() { + let input = PathBuf::from("tests/files/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 rgba_16_should_be_palette_8() { + let input = PathBuf::from("tests/files/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 rgba_8_should_be_palette_8() { + let input = PathBuf::from("tests/files/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 rgba_16_should_be_palette_4() { + let input = PathBuf::from("tests/files/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 rgba_8_should_be_palette_4() { + let input = PathBuf::from("tests/files/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 rgba_16_should_be_palette_2() { + let input = PathBuf::from("tests/files/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 rgba_8_should_be_palette_2() { + let input = PathBuf::from("tests/files/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 rgba_16_should_be_palette_1() { + let input = PathBuf::from("tests/files/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 rgba_8_should_be_palette_1() { + let input = PathBuf::from("tests/files/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 rgba_16_should_be_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/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 rgba_16_should_be_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/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 rgba_8_should_be_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/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 rgba_16_should_be_grayscale_16() { + let input = PathBuf::from("tests/files/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 rgba_16_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/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 rgba_8_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/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 rgba_16_should_be_palette_4_grayscale() { + let input = PathBuf::from("tests/files/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 rgba_8_should_be_palette_4_grayscale() { + let input = PathBuf::from("tests/files/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 rgba_16_should_be_palette_2_grayscale() { + let input = PathBuf::from("tests/files/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 rgba_8_should_be_palette_2_grayscale() { + let input = PathBuf::from("tests/files/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 rgba_16_should_be_palette_1_grayscale() { + let input = PathBuf::from("tests/files/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 rgba_8_should_be_palette_1_grayscale() { + let input = PathBuf::from("tests/files/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 rgb_16_should_be_rgb_16() { + let input = PathBuf::from("tests/files/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 rgb_16_should_be_rgb_8() { + let input = PathBuf::from("tests/files/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 rgb_8_should_be_rgb_8() { + let input = PathBuf::from("tests/files/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 rgb_16_should_be_palette_8() { + let input = PathBuf::from("tests/files/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 rgb_8_should_be_palette_8() { + let input = PathBuf::from("tests/files/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 rgb_16_should_be_palette_4() { + let input = PathBuf::from("tests/files/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 rgb_8_should_be_palette_4() { + let input = PathBuf::from("tests/files/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 rgb_16_should_be_palette_2() { + let input = PathBuf::from("tests/files/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 rgb_8_should_be_palette_2() { + let input = PathBuf::from("tests/files/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 rgb_16_should_be_palette_1() { + let input = PathBuf::from("tests/files/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 rgb_8_should_be_palette_1() { + let input = PathBuf::from("tests/files/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 rgb_16_should_be_grayscale_16() { + let input = PathBuf::from("tests/files/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 rgb_16_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/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 rgb_8_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/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 rgb_16_should_be_palette_4_grayscale() { + let input = PathBuf::from("tests/files/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 rgb_8_should_be_palette_4_grayscale() { + let input = PathBuf::from("tests/files/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 rgb_16_should_be_palette_2_grayscale() { + let input = PathBuf::from("tests/files/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 rgb_8_should_be_palette_2_grayscale() { + let input = PathBuf::from("tests/files/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 rgb_16_should_be_palette_1_grayscale() { + let input = PathBuf::from("tests/files/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 rgb_8_should_be_palette_1_grayscale() { + let input = PathBuf::from("tests/files/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 palette_8_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/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 palette_8_should_be_palette_8() { + let input = PathBuf::from("tests/files/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 palette_8_should_be_palette_4() { + let input = PathBuf::from("tests/files/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 palette_4_should_be_palette_4() { + let input = PathBuf::from("tests/files/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 palette_8_should_be_palette_2() { + let input = PathBuf::from("tests/files/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 palette_4_should_be_palette_2() { + let input = PathBuf::from("tests/files/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 palette_2_should_be_palette_2() { + let input = PathBuf::from("tests/files/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 palette_8_should_be_palette_1() { + let input = PathBuf::from("tests/files/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 palette_4_should_be_palette_1() { + let input = PathBuf::from("tests/files/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 palette_2_should_be_palette_1() { + let input = PathBuf::from("tests/files/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 palette_1_should_be_palette_1() { + let input = PathBuf::from("tests/files/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 grayscale_alpha_16_should_be_grayscale_alpha_16() { + let input = PathBuf::from("tests/files/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 grayscale_alpha_16_should_be_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/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 grayscale_alpha_8_should_be_grayscale_alpha_8() { + let input = PathBuf::from("tests/files/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 grayscale_alpha_16_should_be_grayscale_16() { + let input = PathBuf::from("tests/files/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 grayscale_alpha_16_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/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 grayscale_alpha_8_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/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 grayscale_alpha_16_should_be_palette_4() { + let input = PathBuf::from("tests/files/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 grayscale_alpha_8_should_be_palette_4() { + let input = PathBuf::from("tests/files/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 grayscale_alpha_16_should_be_palette_2() { + let input = PathBuf::from("tests/files/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 grayscale_alpha_8_should_be_palette_2() { + let input = PathBuf::from("tests/files/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 grayscale_alpha_16_should_be_palette_1() { + let input = PathBuf::from("tests/files/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 grayscale_alpha_8_should_be_palette_1() { + let input = PathBuf::from("tests/files/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 grayscale_16_should_be_grayscale_16() { + let input = PathBuf::from("tests/files/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 grayscale_16_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/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 grayscale_16_should_be_palette_4() { + let input = PathBuf::from("tests/files/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 grayscale_16_should_be_palette_2() { + let input = PathBuf::from("tests/files/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 grayscale_16_should_be_palette_1() { + let input = PathBuf::from("tests/files/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 grayscale_8_should_be_grayscale_8() { + let input = PathBuf::from("tests/files/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 grayscale_8_should_be_palette_4() { + let input = PathBuf::from("tests/files/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 grayscale_8_should_be_palette_2() { + let input = PathBuf::from("tests/files/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 grayscale_8_should_be_palette_1() { + let input = PathBuf::from("tests/files/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); +} From 2edf54c9f4dbc2a93b2275d2dc4b233236f2ec9c Mon Sep 17 00:00:00 2001 From: Joshua Holmer Date: Thu, 3 Mar 2016 13:29:16 -0500 Subject: [PATCH 3/4] Rustfmt on tests --- tests/filters.rs | 536 +++++++++++++++++++++++++++++++++----- tests/reduction.rs | 632 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 1022 insertions(+), 146 deletions(-) diff --git a/tests/filters.rs b/tests/filters.rs index 201e334f..125a2d9a 100644 --- a/tests/filters.rs +++ b/tests/filters.rs @@ -48,7 +48,13 @@ fn get_opts(input: &Path) -> oxipng::Options { } } -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) { +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); @@ -89,7 +95,13 @@ fn filter_0_for_rgba_16() { opts.filter.insert(0); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::RGBA, + png::BitDepth::Sixteen); } #[test] @@ -100,7 +112,13 @@ fn filter_1_for_rgba_16() { opts.filter.insert(1); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::RGBA, + png::BitDepth::Sixteen); } #[test] @@ -111,7 +129,13 @@ fn filter_2_for_rgba_16() { opts.filter.insert(2); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::RGBA, + png::BitDepth::Sixteen); } #[test] @@ -122,7 +146,13 @@ fn filter_3_for_rgba_16() { opts.filter.insert(3); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::RGBA, + png::BitDepth::Sixteen); } #[test] @@ -133,7 +163,13 @@ fn filter_4_for_rgba_16() { opts.filter.insert(4); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::RGBA, + png::BitDepth::Sixteen); } #[test] @@ -144,7 +180,13 @@ fn filter_5_for_rgba_16() { opts.filter.insert(5); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::RGBA, + png::BitDepth::Sixteen); } #[test] @@ -155,7 +197,13 @@ fn filter_0_for_rgba_8() { opts.filter.insert(0); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::RGBA, + png::BitDepth::Eight); } #[test] @@ -166,7 +214,13 @@ fn filter_1_for_rgba_8() { opts.filter.insert(1); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::RGBA, + png::BitDepth::Eight); } #[test] @@ -177,7 +231,13 @@ fn filter_2_for_rgba_8() { opts.filter.insert(2); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::RGBA, + png::BitDepth::Eight); } #[test] @@ -188,7 +248,13 @@ fn filter_3_for_rgba_8() { opts.filter.insert(3); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::RGBA, + png::BitDepth::Eight); } #[test] @@ -199,7 +265,13 @@ fn filter_4_for_rgba_8() { opts.filter.insert(4); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::RGBA, + png::BitDepth::Eight); } #[test] @@ -210,7 +282,13 @@ fn filter_5_for_rgba_8() { opts.filter.insert(5); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::RGBA, + png::BitDepth::Eight); } #[test] @@ -221,7 +299,13 @@ fn filter_0_for_rgb_16() { opts.filter.insert(0); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::RGB, + png::BitDepth::Sixteen); } #[test] @@ -232,7 +316,13 @@ fn filter_1_for_rgb_16() { opts.filter.insert(1); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::RGB, + png::BitDepth::Sixteen); } #[test] @@ -243,7 +333,13 @@ fn filter_2_for_rgb_16() { opts.filter.insert(2); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::RGB, + png::BitDepth::Sixteen); } #[test] @@ -254,7 +350,13 @@ fn filter_3_for_rgb_16() { opts.filter.insert(3); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::RGB, + png::BitDepth::Sixteen); } #[test] @@ -265,7 +367,13 @@ fn filter_4_for_rgb_16() { opts.filter.insert(4); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::RGB, + png::BitDepth::Sixteen); } #[test] @@ -276,7 +384,13 @@ fn filter_5_for_rgb_16() { opts.filter.insert(5); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::RGB, + png::BitDepth::Sixteen); } #[test] @@ -287,7 +401,13 @@ fn filter_0_for_rgb_8() { opts.filter.insert(0); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::RGB, + png::BitDepth::Eight); } #[test] @@ -298,7 +418,13 @@ fn filter_1_for_rgb_8() { opts.filter.insert(1); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::RGB, + png::BitDepth::Eight); } #[test] @@ -309,7 +435,13 @@ fn filter_2_for_rgb_8() { opts.filter.insert(2); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::RGB, + png::BitDepth::Eight); } #[test] @@ -320,7 +452,13 @@ fn filter_3_for_rgb_8() { opts.filter.insert(3); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::RGB, + png::BitDepth::Eight); } #[test] @@ -331,7 +469,13 @@ fn filter_4_for_rgb_8() { opts.filter.insert(4); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::RGB, + png::BitDepth::Eight); } #[test] @@ -342,7 +486,13 @@ fn filter_5_for_rgb_8() { opts.filter.insert(5); 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::RGB, + png::BitDepth::Eight); } #[test] @@ -353,7 +503,13 @@ fn filter_0_for_grayscale_alpha_16() { opts.filter.insert(0); 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen); } #[test] @@ -364,7 +520,13 @@ fn filter_1_for_grayscale_alpha_16() { opts.filter.insert(1); 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen); } #[test] @@ -375,7 +537,13 @@ fn filter_2_for_grayscale_alpha_16() { opts.filter.insert(2); 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen); } #[test] @@ -386,7 +554,13 @@ fn filter_3_for_grayscale_alpha_16() { opts.filter.insert(3); 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen); } #[test] @@ -397,7 +571,13 @@ fn filter_4_for_grayscale_alpha_16() { opts.filter.insert(4); 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen); } #[test] @@ -408,7 +588,13 @@ fn filter_5_for_grayscale_alpha_16() { opts.filter.insert(5); 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen); } #[test] @@ -419,7 +605,13 @@ fn filter_0_for_grayscale_alpha_8() { opts.filter.insert(0); 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight); } #[test] @@ -430,7 +622,13 @@ fn filter_1_for_grayscale_alpha_8() { opts.filter.insert(1); 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight); } #[test] @@ -441,7 +639,13 @@ fn filter_2_for_grayscale_alpha_8() { opts.filter.insert(2); 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight); } #[test] @@ -452,7 +656,13 @@ fn filter_3_for_grayscale_alpha_8() { opts.filter.insert(3); 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight); } #[test] @@ -463,7 +673,13 @@ fn filter_4_for_grayscale_alpha_8() { opts.filter.insert(4); 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight); } #[test] @@ -474,7 +690,13 @@ fn filter_5_for_grayscale_alpha_8() { opts.filter.insert(5); 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight); } #[test] @@ -485,7 +707,13 @@ fn filter_0_for_grayscale_16() { opts.filter.insert(0); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Sixteen); } #[test] @@ -496,7 +724,13 @@ fn filter_1_for_grayscale_16() { opts.filter.insert(1); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Sixteen); } #[test] @@ -507,7 +741,13 @@ fn filter_2_for_grayscale_16() { opts.filter.insert(2); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Sixteen); } #[test] @@ -518,7 +758,13 @@ fn filter_3_for_grayscale_16() { opts.filter.insert(3); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Sixteen); } #[test] @@ -529,7 +775,13 @@ fn filter_4_for_grayscale_16() { opts.filter.insert(4); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Sixteen); } #[test] @@ -540,7 +792,13 @@ fn filter_5_for_grayscale_16() { opts.filter.insert(5); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Sixteen); } #[test] @@ -551,7 +809,13 @@ fn filter_0_for_grayscale_8() { opts.filter.insert(0); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); } #[test] @@ -562,7 +826,13 @@ fn filter_1_for_grayscale_8() { opts.filter.insert(1); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); } #[test] @@ -573,7 +843,13 @@ fn filter_2_for_grayscale_8() { opts.filter.insert(2); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); } #[test] @@ -584,7 +860,13 @@ fn filter_3_for_grayscale_8() { opts.filter.insert(3); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); } #[test] @@ -595,7 +877,13 @@ fn filter_4_for_grayscale_8() { opts.filter.insert(4); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); } #[test] @@ -606,7 +894,13 @@ fn filter_5_for_grayscale_8() { opts.filter.insert(5); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); } #[test] @@ -617,7 +911,13 @@ fn filter_0_for_palette_4() { opts.filter.insert(0); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Four, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -628,7 +928,13 @@ fn filter_1_for_palette_4() { opts.filter.insert(1); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Four, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -639,7 +945,13 @@ fn filter_2_for_palette_4() { opts.filter.insert(2); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Four, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -650,7 +962,13 @@ fn filter_3_for_palette_4() { opts.filter.insert(3); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Four, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -661,7 +979,13 @@ fn filter_4_for_palette_4() { opts.filter.insert(4); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Four, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -672,7 +996,13 @@ fn filter_5_for_palette_4() { opts.filter.insert(5); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Four, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -683,7 +1013,13 @@ fn filter_0_for_palette_2() { opts.filter.insert(0); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Two, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -694,7 +1030,13 @@ fn filter_1_for_palette_2() { opts.filter.insert(1); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Two, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -705,7 +1047,13 @@ fn filter_2_for_palette_2() { opts.filter.insert(2); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Two, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -716,7 +1064,13 @@ fn filter_3_for_palette_2() { opts.filter.insert(3); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Two, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -727,7 +1081,13 @@ fn filter_4_for_palette_2() { opts.filter.insert(4); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Two, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -738,7 +1098,13 @@ fn filter_5_for_palette_2() { opts.filter.insert(5); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Two, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -749,7 +1115,13 @@ fn filter_0_for_palette_1() { opts.filter.insert(0); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::One, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -760,7 +1132,13 @@ fn filter_1_for_palette_1() { opts.filter.insert(1); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::One, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -771,7 +1149,13 @@ fn filter_2_for_palette_1() { opts.filter.insert(2); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::One, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -782,7 +1166,13 @@ fn filter_3_for_palette_1() { opts.filter.insert(3); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::One, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -793,7 +1183,13 @@ fn filter_4_for_palette_1() { opts.filter.insert(4); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::One, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -804,5 +1200,11 @@ fn filter_5_for_palette_1() { opts.filter.insert(5); 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::One, + png::ColorType::Indexed, + png::BitDepth::One); } diff --git a/tests/reduction.rs b/tests/reduction.rs index 8e8e8c8c..3662302e 100644 --- a/tests/reduction.rs +++ b/tests/reduction.rs @@ -48,7 +48,13 @@ fn get_opts(input: &Path) -> oxipng::Options { } } -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) { +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); @@ -88,7 +94,13 @@ fn rgba_16_should_be_rgba_16() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::RGBA, + png::BitDepth::Sixteen); } #[test] @@ -97,7 +109,13 @@ fn rgba_16_should_be_rgba_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::RGBA, + png::BitDepth::Eight); } #[test] @@ -106,7 +124,13 @@ fn rgba_8_should_be_rgba_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::RGBA, + png::BitDepth::Eight); } #[test] @@ -115,7 +139,13 @@ fn rgba_16_should_be_rgb_16() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::RGB, + png::BitDepth::Sixteen); } #[test] @@ -124,7 +154,13 @@ fn rgba_16_should_be_rgb_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::RGB, + png::BitDepth::Eight); } #[test] @@ -133,7 +169,13 @@ fn rgba_8_should_be_rgb_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::RGB, + png::BitDepth::Eight); } #[test] @@ -142,7 +184,13 @@ fn rgba_16_should_be_palette_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Eight); } #[test] @@ -151,7 +199,13 @@ fn rgba_8_should_be_palette_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Eight); } #[test] @@ -160,7 +214,13 @@ fn rgba_16_should_be_palette_4() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -169,7 +229,13 @@ fn rgba_8_should_be_palette_4() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -178,7 +244,13 @@ fn rgba_16_should_be_palette_2() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -187,7 +259,13 @@ fn rgba_8_should_be_palette_2() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -196,7 +274,13 @@ fn rgba_16_should_be_palette_1() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -205,7 +289,13 @@ fn rgba_8_should_be_palette_1() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -214,7 +304,13 @@ fn rgba_16_should_be_grayscale_alpha_16() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen); } #[test] @@ -223,7 +319,13 @@ fn rgba_16_should_be_grayscale_alpha_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight); } #[test] @@ -232,7 +334,13 @@ fn rgba_8_should_be_grayscale_alpha_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight); } #[test] @@ -241,7 +349,13 @@ fn rgba_16_should_be_grayscale_16() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Sixteen); } #[test] @@ -250,7 +364,13 @@ fn rgba_16_should_be_grayscale_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Eight); } #[test] @@ -259,7 +379,13 @@ fn rgba_8_should_be_grayscale_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); } #[test] @@ -268,7 +394,13 @@ fn rgba_16_should_be_palette_4_grayscale() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -277,7 +409,13 @@ fn rgba_8_should_be_palette_4_grayscale() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -286,7 +424,13 @@ fn rgba_16_should_be_palette_2_grayscale() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -295,7 +439,13 @@ fn rgba_8_should_be_palette_2_grayscale() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -304,7 +454,13 @@ fn rgba_16_should_be_palette_1_grayscale() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -313,7 +469,13 @@ fn rgba_8_should_be_palette_1_grayscale() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGBA, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -322,7 +484,13 @@ fn rgb_16_should_be_rgb_16() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::RGB, + png::BitDepth::Sixteen); } #[test] @@ -331,7 +499,13 @@ fn rgb_16_should_be_rgb_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::RGB, + png::BitDepth::Eight); } #[test] @@ -340,7 +514,13 @@ fn rgb_8_should_be_rgb_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::RGB, + png::BitDepth::Eight); } #[test] @@ -349,7 +529,13 @@ fn rgb_16_should_be_palette_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Eight); } #[test] @@ -358,7 +544,13 @@ fn rgb_8_should_be_palette_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Eight); } #[test] @@ -367,7 +559,13 @@ fn rgb_16_should_be_palette_4() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -376,7 +574,13 @@ fn rgb_8_should_be_palette_4() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -385,7 +589,13 @@ fn rgb_16_should_be_palette_2() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -394,7 +604,13 @@ fn rgb_8_should_be_palette_2() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -403,7 +619,13 @@ fn rgb_16_should_be_palette_1() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -412,7 +634,13 @@ fn rgb_8_should_be_palette_1() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -421,7 +649,13 @@ fn rgb_16_should_be_grayscale_16() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Sixteen); } #[test] @@ -430,7 +664,13 @@ fn rgb_16_should_be_grayscale_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Eight); } #[test] @@ -439,7 +679,13 @@ fn rgb_8_should_be_grayscale_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); } #[test] @@ -448,7 +694,13 @@ fn rgb_16_should_be_palette_4_grayscale() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -457,7 +709,13 @@ fn rgb_8_should_be_palette_4_grayscale() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -466,7 +724,13 @@ fn rgb_16_should_be_palette_2_grayscale() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -475,7 +739,13 @@ fn rgb_8_should_be_palette_2_grayscale() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -484,7 +754,13 @@ fn rgb_16_should_be_palette_1_grayscale() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -493,7 +769,13 @@ fn rgb_8_should_be_palette_1_grayscale() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::RGB, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -502,7 +784,13 @@ fn palette_8_should_be_grayscale_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); } #[test] @@ -511,7 +799,13 @@ fn palette_8_should_be_palette_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Eight); } #[test] @@ -520,7 +814,13 @@ fn palette_8_should_be_palette_4() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -529,7 +829,13 @@ fn palette_4_should_be_palette_4() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Four, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -538,7 +844,13 @@ fn palette_8_should_be_palette_2() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -547,7 +859,13 @@ fn palette_4_should_be_palette_2() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Four, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -556,7 +874,13 @@ fn palette_2_should_be_palette_2() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Two, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -565,7 +889,13 @@ fn palette_8_should_be_palette_1() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -574,7 +904,13 @@ fn palette_4_should_be_palette_1() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Four, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -583,7 +919,13 @@ fn palette_2_should_be_palette_1() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::Two, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -592,7 +934,13 @@ fn palette_1_should_be_palette_1() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Indexed, + png::BitDepth::One, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -601,7 +949,13 @@ fn grayscale_alpha_16_should_be_grayscale_alpha_16() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen); } #[test] @@ -610,7 +964,13 @@ fn grayscale_alpha_16_should_be_grayscale_alpha_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight); } #[test] @@ -619,7 +979,13 @@ fn grayscale_alpha_8_should_be_grayscale_alpha_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight); } #[test] @@ -628,7 +994,13 @@ fn grayscale_alpha_16_should_be_grayscale_16() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Sixteen); } #[test] @@ -637,7 +1009,13 @@ fn grayscale_alpha_16_should_be_grayscale_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Eight); } #[test] @@ -646,7 +1024,13 @@ fn grayscale_alpha_8_should_be_grayscale_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); } #[test] @@ -655,7 +1039,13 @@ fn grayscale_alpha_16_should_be_palette_4() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -664,7 +1054,13 @@ fn grayscale_alpha_8_should_be_palette_4() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -673,7 +1069,13 @@ fn grayscale_alpha_16_should_be_palette_2() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -682,7 +1084,13 @@ fn grayscale_alpha_8_should_be_palette_2() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -691,7 +1099,13 @@ fn grayscale_alpha_16_should_be_palette_1() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -700,7 +1114,13 @@ fn grayscale_alpha_8_should_be_palette_1() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::GrayscaleAlpha, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -709,7 +1129,13 @@ fn grayscale_16_should_be_grayscale_16() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Sixteen); } #[test] @@ -718,7 +1144,13 @@ fn grayscale_16_should_be_grayscale_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Grayscale, + png::BitDepth::Eight); } #[test] @@ -727,7 +1159,13 @@ fn grayscale_16_should_be_palette_4() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -736,7 +1174,13 @@ fn grayscale_16_should_be_palette_2() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -745,7 +1189,13 @@ fn grayscale_16_should_be_palette_1() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Sixteen, + png::ColorType::Indexed, + png::BitDepth::One); } #[test] @@ -754,7 +1204,13 @@ fn grayscale_8_should_be_grayscale_8() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Eight, + png::ColorType::Grayscale, + png::BitDepth::Eight); } #[test] @@ -763,7 +1219,13 @@ fn grayscale_8_should_be_palette_4() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Four); } #[test] @@ -772,7 +1234,13 @@ fn grayscale_8_should_be_palette_2() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::Two); } #[test] @@ -781,5 +1249,11 @@ fn grayscale_8_should_be_palette_1() { 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_it_converts(&input, + &output, + &opts, + png::ColorType::Grayscale, + png::BitDepth::Eight, + png::ColorType::Indexed, + png::BitDepth::One); } From 9a8c3f64b91f08803c220d5ed1a4be0c1054afd9 Mon Sep 17 00:00:00 2001 From: Joshua Holmer Date: Thu, 3 Mar 2016 13:52:52 -0500 Subject: [PATCH 4/4] Fix alternative filter modes Fixes #9 --- src/png.rs | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/png.rs b/src/png.rs index 02d71bc1..a3f73b74 100644 --- a/src/png.rs +++ b/src/png.rs @@ -343,8 +343,7 @@ impl PngData { pub fn unfilter_image(&self) -> Vec { let mut unfiltered = Vec::with_capacity(self.raw_data.len()); let tmp = self.ihdr_data.bit_depth.as_u8() * self.channels_per_pixel(); - // Round up without converting to float - let bpp = (tmp + tmp % 8) >> 3; + let bpp = ((tmp as f32) / 8f32).ceil() as usize; let mut last_line: Vec = vec![]; for line in self.scan_lines() { unfiltered.push(0); @@ -355,7 +354,7 @@ impl PngData { 1 => { let mut data = Vec::with_capacity(line.data.len()); for (i, byte) in line.data.iter().enumerate() { - match i.checked_sub(bpp as usize) { + match i.checked_sub(bpp) { Some(x) => { let b = data[x]; data.push(byte.wrapping_add(b)) @@ -382,7 +381,7 @@ impl PngData { let mut data = Vec::with_capacity(line.data.len()); for (i, byte) in line.data.iter().enumerate() { if last_line.is_empty() { - match i.checked_sub(bpp as usize) { + match i.checked_sub(bpp) { Some(x) => { let b = data[x]; data.push(byte.wrapping_add(b >> 1)) @@ -390,7 +389,7 @@ impl PngData { None => data.push(*byte), }; } else { - match i.checked_sub(bpp as usize) { + match i.checked_sub(bpp) { Some(x) => { let b = data[x]; data.push(byte.wrapping_add( @@ -408,7 +407,7 @@ impl PngData { let mut data = Vec::with_capacity(line.data.len()); for (i, byte) in line.data.iter().enumerate() { if last_line.is_empty() { - match i.checked_sub(bpp as usize) { + match i.checked_sub(bpp) { Some(x) => { let b = data[x]; data.push(byte.wrapping_add(b)) @@ -416,7 +415,7 @@ impl PngData { None => data.push(*byte), }; } else { - match i.checked_sub(bpp as usize) { + match i.checked_sub(bpp) { Some(x) => { let b = data[x]; data.push(byte.wrapping_add(paeth_predictor(b, @@ -438,8 +437,7 @@ impl PngData { pub fn filter_image(&self, filter: u8) -> Vec { let mut filtered = Vec::with_capacity(self.raw_data.len()); let tmp = self.ihdr_data.bit_depth.as_u8() * self.channels_per_pixel(); - // Round up without converting to float - let bpp = (tmp + tmp % 8) >> 3; + let bpp = ((tmp as f32) / 8f32).ceil() as usize; let mut last_line: Vec = vec![]; // We could try a different filter method for each line // But that would be prohibitively slow and probably not provide much benefit @@ -454,7 +452,7 @@ impl PngData { } 1 => { for (i, byte) in line.data.iter().enumerate() { - filtered.push(match i.checked_sub(bpp as usize) { + filtered.push(match i.checked_sub(bpp) { Some(x) => byte.wrapping_sub(line.data[x]), None => *byte, }); @@ -472,12 +470,12 @@ impl PngData { 3 => { for (i, byte) in line.data.iter().enumerate() { if last_line.is_empty() { - filtered.push(match i.checked_sub(bpp as usize) { + filtered.push(match i.checked_sub(bpp) { Some(x) => byte.wrapping_sub(line.data[x] >> 1), None => *byte, }); } else { - filtered.push(match i.checked_sub(bpp as usize) { + filtered.push(match i.checked_sub(bpp) { Some(x) => byte.wrapping_sub( ((line.data[x] as u16 + last_line[i] as u16) >> 1) as u8 ), @@ -489,12 +487,12 @@ impl PngData { 4 => { for (i, byte) in line.data.iter().enumerate() { if last_line.is_empty() { - filtered.push(match i.checked_sub(bpp as usize) { + filtered.push(match i.checked_sub(bpp) { Some(x) => byte.wrapping_sub(line.data[x]), None => *byte, }); } else { - filtered.push(match i.checked_sub(bpp as usize) { + filtered.push(match i.checked_sub(bpp) { Some(x) => { byte.wrapping_sub(paeth_predictor(line.data[x], last_line[i], @@ -520,7 +518,7 @@ impl PngData { let mut line_4 = Vec::with_capacity(line.data.len()); for (i, byte) in line.data.iter().enumerate() { if last_line.is_empty() { - match i.checked_sub(bpp as usize) { + match i.checked_sub(bpp) { Some(x) => { line_1.push(byte.wrapping_sub(line.data[x])); line_2.push(*byte); @@ -535,7 +533,7 @@ impl PngData { } } } else { - match i.checked_sub(bpp as usize) { + match i.checked_sub(bpp) { Some(x) => { line_1.push(byte.wrapping_sub(line.data[x])); line_2.push(byte.wrapping_sub(last_line[i]));