Fix handling of PNGs that are not 8 bit

This commit is contained in:
Surma
2021-07-21 16:16:44 +01:00
parent 011c0346c1
commit bf95eb39c2
2 changed files with 5 additions and 1 deletions

Binary file not shown.

View File

@ -53,7 +53,11 @@ where
#[wasm_bindgen]
pub fn decode(mut data: &[u8]) -> ImageData {
let mut decoder = png::Decoder::new(&mut data);
decoder.set_transformations(png::Transformations::EXPAND);
decoder.set_transformations(
png::Transformations::EXPAND | // Turn paletted images into RGB
png::Transformations::PACKING | // Turn images <8bit to 8bit
png::Transformations::STRIP_16, // Turn 16bit into 8 bit
);
let (info, mut reader) = decoder.read_info().unwrap_throw();
let num_pixels = (info.width * info.height) as usize;
let mut buf = vec![0; num_pixels * 4];