xrif
A fast lossless compression system
xrif.h File Reference

The eXtreme-ao Reordered Image Format: Declarations. More...

The eXtreme-ao Reordered Image Format: Declarations.

Author
Jared R. Males (jared.nosp@m.male.nosp@m.s@gma.nosp@m.il.c.nosp@m.om)

Definition in file xrif.h.

#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdio.h>
#include "lz4/lz4.h"
#include "lz4/lz4hc.h"
Include dependency graph for xrif.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

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

Macros

#define _POSIX_C_SOURCE   199309L
 
#define LZ4_MEMORY_USAGE   (20)
 
#define XRIF_VERSION   (0)
 
#define XRIF_HEADER_SIZE   (48)
 
#define XRIF_DIFFERENCE_NONE   (-1)
 
#define XRIF_DIFFERENCE_DEFAULT   (100)
 
#define XRIF_DIFFERENCE_PREVIOUS   (100)
 
#define XRIF_DIFFERENCE_FIRST   (200)
 
#define XRIF_DIFFERENCE_PIXEL   (300)
 
#define XRIF_REORDER_NONE   (-1)
 
#define XRIF_REORDER_DEFAULT   (100)
 
#define XRIF_REORDER_BYTEPACK   (100)
 
#define XRIF_REORDER_BYTEPACK_RENIBBLE   (200)
 
#define XRIF_REORDER_BITPACK   (300)
 
#define XRIF_COMPRESS_NONE   (-1)
 
#define XRIF_COMPRESS_DEFAULT   (100)
 
#define XRIF_COMPRESS_LZ4   (100)
 
#define XRIF_LZ4_ACCEL_MIN   (1)
 
#define XRIF_LZ4_ACCEL_MAX   (65537)
 
#define XRIF_NOERROR   (0)
 Return code for success.
 
#define XRIF_ERROR_NULLPTR   (-5)
 Return code indicating that a NULL pointer was passed.
 
#define XRIF_ERROR_NOT_SETUP   (-10)
 Return code indicating that the handle was not setup.
 
#define XRIF_ERROR_INVALID_SIZE   (-20)
 Return code indicating that an invalid size was passed.
 
#define XRIF_ERROR_INVALID_TYPE   (-22)
 Return code indicating that an invalid type was passed.
 
#define XRIF_ERROR_INSUFFICIENT_SIZE   (-25)
 Return code indicating that an insufficient size was given.
 
#define XRIF_ERROR_MALLOC   (-30)
 Return code indicating a malloc failure.
 
#define XRIF_ERROR_NOTIMPL   (-100)
 Return code indicating that the requested feature is not available.
 
#define XRIF_ERROR_BADARG   (-110)
 Return code indicating that a bad argument was passed.
 
#define XRIF_ERROR_BADHEADER   (-1000)
 Return code indicating that the header is bad.
 
#define XRIF_ERROR_WRONGVERSION   (-1010)
 Return code indicating that a wrong version was specified.
 
#define XRIF_ERROR_LIBERR   (-10000)
 Return code indicating a library returned an error (e.g. LZ4). The library error code may be added to this.
 
#define XRIF_ERROR_PRINT(function, msg)   fprintf(stderr, "%s: %s\n", function, msg)
 Standard error report.
 
#define XRIF_TYPECODE_UINT8   (1)
 8-bit unsigned integer

 
#define XRIF_TYPECODE_INT8   (2)
 8-bit signed integer
 
#define XRIF_TYPECODE_UINT16   (3)
 16-bit unsigned integer
 
#define XRIF_TYPECODE_INT16   (4)
 16-bit signed integer
 
#define XRIF_TYPECODE_UINT32   (5)
 32-bit unsigned integer
 
#define XRIF_TYPECODE_INT32   (6)
 32-bit signed integer
 
#define XRIF_TYPECODE_UINT64   (7)
 64-bit unsigned integer
 
#define XRIF_TYPECODE_INT64   (8)
 64-bit signed integer
 
#define XRIF_TYPECODE_HALF   (13)
 IEEE 754 half-precision 16-bit (uses uint16_t for storage)
 
#define XRIF_TYPECODE_FLOAT   (9)
 IEEE 754 single-precision binary floating-point format: binary32.
 
#define XRIF_TYPECODE_DOUBLE   (10)
 IEEE 754 double-precision binary floating-point format: binary64.
 
#define XRIF_TYPECODE_COMPLEX_FLOAT   (11)
 complex float
 
#define XRIF_TYPECODE_COMPLEX_DOUBLE   (12)
 complex double
 

Typedefs

typedef uint32_t xrif_dimension_t
 The type used for storing the width and height and depth dimensions of images.
 
typedef int xrif_error_t
 The error reporting type.

 
typedef uint8_t xrif_typecode_t
 The type used for storing the ImageStreamIO data type code.
 
typedef xrif_handlexrif_t
 The xrif handle pointer type. This provides the main interface to the xrif library.
 

Functions

xrif_error_t xrif_new (xrif_t *handle_ptr)
 Allocate a handle and initialize it. More...
 
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. More...
 
