# Rust JPEG Codec

Canonical page: https://frames-sg.com/rust-jpeg-codec/

`j2k-jpeg` is a pure-Rust JPEG inspection, decoding and encoding crate for general imaging, pathology, medical imaging and transcode pipelines. The CPU implementation is the reference route; optional CUDA and Apple Metal adapter crates cover supported GPU operations.

## Decode

- Baseline, extended and progressive DCT JPEG at 8 or 12 bits.
- Lossless JPEG from 2 through 16 bits, including predictors 1–7, point transforms, restart intervals and split scans.
- Grayscale, YCbCr, RGB and supported Adobe CMYK/YCCK layouts.
- One-half, one-quarter and one-eighth reduced IDCT output for sequential and progressive DCT images.
- TIFF shared-table normalization and APP2 ICC profile extraction, insertion and replacement.

## Encode

- 8-bit baseline grayscale or YCbCr 4:4:4, 4:2:2 and 4:2:0.
- Optimized baseline Huffman tables.
- 12-bit extended sequential JPEG for DICOM-oriented lossy workflows.
- Lossless JPEG at 2–16 bits from supported grayscale and RGB samples.

The encoders write JPEG codestreams. Wrapping those codestreams in DICOM or another container belongs to the caller.

## Explicit limits

Arithmetic coding, hierarchical JPEG, four-component lossless JPEG and incompatible sampling layouts are unsupported and return errors.

## Install and references

```sh
cargo add j2k-jpeg
```

- [API documentation](https://docs.rs/j2k-jpeg)
- [Crate source and README](https://github.com/frames-sg/j2k/tree/main/crates/j2k-jpeg)
- [JPEG-to-HTJ2K transcoding](https://frames-sg.com/jpeg-to-htj2k-transcoding/)
- [J2K support matrix](https://github.com/frames-sg/j2k/blob/main/docs/public-support.md)
