From bf95eb39c2d837e388dec66eb35d9ad1f1d70ca7 Mon Sep 17 00:00:00 2001 From: Surma Date: Wed, 21 Jul 2021 16:16:44 +0100 Subject: [PATCH] Fix handling of PNGs that are not 8 bit --- codecs/png/pkg/squoosh_png_bg.wasm | Bin 123698 -> 123698 bytes codecs/png/src/lib.rs | 6 +++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/codecs/png/pkg/squoosh_png_bg.wasm b/codecs/png/pkg/squoosh_png_bg.wasm index 15d0ec0354dff815deb11bba1f17e20d3946a271..cc5cf3660e097015b9e777aaefe90cc4cc4b6e10 100644 GIT binary patch delta 28 kcmdmVjD6EF_6>oP7%wyjP1+tbiSe~JqtAA`dyHRL0Kwx7wEzGB delta 28 kcmdmVjD6EF_6>oP7#o^{CT$Oz#Q55q(Q~`qJ;pCA0K6^?VgLXD diff --git a/codecs/png/src/lib.rs b/codecs/png/src/lib.rs index d5eacfce..e23cf7dd 100644 --- a/codecs/png/src/lib.rs +++ b/codecs/png/src/lib.rs @@ -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];