jpeg2k-sandboxed

Crates.iojpeg2k-sandboxed
lib.rsjpeg2k-sandboxed
version0.9.1
sourcesrc
created_at2023-03-04 17:15:21.327112
updated_at2024-07-11 13:22:33.597455
descriptionSandboxed Openjpeg image decoder
homepagehttps://github.com/Neopallium/jpeg2k-sandboxed
repositoryhttps://github.com/Neopallium/jpeg2k-sandboxed
max_upload_size
id800724
size1,308,920
Robert Gabriel Jakabosky (Neopallium)

documentation

README

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")?;
}
Commit count: 12

cargo fmt