1 /* lzo2a_d.ch -- implementation of the LZO2A decompression algorithm
3 This file is part of the LZO real-time data compression library.
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
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.
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.
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.
38 Markus F.X.J. Oberhumer
39 <markus@oberhumer.com>
40 http://www.oberhumer.com/opensource/lzo/
47 /***********************************************************************
48 // decompress a block of data.
49 ************************************************************************/
51 #define _NEEDBYTE NEED_IP(1)
52 #define _NEXTBYTE (*ip++)
55 DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
56 lzo_bytep out, lzo_uintp out_len,
59 register lzo_bytep op;
60 register const lzo_bytep ip;
61 register const lzo_bytep m_pos;
64 const lzo_bytep const ip_end = in + in_len;
65 #if defined(HAVE_ANY_OP)
66 lzo_bytep const op_end = out + *out_len;
69 lzo_uint32 b = 0; /* bit buffer */
70 unsigned k = 0; /* bits in bit buffer */
77 while (TEST_IP && TEST_OP)
84 NEED_IP(1); NEED_OP(1);
96 t = M1_MIN_LEN + (lzo_uint) MASKBITS(2);
98 NEED_IP(1); NEED_OP(t);
99 m_pos = op - 1 - *ip++;
100 assert(m_pos >= out); assert(m_pos < op);
102 MEMCPY_DS(op,m_pos,t);
110 m_pos -= (t & 31) | (((lzo_uint) *ip++) << 5);
123 m_pos -= 8192; /* t << 13 */
140 #if defined(LZO_EOF_CODE)
146 assert(m_pos >= out); assert(m_pos < op);
149 MEMCPY_DS(op,m_pos,t);
153 #if defined(LZO_EOF_CODE)
154 #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
155 /* no EOF code was found */
156 *out_len = pd(op, out);
157 return LZO_E_EOF_NOT_FOUND;
163 *out_len = pd(op, out);
164 return (ip == ip_end ? LZO_E_OK :
165 (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
168 #if defined(HAVE_NEED_IP)
170 *out_len = pd(op, out);
171 return LZO_E_INPUT_OVERRUN;
174 #if defined(HAVE_NEED_OP)
176 *out_len = pd(op, out);
177 return LZO_E_OUTPUT_OVERRUN;
180 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
182 *out_len = pd(op, out);
183 return LZO_E_LOOKBEHIND_OVERRUN;