xrif
A fast lossless compression system
Top-level interface

The top-level interface to the XRIF library. More...

The top-level interface to the XRIF library.

The following code illustrates how the XRIF library shoud used to compress data under most circumstances.
Lower level access is provided if fine-grain control is needed.

First, create the xrif library handle:

xrif_t handle; //note: this is a pointer type
rv = xrif_new(&handle); //note: the argument is a pointer to pointer
//check rv for errors here . . .

You now have an initialized xrif handle. The xrif_t type can not be used until xrif_new has been called on it. Never call xrif_new twice on the same handle, unless xrif_delete (see below) has been called.

Next you need to configure and allocate the handle:

rv = xrif_set_size(handle, 64,64, 1,1024, XRIF_TYPECODE_INT16);
rv = xrif_configure(handle, XRIF_DIFFERENCE_PREVIOUS, XRIF_REORDER_BYTEPACK, XRIF_COMPRESS_LZ4); //Note this is optional if defaults are ok.
rv = xrif_allocate(handle);

The above results in an xrif handle prepared to operate on 1024 signed 16-bit images of size 64x64. (Note that you should check the value of rv for errors!)

Now to compress data:

memcpy(xrif->raw_buffer, my_source, handle->width*handle->height*handle->depth*handle->frames*handle->data_size); //You are responsible for `my_source`.
rv = xrif_encode(handle);
printf("%f\%\n", handle->compression_ratio*100.0);

After this handle->raw_buffer contains the compressed data. This is because handle->compress_on_raw == 1 by default, causing the raw_buffer to be re-used. This also illustrates the built in performance monitoring, which is on by default but can be turned off.

To decompress:

rv = xrif_decode(handle);
memcpy(my_dest, xrif->raw_buffer, xrif->width*xrif->height*xrif->depth*xrif->frames*xrif->data_size); //You are responsible for `my_dest`.

after which my_dest will contain the original data.

To start over, use:

rv = xrif_reset(handle);

And when you are done with the handle, it can be fully de-allocated with

rv = xrif_delete(handle);

after which the handle should not be used again, unless xrif_new is called on it.

Collaboration diagram for Top-level interface:

Data Structures

struct  xrif_handle
 The xrif library configuration structure, organizing various parameters used by the functions. More...
 

Modules

 Initialization, Setup, and Allocation
 
 Current Configuration
 
 Header Processing
 
 Encoding & Decoding
 
 Performance Measurements
 

Typedefs

typedef xrif_handlexrif_t
 The xrif handle pointer type. This provides the main interface to the xrif library.
 
xrif_handle::compression_ratio
double compression_ratio
The compression ratio, calculated as output-size/input-size.
Definition: xrif.h:360
xrif_handle::width
xrif_dimension_t width
The width of a single image, in pixels.
Definition: xrif.h:308
XRIF_TYPECODE_INT16
#define XRIF_TYPECODE_INT16
16-bit signed integer
Definition: xrif.h:217
xrif_handle
The xrif library configuration structure, organizing various parameters used by the functions.
Definition: xrif.h:306
xrif_handle::frames
xrif_dimension_t frames
The number of frames in the stream.
Definition: xrif.h:311
xrif_new
xrif_error_t xrif_new(xrif_t *handle_ptr)
Allocate a handle and initialize it.
Definition: xrif.c:107
xrif_handle::height
xrif_dimension_t height
The height of a single image, in pixels.
Definition: xrif.h:309
xrif_error_t
int xrif_error_t
The error reporting type.
Definition: xrif.h:157
xrif_set_size
xrif_error_t xrif_set_size(xrif_t handle, xrif_dimension_t w, xrif_dimension_t h, xrif_dimension_t d, xrif_dimension_t f, xrif_typecode_t c)
Set the basic parameters of an xrif handle.
Definition: xrif.c:128
xrif_reset
xrif_error_t xrif_reset(xrif_t handle)
Reset a handle, restoring it to the initialized state. De-allocates owned pointers and re-initializes...
Definition: xrif.c:243
xrif_handle::depth
xrif_dimension_t depth
The depth of a single image, in pixels.
Definition: xrif.h:310
xrif_delete
xrif_error_t xrif_delete(xrif_t handle)
Deallocate a handle, including any memory that it owns.
Definition: xrif.c:277
xrif_decode
xrif_error_t xrif_decode(xrif_t handle)
Decode data from the xrif format.
Definition: xrif.c:1043
xrif_allocate
xrif_error_t xrif_allocate(xrif_t handle)
Allocate all memory buffers according to the configuration specified in the handle.
Definition: xrif.c:199
xrif_encode
xrif_error_t xrif_encode(xrif_t handle)
Encode data using the xrif format.
Definition: xrif.c:966
xrif_handle::data_size
size_t data_size
The size of the pixels, bytes. This corresponds to sizeof(type).
Definition: xrif.h:315
xrif_configure
xrif_error_t xrif_configure(xrif_t handle, int difference_method, int reorder_method, int compress_method)
Configure the difference, reorder, and compression methods.
Definition: xrif.c:172