A fast, correct and safe jpeg decoder.
This crate contains a pure Rust jpeg decoder
The library provides a simple-to-use API for jpeg decoding and an ability to add options to influence decoding
```Rust // Import the library use zune_jpeg::JpegDecoder; use std::fs::read; // load some jpeg data let data = read("cat.jpg").unwrap();
// create a decoder let mut decoder = JpegDecoder::new( & data); // decode the file let pixels = decoder.decode().unwrap(); ```
The decoder supports more manipulations via DecoderOptions
,
see additional documentation in the library.
The implementation aims to have the following goals achieved, in order of importance
unsafe
should be used sparinglyno_std
| feature | on | Capabilities |
|---------|-----|---------------------------------------------------------------------------------------------|
| x86
| yes | Enables x86
specific instructions, specifically avx
and sse
for accelerated decoding. |
| std
| yes | Enable linking to the std
crate |
Note that the x86
features are automatically disabled on platforms that aren't x86 during compile
time hence there is no need to disable them explicitly if you are targeting such a platform.
no_std
environmentThe crate can be used in a no_std
environment with the alloc
feature.
But one is required to link to a working allocator for whatever environment the decoder will be running on
The decoder heavily relies on platform specific intrinsics, namely AVX2 and SSE to gain speed-ups in decoding,
but in debug build rust generally doesn't like platform specific intrinsics (try
passing -O
parameter to see optimized build) hence obviously speeds tank so bad during debug builds, and there is
probably nothing
we can do about that.
The library tries to be at fast as [libjpeg-turbo] while being as safe as possible. Platform specific intrinsics help get speed up intensive operations ensuring we can almost match [libjpeg-turbo] speeds but speeds are always +- 10 ms of this library.
For more up-to-date benchmarks, see the online repo with benchmarks here