rice#
Pure OCaml implementation of CCSDS 121.0-B-3 Lossless Data Compression.
Overview#
Rice/Golomb adaptive entropy coding for science instrument data. Used by missions including Mars rovers, JWST, and Earth observation satellites for lossless compression of image and science data.
The codec implements the full CCSDS 121.0-B-3 bitstream format: configurable block size, sample bit depth, reference sample interval, and two prediction modes (unit delay and neighborhood).
Installation#
Install with opam:
$ opam install rice
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install rice
Usage#
(* Configure: 16 samples per block, 16-bit samples. *)
let cfg = Rice.config ~block_size:16 ~bits_per_sample:16 ()
(* Compress + decompress 512 16-bit samples. *)
let data = Bytes.make 1024 '\x00'
let compressed = Rice.compress cfg data
let () =
match Rice.decompress ~sample_count:512 cfg compressed with
| Ok original -> assert (Bytes.length original = 1024)
| Error msg -> Fmt.failwith "decompression failed: %s" msg
(* Use neighborhood predictor for 2D image data. *)
let cfg_2d = Rice.config_with_predictor Neighborhood cfg
API Overview#
config-- Create compression configuration:block_size(8-64),bits_per_sample(1-32),rsicompress-- Compress data to CCSDS 121.0-B-3 compliant bitstreamdecompress-- Decompress with explicit sample countconfig_with_predictor-- Set prediction mode:Unit_delayorNeighborhood
References#
- CCSDS 121.0-B-3 -- Lossless Data Compression. Consultative Committee for Space Data Systems, 2020.
Licence#
ISC License. See LICENSE.md for details.