#image #jpeg2000 #j2k

bin+lib jpeg2k-sandboxed

Sandboxed Openjpeg image decoder

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

Download history 14/week @ 2024-07-14 16/week @ 2024-09-15 11/week @ 2024-09-22 2/week @ 2024-09-29

357 downloads per month

MIT/Apache

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