Add grayscale depth tests and benches

This commit is contained in:
Andrew 2022-12-16 08:18:47 +13:00
parent 2008d09915
commit 886dedd487
8 changed files with 132 additions and 0 deletions

View file

@ -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"));

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -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(