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