7 unstable releases (3 breaking)
0.9.1 | Jul 11, 2024 |
---|---|
0.8.0 | Jul 10, 2024 |
0.7.0 | Apr 20, 2024 |
0.6.3 | Apr 10, 2023 |
0.6.2 | Mar 8, 2023 |
#236 in WebAssembly
357 downloads per month
425KB
354 lines
jpeg2k-sandboxed
A sandboxed Jpeg2k image decoder. The jpeg2k decoder (uses openjpeg-sys
) is compiled to a WASI module
and sandboxed using wasmtime
.
Build
The ./src/wasi-decoder.wasm
file can be rebuild by running ./rebuild-wasi-decoder.sh
.
Requires wasi-sdk.
Example: Convert a Jpeg 2000 image to a png image.
use jpeg2k_sandboxed::*;
fn main() {
// The decoder object can be shared across threads.
let decoder = Jpeg2kSandboxed::new().expect("Failed to load decoder");
let mut file = File::open("./assets/example.j2k").expect("Failed to open file.");
let mut buf = Vec::new();
file.read_to_end(&mut buf).expect("Failed to read file.");
// Request decoding of image from bytes.
let req = DecodeImageRequest::new(buf);
let image = decoder.decode(&req).expect("Decode failed.");
// Convert to a `image::DynamicImage`
let img: image::DynamicImage = image.try_into()?;
// Save as png file.
img.save("out.png")?;
}
Dependencies
~0.8–20MB
~248K SLoC