dicom_toolkit_codec/jp2k/mod.rs
1//! JPEG 2000 codec integration for DICOM transfer syntaxes.
2//!
3//! Uses the forked `dicom-toolkit-jpeg2000` crate for both encoding and decoding at native
4//! bit depth (8/12/16-bit), preserving full diagnostic quality.
5
6pub mod decoder;
7pub mod encoder;
8
9use dicom_toolkit_core::error::DcmResult;
10
11/// JPEG 2000 codec for DICOM pixel data.
12///
13/// Supports encoding and decoding of JPEG 2000 and HTJ2K compressed DICOM images
14/// at native bit depth (8, 12, or 16-bit), which is critical for diagnostic-quality
15/// medical imaging.
16pub struct Jp2kCodec;
17
18impl Jp2kCodec {
19 /// Decode a JPEG 2000 codestream from compressed data.
20 pub fn decode_frame(data: &[u8]) -> DcmResult<decoder::DecodedFrame> {
21 decoder::decode_jp2k(data)
22 }
23
24 /// Encode pixel data into a classic JPEG 2000 codestream.
25 pub fn encode_frame(
26 pixels: &[u8],
27 width: u32,
28 height: u32,
29 bits_per_sample: u8,
30 samples_per_pixel: u8,
31 lossless: bool,
32 ) -> DcmResult<Vec<u8>> {
33 encoder::encode_jp2k(
34 pixels,
35 width,
36 height,
37 bits_per_sample,
38 samples_per_pixel,
39 lossless,
40 )
41 }
42
43 /// Encode pixel data into an HTJ2K codestream.
44 pub fn encode_frame_htj2k(
45 pixels: &[u8],
46 width: u32,
47 height: u32,
48 bits_per_sample: u8,
49 samples_per_pixel: u8,
50 lossless: bool,
51 ) -> DcmResult<Vec<u8>> {
52 encoder::encode_htj2k(
53 pixels,
54 width,
55 height,
56 bits_per_sample,
57 samples_per_pixel,
58 lossless,
59 )
60 }
61}