#jpeg #libjpeg #image #encoder #decoder

mozjpeg

Higher-level wrapper for Mozilla’s JPEG library

16 releases

✓ Uses Rust 2018 edition

new 0.8.19 Jul 6, 2020
0.8.16 Apr 2, 2020
0.8.15 Jan 4, 2020
0.8.14 Mar 13, 2019
0.8.5 May 9, 2018

#120 in Images

Download history 329/week @ 2020-03-16 505/week @ 2020-03-23 232/week @ 2020-03-30 453/week @ 2020-04-06 506/week @ 2020-04-13 356/week @ 2020-04-20 423/week @ 2020-04-27 289/week @ 2020-05-04 418/week @ 2020-05-11 374/week @ 2020-05-18 234/week @ 2020-05-25 422/week @ 2020-06-01 575/week @ 2020-06-08 789/week @ 2020-06-15 525/week @ 2020-06-22 541/week @ 2020-06-29

1,992 downloads per month
Used in 4 crates (2 directly)

IJG license

53KB
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

~4.5MB
~88K SLoC