diff --git a/benches/reductions.rs b/benches/reductions.rs index 774c346a..be9b6e06 100644 --- a/benches/reductions.rs +++ b/benches/reductions.rs @@ -75,6 +75,66 @@ fn reductions_2_to_1_bits(b: &mut Bencher) { b.iter(|| bit_depth::reduce_bit_depth(&png.raw, 1)); } +#[bench] +fn reductions_grayscale_8_to_4_bits(b: &mut Bencher) { + let input = test::black_box(PathBuf::from( + "tests/files/grayscale_8_should_be_grayscale_4.png", + )); + let png = PngData::new(&input, false).unwrap(); + + b.iter(|| bit_depth::reduce_bit_depth(&png.raw, 1)); +} + +#[bench] +fn reductions_grayscale_8_to_2_bits(b: &mut Bencher) { + let input = test::black_box(PathBuf::from( + "tests/files/grayscale_8_should_be_grayscale_2.png", + )); + let png = PngData::new(&input, false).unwrap(); + + b.iter(|| bit_depth::reduce_bit_depth(&png.raw, 1)); +} + +#[bench] +fn reductions_grayscale_8_to_1_bits(b: &mut Bencher) { + let input = test::black_box(PathBuf::from( + "tests/files/grayscale_8_should_be_grayscale_1.png", + )); + let png = PngData::new(&input, false).unwrap(); + + b.iter(|| bit_depth::reduce_bit_depth(&png.raw, 1)); +} + +#[bench] +fn reductions_grayscale_4_to_2_bits(b: &mut Bencher) { + let input = test::black_box(PathBuf::from( + "tests/files/grayscale_4_should_be_grayscale_2.png", + )); + let png = PngData::new(&input, false).unwrap(); + + b.iter(|| bit_depth::reduce_bit_depth(&png.raw, 1)); +} + +#[bench] +fn reductions_grayscale_4_to_1_bits(b: &mut Bencher) { + let input = test::black_box(PathBuf::from( + "tests/files/grayscale_4_should_be_grayscale_1.png", + )); + let png = PngData::new(&input, false).unwrap(); + + b.iter(|| bit_depth::reduce_bit_depth(&png.raw, 1)); +} + +#[bench] +fn reductions_grayscale_2_to_1_bits(b: &mut Bencher) { + let input = test::black_box(PathBuf::from( + "tests/files/grayscale_2_should_be_grayscale_1.png", + )); + let png = PngData::new(&input, false).unwrap(); + + b.iter(|| bit_depth::reduce_bit_depth(&png.raw, 1)); +} + #[bench] fn reductions_rgba_to_rgb_16(b: &mut Bencher) { let input = test::black_box(PathBuf::from("tests/files/rgba_16_should_be_rgb_16.png")); diff --git a/tests/files/grayscale_2_should_be_grayscale_1.png b/tests/files/grayscale_2_should_be_grayscale_1.png new file mode 100644 index 00000000..c614d443 Binary files /dev/null and b/tests/files/grayscale_2_should_be_grayscale_1.png differ diff --git a/tests/files/grayscale_4_should_be_grayscale_1.png b/tests/files/grayscale_4_should_be_grayscale_1.png new file mode 100644 index 00000000..12d05931 Binary files /dev/null and b/tests/files/grayscale_4_should_be_grayscale_1.png differ diff --git a/tests/files/grayscale_4_should_be_grayscale_2.png b/tests/files/grayscale_4_should_be_grayscale_2.png new file mode 100644 index 00000000..eb4570ff Binary files /dev/null and b/tests/files/grayscale_4_should_be_grayscale_2.png differ diff --git a/tests/files/grayscale_8_should_be_grayscale_1.png b/tests/files/grayscale_8_should_be_grayscale_1.png new file mode 100644 index 00000000..89248c61 Binary files /dev/null and b/tests/files/grayscale_8_should_be_grayscale_1.png differ diff --git a/tests/files/grayscale_8_should_be_grayscale_2.png b/tests/files/grayscale_8_should_be_grayscale_2.png new file mode 100644 index 00000000..a3e063c9 Binary files /dev/null and b/tests/files/grayscale_8_should_be_grayscale_2.png differ diff --git a/tests/files/grayscale_8_should_be_grayscale_4.png b/tests/files/grayscale_8_should_be_grayscale_4.png new file mode 100644 index 00000000..c561432e Binary files /dev/null and b/tests/files/grayscale_8_should_be_grayscale_4.png differ diff --git a/tests/reduction.rs b/tests/reduction.rs index e6ec5a2a..f3afdb88 100644 --- a/tests/reduction.rs +++ b/tests/reduction.rs @@ -718,6 +718,78 @@ fn grayscale_8_should_be_grayscale_8() { ); } +#[test] +fn grayscale_8_should_be_grayscale_4() { + test_it_converts( + "tests/files/grayscale_8_should_be_grayscale_4.png", + false, + ColorType::Grayscale, + BitDepth::Eight, + ColorType::Grayscale, + BitDepth::Four, + ); +} + +#[test] +fn grayscale_8_should_be_grayscale_2() { + test_it_converts( + "tests/files/grayscale_8_should_be_grayscale_2.png", + false, + ColorType::Grayscale, + BitDepth::Eight, + ColorType::Grayscale, + BitDepth::Two, + ); +} + +#[test] +fn grayscale_4_should_be_grayscale_2() { + test_it_converts( + "tests/files/grayscale_4_should_be_grayscale_2.png", + false, + ColorType::Grayscale, + BitDepth::Four, + ColorType::Grayscale, + BitDepth::Two, + ); +} + +#[test] +fn grayscale_8_should_be_grayscale_1() { + test_it_converts( + "tests/files/grayscale_8_should_be_grayscale_1.png", + false, + ColorType::Grayscale, + BitDepth::Eight, + ColorType::Grayscale, + BitDepth::One, + ); +} + +#[test] +fn grayscale_4_should_be_grayscale_1() { + test_it_converts( + "tests/files/grayscale_4_should_be_grayscale_1.png", + false, + ColorType::Grayscale, + BitDepth::Four, + ColorType::Grayscale, + BitDepth::One, + ); +} + +#[test] +fn grayscale_2_should_be_grayscale_1() { + test_it_converts( + "tests/files/grayscale_2_should_be_grayscale_1.png", + false, + ColorType::Grayscale, + BitDepth::Two, + ColorType::Grayscale, + BitDepth::One, + ); +} + #[test] fn grayscale_alpha_16_should_be_grayscale_trns_16() { test_it_converts(