4 releases (2 breaking)

0.3.1 Oct 28, 2019
0.3.0 Oct 28, 2019
0.2.0 Oct 3, 2019
0.1.0 Sep 6, 2019

#6 in #jpeg2000


4.5K SLoC


Rust bindings to OpenJPEG

Supports loading JPEG2000 images into image::DynamicImage.Rust

Forked from https://framagit.org/leoschwarz/jpeg2000-rust before its GPL-v3 relicensing, with some additional features:

  • Specify decoding area and quality layers in addition to reduction factor
  • Improved OpenJPEG -> DynamicImage loading process
  • Get basic metadata from JPEG2000 headings
  • Docs (albeit minimal ones)

This library brings its own libopenjpeg, which is statically linked. If you just need raw FFI bindings, see openjpeg2-sys or openjpeg-sys.


fn main() {
    let bytes = include_bytes!("./rust-logo-512x512-blk.jp2");

    let jp2k::Image(img) = jp2k::Image::from_bytes(
        Some(jp2k::DecodeParams::default().with_decoding_area(0, 0, 256, 256))

    let mut output = std::path::Path::new("examples/output/result.png");
    let _ = img.save(&mut output);

Original warnings and license statement


Please be advised that using C code means this crate is likely vulnerable to various memory exploits, e.g. see http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-8332 for an actual example from the past.

As soon as someone writes an efficient JPEG2000 decoder in pure Rust you should probably switch over to that.


You can use the Rust code in the directories src and openjp2-sys/src under the terms of either the MIT license (LICENSE-MIT file) or the Apache license (LICENSE-APACHE file). Please note that this will link statically to OpenJPEG, which has its own license which you can find at openjpeg-sys/libopenjpeg/LICENSE (you might have to check out the git submodule first).

License: MIT OR Apache-2.0


~34K SLoC