Skip to content

API: C API: Functions

Samuel Li edited this page Oct 23, 2023 · 5 revisions

Compression modes

SPERR C API supports 3 different compression modes: 1) fixed-bpp, 2) fixed-psnr, and 3) fixed-pwe.

The intended compression mode to use, thus, is passed to the C API by an integer:

mode == 1 means fixed-bpp
mode == 2 means fixed-psnr
mode == 3 means fixed-pwe

Any other mode numbers passed in will result in an error.

Compression and decompression in 2D

A pair of functions provide support for fixed-size compression in 2D:

  • sperr_comp_2d() takes in a 2D slice and produces a compressed bitstream.
  • sperr_decomp_2d() decompresses a bitstream and reconstructs a 2D slice.

Each of his pair of functions takes a relatively long list of parameters, and the best place to look up their meanings is the C header.

This example code demonstrates the usage of 2D compression and decompression.

Compression and decompression in 3D

Again, a pair of functions provide support for compression and decompression in 3D:

  • sperr_comp_3d() compresses a 3D volume and produces a compressed bitstream.
  • sperr_decomp_3d() decompresses a bitstream and reconstructs a 3D volume.

Each of his pair of functions takes a relatively long list of parameters, and the best place to look up their meanings is the C header.

This example code demonstrates the usage of 3D compression and decompression.

Parse header

All bitstreams produced by sperr_comp_3d() contain a header. All bitstreams produced by sperr_comp_2d() with the out_inc_header option on contain a header too. These headers are mainly used to keep the data dimensions, along with a few other pieces of information.

  • sperr_parse_header() can be used to parse these headers and extract relevant information.

Truncate an existing 3D SPERR bitstream for progressive access

A 3D SPERR bitstream can be simply truncated to take less space and still valid for decompression, only at a lower quality. This fashion of data access, namely progressive access, can be used for quick data sharing or transmission. Because a 3D volume is often divided into chunks and each chunk is compressed individually, the truncation operation needs to be applied on each chunk individually too.

  • sperr_trunc_3d() correctly truncates bitstreams from each chunk and concatenates them together as a smaller bitstream to be returned.