Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

End-to-end decoding benchmarks of paletted PNG images. #453

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions benches/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fs;
use criterion::{
criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion, Throughput,
};
use png::Decoder;
use png::{Decoder, Reader, Transformations};

#[path = "../src/test_utils.rs"]
mod test_utils;
Expand Down Expand Up @@ -57,17 +57,25 @@ fn bench_file(g: &mut BenchmarkGroup<WallTime>, data: Vec<u8>, name: String) {
g.sample_size(10);
}

let decoder = Decoder::new(&*data);
let mut reader = decoder.read_info().unwrap();
fn create_reader(data: &[u8]) -> Reader<&[u8]> {
let mut decoder = Decoder::new(data);

// Cover default transformations used by the `image` crate when constructing
// `image::codecs::png::PngDecoder`.
decoder.set_transformations(Transformations::EXPAND);

decoder.read_info().unwrap()
}

let mut reader = create_reader(data.as_slice());
let mut image = vec![0; reader.output_buffer_size()];
let info = reader.next_frame(&mut image).unwrap();

g.throughput(Throughput::Bytes(info.buffer_size() as u64));
g.bench_with_input(name, &data, |b, data| {
b.iter(|| {
let decoder = Decoder::new(data.as_slice());
let mut decoder = decoder.read_info().unwrap();
decoder.next_frame(&mut image).unwrap();
let mut reader = create_reader(data.as_slice());
reader.next_frame(&mut image).unwrap();
})
});
}
6 changes: 6 additions & 0 deletions tests/benches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ Copyrights:
* `Lohengrin_-_Illustrated_Sporting_and_Dramatic_News.png`: Public Domain, according to Wikimedia
* `kodim*.png`: Eastman Kodak Company, released for unrestricted use
* `Transparency.png`: Public Domain, according to Wikimedia
* `zune-paletted.png`:
[Creative Commons Attribution-Share Alike 3.0 Unported](https://creativecommons.org/licenses/by-sa/3.0/deed.en). This is based on
https://commons.wikimedia.org/wiki/File:Stadt_Onex_2021.png - it has been
downloaded at 2048px resolution and modified to use `ColorType::Indexed` with
`convert -type palette -colors 256 2048px-Stadt_Onex_2021.png
tests/benches/paletted-zune.png`.

The images use different filtering:

Expand Down
Binary file added tests/benches/paletted-zune.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading