8
#define HAVE_LZO_LIB /* The API for LZO and LZO2 are mostly identical */
10
/* Test with assembler versions (see later) */
12
/* LZO_EXTERN_CDECL(int) */
13
/* _lzo1x_decompress_asm_safe( const lzo_byte *src, lzo_uint src_len, */
14
/* lzo_byte *dst, lzo_uintp dst_len, */
15
/* lzo_voidp wrkmem /\* NOT USED *\/ ); */
24
17
/* Activate the checksum. It is safer and takes only a 1% more of
25
18
space and a 2% more of CPU (but sometimes is faster than without
26
checksum, which is almost negligible. F. Alted 2003/07/22
19
checksum, which is almost negligible. F. Altet 2003/07/22
28
21
Added code for pytables 0.5 backward compatibility.
31
24
Added code for saving the uncompressed length buffer as well.
36
29
/* Ok. from pytables 0.8 on I decided to let the user select the
37
30
fletcher32 checksum provided in HDF5 1.6 or higher. So, even though
38
31
the CHECKSUM support here seems pretty stable it will be disabled.
39
F. Alted 2004/01/02 */
32
F. Altet 2004/01/02 */
42
35
int register_lzo(void) {
44
37
#ifdef HAVE_LZO_LIB
47
/* Feed the filter_class data structure */
49
H5Z_class_t filter_class = {
50
(H5Z_filter_t)FILTER_LZO, /* filter_id */
52
NULL, /* can_apply_func */
53
NULL, /* set_local_func */
54
(H5Z_func_t)lzo_deflate /* filter_func */
57
/* H5Z_class_t filter_class = { */
58
/* H5Z_CLASS_T_VERS, /\* H5Z_class_t version *\/ */
59
/* (H5Z_filter_t)FILTER_LZO, /\* filter_id *\/ */
60
/* 1, 1, /\* Encoding and decoding enabled *\/ */
61
/* "lzo", /\* comment *\/ */
62
/* NULL, /\* can_apply_func *\/ */
63
/* NULL, /\* set_local_func *\/ */
64
/* (H5Z_func_t)lzo_deflate /\* filter_func *\/ */
41
#if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 7
43
H5Z_class_t filter_class = {
44
(H5Z_filter_t)(FILTER_LZO), /* filter_id */
46
NULL, /* can_apply_func */
47
NULL, /* set_local_func */
48
(H5Z_func_t)(lzo_deflate) /* filter_func */
52
H5Z_class_t filter_class = {
53
H5Z_CLASS_T_VERS, /* H5Z_class_t version */
54
(H5Z_filter_t)(FILTER_LZO), /* filter_id */
55
1, 1, /* Encoding and decoding enabled */
57
NULL, /* can_apply_func */
58
NULL, /* set_local_func */
59
(H5Z_func_t)(lzo_deflate) /* filter_func */
61
#endif /* if H5_VERSION < "1.7" */
68
63
/* Init the LZO library */
69
64
if (lzo_init()!=LZO_E_OK)
217
209
checksum=lzo_adler32(lzo_adler32(0,NULL,0), outbuf, out_len);
220
if (memcmp(&checksum, (char*)(*buf)+nbytes, 4)) {
212
if (memcmp(&checksum, (unsigned char*)(*buf)+nbytes, 4)) {
221
213
ret_value = 0; /*fail*/
222
214
fprintf(stderr,"Checksum failed!.\n");
240
232
lzo_byte *z_src = (lzo_byte*)(*buf);
241
233
lzo_byte *z_dst; /*destination buffer */
242
234
lzo_uint z_src_nbytes = (lzo_uint)(nbytes);
243
lzo_uint z_dst_nbytes = (lzo_uint)(nbytes + (nbytes / 64) + 16 + 3);
235
/* The next was the original computation for worst-case expansion */
236
/* I don't know why the difference with LZO1*. Perhaps some wrong docs in
238
/* lzo_uint z_dst_nbytes = (lzo_uint)(nbytes + (nbytes / 64) + 16 + 3); */
239
/* The next is for LZO1* algorithms */
240
/* lzo_uint z_dst_nbytes = (lzo_uint)(nbytes + (nbytes / 16) + 64 + 3); */
241
/* The next is for LZO2* algorithms. This will be the default */
242
lzo_uint z_dst_nbytes = (lzo_uint)(nbytes + (nbytes / 8) + 128 + 3);
246
245
if ((object_type == Table && object_version >= 20) ||
258
257
/* Compress this buffer */
259
/* status = lzo1x_1_compress (z_src, z_src_nbytes, z_dst, &z_dst_nbytes, */
258
wrkmem = malloc(LZO1X_1_MEM_COMPRESS);
259
if (wrkmem == NULL) {
260
fprintf(stderr, "Memory allocation failed for lzo compression\n");
261
265
status = lzo1x_1_compress (z_src, z_src_nbytes, z_dst, &z_dst_nbytes,
265
272
if ((object_type == Table && object_version >= 20) ||
266
273
object_type != Table) {
271
278
/* Append checksum of *uncompressed* data at the end */
272
279
checksum = lzo_adler32(lzo_adler32(0,NULL,0), *buf, nbytes);
273
memcpy((char*)(z_dst)+z_dst_nbytes, &checksum, 4);
274
memcpy((char*)(z_dst)+z_dst_nbytes+4, &nbytes, 4);
280
memcpy((unsigned char*)(z_dst)+z_dst_nbytes, &checksum, 4);
281
memcpy((unsigned char*)(z_dst)+z_dst_nbytes+4, &nbytes, 4);
275
282
z_dst_nbytes += (lzo_uint)4+4;