mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 09:39:15 +00:00
Fix PNG decoder returning Rust-owned ImageData
This commit is contained in:
@@ -1,7 +1,22 @@
|
||||
use std::io::Cursor;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use web_sys::ImageData;
|
||||
use wasm_bindgen::Clamped;
|
||||
|
||||
// Custom ImageData bindings to allow construction with
|
||||
// a JS-owned copy of the data.
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(typescript_type = ImageData)]
|
||||
pub type ImageData;
|
||||
|
||||
#[wasm_bindgen(constructor)]
|
||||
fn new_with_owned_u8_clamped_array_and_sh(
|
||||
data: Clamped<Vec<u8>>,
|
||||
sw: u32,
|
||||
sh: u32,
|
||||
) -> ImageData;
|
||||
}
|
||||
|
||||
#[wasm_bindgen(catch)]
|
||||
pub fn encode(data: &[u8], width: u32, height: u32) -> Vec<u8> {
|
||||
@@ -38,10 +53,9 @@ pub fn decode(data: &[u8]) -> ImageData {
|
||||
}
|
||||
}
|
||||
|
||||
ImageData::new_with_u8_clamped_array_and_sh(
|
||||
wasm_bindgen::Clamped(&mut buf),
|
||||
ImageData::new_with_owned_u8_clamped_array_and_sh(
|
||||
wasm_bindgen::Clamped(buf),
|
||||
info.width,
|
||||
info.height,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user