1/* lzo1a_99.c -- implementation of the LZO1A-99 algorithm
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#define COMPRESS_ID     99
43
44#define DDBITS          3
45#define CLEVEL          9
46
47
48/***********************************************************************
49//
50************************************************************************/
51
52#define LZO_NEED_DICT_H
53#include "config1a.h"
54
55
56/***********************************************************************
57// compression internal entry point.
58************************************************************************/
59
60static int
61_lzo1a_do_compress ( const lzo_bytep in,  lzo_uint  in_len,
62                           lzo_bytep out, lzo_uintp out_len,
63                           lzo_voidp wrkmem,
64                           lzo_compress_t func )
65{
66    int r;
67
68    /* don't try to compress a block that's too short */
69    if (in_len <= 0)
70    {
71        *out_len = 0;
72        r = LZO_E_OK;
73    }
74    else if (in_len <= MIN_LOOKAHEAD + 1)
75    {
76#if defined(LZO_RETURN_IF_NOT_COMPRESSIBLE)
77        *out_len = 0;
78        r = LZO_E_NOT_COMPRESSIBLE;
79#else
80        *out_len = pd(STORE_RUN(out,in,in_len), out);
81        r = (*out_len > in_len) ? LZO_E_OK : LZO_E_ERROR;
82#endif
83    }
84    else
85        r = func(in,in_len,out,out_len,wrkmem);
86
87    return r;
88}
89
90
91/***********************************************************************
92//
93************************************************************************/
94
95#if !defined(COMPRESS_ID)
96#define COMPRESS_ID     _LZO_ECONCAT2(DD_BITS,CLEVEL)
97#endif
98
99
100#define LZO_CODE_MATCH_INCLUDE_FILE     "lzo1a_cm.ch"
101#include "lzo1b_c.ch"
102
103
104/***********************************************************************
105//
106************************************************************************/
107
108#define LZO_COMPRESS \
109    LZO_CPP_ECONCAT3(lzo1a_,COMPRESS_ID,_compress)
110
111#define LZO_COMPRESS_FUNC \
112    LZO_CPP_ECONCAT3(_lzo1a_,COMPRESS_ID,_compress_func)
113
114
115/***********************************************************************
116//
117************************************************************************/
118
119LZO_PUBLIC(int)
120LZO_COMPRESS ( const lzo_bytep in,  lzo_uint  in_len,
121                     lzo_bytep out, lzo_uintp out_len,
122                     lzo_voidp wrkmem )
123{
124    return _lzo1a_do_compress(in,in_len,out,out_len,wrkmem,do_compress);
125}
126
127
128/*
129vi:ts=4:et
130*/
131