Skip to main content

Crate rusty_jpeg

Crate rusty_jpeg 

Source
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 — from jpeg-decoder 0.3.2 (image-rs), MIT OR Apache-2.0.
  • encode — from jpeg-encoder 0.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

use std::io::Cursor;
let bytes = std::fs::read("in.jpg").unwrap();
let mut decoder = rusty_jpeg::decode::Decoder::new(Cursor::new(bytes));
let pixels = decoder.decode()?;
let info = decoder.info().unwrap();

§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)?;

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;

Modules§

decode
JPEG decoding.
encode
JPEG encoding.
prof
Feature-gated stage profiler — where the time goes, at zero cost when off.