# JPEG-to-HTJ2K Transcoding in Rust

Canonical page: https://frames-sg.com/jpeg-to-htj2k-transcoding/

`j2k-transcode` converts supported baseline JPEG inputs to HTJ2K from their DCT coefficients without first decoding the image to pixels. The crate owns the CPU pipeline and shared contracts used by optional CUDA and Apple Metal adapter crates. HTJ2K codestream assembly remains in the core transcode crate.

## Pipeline

1. Parse a supported baseline JPEG and retain its coefficient-domain information.
2. Run the coefficient-domain transform and HT block-coding stages.
3. Assemble the ordered HTJ2K codestream and return per-input results.

The default CPU batch route processes tiles in parallel waves bounded by the Rayon pool and host-memory cap. Outputs and per-tile errors retain input order. Optional accelerator adapters describe checked resident DCT grids, wavelet subbands and codestream buffers for supported stages.

The coefficient-domain route is intentionally narrower than general JPEG decoding. Unsupported JPEG types and modes return errors; they do not trigger a hidden decoded-pixel fallback.

## Install and CLI

```sh
cargo add j2k-transcode
cargo install j2k-cli
j2k transcode input.jpg output.j2k --htj2k --lossless-53
```

- [API documentation](https://docs.rs/j2k-transcode)
- [Crate source and README](https://github.com/frames-sg/j2k/tree/main/crates/j2k-transcode)
- [Rust JPEG codec](https://frames-sg.com/rust-jpeg-codec/)
- [HTJ2K in Rust](https://frames-sg.com/j2k/htj2k-rust/)
