xrif
A fast lossless compression system
|
Go to the documentation of this file.
109 if( handle_ptr == NULL)
117 if( *handle_ptr == NULL)
143 if(w == 0 || h == 0 || d == 0 || f == 0)
173 int difference_method,
209 XRIF_ERROR_PRINT(
"xrif_allocate",
"the handle is not setup for allocation");
298 XRIF_ERROR_PRINT(
"xrif_initialize_handle",
"can not initialize null pointer");
356 int difference_method
361 XRIF_ERROR_PRINT(
"xrif_set_difference_method",
"can not configure null pointer.");
366 if( difference_method == XRIF_DIFFERENCE_NONE ) handle->
difference_method = XRIF_DIFFERENCE_NONE;
367 else if( difference_method == XRIF_DIFFERENCE_DEFAULT ) handle->
difference_method = XRIF_DIFFERENCE_DEFAULT;
368 else if( difference_method == XRIF_DIFFERENCE_PREVIOUS ) handle->
difference_method = XRIF_DIFFERENCE_PREVIOUS;
369 else if( difference_method == XRIF_DIFFERENCE_FIRST ) handle->
difference_method = XRIF_DIFFERENCE_FIRST;
370 else if( difference_method == XRIF_DIFFERENCE_PIXEL ) handle->
difference_method = XRIF_DIFFERENCE_PIXEL;
374 XRIF_ERROR_PRINT(
"xrif_set_difference_method",
"unrecognized difference method. Setting default");
388 XRIF_ERROR_PRINT(
"xrif_set_reorder_method",
"can not configure null pointer");
392 if( reorder_method == XRIF_REORDER_NONE ) handle->
reorder_method = XRIF_REORDER_NONE;
393 else if( reorder_method == XRIF_REORDER_DEFAULT ) handle->
reorder_method = XRIF_REORDER_DEFAULT;
394 else if( reorder_method == XRIF_REORDER_BYTEPACK ) handle->
reorder_method = XRIF_REORDER_BYTEPACK;
395 else if( reorder_method == XRIF_REORDER_BYTEPACK_RENIBBLE ) handle->
reorder_method = XRIF_REORDER_BYTEPACK_RENIBBLE;
396 else if( reorder_method == XRIF_REORDER_BITPACK ) handle->
reorder_method = XRIF_REORDER_BITPACK;
400 XRIF_ERROR_PRINT(
"xrif_set_reorder_method",
"unrecognized reorder method. Setting default");
414 XRIF_ERROR_PRINT(
"xrif_set_compress_method",
"can not configure null pointer");
418 if( compress_method == XRIF_COMPRESS_NONE ) handle->
compress_method = XRIF_COMPRESS_NONE;
419 else if( compress_method == XRIF_COMPRESS_DEFAULT ) handle->
compress_method = XRIF_COMPRESS_DEFAULT;
420 else if( compress_method == XRIF_COMPRESS_LZ4 ) handle->
compress_method = XRIF_COMPRESS_LZ4;
424 XRIF_ERROR_PRINT(
"xrif_set_compress_method",
"unrecognized compress method. Setting default");
438 XRIF_ERROR_PRINT(
"xrif_set_lz4_acceleration",
"can not configure null pointer");
442 if(lz4_accel < XRIF_LZ4_ACCEL_MIN)
444 XRIF_ERROR_PRINT(
"xrif_set_lz4_acceleration",
"LZ4 acceleration can't be less than XRIF_LZ4_ACCEL_MIN. Setting to XRIF_LZ4_ACCEL_MIN.");
449 if(lz4_accel > XRIF_LZ4_ACCEL_MAX)
451 XRIF_ERROR_PRINT(
"xrif_set_lz4_acceleration",
"LZ4 acceleration can't be greater than XRIF_LZ4_ACCEL_MAX. Setting to XRIF_LZ4_ACCEL_MAX.");
487 if(handle == NULL)
return 0;
498 return one_frame * (handle->
frames);
505 return one_frame * (handle->
frames+1);
512 if(one_frame < 16) one_frame = 16;
514 return one_frame * (handle->
frames+1);
570 XRIF_ERROR_PRINT(
"xrif_set_raw",
"error calculating minimum raw buffer size - check configuration.");
576 XRIF_ERROR_PRINT(
"xrif_set_raw",
"the raw buffer size is too small for configured parameters");
594 XRIF_ERROR_PRINT(
"xrif_allocate_raw",
"the handle is not setup for allocation");
606 XRIF_ERROR_PRINT(
"xrif_allocate_raw",
"error calculating minimum raw buffer size - check configuration.");
659 XRIF_ERROR_PRINT(
"xrif_set_reordered",
"error calculating minimum reordered buffer size - check configuration.");
665 XRIF_ERROR_PRINT(
"xrif_set_reordered",
"the reordered buffer size is too small for configured parameters");
677 XRIF_ERROR_PRINT(
"xrif_allocate_reordered",
"can not configure null pointer");
683 XRIF_ERROR_PRINT(
"xrif_allocate_reordered",
"the handle is not setup for allocation");
695 XRIF_ERROR_PRINT(
"xrif_allocate_reordered",
"error calculating minimum reordered buffer size - check configuration.");
747 XRIF_ERROR_PRINT(
"xrif_set_compressed",
"error calculating minimum compressed buffer size - check configuration.");
753 XRIF_ERROR_PRINT(
"xrif_set_compressed",
"the compressed buffer size is too small for configured parameters");
764 XRIF_ERROR_PRINT(
"xrif_allocate_compressed",
"can not configure null pointer");
775 XRIF_ERROR_PRINT(
"xrif_allocate_compressed",
"the handle is not setup for allocation");
782 XRIF_ERROR_PRINT(
"xrif_allocate_compressed",
"error calculating minimum compressed buffer size - check configuration.");
809 return handle->
width;
831 return handle->
depth;
858 XRIF_ERROR_PRINT(
"xrif_write_header",
"can not read from a null pointer handle");
867 *((uint32_t *) &header[4]) = XRIF_VERSION;
869 *((uint32_t *) &header[8]) = XRIF_HEADER_SIZE;
871 *((uint32_t *) &header[12]) = handle->
width;
873 *((uint32_t *) &header[16]) = handle->
height;
875 *((uint32_t *) &header[20]) = handle->
depth;
877 *((uint32_t *) &header[24]) = handle->
frames;
879 *((uint16_t *) &header[28]) = handle->
type_code;
889 memset(&header[40], 0, 8);
902 uint32_t * header_size,
908 XRIF_ERROR_PRINT(
"xrif_read_header",
"can not configure a null pointer handle");
912 if( header_size == NULL)
914 XRIF_ERROR_PRINT(
"xrif_read_header",
"can not configure a null pointer uint32_t");
924 if( header[0] !=
'x' || header[1] !=
'r' || header[2] !=
'i' || header[3] !=
'f')
930 if( *((uint32_t *) &header[4]) > XRIF_VERSION)
936 *header_size = *((uint32_t *) &header[8]);
938 handle->
width = *((uint32_t *) &header[12]);
940 handle->
height = *((uint32_t *) &header[16]);
942 handle->
depth = *((uint32_t *) &header[20]);
944 handle->
frames = *((uint32_t *) &header[24]);
946 handle->
type_code = *((uint16_t *) &header[28]);
1073 fprintf(stderr,
"xrif_decode: error returned by xrif_decompress\n");
1082 fprintf(stderr,
"xrif_decode: error returned by xrif_unreorder\n");
1092 fprintf(stderr,
"xrif_decode: error returned by xrif_undifference\n");
1112 if(method == 0) method = XRIF_DIFFERENCE_DEFAULT;
1116 case XRIF_DIFFERENCE_NONE:
1118 case XRIF_DIFFERENCE_PREVIOUS:
1120 case XRIF_DIFFERENCE_FIRST:
1122 case XRIF_DIFFERENCE_PIXEL:
1139 if(method == 0) method = XRIF_DIFFERENCE_DEFAULT;
1143 case XRIF_DIFFERENCE_NONE:
1145 case XRIF_DIFFERENCE_PREVIOUS:
1147 case XRIF_DIFFERENCE_FIRST:
1149 case XRIF_DIFFERENCE_PIXEL:
1160 for(
int n=0; n < handle->
frames-1; ++n)
1162 if( (handle->
frames - 1 - n) % 3 == 0)
1164 size_t n_stride0 = (handle->
frames - 4 - n) * npix;
1165 size_t n_stride = (handle->
frames - 1 - n) * npix;
1167 for(
int ii=0; ii< handle->
width; ++ii)
1169 size_t ii_stride = ii*handle->
height;
1171 for(
int jj=0; jj< handle->
height; ++jj)
1173 size_t idx0 = n_stride0 + ii_stride + jj;
1174 size_t idx = n_stride + ii_stride + jj;
1182 size_t n_stride0 = (handle->
frames - 2 - n) * npix;
1183 size_t n_stride = (handle->
frames - 1 - n) * npix;
1186 for(
int ii=0; ii< handle->
width; ++ii)
1188 size_t ii_stride = ii*handle->
height;
1190 for(
int jj=0; jj< handle->
height; ++jj)
1192 size_t idx0 = n_stride0 + ii_stride + jj;
1193 size_t idx = n_stride + ii_stride + jj;
1201 for(
int n=0; n < handle->
frames-3; ++n)
1203 if( (handle->
frames - 1 - n) % 3 == 0)
continue;
1206 size_t n_stride0 = (handle->
frames - 4 - n) * npix;
1207 size_t n_stride = (handle->
frames - 1 - n) * npix;
1210 for(
int ii=0; ii< handle->
width; ++ii)
1212 size_t ii_stride = ii*handle->
height;
1214 for(
int jj=0; jj< handle->
height; ++jj)
1216 size_t idx0 = n_stride0 + ii_stride + jj;
1217 size_t idx = n_stride + ii_stride + jj;
1231 if(method == 0) method = XRIF_REORDER_DEFAULT;
1235 case XRIF_REORDER_NONE:
1237 case XRIF_REORDER_BYTEPACK:
1239 case XRIF_REORDER_BYTEPACK_RENIBBLE:
1241 case XRIF_REORDER_BITPACK:
1252 if(method == 0) method = XRIF_REORDER_DEFAULT;
1256 case XRIF_REORDER_NONE:
1258 case XRIF_REORDER_BYTEPACK:
1260 case XRIF_REORDER_BYTEPACK_RENIBBLE:
1262 case XRIF_REORDER_BITPACK:
1319 XRIF_ERROR_PRINT(
"xrif_reorder_bytepack",
"bytepack reordering not implemented for 32 bit ints");
1324 XRIF_ERROR_PRINT(
"xrif_reorder_bytepack",
"bytepack reordering not implemented for 64 bit ints");
1329 XRIF_ERROR_PRINT(
"xrif_reorder_bytepack",
"bytepack reordering not implemented for type");
1338 size_t one_frame, npix;
1342 XRIF_ERROR_PRINT(
"xrif_reorder_bytepack_sint16",
"can not use a null pointer");
1368 char * raw_buffer = handle->
raw_buffer + one_frame ;
1370 char * reordered_buffer2 = reordered_buffer + npix;
1380 #pragma omp parallel if (handle->omp_parallel > 0)
1384 for(
size_t pix = 0; pix < npix; ++pix)
1387 int_fast8_t x2 = raw_buffer[2*pix];
1388 int_fast8_t x1 = raw_buffer[2*pix+1];
1392 if(x1 == -1) x1 = 0;
1393 else if(x1 == 0) x1 = -1;
1396 reordered_buffer[pix] = x2;
1397 reordered_buffer2[pix] = x1;
1412 #include "bitshift_and_nibbles.inc"
1414 size_t one_frame, npix;
1441 int16_t * raw_buffer = (int16_t*)(handle->
raw_buffer + one_frame);
1444 unsigned char * reordered_buffer = (
unsigned char *) handle->
reordered_buffer + one_frame;
1447 unsigned char * reordered_buffer2 = (
unsigned char*) reordered_buffer + npix;
1457 size_t halfoff = ((double) npix)/2.0 + 0.5;
1459 if(halfoff > npix/2) oneoff = 0;
1462 #pragma omp parallel if (handle->omp_parallel > 0)
1466 for(
size_t pix = 0; pix < npix; ++pix)
1503 const unsigned char * bsn = &bitshift_and_nibbles[ ((uint16_t) raw_buffer[pix]) * 6 + (pix&1)*3];
1504 reordered_buffer[pix] = (char) bsn[0];
1505 reordered_buffer2[pix/2] += bsn[1];
1506 reordered_buffer2[pix/2 + oneoff + halfoff] += bsn[2];
1520 #include "bit_to_position.inc"
1521 #include "set_bits.inc"
1523 size_t one_frame, npix;
1537 for(
size_t pix=0; pix < one_frame; ++pix)
1542 int16_t * raw_buffer = (int16_t *) (handle->
raw_buffer + one_frame);
1543 uint16_t * reordered_buffer = (uint16_t *) (handle->
reordered_buffer + one_frame);
1550 #pragma omp parallel if (handle->omp_parallel > 0)
1556 for(
size_t pix = 0; pix<npix; ++pix)
1558 size_t sbyte = pix/16;
1559 int_fast8_t bit = pix % 16;
1569 int8_t sbit = (raw_buffer[pix] < 0);
1570 uint16_t us = 2*raw_buffer[pix]*(1-2*sbit)+sbit;
1586 size_t sbyte8 = sbyte + 8*stride;
1587 size_t st0 = ((
unsigned char *) &us)[0]*16*8 + bit*8;
1588 size_t st1 = ((
unsigned char *) &us)[1]*16*8 + bit*8;
1590 for(int_fast8_t b = 0; b < 8; ++b)
1592 reordered_buffer[sbyte + b*stride] += bit_to_position[st0 + b] ;
1594 if(((
unsigned char *) &us)[1] == 0)
continue;
1597 unsigned char nbits2 = set_bits[((
unsigned char *) &us)[1]*9];
1598 const unsigned char* bits2 = &set_bits[((
unsigned char *) &us)[1]*9 + 1];
1599 for(int_fast8_t b = 0; b < nbits2; ++b)
1601 reordered_buffer[sbyte8 + bits2[b]*stride] += bit_to_position[st1 + bits2[b]];
1665 XRIF_ERROR_PRINT(
"xrif_unreorder_bytepack",
"bytepack unreordering not implemented for 32 bit ints");
1670 XRIF_ERROR_PRINT(
"xrif_unreorder_bytepack",
"bytepack unreordering not implemented for 64 bit ints");
1675 XRIF_ERROR_PRINT(
"xrif_unreorder_bytepack",
"bytepack unreordering not implemented for type");
1686 size_t one_frame, npix;
1690 XRIF_ERROR_PRINT(
"xrif_unreorder_bytepack_sint16",
"can not use a null pointer");
1706 char * raw_buffer = handle->
raw_buffer + one_frame;
1709 for(
size_t pix=0; pix<one_frame; ++pix)
1715 #pragma omp parallel if (handle->omp_parallel > 0)
1719 for(
size_t pix = 0; pix < npix; ++pix)
1721 int_fast8_t x2 = reordered_buffer[pix];
1722 int_fast8_t x1 = reordered_buffer[npix+pix];
1726 if(x1 == -1) x1 = 0;
1727 else if(x1 == 0) x1 = -1;
1730 raw_buffer[2*pix] = x2;
1731 raw_buffer[2*pix+1] = x1;
1744 size_t one_frame, npix;
1758 int16_t * raw_buffer = (int16_t*)(handle->
raw_buffer + one_frame);
1759 unsigned char * reordered_buffer = (
unsigned char *) handle->
reordered_buffer + one_frame;
1760 unsigned char * reordered_buffer2 = (
unsigned char*) reordered_buffer + npix;
1762 for(
size_t pix=0; pix<one_frame; ++pix)
1767 size_t halfoff = ((double) npix)/2 + 0.5;
1769 if(halfoff > npix/2) oneoff = 0;
1772 #pragma omp parallel if (handle->omp_parallel > 0)
1776 for(
size_t pix = 0; pix < npix; ++pix)
1779 byte1 = reordered_buffer[pix];
1785 nib1 |= ((reordered_buffer2[pix/2+oneoff])) >> 4;
1786 nib2 |= reordered_buffer2[pix/2+oneoff + halfoff] & 240;
1790 nib1 |= reordered_buffer2[pix/2] & 15;
1791 nib2 |= (reordered_buffer2[pix/2 + oneoff + halfoff] & 15) << 4;
1794 byte1 |= (nib1 << 8);
1795 byte1 |= (nib2 << 8);
1798 unsigned int sbit = (byte1 & 1);
1800 unsigned int s = (byte1 >> 1);
1803 if(sbit == 1 && s == 0)
1805 raw_buffer[pix] = -32768;
1809 raw_buffer[pix] = s*(1-2*sbit);
1822 size_t one_frame, npix;
1836 for(
size_t pix=0; pix< one_frame; ++pix)
1841 int16_t * raw_buffer = (int16_t *) (handle->
raw_buffer + one_frame);
1842 uint16_t * reordered_buffer = (uint16_t *) (handle->
reordered_buffer + one_frame);
1844 memset(raw_buffer, 0, npix*2);
1851 #pragma omp parallel if (handle->omp_parallel > 0)
1855 for(
size_t pix = 0; pix<npix; ++pix)
1858 size_t sbyte = pix/16;
1859 size_t bit = pix % 16;
1861 char sbit = (reordered_buffer[sbyte] >> bit) & 1;
1863 for(int_fast8_t b=1; b<16;++b)
1865 raw_buffer[pix] |= ((reordered_buffer[sbyte + b*stride] >> bit) & 1) << (b-1);
1872 if(raw_buffer[pix] == 0) raw_buffer[pix] = -32768;
1873 else raw_buffer[pix] *= -1;
1892 if(method == 0) method = XRIF_COMPRESS_DEFAULT;
1896 case XRIF_COMPRESS_NONE:
1898 case XRIF_COMPRESS_LZ4:
1910 if(method == 0) method = XRIF_COMPRESS_DEFAULT;
1914 case XRIF_COMPRESS_NONE:
1916 case XRIF_COMPRESS_LZ4:
1919 fprintf(stderr,
"xrif_decompress: unknown compression method (%d)\n", method);
1928 char *compressed_buffer;
1929 size_t compressed_size;
1943 if( compressed_size < handle->reordered_buffer_size )
1952 memset(compressed_buffer, 0, compressed_size);
1964 char *compressed_buffer;
1998 char *compressed_buffer;
1999 size_t compressed_size;
2019 fprintf(stderr,
"xrif_compress_lz4: compression failed.\n");
2035 char *compressed_buffer;
2057 XRIF_ERROR_PRINT(
"xrif_decompress_lz4",
"size mismatch after decompression.");
2155 return sizeof(uint8_t);
2157 return sizeof(int8_t);
2159 return sizeof(uint16_t);
2161 return sizeof(int16_t);
2163 return sizeof(uint32_t);
2165 return sizeof(int32_t);
2167 return sizeof(uint64_t);
2169 return sizeof(int64_t);
2171 return sizeof(uint16_t);
2173 return sizeof(float);
2175 return sizeof(double);
2177 return sizeof(
float[2]);
2179 return sizeof(
double[2]);
2186 struct timespec * ts0
2189 return ((
double)ts1->tv_sec) + ((double)ts1->tv_nsec)/1e9 - ((double)ts0->tv_sec) - ((double)ts0->tv_nsec)/1e9;
2196 case XRIF_DIFFERENCE_NONE:
2198 case XRIF_DIFFERENCE_PREVIOUS:
2200 case XRIF_DIFFERENCE_FIRST:
2209 switch(reorder_method)
2211 case XRIF_REORDER_NONE:
2213 case XRIF_REORDER_BYTEPACK:
2215 case XRIF_REORDER_BYTEPACK_RENIBBLE:
2216 return "bytepack w/ renibble";
2217 case XRIF_REORDER_BITPACK:
2226 switch(compress_method)
2228 case XRIF_COMPRESS_NONE:
2230 case XRIF_COMPRESS_LZ4:
xrif_dimension_t xrif_frames(xrif_t handle)
Get the current number of frames of the configured handle.
double compression_ratio
The compression ratio, calculated as output-size/input-size.
xrif_error_t xrif_set_compressed(xrif_t handle, void *compressed, size_t size)
Set the compressed data buffer to a pre-allocated pointer.
double compress_time
Time in seconds taken to compress the data.
#define XRIF_ERROR_INVALID_SIZE
Return code indicating that an invalid size was passed.
#define XRIF_TYPECODE_INT32
32-bit signed integer
#define XRIF_ERROR_NULLPTR
Return code indicating that a NULL pointer was passed.
xrif_dimension_t width
The width of a single image, in pixels.
char * reordered_buffer
The reordered buffer pointer, contains the reordered data.
int difference_method
The difference method to use.
struct timespec ts_undifference_start
Timespec used to mark the beginning of undifferencing, which is the end of unreordering.
#define XRIF_TYPECODE_DOUBLE
IEEE 754 double-precision binary floating-point format: binary64.
xrif_error_t xrif_undifference_first(xrif_t handle)
Undifference the images using the first image as a reference.
xrif_error_t xrif_difference_previous(xrif_t handle)
Difference the images using the previous image as a reference.
xrif_error_t xrif_allocate_reordered(xrif_t handle)
Allocate the reordered buffer based on the already set stream dimensions.
struct timespec ts_compress_start
Timespec used to mark the beginning of compression, which is the end of reordering.
struct timespec ts_decompress_start
Timespec used to mark the beginning of decompression, which is also the beginning of decoding.
double xrif_ts_difference(struct timespec *ts1, struct timespec *ts0)
Calculate the difference between two timespecs.
int compress_method
The compression method used.
size_t xrif_min_raw_size(xrif_t handle)
Calculate the minimum size of the raw buffer.
uint8_t xrif_typecode_t
The type used for storing the ImageStreamIO data type code.
xrif_handle * xrif_t
The xrif handle pointer type. This provides the main interface to the xrif library.
char * compressed_buffer
The compressed buffer pointer, contains the compressed data.
#define XRIF_TYPECODE_INT16
16-bit signed integer
int reorder_method
The method to use for bit reordering.
xrif_dimension_t xrif_depth(xrif_t handle)
Get the current depth of the configured handle.
size_t xrif_min_compressed_size(xrif_t handle)
Calculate the minimum size of the compressed buffer.
xrif_error_t xrif_reorder_bytepack_renibble(xrif_t handle)
xrif_error_t xrif_allocate_raw(xrif_t handle)
Allocate the raw buffer based on the already set stream dimensions.
struct timespec ts_reorder_start
Timespec used to mark the beginning of reordering, which is the end of differencing.
int lz4_acceleration
LZ4 acceleration parameter, >=1, higher is faster with less comporession. Default is 1.
xrif_error_t xrif_set_compress_method(xrif_t handle, int compress_method)
Set the compress method.
#define XRIF_TYPECODE_UINT64
64-bit unsigned integer
The xrif library configuration structure, organizing various parameters used by the functions.
xrif_dimension_t frames
The number of frames in the stream.
const char * xrif_difference_method_string(int diff_method)
Get a string describing the difference method.
xrif_error_t xrif_set_raw(xrif_t handle, void *raw, size_t size)
Set the raw data buffer to a pre-allocated pointer.
#define XRIF_ERROR_BADHEADER
Return code indicating that the header is bad.
xrif_error_t xrif_set_lz4_acceleration(xrif_t handle, int32_t lz4_accel)
Set the LZ4 acceleration parameter.
xrif_error_t xrif_reorder_bytepack_sint16(xrif_t handle)
Perform bytepack reodering for signed 16 bit ints.
xrif_error_t xrif_undifference_pixel(xrif_t handle)
Undifference the images using the previous pixel as a reference.
#define XRIF_ERROR_PRINT(function, msg)
Standard error report.
unsigned char calc_performance
Flag (true/false) controlling whether performance metrics are calculated. Default is true.
xrif_error_t xrif_decompress_lz4(xrif_t handle)
const char * xrif_reorder_method_string(int reorder_method)
Get a string describing the reordering method.
#define XRIF_ERROR_NOT_SETUP
Return code indicating that the handle was not setup.
#define XRIF_TYPECODE_COMPLEX_DOUBLE
complex double
#define XRIF_ERROR_BADARG
Return code indicating that a bad argument was passed.
size_t reordered_buffer_size
double reorder_time
Time in seconds taken to reorder the data.
xrif_error_t xrif_new(xrif_t *handle_ptr)
Allocate a handle and initialize it.
xrif_error_t xrif_unreorder_none(xrif_t handle)
Perform no un-re-ordering, simply copy reordered to raw.
xrif_dimension_t height
The height of a single image, in pixels.
#define XRIF_TYPECODE_UINT32
32-bit unsigned integer
unsigned char own_reordered
Flag (true/false) indicating whether the reordered_buffer pointer is managed by this handle.
xrif_error_t xrif_allocate_compressed(xrif_t handle)
Allocate the compressed buffer based on the already set stream dimensions.
#define XRIF_ERROR_WRONGVERSION
Return code indicating that a wrong version was specified.
xrif_dimension_t xrif_width(xrif_t handle)
Get the current width of the configured handle.
xrif_error_t xrif_unreorder_bytepack_renibble(xrif_t handle)
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.
xrif_error_t xrif_compress_none(xrif_t handle)
xrif_error_t xrif_set_difference_method(xrif_t handle, int difference_method)
Set the difference method.
unsigned char compress_on_raw
Flag (true/false) indicating whether the raw buffer is used for compression. Default on initializeati...
int xrif_error_t
The error reporting type.
xrif_error_t xrif_difference(xrif_t handle)
Difference the image(s)
#define XRIF_TYPECODE_UINT8
8-bit unsigned integer
xrif_error_t xrif_compress_lz4(xrif_t handle)
#define XRIF_TYPECODE_INT8
8-bit signed integer
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.
#define XRIF_ERROR_MALLOC
Return code indicating a malloc failure.
#define XRIF_TYPECODE_FLOAT
IEEE 754 single-precision binary floating-point format: binary32.
xrif_error_t xrif_undifference(xrif_t handle)
Undifference the image(s)
struct timespec ts_undifference_done
Timespec used to mark the end of undifferencing and decoding.
const char * xrif_compress_method_string(int compress_method)
Get a string describing the compression method.
xrif_error_t xrif_decompress_none(xrif_t handle)
xrif_error_t xrif_reorder(xrif_t handle)
Reorder the data using the method specified by reorder_method
double encode_rate
Rate at which the data was encoded in bytes per second.
xrif_error_t xrif_reorder_bytepack(xrif_t handle)
Dispatch bytepack reodering based on type.
xrif_error_t xrif_initialize_handle(xrif_t handle)
Initialize an xrif handle object.
#define XRIF_ERROR_NOTIMPL
Return code indicating that the requested feature is not available.
size_t raw_size
Size of the stream before compression. Set dynamically by xrif_set_size or from header.
#define XRIF_TYPECODE_COMPLEX_FLOAT
complex float
xrif_error_t xrif_difference_pixel(xrif_t handle)
Difference the images using the previous pixel as a reference.
double encode_time
Time in seconds taken to encode the data.
char * raw_buffer
The raw buffer pointer, contains the image data, and if compress_on_raw == true the compressed data.
xrif_error_t xrif_reset(xrif_t handle)
Reset a handle, restoring it to the initialized state. De-allocates owned pointers and re-initializes...
xrif_error_t xrif_unreorder_bytepack_sint16(xrif_t handle)
Perform bytepack unreodering for signed 16 bit ints.
double reorder_rate
Rate at which the data was reordered in bytes per second.
double difference_time
Time in seconds taken to difference the data.
#define XRIF_ERROR_LIBERR
Return code indicating a library returned an error (e.g. LZ4). The library error code may be added to...
struct timespec ts_difference_start
Timespec used to mark the beginning of differencing, which is also the beginning of encoding.
size_t xrif_min_reordered_size(xrif_t handle)
Calculate the minimum size of the reordered buffer.
#define XRIF_TYPECODE_HALF
IEEE 754 half-precision 16-bit (uses uint16_t for storage)
xrif_dimension_t depth
The depth of a single image, in pixels.
xrif_error_t xrif_delete(xrif_t handle)
Deallocate a handle, including any memory that it owns.
xrif_error_t xrif_difference_first(xrif_t handle)
Difference the images using the first image as a reference.
xrif_error_t xrif_undifference_previous(xrif_t handle)
Undifference the images using the previous image as a reference.
xrif_error_t xrif_decode(xrif_t handle)
Decode data from the xrif format.
size_t compressed_size
Size of the stream after compression. Set dynamically by compression functions or from header.
#define XRIF_TYPECODE_INT64
64-bit signed integer
xrif_error_t xrif_allocate(xrif_t handle)
Allocate all memory buffers according to the configuration specified in the handle.
xrif_error_t xrif_unreorder(xrif_t handle)
Un-reorder the data using the method specified by reorder_method
xrif_error_t xrif_encode(xrif_t handle)
Encode data using the xrif format.
struct timespec ts_unreorder_start
Timespec used to mark the beginning of unreordering, which is the end of decompression.
size_t xrif_typesize(xrif_typecode_t type_code)
Return the size of the type specified by the code.
#define XRIF_NOERROR
Return code for success.
xrif_error_t xrif_reorder_bitpack(xrif_t handle)
struct timespec ts_compress_done
Timespec used to mark the end of compression and encoding.
#define XRIF_TYPECODE_UINT16
16-bit unsigned integer
xrif_error_t xrif_set_reorder_method(xrif_t handle, int reorder_method)
Set the reorder method.
size_t compressed_buffer_size
xrif_dimension_t xrif_height(xrif_t handle)
Get the current height of the configured handle.
unsigned char own_raw
Flag (true/false) indicating whether the raw_buffer pointer is managed by this handle.
size_t data_size
The size of the pixels, bytes. This corresponds to sizeof(type).
xrif_error_t xrif_decompress(xrif_t handle)
xrif_error_t xrif_unreorder_bytepack(xrif_t handle)
Dispatch bytepack unreodering based on type.
unsigned char own_compressed
Flag (true/false) indicating whether the compressed_buffer pointer is managed by this handle.
double compress_rate
Rate at which the data was compressed in bytes per second.
#define XRIF_ERROR_INSUFFICIENT_SIZE
Return code indicating that an insufficient size was given.
xrif_error_t xrif_unreorder_bitpack(xrif_t handle)
#define XRIF_ERROR_INVALID_TYPE
Return code indicating that an invalid type was passed.
xrif_typecode_t type_code
The code specifying the data type of the pixels.
uint32_t xrif_dimension_t
The type used for storing the width and height and depth dimensions of images.
xrif_error_t xrif_reorder_none(xrif_t handle)
Perform no re-ordering, simply copy raw to reordered.
xrif_error_t xrif_configure(xrif_t handle, int difference_method, int reorder_method, int compress_method)
Configure the difference, reorder, and compression methods.
double difference_rate
Rate at which the data was differenced in bytes per second.
The eXtreme-ao Reordered Image Format: Declarations.
xrif_error_t xrif_compress(xrif_t handle)