Expand description
Pure-Rust JPEG / MJPEG decoder and encoder — no C, no FFI.
This crate vendors two upstream pure-Rust implementations and carries them
forward as one codec (see NOTICE.md for full attribution):
decode— fromjpeg-decoder0.3.2 (image-rs), MIT OR Apache-2.0.encode— fromjpeg-encoder0.7.0, (MIT OR Apache-2.0) AND IJG.
They were merged so the two halves can share primitives — quantization tables, zig-zag order, the profiler — and so the encoder can be held to the decoder as a round-trip oracle, which is the standing correctness gate for every change made here.
§Decode
let bytes = std::fs::read("in.jpg").unwrap();
let mut decoder = rusty_jpeg::decode::Decoder::new(&bytes[..]);
let pixels = decoder.decode()?;
let info = decoder.info().unwrap();The decoder reads any decode::Source: with std that is every
std::io::Read; without it, a &[u8].
§Encode
use rusty_jpeg::encode::{ColorType, Encoder};
let mut out = Vec::new();
let encoder = Encoder::new(&mut out, 90);
encoder.encode(&[255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255], 2, 2, ColorType::Rgb)?;§Without std
--no-default-features makes the crate no_std + alloc. The encoder
writes into a Vec<u8>, a &mut [u8] or an encode::SliceWriter (a
caller-owned buffer that reports how much it holds); the decoder reads a
&[u8], and decode::Decoder::scale decodes a sensor-sized picture at
1/2, 1/4 or 1/8 for a fraction of the work. No libm is needed: every float
on the coding path was replaced by exact integer arithmetic, so a host and
a chip produce the same bytes. Environment knobs (RUSTY_JPEG_*) read as
their defaults; a chip’s configuration is a field, not a variable.
Re-exports§
pub use decode::ColorTransform;pub use decode::Decoder;pub use decode::ImageInfo;pub use decode::PixelFormat;pub use encode::ColorType;pub use encode::Encoder;pub use encode::EncodingError;pub use encode::JpegColorType;pub use encode::QuantizationTableType;pub use encode::SamplingFactor;