xrif_error_t xrif_configure (xrif_t handle, int difference_method, int reorder_method, int compress_method)
 Configure the difference, reorder, and compression methods. More...
 
xrif_error_t xrif_allocate (xrif_t handle)
 Allocate all memory buffers according to the configuration specified in the handle. More...
 
xrif_error_t xrif_reset (xrif_t handle)
 Reset a handle, restoring it to the initialized state. De-allocates owned pointers and re-initializes. More...
 
xrif_error_t xrif_delete (xrif_t handle)
 Deallocate a handle, including any memory that it owns. More...
 
xrif_error_t xrif_initialize_handle (xrif_t handle)
 Initialize an xrif handle object. More...
 
xrif_error_t xrif_set_difference_method (xrif_t handle, int difference_method)
 Set the difference method. More...
 
xrif_error_t xrif_set_reorder_method (xrif_t handle, int reorder_method)
 Set the reorder method. More...
 
xrif_error_t xrif_set_compress_method (xrif_t handle, int compress_method)
 Set the compress method. More...
 
xrif_error_t xrif_set_lz4_acceleration (xrif_t handle, int32_t lz4_accel)
 Set the LZ4 acceleration parameter. More...
 
size_t xrif_min_raw_size (xrif_t handle)
 Calculate the minimum size of the raw buffer. More...
 
size_t xrif_min_reordered_size (xrif_t handle)
 Calculate the minimum size of the reordered buffer. More...
 
size_t xrif_min_compressed_size (xrif_t handle)
 Calculate the minimum size of the compressed buffer. More...
 
xrif_error_t xrif_set_raw (xrif_t handle, void *raw, size_t size)
 Set the raw data buffer to a pre-allocated pointer. More...
 
xrif_error_t xrif_allocate_raw (xrif_t handle)
 Allocate the raw buffer based on the already set stream dimensions. More...
 
xrif_error_t xrif_set_reordered (xrif_t handle, void *reordered, size_t size)
 Set the rordered (working) data buffer to a pre-allocated pointer. More...
 
xrif_error_t xrif_allocate_reordered (xrif_t handle)
 Allocate the reordered buffer based on the already set stream dimensions. More...
 
xrif_error_t xrif_set_compressed (xrif_t handle, void *reordered, size_t size)
 Set the compressed data buffer to a pre-allocated pointer. More...
 
xrif_error_t xrif_allocate_compressed (xrif_t handle)
 Allocate the compressed buffer based on the already set stream dimensions. More...
 
xrif_dimension_t xrif_width (xrif_t handle)
 Get the current width of the configured handle. More...
 
xrif_dimension_t xrif_height (xrif_t handle)
 Get the current height of the configured handle. More...
 
xrif_dimension_t xrif_depth (xrif_t handle)
 Get the current depth of the configured handle. More...
 
xrif_dimension_t xrif_frames (xrif_t handle)
 Get the current number of frames of the configured handle. More...
 
xrif_error_t xrif_write_header (char *header, xrif_t handle)
 Populate a header buffer with the xrif protocol details. More...
 
xrif_error_t xrif_read_header (xrif_t handle, uint32_t *header_size, char *header)
 Configure an xrif handle by reading a xrif protocol header. More...
 
xrif_error_t xrif_encode (xrif_t handle)
 Encode data using the xrif format. More...
 
xrif_error_t xrif_decode (xrif_t handle)
 Decode data from the xrif format. More...
 
xrif_error_t xrif_difference (xrif_t handle)
 Difference the image(s) More...
 
xrif_error_t xrif_undifference (xrif_t handle)
 Undifference the image(s) More...
 
xrif_error_t xrif_difference_previous (xrif_t handle)
 Difference the images using the previous image as a reference. More...
 
xrif_error_t xrif_difference_first (xrif_t handle)
 Difference the images using the first image as a reference. More...
 
xrif_error_t xrif_difference_pixel (xrif_t handle)
 Difference the images using the previous pixel as a reference. More...
 
xrif_error_t xrif_undifference_previous (xrif_t handle)
 Undifference the images using the previous image as a reference. More...
 
xrif_error_t xrif_undifference_first (xrif_t handle)
 Undifference the images using the first image as a reference. More...
 
xrif_error_t xrif_undifference_pixel (xrif_t handle)
 Undifference the images using the previous pixel as a reference. More...
 
xrif_error_t xrif_reorder (xrif_t handle)
 Reorder the data using the method specified by reorder_method More...
 
xrif_error_t xrif_unreorder (xrif_t handle)
 Un-reorder the data using the method specified by reorder_method More...
 
xrif_error_t xrif_reorder_none (xrif_t handle)
 Perform no re-ordering, simply copy raw to reordered. More...
 
xrif_error_t xrif_reorder_bytepack (xrif_t handle)
 Dispatch bytepack reodering based on type. More...
 
xrif_error_t xrif_reorder_bytepack_sint16 (xrif_t handle)
 Perform bytepack reodering for signed 16 bit ints. More...
 
xrif_error_t xrif_reorder_bytepack_renibble (xrif_t handle)
 
xrif_error_t xrif_reorder_bytepack_renibble_sint16 (xrif_t handle)
 
