Skip to content

Commit

Permalink
End-to-end decoding benchmarks of paletted PNG images.
Browse files Browse the repository at this point in the history
Credit for the `zune-paletted.png` image: github.com/Shnatsel
(based on https://commons.wikimedia.org/wiki/File:Stadt_Onex_2021.png)
  • Loading branch information
fintelia authored and anforowicz committed Jan 11, 2024
1 parent b00fb53 commit b49f246
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
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();
})
});
}
4 changes: 4 additions & 0 deletions tests/benches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ 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
modified to use `ColorType::Indexed`.

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.

0 comments on commit b49f246

Please sign in to comment.