source: thirdparty/blosc/blosc.h @ 00587dc

Revision 00587dc, 7.3 KB checked in by Hal Finkel <hfinkel@…>, 10 years ago (diff)

Initial Commit (gio-base-20150317)

  • Property mode set to 100644
RevLine 
[00587dc]1/*********************************************************************
2  Blosc - Blocked Suffling and Compression Library
3
4  Author: Francesc Alted <[email protected]>
5
6  See LICENSES/BLOSC.txt for details about copyright and rights to use.
7**********************************************************************/
8
9#include <limits.h>
10
11#ifndef BLOSC_H
12#define BLOSC_H
13
14/* Version numbers */
15#define BLOSC_VERSION_MAJOR    1    /* for major interface/format changes  */
16#define BLOSC_VERSION_MINOR    2    /* for minor interface/format changes  */
17#define BLOSC_VERSION_RELEASE  3    /* for tweaks, bug-fixes, or development */
18
19#define BLOSC_VERSION_STRING   "1.2.3"  /* string version.  Sync with above! */
20#define BLOSC_VERSION_REVISION "$Rev$"   /* revision version */
21#define BLOSC_VERSION_DATE     "$Date:: 2013-05-17 #$"    /* date version */
22
23/* The *_VERS_FORMAT should be just 1-byte long */
24#define BLOSC_VERSION_FORMAT    2   /* Blosc format version, starting at 1 */
25#define BLOSCLZ_VERSION_FORMAT  1   /* Blosclz format version, starting at 1 */
26
27/* The combined blosc and blosclz formats */
28#define BLOSC_VERSION_CFORMAT (BLOSC_VERSION_FORMAT << 8) & (BLOSCLZ_VERSION_FORMAT)
29
30/* Minimum header length */
31#define BLOSC_MIN_HEADER_LENGTH 16
32
33/* The maximum overhead during compression in bytes.  This equals to
34   BLOSC_MIN_HEADER_LENGTH now, but can be higher in future
35   implementations */
36#define BLOSC_MAX_OVERHEAD BLOSC_MIN_HEADER_LENGTH
37
38/* Maximum buffer size to be compressed */
39#define BLOSC_MAX_BUFFERSIZE (INT_MAX - BLOSC_MAX_OVERHEAD)
40
41/* Maximum typesize before considering buffer as a stream of bytes */
42#define BLOSC_MAX_TYPESIZE 255         /* Cannot be larger than 255 */
43
44/* The maximum number of threads (for some static arrays) */
45#define BLOSC_MAX_THREADS 256
46
47/* Codes for internal flags (see blosc_cbuffer_metainfo) */
48#define BLOSC_DOSHUFFLE 0x1
49#define BLOSC_MEMCPYED  0x2
50
51
52
53/**
54  Initialize the Blosc library. You must call this previous to any other
55  Blosc call, and make sure that you call this in a non-threaded environment.
56  Other Blosc calls can be called in a threaded environment, if desired.
57
58 */
59
60void blosc_init(void);
61
62
63/**
64
65  Destroy the Blosc library environment. You must call this after to you are
66  done with all the Blosc calls, and make sure that you call this in a
67  non-threaded environment.
68
69 */
70
71void blosc_destroy(void);
72
73
74/**
75  Compress a block of data in the `src` buffer and returns the size of
76  compressed block.  The size of `src` buffer is specified by
77  `nbytes`.  There is not a minimum for `src` buffer size (`nbytes`).
78
79  `clevel` is the desired compression level and must be a number
80  between 0 (no compression) and 9 (maximum compression).
81
82  `doshuffle` specifies whether the shuffle compression preconditioner
83  should be applied or not.  0 means not applying it and 1 means
84  applying it.
85
86  `typesize` is the number of bytes for the atomic type in binary
87  `src` buffer.  This is mainly useful for the shuffle preconditioner.
88  Only a typesize > 1 will allow the shuffle to work.
89
90  The `dest` buffer must have at least the size of `destsize`.  Blosc
91  guarantees that if you set `destsize` to, at least,
92  (`nbytes`+BLOSC_MAX_OVERHEAD), the compression will always succeed.
93  The `src` buffer and the `dest` buffer can not overlap.
94
95  If `src` buffer cannot be compressed into `destsize`, the return
96  value is zero and you should discard the contents of the `dest`
97  buffer.
98
99  A negative return value means that an internal error happened.  This
100  should never happen.  If you see this, please report it back
101  together with the buffer data causing this and compression settings.
102
103  Compression is memory safe and guaranteed not to write the `dest`
104  buffer more than what is specified in `destsize`.  However, it is
105  not re-entrant and not thread-safe (despite the fact that it uses
106  threads internally).
107 */
108
109int blosc_compress(int clevel, int doshuffle, size_t typesize, size_t nbytes,
110                   const void *src, void *dest, size_t destsize);
111
112
113/**
114  Decompress a block of compressed data in `src`, put the result in
115  `dest` and returns the size of the decompressed block. If error
116  occurs, e.g. the compressed data is corrupted or the output buffer
117  is not large enough, then 0 (zero) or a negative value will be
118  returned instead.
119
120  The `src` buffer and the `dest` buffer can not overlap.
121
122  Decompression is memory safe and guaranteed not to write the `dest`
123  buffer more than what is specified in `destsize`.  However, it is
124  not re-entrant and not thread-safe (despite the fact that it uses
125  threads internally).
126*/
127
128int blosc_decompress(const void *src, void *dest, size_t destsize);
129
130
131/**
132  Get `nitems` (of typesize size) in `src` buffer starting in `start`.
133  The items are returned in `dest` buffer, which has to have enough
134  space for storing all items.  Returns the number of bytes copied to
135  `dest` or a negative value if some error happens.
136 */
137
138int blosc_getitem(const void *src, int start, int nitems, void *dest);
139
140
141/**
142  Initialize a pool of threads for compression/decompression.  If
143  `nthreads` is 1, then the serial version is chosen and a possible
144  previous existing pool is ended.  Returns the previous number of
145  threads.  If this is not called, `nthreads` is set to 1 internally.
146*/
147
148int blosc_set_nthreads(int nthreads);
149
150
151/**
152  Free possible memory temporaries and thread resources.  Use this when you
153  are not going to use Blosc for a long while.  In case of problems releasing
154  the resources, it returns a negative number, else it returns 0.
155*/
156
157int blosc_free_resources(void);
158
159
160/**
161  Return information about a compressed buffer, namely the number of
162  uncompressed bytes (`nbytes`) and compressed (`cbytes`).  It also
163  returns the `blocksize` (which is used internally for doing the
164  compression by blocks).
165
166  You only need to pass the first BLOSC_MIN_HEADER_LENGTH bytes of a
167  compressed buffer for this call to work.
168
169  This function should always succeed.
170*/
171
172void blosc_cbuffer_sizes(const void *cbuffer, size_t *nbytes,
173                         size_t *cbytes, size_t *blocksize);
174
175
176/**
177  Return information about a compressed buffer, namely the type size
178  (`typesize`), as well as some internal `flags`.
179
180  The `flags` is a set of bits, where the currently used ones are:
181    * bit 0: whether the shuffle filter has been applied or not
182    * bit 1: whether the internal buffer is a pure memcpy or not
183
184  You can use the `BLOSC_DOSHUFFLE` and `BLOSC_MEMCPYED` symbols for
185  extracting the interesting bits (e.g. ``flags & BLOSC_DOSHUFFLE``
186  says whether the buffer is shuffled or not).
187
188  This function should always succeed.
189*/
190
191void blosc_cbuffer_metainfo(const void *cbuffer, size_t *typesize,
192                            int *flags);
193
194
195/**
196  Return information about a compressed buffer, namely the internal
197  Blosc format version (`version`) and the format for the internal
198  Lempel-Ziv algorithm (`versionlz`).  This function should always
199  succeed.
200*/
201
202void blosc_cbuffer_versions(const void *cbuffer, int *version,
203                            int *versionlz);
204
205
206
207/*********************************************************************
208
209  Low-level functions follows.  Use them only if you are an expert!
210
211*********************************************************************/
212
213
214/**
215  Force the use of a specific blocksize.  If 0, an automatic
216  blocksize will be used (the default).
217*/
218
219void blosc_set_blocksize(size_t blocksize);
220
221
222#endif
Note: See TracBrowser for help on using the repository browser.