#jpeg #image #encoder #decoder #libjpeg

mozjpeg

Higher-level wrapper for Mozilla’s JPEG library

12 releases

0.8.14 Mar 13, 2019
0.8.13 Feb 26, 2019
0.8.11 Jan 16, 2019
0.8.9 Oct 23, 2018
0.8.1 Apr 29, 2018

#38 in Images

Download history 99/week @ 2018-11-28 28/week @ 2018-12-05 103/week @ 2018-12-12 94/week @ 2018-12-19 22/week @ 2018-12-26 31/week @ 2019-01-02 35/week @ 2019-01-09 35/week @ 2019-01-16 11/week @ 2019-01-23 41/week @ 2019-01-30 37/week @ 2019-02-06 24/week @ 2019-02-13 12/week @ 2019-02-20 92/week @ 2019-02-27 58/week @ 2019-03-06

174 downloads per month
Used in 2 crates

IJG license

50KB
1K SLoC

Rust wrapper for MozJPEG library

This library is compatible with Rust versions 1.27 to 1.32 only. In Rust 1.33 or later any errors will cause the entire process to abort due to changes in Rust's unwinding


This library offers convenient reading and writing of well-compressed JPEG images using a safe Rust interface.

The interface is still being developed, so it has rough edges and may change.

Decoding

let d = mozjpeg::Decompress::with_markers(mozjpeg::ALL_MARKERS)
    .from_path("tests/test.jpg")?;

d.width();
d.height();
d.color_space() == mozjpeg::ColorSpace::JCS_YCbCr;
for marker in d.markers() {}

let image = d.rgb().unwrap();
image.width();
image.height();
image.color_space() == mozjpeg::ColorSpace::JCS_RGB;

Error handling

In Rust v1.32 and older, errors detected by libjpeg cause panic!(), and you can use catch_unwind() to handle these errors gracefully.

In Rust v1.33 and later (until issue #58760 is resolved) any error in libjpeg causes a crash of the entire process, and there is no way to gracefully handle even most trivial errors.

Dependencies

~5MB
~102K SLoC