CCSDS 121.0-B-3 Lossless Data Compression (Rice/Golomb coding)
1# rice
2
3Pure OCaml implementation of CCSDS 121.0-B-3 Lossless Data Compression.
4
5## Overview
6
7Rice/Golomb adaptive entropy coding for science instrument data. Used by
8missions including Mars rovers, JWST, and Earth observation satellites for
9lossless compression of image and science data.
10
11The codec implements the full CCSDS 121.0-B-3 bitstream format: configurable
12block size, sample bit depth, reference sample interval, and two prediction
13modes (unit delay and neighborhood).
14
15## Installation
16
17Install with opam:
18
19<!-- $MDX skip -->
20```sh
21$ opam install rice
22```
23
24If opam cannot find the package, it may not yet be released in the public
25`opam-repository`. Add the overlay repository, then install it:
26
27<!-- $MDX skip -->
28```sh
29$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
30$ opam update
31$ opam install rice
32```
33
34## Usage
35
36```ocaml
37(* Configure: 16 samples per block, 16-bit samples. *)
38let cfg = Rice.config ~block_size:16 ~bits_per_sample:16 ()
39
40(* Compress + decompress 512 16-bit samples. *)
41let data = Bytes.make 1024 '\x00'
42let compressed = Rice.compress cfg data
43
44let () =
45 match Rice.decompress ~sample_count:512 cfg compressed with
46 | Ok original -> assert (Bytes.length original = 1024)
47 | Error msg -> Fmt.failwith "decompression failed: %s" msg
48
49(* Use neighborhood predictor for 2D image data. *)
50let cfg_2d = Rice.config_with_predictor Neighborhood cfg
51```
52
53## API Overview
54
55- **`config`** -- Create compression configuration: `block_size` (8-64), `bits_per_sample` (1-32), `rsi`
56- **`compress`** -- Compress data to CCSDS 121.0-B-3 compliant bitstream
57- **`decompress`** -- Decompress with explicit sample count
58- **`config_with_predictor`** -- Set prediction mode: `Unit_delay` or `Neighborhood`
59
60## References
61
62- [CCSDS 121.0-B-3](https://public.ccsds.org/Pubs/121x0b3.pdf) -- Lossless
63 Data Compression. Consultative Committee for Space Data Systems, 2020.
64
65## Licence
66
67ISC License. See [LICENSE.md](LICENSE.md) for details.