Crates.io | jpeg2k-sandboxed |
lib.rs | jpeg2k-sandboxed |
version | 0.9.1 |
source | src |
created_at | 2023-03-04 17:15:21.327112 |
updated_at | 2024-07-11 13:22:33.597455 |
description | Sandboxed Openjpeg image decoder |
homepage | https://github.com/Neopallium/jpeg2k-sandboxed |
repository | https://github.com/Neopallium/jpeg2k-sandboxed |
max_upload_size | |
id | 800724 |
size | 1,308,920 |
A sandboxed Jpeg2k image decoder. The jpeg2k decoder (uses openjpeg-sys
) is compiled to a WASI module
and sandboxed using wasmtime
.
The ./src/wasi-decoder.wasm
file can be rebuild by running ./rebuild-wasi-decoder.sh
.
Requires wasi-sdk.
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")?;
}