1 /* wrapmisc.h -- misc wrapper functions for the test driver
3 This file is part of the LZO real-time data compression library.
5 Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer
8 The LZO library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 The LZO library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the LZO library; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 Markus F.X.J. Oberhumer
24 <markus@oberhumer.com>
25 http://www.oberhumer.com/opensource/lzo/
29 /*************************************************************************
30 // compression levels of zlib
31 **************************************************************************/
35 #define ZLIB_MEM_COMPRESS 0
36 #define ZLIB_MEM_DECOMPRESS 0
39 int zlib_compress ( const m_bytep src, m_uint src_len,
40 m_bytep dst, m_uintp dst_len,
42 int method, int compression_level )
47 assert(method == Z_DEFLATED);
48 destLen = (uLong) *dst_len;
49 err = compress2(dst, &destLen, src, (uLong) src_len, compression_level);
58 zlib_decompress ( const m_bytep src, m_uint src_len,
59 m_bytep dst, m_uintp dst_len,
65 destLen = (uLong) *dst_len;
66 err = uncompress(dst, &destLen, src, (uLong) src_len);
74 zlib_8_1_compress ( const m_bytep src, m_uint src_len,
75 m_bytep dst, m_uintp dst_len,
77 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,1); }
80 zlib_8_2_compress ( const m_bytep src, m_uint src_len,
81 m_bytep dst, m_uintp dst_len,
83 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,2); }
86 zlib_8_3_compress ( const m_bytep src, m_uint src_len,
87 m_bytep dst, m_uintp dst_len,
89 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,3); }
92 zlib_8_4_compress ( const m_bytep src, m_uint src_len,
93 m_bytep dst, m_uintp dst_len,
95 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,4); }
98 zlib_8_5_compress ( const m_bytep src, m_uint src_len,
99 m_bytep dst, m_uintp dst_len,
101 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,5); }
104 zlib_8_6_compress ( const m_bytep src, m_uint src_len,
105 m_bytep dst, m_uintp dst_len,
107 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,6); }
110 zlib_8_7_compress ( const m_bytep src, m_uint src_len,
111 m_bytep dst, m_uintp dst_len,
113 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,7); }
116 zlib_8_8_compress ( const m_bytep src, m_uint src_len,
117 m_bytep dst, m_uintp dst_len,
119 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,8); }
122 zlib_8_9_compress ( const m_bytep src, m_uint src_len,
123 m_bytep dst, m_uintp dst_len,
125 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,9); }
128 #endif /* ALG_ZLIB */
131 /*************************************************************************
132 // compression levels of bzip2
133 **************************************************************************/
135 #if defined(ALG_BZIP2)
137 #define BZIP2_MEM_COMPRESS 0
138 #define BZIP2_MEM_DECOMPRESS 0
141 int bzip2_compress ( const m_bytep src, m_uint src_len,
142 m_bytep dst, m_uintp dst_len,
144 int compression_level )
148 union { const m_bytep csrc; char *src; } u;
150 u.csrc = src; /* UNCONST */
152 err = BZ2_bzBuffToBuffCompress((char*)dst, &destLen, u.src, src_len, compression_level, 0, 0);
160 bzip2_decompress ( const m_bytep src, m_uint src_len,
161 m_bytep dst, m_uintp dst_len,
166 union { const m_bytep csrc; char *src; } u;
168 u.csrc = src; /* UNCONST */
170 err = BZ2_bzBuffToBuffDecompress((char*)dst, &destLen, u.src, src_len, 0, 0);
178 bzip2_1_compress ( const m_bytep src, m_uint src_len,
179 m_bytep dst, m_uintp dst_len,
181 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,1); }
184 bzip2_2_compress ( const m_bytep src, m_uint src_len,
185 m_bytep dst, m_uintp dst_len,
187 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,2); }
190 bzip2_3_compress ( const m_bytep src, m_uint src_len,
191 m_bytep dst, m_uintp dst_len,
193 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,3); }
196 bzip2_4_compress ( const m_bytep src, m_uint src_len,
197 m_bytep dst, m_uintp dst_len,
199 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,4); }
202 bzip2_5_compress ( const m_bytep src, m_uint src_len,
203 m_bytep dst, m_uintp dst_len,
205 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,5); }
208 bzip2_6_compress ( const m_bytep src, m_uint src_len,
209 m_bytep dst, m_uintp dst_len,
211 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,6); }
214 bzip2_7_compress ( const m_bytep src, m_uint src_len,
215 m_bytep dst, m_uintp dst_len,
217 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,7); }
220 bzip2_8_compress ( const m_bytep src, m_uint src_len,
221 m_bytep dst, m_uintp dst_len,
223 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,8); }
226 bzip2_9_compress ( const m_bytep src, m_uint src_len,
227 m_bytep dst, m_uintp dst_len,
229 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,9); }
232 #endif /* ALG_BZIP2 */
235 /*************************************************************************
236 // other wrappers (for benchmarking the checksum algorithms)
237 **************************************************************************/
239 #if defined(ALG_ZLIB)
242 zlib_adler32_x_compress ( const m_bytep src, m_uint src_len,
243 m_bytep dst, m_uintp dst_len,
247 adler = adler32(1L, src, (uInt) src_len);
257 zlib_crc32_x_compress ( const m_bytep src, m_uint src_len,
258 m_bytep dst, m_uintp dst_len,
262 crc = crc32(0L, src, (uInt) src_len);
270 #endif /* ALG_ZLIB */
273 /* vim:set ts=4 sw=4 et: */