pi-frame-server/benches/dithering.rs
saji 2011ece21d
All checks were successful
cargo_test_bench / Run Tests (push) Successful in 1m28s
cargo_test_bench / Run Benchmarks (push) Successful in 2m18s
add toml; move eink-specific palettes to separate file
2024-07-31 20:20:22 -05:00

33 lines
1 KiB
Rust

use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use image::{ImageReader, RgbImage};
use pi_frame_server::dither::{DitherMethod, DitheredImage};
use pi_frame_server::eink::Palette;
fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("dithering_benchmark");
let sample_file = "sample_0.tiff";
let image: RgbImage = ImageReader::open(format!("samples/{sample_file}"))
.expect("file exists")
.decode()
.expect("file is valid")
.into_rgb8();
group.sample_size(20);
group.bench_with_input(BenchmarkId::new("dither", "sample_0"), &image, |b, i| {
b.iter(|| {
let mut method = DitherMethod::Atkinson.get_ditherer();
let mut result = DitheredImage::new(
image.width(),
image.height(),
Palette::Default.value().to_vec(),
);
method.dither(i, &mut result);
});
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);