Skip to content

Instantly share code, notes, and snippets.

@Shnatsel

Shnatsel/main.rs Secret

Created January 11, 2024 20:06
Show Gist options
  • Save Shnatsel/ec75b05205ef55c96b9d256fdc36c2ec to your computer and use it in GitHub Desktop.
Save Shnatsel/ec75b05205ef55c96b9d256fdc36c2ec to your computer and use it in GitHub Desktop.
Profiling harness for palette expansion in `png` crate
use std::fs::File;
fn main() {
// loop 10 times to get lots of samples and a more clear profile
for i in 0..10 {
let filename = std::env::args_os().nth(1).expect("No input file provided");
let mut decoder = png::Decoder::new(File::open(filename).unwrap());
// Set the decoder to expand palletted images into RGBA instead of simply outputting palette indices
// Without this the
decoder.set_transformations(png::Transformations::EXPAND);
let mut reader = decoder.read_info().unwrap();
// Allocate the output buffer.
let mut buf = vec![0; reader.output_buffer_size()];
// Read the next frame. An APNG might contain multiple frames.
let _info = reader.next_frame(&mut buf).unwrap();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment