pi-frame-server/benches/dithering.rs

29 lines
944 B
Rust
Raw Normal View History

2024-07-31 03:32:39 +00:00
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use image::{ImageReader, RgbImage};
use pi_frame_server::dither::{DitherMethod, DitheredImage, Palette};
2024-07-30 17:24:39 +00:00
fn criterion_benchmark(c: &mut Criterion) {
2024-07-31 03:32:39 +00:00
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();
c.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);
});
});
2024-07-30 17:24:39 +00:00
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);