1/* wrapmisc.h -- misc wrapper functions for the test driver
2
3   This file is part of the LZO real-time data compression library.
4
5   Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer
6   Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer
7   Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer
8   Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
9   Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
10   Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
11   Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
12   Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
13   Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
14   Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
15   Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
16   Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
17   Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
18   Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
19   Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
20   Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
21   All Rights Reserved.
22
23   The LZO library is free software; you can redistribute it and/or
24   modify it under the terms of the GNU General Public License as
25   published by the Free Software Foundation; either version 2 of
26   the License, or (at your option) any later version.
27
28   The LZO library is distributed in the hope that it will be useful,
29   but WITHOUT ANY WARRANTY; without even the implied warranty of
30   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31   GNU General Public License for more details.
32
33   You should have received a copy of the GNU General Public License
34   along with the LZO library; see the file COPYING.
35   If not, write to the Free Software Foundation, Inc.,
36   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
37
38   Markus F.X.J. Oberhumer
39   <markus@oberhumer.com>
40   http://www.oberhumer.com/opensource/lzo/
41 */
42
43
44/*************************************************************************
45// compression levels of zlib
46**************************************************************************/
47
48#if defined(ALG_ZLIB)
49
50#define ZLIB_MEM_COMPRESS       0
51#define ZLIB_MEM_DECOMPRESS     0
52
53static
54int zlib_compress       ( const m_bytep src, m_uint  src_len,
55                                m_bytep dst, m_uintp dst_len,
56                                m_voidp wrkmem,
57                                int method, int compression_level )
58{
59    int err;
60    uLong destLen;
61
62    assert(method == Z_DEFLATED);
63    destLen = (uLong) *dst_len;
64    err = compress2(dst, &destLen, src, (uLong) src_len, compression_level);
65    *dst_len = destLen;
66    LZO_UNUSED(method);
67    LZO_UNUSED(wrkmem);
68    return err;
69}
70
71
72M_PRIVATE(int)
73zlib_decompress         ( const m_bytep src, m_uint  src_len,
74                                m_bytep dst, m_uintp dst_len,
75                                m_voidp wrkmem )
76{
77    int err;
78    uLong destLen;
79
80    destLen = (uLong) *dst_len;
81    err = uncompress(dst, &destLen, src, (uLong) src_len);
82    *dst_len = destLen;
83    LZO_UNUSED(wrkmem);
84    return err;
85}
86
87
88M_PRIVATE(int)
89zlib_8_1_compress       ( const m_bytep src, m_uint  src_len,
90                                m_bytep dst, m_uintp dst_len,
91                                m_voidp wrkmem )
92{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,1); }
93
94M_PRIVATE(int)
95zlib_8_2_compress       ( const m_bytep src, m_uint  src_len,
96                                m_bytep dst, m_uintp dst_len,
97                                m_voidp wrkmem )
98{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,2); }
99
100M_PRIVATE(int)
101zlib_8_3_compress       ( const m_bytep src, m_uint  src_len,
102                                m_bytep dst, m_uintp dst_len,
103                                m_voidp wrkmem )
104{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,3); }
105
106M_PRIVATE(int)
107zlib_8_4_compress       ( const m_bytep src, m_uint  src_len,
108                                m_bytep dst, m_uintp dst_len,
109                                m_voidp wrkmem )
110{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,4); }
111
112M_PRIVATE(int)
113zlib_8_5_compress       ( const m_bytep src, m_uint  src_len,
114                                m_bytep dst, m_uintp dst_len,
115                                m_voidp wrkmem )
116{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,5); }
117
118M_PRIVATE(int)
119zlib_8_6_compress       ( const m_bytep src, m_uint  src_len,
120                                m_bytep dst, m_uintp dst_len,
121                                m_voidp wrkmem )
122{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,6); }
123
124M_PRIVATE(int)
125zlib_8_7_compress       ( const m_bytep src, m_uint  src_len,
126                                m_bytep dst, m_uintp dst_len,
127                                m_voidp wrkmem )
128{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,7); }
129
130M_PRIVATE(int)
131zlib_8_8_compress       ( const m_bytep src, m_uint  src_len,
132                                m_bytep dst, m_uintp dst_len,
133                                m_voidp wrkmem )
134{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,8); }
135
136M_PRIVATE(int)
137zlib_8_9_compress       ( const m_bytep src, m_uint  src_len,
138                                m_bytep dst, m_uintp dst_len,
139                                m_voidp wrkmem )
140{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,9); }
141
142
143#endif /* ALG_ZLIB */
144
145
146/*************************************************************************
147// compression levels of bzip2
148**************************************************************************/
149
150#if defined(ALG_BZIP2)
151
152#define BZIP2_MEM_COMPRESS      0
153#define BZIP2_MEM_DECOMPRESS    0
154
155static
156int bzip2_compress      ( const m_bytep src, m_uint  src_len,
157                                m_bytep dst, m_uintp dst_len,
158                                m_voidp wrkmem,
159                                int compression_level )
160{
161    int err;
162    unsigned destLen;
163    union { const m_bytep csrc; char *src; } u;
164
165    u.csrc = src; /* UNCONST */
166    destLen = *dst_len;
167    err = BZ2_bzBuffToBuffCompress((char*)dst, &destLen, u.src, src_len, compression_level, 0, 0);
168    *dst_len = destLen;
169    LZO_UNUSED(wrkmem);
170    return err;
171}
172
173
174M_PRIVATE(int)
175bzip2_decompress        ( const m_bytep src, m_uint  src_len,
176                                m_bytep dst, m_uintp dst_len,
177                                m_voidp wrkmem )
178{
179    int err;
180    unsigned destLen;
181    union { const m_bytep csrc; char *src; } u;
182
183    u.csrc = src; /* UNCONST */
184    destLen = *dst_len;
185    err = BZ2_bzBuffToBuffDecompress((char*)dst, &destLen, u.src, src_len, 0, 0);
186    *dst_len = destLen;
187    LZO_UNUSED(wrkmem);
188    return err;
189}
190
191
192M_PRIVATE(int)
193bzip2_1_compress        ( const m_bytep src, m_uint  src_len,
194                                m_bytep dst, m_uintp dst_len,
195                                m_voidp wrkmem )
196{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,1); }
197
198M_PRIVATE(int)
199bzip2_2_compress        ( const m_bytep src, m_uint  src_len,
200                                m_bytep dst, m_uintp dst_len,
201                                m_voidp wrkmem )
202{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,2); }
203
204M_PRIVATE(int)
205bzip2_3_compress        ( const m_bytep src, m_uint  src_len,
206                                m_bytep dst, m_uintp dst_len,
207                                m_voidp wrkmem )
208{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,3); }
209
210M_PRIVATE(int)
211bzip2_4_compress        ( const m_bytep src, m_uint  src_len,
212                                m_bytep dst, m_uintp dst_len,
213                                m_voidp wrkmem )
214{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,4); }
215
216M_PRIVATE(int)
217bzip2_5_compress        ( const m_bytep src, m_uint  src_len,
218                                m_bytep dst, m_uintp dst_len,
219                                m_voidp wrkmem )
220{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,5); }
221
222M_PRIVATE(int)
223bzip2_6_compress        ( const m_bytep src, m_uint  src_len,
224                                m_bytep dst, m_uintp dst_len,
225                                m_voidp wrkmem )
226{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,6); }
227
228M_PRIVATE(int)
229bzip2_7_compress        ( const m_bytep src, m_uint  src_len,
230                                m_bytep dst, m_uintp dst_len,
231                                m_voidp wrkmem )
232{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,7); }
233
234M_PRIVATE(int)
235bzip2_8_compress        ( const m_bytep src, m_uint  src_len,
236                                m_bytep dst, m_uintp dst_len,
237                                m_voidp wrkmem )
238{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,8); }
239
240M_PRIVATE(int)
241bzip2_9_compress        ( const m_bytep src, m_uint  src_len,
242                                m_bytep dst, m_uintp dst_len,
243                                m_voidp wrkmem )
244{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,9); }
245
246
247#endif /* ALG_BZIP2 */
248
249
250/*************************************************************************
251// other wrappers (for benchmarking the checksum algorithms)
252**************************************************************************/
253
254#if defined(ALG_ZLIB)
255
256M_PRIVATE(int)
257zlib_adler32_x_compress ( const m_bytep src, m_uint  src_len,
258                                m_bytep dst, m_uintp dst_len,
259                                m_voidp wrkmem )
260{
261    uLong adler;
262    adler = adler32(1L, src, (uInt) src_len);
263    *dst_len = src_len;
264    LZO_UNUSED(adler);
265    LZO_UNUSED(dst);
266    LZO_UNUSED(wrkmem);
267    return 0;
268}
269
270
271M_PRIVATE(int)
272zlib_crc32_x_compress   ( const m_bytep src, m_uint  src_len,
273                                m_bytep dst, m_uintp dst_len,
274                                m_voidp wrkmem )
275{
276    uLong crc;
277    crc = crc32(0L, src, (uInt) src_len);
278    *dst_len = src_len;
279    LZO_UNUSED(crc);
280    LZO_UNUSED(dst);
281    LZO_UNUSED(wrkmem);
282    return 0;
283}
284
285#endif /* ALG_ZLIB */
286
287
288/*
289vi:ts=4:et
290*/
291
292