Skip to main content

dicom_toolkit_codec/jpeg_ls/
mod.rs

1//! Pure-Rust JPEG-LS codec (ISO/IEC 14495-1).
2//!
3//! Implements both lossless (NEAR=0) and near-lossless encoding/decoding
4//! for 2–16 bit depths, 1–4 components, all interleave modes.
5//!
6//! This is a port of the CharLS algorithm — no C/C++ dependencies.
7
8pub mod bitstream;
9pub mod context;
10pub mod decoder;
11pub mod encoder;
12pub mod golomb;
13pub mod marker;
14pub mod params;
15pub mod prediction;
16pub mod sample;
17pub mod scan;
18
19use dicom_toolkit_core::error::DcmResult;
20
21// ── JpegLsCodec ───────────────────────────────────────────────────────────────
22
23/// Pure-Rust JPEG-LS codec.
24///
25/// Supports lossless and near-lossless encoding/decoding for 2–16 bit depths.
26pub struct JpegLsCodec;
27
28impl JpegLsCodec {
29    /// Decode a JPEG-LS frame from compressed data.
30    pub fn decode_frame(data: &[u8]) -> DcmResult<decoder::DecodedFrame> {
31        decoder::decode_jpeg_ls(data)
32    }
33
34    /// Encode raw pixels as a JPEG-LS bitstream.
35    pub fn encode_frame(
36        pixels: &[u8],
37        width: u32,
38        height: u32,
39        bits_per_sample: u8,
40        components: u8,
41        near: i32,
42    ) -> DcmResult<Vec<u8>> {
43        encoder::encode_jpeg_ls(pixels, width, height, bits_per_sample, components, near)
44    }
45}