kusano 7d535a
/* wrapmisc.h -- misc wrapper functions for the test driver
kusano 7d535a
kusano 7d535a
   This file is part of the LZO real-time data compression library.
kusano 7d535a
kusano 7d535a
   Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   All Rights Reserved.
kusano 7d535a
kusano 7d535a
   The LZO library is free software; you can redistribute it and/or
kusano 7d535a
   modify it under the terms of the GNU General Public License as
kusano 7d535a
   published by the Free Software Foundation; either version 2 of
kusano 7d535a
   the License, or (at your option) any later version.
kusano 7d535a
kusano 7d535a
   The LZO library is distributed in the hope that it will be useful,
kusano 7d535a
   but WITHOUT ANY WARRANTY; without even the implied warranty of
kusano 7d535a
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
kusano 7d535a
   GNU General Public License for more details.
kusano 7d535a
kusano 7d535a
   You should have received a copy of the GNU General Public License
kusano 7d535a
   along with the LZO library; see the file COPYING.
kusano 7d535a
   If not, write to the Free Software Foundation, Inc.,
kusano 7d535a
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
kusano 7d535a
kusano 7d535a
   Markus F.X.J. Oberhumer
kusano 7d535a
   <markus@oberhumer.com></markus@oberhumer.com>
kusano 7d535a
   http://www.oberhumer.com/opensource/lzo/
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*************************************************************************
kusano 7d535a
// compression levels of zlib
kusano 7d535a
**************************************************************************/
kusano 7d535a
kusano 7d535a
#if defined(ALG_ZLIB)
kusano 7d535a
kusano 7d535a
#define ZLIB_MEM_COMPRESS       0
kusano 7d535a
#define ZLIB_MEM_DECOMPRESS     0
kusano 7d535a
kusano 7d535a
static
kusano 7d535a
int zlib_compress       ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem,
kusano 7d535a
                                int method, int level )
kusano 7d535a
{
kusano 7d535a
    int err;
kusano 7d535a
    uLong destLen;
kusano 7d535a
kusano 7d535a
    assert(method == Z_DEFLATED);
kusano 7d535a
    destLen = *dst_len;
kusano 7d535a
    err = compress2(dst, &destLen, src, src_len, level);
kusano 7d535a
    *dst_len = destLen;
kusano 7d535a
    LZO_UNUSED(method);
kusano 7d535a
    LZO_UNUSED(wrkmem);
kusano 7d535a
    return err;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
zlib_decompress         ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{
kusano 7d535a
    int err;
kusano 7d535a
    uLong destLen;
kusano 7d535a
kusano 7d535a
    destLen = *dst_len;
kusano 7d535a
    err = uncompress(dst, &destLen, src, src_len);
kusano 7d535a
    *dst_len = destLen;
kusano 7d535a
    LZO_UNUSED(wrkmem);
kusano 7d535a
    return err;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
zlib_8_1_compress       ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,1); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
zlib_8_2_compress       ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,2); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
zlib_8_3_compress       ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,3); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
zlib_8_4_compress       ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,4); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
zlib_8_5_compress       ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,5); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
zlib_8_6_compress       ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,6); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
zlib_8_7_compress       ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,7); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
zlib_8_8_compress       ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,8); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
zlib_8_9_compress       ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,9); }
kusano 7d535a
kusano 7d535a
kusano 7d535a
#endif /* ALG_ZLIB */
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*************************************************************************
kusano 7d535a
// compression levels of bzip2
kusano 7d535a
**************************************************************************/
kusano 7d535a
kusano 7d535a
#if defined(ALG_BZIP2)
kusano 7d535a
kusano 7d535a
#define BZIP2_MEM_COMPRESS      0
kusano 7d535a
#define BZIP2_MEM_DECOMPRESS    0
kusano 7d535a
kusano 7d535a
static
kusano 7d535a
int bzip2_compress      ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem,
kusano 7d535a
                                int level )
kusano 7d535a
{
kusano 7d535a
    int err;
kusano 7d535a
    unsigned destLen;
kusano 7d535a
    union { const m_bytep csrc; char* src; } u;
kusano 7d535a
kusano 7d535a
    u.csrc = src; /* UNCONST */
kusano 7d535a
    destLen = *dst_len;
kusano 7d535a
    err = BZ2_bzBuffToBuffCompress((char*)dst, &destLen, u.src, src_len, level, 0, 0);
kusano 7d535a
    *dst_len = destLen;
kusano 7d535a
    LZO_UNUSED(wrkmem);
kusano 7d535a
    return err;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
bzip2_decompress        ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{
kusano 7d535a
    int err;
kusano 7d535a
    unsigned destLen;
kusano 7d535a
    union { const m_bytep csrc; char* src; } u;
kusano 7d535a
kusano 7d535a
    u.csrc = src; /* UNCONST */
kusano 7d535a
    destLen = *dst_len;
kusano 7d535a
    err = BZ2_bzBuffToBuffDecompress((char*)dst, &destLen, u.src, src_len, 0, 0);
kusano 7d535a
    *dst_len = destLen;
kusano 7d535a
    LZO_UNUSED(wrkmem);
kusano 7d535a
    return err;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
bzip2_1_compress        ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,1); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
bzip2_2_compress        ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,2); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
bzip2_3_compress        ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,3); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
bzip2_4_compress        ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,4); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
bzip2_5_compress        ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,5); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
bzip2_6_compress        ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,6); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
bzip2_7_compress        ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,7); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
bzip2_8_compress        ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,8); }
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
bzip2_9_compress        ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,9); }
kusano 7d535a
kusano 7d535a
kusano 7d535a
#endif /* ALG_BZIP2 */
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*************************************************************************
kusano 7d535a
// other wrappers (for benchmarking the checksum algorithms)
kusano 7d535a
**************************************************************************/
kusano 7d535a
kusano 7d535a
#if defined(ALG_ZLIB)
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
zlib_adler32_x_compress ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{
kusano 7d535a
    uLong adler;
kusano 7d535a
    adler = adler32(1L, src, src_len);
kusano 7d535a
    *dst_len = src_len;
kusano 7d535a
    LZO_UNUSED(adler);
kusano 7d535a
    LZO_UNUSED(dst);
kusano 7d535a
    LZO_UNUSED(wrkmem);
kusano 7d535a
    return 0;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
M_PRIVATE(int)
kusano 7d535a
zlib_crc32_x_compress   ( const m_bytep src, m_uint  src_len,
kusano 7d535a
                                m_bytep dst, m_uintp dst_len,
kusano 7d535a
                                m_voidp wrkmem )
kusano 7d535a
{
kusano 7d535a
    uLong crc;
kusano 7d535a
    crc = crc32(0L, src, src_len);
kusano 7d535a
    *dst_len = src_len;
kusano 7d535a
    LZO_UNUSED(crc);
kusano 7d535a
    LZO_UNUSED(dst);
kusano 7d535a
    LZO_UNUSED(wrkmem);
kusano 7d535a
    return 0;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
#endif /* ALG_ZLIB */
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
vi:ts=4:et
kusano 7d535a
*/
kusano 7d535a