xrif_error_t xrif_reorder_bitpack (xrif_t handle)
 
xrif_error_t xrif_reorder_bitpack_sint16 (xrif_t handle)
 
xrif_error_t xrif_unreorder_none (xrif_t handle)
 Perform no un-re-ordering, simply copy reordered to raw. More...
 
xrif_error_t xrif_unreorder_bytepack (xrif_t handle)
 Dispatch bytepack unreodering based on type. More...
 
xrif_error_t xrif_unreorder_bytepack_sint16 (xrif_t handle)
 Perform bytepack unreodering for signed 16 bit ints. More...
 
xrif_error_t xrif_unreorder_bytepack_renibble (xrif_t handle)
 
xrif_error_t xrif_unreorder_bitpack (xrif_t handle)
 
xrif_error_t xrif_compress (xrif_t handle)
 
xrif_error_t xrif_decompress (xrif_t handle)
 
xrif_error_t xrif_compress_none (xrif_t handle)
 
xrif_error_t xrif_decompress_none (xrif_t handle)
 
xrif_error_t xrif_compress_lz4 (xrif_t handle)
 
xrif_error_t xrif_decompress_lz4 (xrif_t handle)
 
double xrif_compression_ratio (xrif_t handle)
 Calculate the compression ratio. More...
 
double xrif_encode_time (xrif_t handle)
 Calculate the time in seconds taken to encode the data. More...
 
double xrif_encode_rate (xrif_t handle)
 Calculate the encode rate in bytes/sec. More...
 
double xrif_difference_time (xrif_t handle)
 Calculate the time in seconds taken to difference the data. More...
 
double xrif_difference_rate (xrif_t handle)
 Calculate the differencing rate in bytes/sec. More...
 
double xrif_reorder_time (xrif_t handle)
 Calculate the time in seconds taken to reorder the data. More...
 
double xrif_reorder_rate (xrif_t handle)
 Calculate the reordering rate in bytes/sec. More...
 
double xrif_compress_time (xrif_t handle)
 Calculate the time in seconds taken to compress the differenced and reordered data. More...
 
double xrif_compress_rate (xrif_t handle)
 Calculate the compression rate in bytes/sec. More...
 
double xrif_decode_time (xrif_t handle)
 Calculate the time in seconds taken to decode the data. More...
 
double xrif_decode_rate (xrif_t handle)
 Calculate the decode rate in bytes/sec. More...
 
double xrif_undifference_time (xrif_t handle)
 Calculate the time in seconds taken to undifference the data. More...
 
double xrif_undifference_rate (xrif_t handle)
 Calculate the undifferencing rate in bytes/sec. More...
 
double xrif_unreorder_time (xrif_t handle)
 Calculate the time in seconds taken to unreorder the data. More...
 
double xrif_unreorder_rate (xrif_t handle)
 Calculate the unreordering rate in bytes/sec. More...
 
double xrif_decompress_time (xrif_t handle)
 Calculate the time in seconds taken to decompress the differenced and reordered data. More...
 
double xrif_decompress_rate (xrif_t handle)
 Calculate the decompression rate in bytes/sec. More...
 
size_t xrif_typesize (xrif_typecode_t type_code)
 Return the size of the type specified by the code. More...
 
double xrif_ts_difference (struct timespec *ts1, struct timespec *ts0)
 Calculate the difference between two timespecs. More...
 
const char * xrif_difference_method_string (int diff_method)
 Get a string describing the difference method. More...
 
const char * xrif_reorder_method_string (int reorder_method)
 Get a string describing the reordering method. More...
 
const char * xrif_compress_method_string (int compress_method)
 Get a string describing the compression method. More...
 

Function Documentation

◆ xrif_reorder_bitpack()

xrif_error_t xrif_reorder_bitpack ( xrif_t  handle)
Todo:
xrif_reorder_bitpack needs a size check

Definition at line 1517 of file xrif.c.

References xrif_handle::difference_method.

◆ xrif_reorder_bitpack_sint16()

xrif_error_t xrif_reorder_bitpack_sint16 ( xrif_t  handle)
Parameters
[in,out]handle[in/out] the xrif handle

◆ xrif_reorder_bytepack_renibble()

xrif_error_t xrif_reorder_bytepack_renibble ( xrif_t  handle)
Parameters
[in,out]handle[in/out] the xrif handle

Definition at line 1409 of file xrif.c.

References xrif_handle::difference_method.

◆ xrif_reorder_bytepack_renibble_sint16()

xrif_error_t xrif_reorder_bytepack_renibble_sint16 ( xrif_t  handle)
Parameters
[in,out]handle[in/out] the xrif handle

◆ xrif_unreorder_bitpack()

xrif_error_t xrif_unreorder_bitpack ( xrif_t  handle)
Parameters
[in,out]handle[in/out] the xrif handle

Definition at line 1820 of file xrif.c.

References xrif_handle::difference_method.

◆ xrif_unreorder_bytepack_renibble()

xrif_error_t xrif_unreorder_bytepack_renibble ( xrif_t  handle)
Parameters
[in,out]handle[in/out] the xrif handle

Definition at line 1742 of file xrif.c.

References xrif_handle::difference_method.