1 /* lzo1f_d.ch -- implementation of the LZO1F decompression algorithm
3 This file is part of the LZO real-time data compression library.
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
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.
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.
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.
35 Markus F.X.J. Oberhumer
36 <markus@oberhumer.com>
37 http://www.oberhumer.com/opensource/lzo/
44 /***********************************************************************
45 // decompress a block of data.
46 ************************************************************************/
49 DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len,
50 lzo_bytep out, lzo_uintp out_len,
53 register lzo_bytep op;
54 register const lzo_bytep ip;
56 register const lzo_bytep m_pos;
58 const lzo_bytep const ip_end = in + in_len;
59 #if defined(HAVE_ANY_OP)
60 lzo_bytep const op_end = out + *out_len;
70 while (TEST_IP && TEST_OP)
89 assert(t > 0); NEED_OP(t); NEED_IP(t+1);
90 #if defined(LZO_UNALIGNED_OK_4)
94 * (lzo_uint32p) op = * (const lzo_uint32p) ip;
95 op += 4; ip += 4; t -= 4;
97 if (t > 0) do *op++ = *ip++; while (--t > 0);
101 do *op++ = *ip++; while (--t > 0);
105 while (TEST_IP && TEST_OP)
110 m_pos = op - 1 - 0x800;
111 m_pos -= (t >> 2) & 7;
113 TEST_LB(m_pos); NEED_OP(3);
114 *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos++;
122 m_pos -= (t >> 2) & 7;
125 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
144 #if defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
145 m_pos -= (* (const lzo_ushortp) ip) >> 2;
156 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
157 #if defined(LZO_UNALIGNED_OK_4)
158 if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
160 * (lzo_uint32p) op = * (const lzo_uint32p) m_pos;
161 op += 4; m_pos += 4; t -= 4 - (3 - 1);
163 * (lzo_uint32p) op = * (const lzo_uint32p) m_pos;
164 op += 4; m_pos += 4; t -= 4;
166 if (t > 0) do *op++ = *m_pos++; while (--t > 0);
172 *op++ = *m_pos++; *op++ = *m_pos++;
173 do *op++ = *m_pos++; while (--t > 0);
181 assert(t > 0); NEED_OP(t); NEED_IP(t+1);
182 do *op++ = *ip++; while (--t > 0);
187 #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
188 /* no EOF code was found */
189 *out_len = pd(op, out);
190 return LZO_E_EOF_NOT_FOUND;
195 *out_len = pd(op, out);
196 return (ip == ip_end ? LZO_E_OK :
197 (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
200 #if defined(HAVE_NEED_IP)
202 *out_len = pd(op, out);
203 return LZO_E_INPUT_OVERRUN;
206 #if defined(HAVE_NEED_OP)
208 *out_len = pd(op, out);
209 return LZO_E_OUTPUT_OVERRUN;
212 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
214 *out_len = pd(op, out);
215 return LZO_E_LOOKBEHIND_OVERRUN;