00001 /* 00002 * Bitshuffle - Filter for improving compression of typed binary data. 00003 * 00004 * This file is part of Bitshuffle 00005 * Author: Kiyoshi Masui <kiyo@physics.ubc.ca> 00006 * Website: http://www.github.com/kiyo-masui/bitshuffle 00007 * Created: 2014 00008 * 00009 * See LICENSE file for details about copyright and rights to use. 00010 * 00011 * 00012 * Header File 00013 * 00014 * Worker routines return an int64_t which is the number of bytes processed 00015 * if positive or an error code if negative. 00016 * 00017 * Error codes: 00018 * -1 : Failed to allocate memory. 00019 * -11 : Missing SSE. 00020 * -12 : Missing AVX. 00021 * -80 : Input size not a multiple of 8. 00022 * -81 : block_size not multiple of 8. 00023 * -91 : Decompression error, wrong number of bytes processed. 00024 * -1YYY : Error internal to compression routine with error code -YYY. 00025 */ 00026 00027 00028 #ifndef BITSHUFFLE_H 00029 #define BITSHUFFLE_H 00030 00031 #include <stdlib.h> 00032 #include "bitshuffle_core.h" 00033 00034 #ifdef __cplusplus 00035 extern "C" { 00036 #endif 00037 00038 /* ---- bshuf_compress_lz4_bound ---- 00039 * 00040 * Bound on size of data compressed with *bshuf_compress_lz4*. 00041 * 00042 * Parameters 00043 * ---------- 00044 * size : number of elements in input 00045 * elem_size : element size of typed data 00046 * block_size : Process in blocks of this many elements. Pass 0 to 00047 * select automatically (recommended). 00048 * 00049 * Returns 00050 * ------- 00051 * Bound on compressed data size. 00052 * 00053 */ 00054 size_t bshuf_compress_lz4_bound(const size_t size, 00055 const size_t elem_size, size_t block_size); 00056 00057 00058 /* ---- bshuf_compress_lz4 ---- 00059 * 00060 * Bitshuffled and compress the data using LZ4. 00061 * 00062 * Transpose within elements, in blocks of data of *block_size* elements then 00063 * compress the blocks using LZ4. In the output buffer, each block is prefixed 00064 * by a 4 byte integer giving the compressed size of that block. 00065 * 00066 * Output buffer must be large enough to hold the compressed data. This could 00067 * be in principle substantially larger than the input buffer. Use the routine 00068 * *bshuf_compress_lz4_bound* to get an upper limit. 00069 * 00070 * Parameters 00071 * ---------- 00072 * in : input buffer, must be of size * elem_size bytes 00073 * out : output buffer, must be large enough to hold data. 00074 * size : number of elements in input 00075 * elem_size : element size of typed data 00076 * block_size : Process in blocks of this many elements. Pass 0 to 00077 * select automatically (recommended). 00078 * 00079 * Returns 00080 * ------- 00081 * number of bytes used in output buffer, negative error-code if failed. 00082 * 00083 */ 00084 int64_t bshuf_compress_lz4(const void* in, void* out, const size_t size, const size_t 00085 elem_size, size_t block_size); 00086 00087 00088 /* ---- bshuf_decompress_lz4 ---- 00089 * 00090 * Undo compression and bitshuffling. 00091 * 00092 * Decompress data then un-bitshuffle it in blocks of *block_size* elements. 00093 * 00094 * To properly unshuffle bitshuffled data, *size*, *elem_size* and *block_size* 00095 * must patch the parameters used to compress the data. 00096 * 00097 * NOT TO BE USED WITH UNTRUSTED DATA: This routine uses the function 00098 * LZ4_decompress_fast from LZ4, which does not protect against maliciously 00099 * formed datasets. By modifying the compressed data, this function could be 00100 * coerced into leaving the boundaries of the input buffer. 00101 * 00102 * Parameters 00103 * ---------- 00104 * in : input buffer 00105 * out : output buffer, must be of size * elem_size bytes 00106 * size : number of elements in input 00107 * elem_size : element size of typed data 00108 * block_size : Process in blocks of this many elements. Pass 0 to 00109 * select automatically (recommended). 00110 * 00111 * Returns 00112 * ------- 00113 * number of bytes consumed in *input* buffer, negative error-code if failed. 00114 * 00115 */ 00116 int64_t bshuf_decompress_lz4(const void* in, void* out, const size_t size, 00117 const size_t elem_size, size_t block_size); 00118 00119 #ifdef __cplusplus 00120 } // extern "C" 00121 #endif 00122 00123 #endif // BITSHUFFLE_H