/src/lzo-2.10/src/lzo2a_d.ch
Line | Count | Source |
1 | | /* lzo2a_d.ch -- implementation of the LZO2A decompression algorithm |
2 | | |
3 | | This file is part of the LZO real-time data compression library. |
4 | | |
5 | | Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer |
6 | | All Rights Reserved. |
7 | | |
8 | | The LZO library is free software; you can redistribute it and/or |
9 | | modify it under the terms of the GNU General Public License as |
10 | | published by the Free Software Foundation; either version 2 of |
11 | | the License, or (at your option) any later version. |
12 | | |
13 | | The LZO library is distributed in the hope that it will be useful, |
14 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | GNU General Public License for more details. |
17 | | |
18 | | You should have received a copy of the GNU General Public License |
19 | | along with the LZO library; see the file COPYING. |
20 | | If not, write to the Free Software Foundation, Inc., |
21 | | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
22 | | |
23 | | Markus F.X.J. Oberhumer |
24 | | <markus@oberhumer.com> |
25 | | http://www.oberhumer.com/opensource/lzo/ |
26 | | */ |
27 | | |
28 | | |
29 | | #include "lzo1_d.ch" |
30 | | |
31 | | |
32 | | /*********************************************************************** |
33 | | // decompress a block of data. |
34 | | ************************************************************************/ |
35 | | |
36 | 1.07M | #define _NEEDBYTE NEED_IP(1) |
37 | 1.07M | #define _NEXTBYTE (*ip++) |
38 | | |
39 | | LZO_PUBLIC(int) |
40 | | DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, |
41 | | lzo_bytep out, lzo_uintp out_len, |
42 | | lzo_voidp wrkmem ) |
43 | 891 | { |
44 | 891 | lzo_bytep op; |
45 | 891 | const lzo_bytep ip; |
46 | 891 | const lzo_bytep m_pos; |
47 | | |
48 | 891 | lzo_uint t; |
49 | 891 | const lzo_bytep const ip_end = in + in_len; |
50 | | #if defined(HAVE_ANY_OP) |
51 | 202 | lzo_bytep const op_end = out + *out_len; |
52 | | #endif |
53 | | |
54 | 891 | lzo_uint32_t b = 0; /* bit buffer */ |
55 | 891 | unsigned k = 0; /* bits in bit buffer */ |
56 | | |
57 | 891 | LZO_UNUSED(wrkmem); |
58 | | |
59 | 891 | op = out; |
60 | 891 | ip = in; |
61 | | |
62 | 5.76M | while (TEST_IP_AND_TEST_OP) |
63 | 6.15M | { |
64 | 6.15M | NEEDBITS(1); |
65 | 6.15M | if (MASKBITS(1) == 0) |
66 | 5.26M | { |
67 | 5.26M | DUMPBITS(1); |
68 | | /* a literal */ |
69 | 5.26M | NEED_IP(1); NEED_OP(1); |
70 | 362k | *op++ = *ip++; |
71 | 362k | continue; |
72 | 362k | } |
73 | 886k | DUMPBITS(1); |
74 | | |
75 | 886k | NEEDBITS(1); |
76 | 886k | if (MASKBITS(1) == 0) |
77 | 765k | { |
78 | 765k | DUMPBITS(1); |
79 | | /* a M1 match */ |
80 | 765k | NEEDBITS(2); |
81 | 765k | t = M1_MIN_LEN + (lzo_uint) MASKBITS(2); |
82 | 765k | DUMPBITS(2); |
83 | 765k | NEED_IP(1); NEED_OP(t); |
84 | 11.5k | m_pos = op - 1 - *ip++; |
85 | 11.5k | assert(m_pos >= out); assert(m_pos < op); |
86 | 765k | TEST_LB(m_pos); |
87 | 765k | MEMCPY_DS(op,m_pos,t); |
88 | 11.5k | continue; |
89 | 11.5k | } |
90 | 121k | DUMPBITS(1); |
91 | | |
92 | 121k | NEED_IP(2); |
93 | 10.3k | t = *ip++; |
94 | 10.3k | m_pos = op; |
95 | 10.3k | m_pos -= (t & 31) | (((lzo_uint) *ip++) << 5); |
96 | 10.3k | t >>= 5; |
97 | 121k | if (t == 0) |
98 | 22.4k | { |
99 | | #if (SWD_N >= 8192) |
100 | | NEEDBITS(1); |
101 | | t = MASKBITS(1); |
102 | | DUMPBITS(1); |
103 | | if (t == 0) |
104 | | t = 10 - 1; |
105 | | else |
106 | | { |
107 | | /* a M3 match */ |
108 | | m_pos -= 8192; /* t << 13 */ |
109 | | t = M3_MIN_LEN - 1; |
110 | | } |
111 | | #else |
112 | 22.4k | t = 10 - 1; |
113 | 22.4k | #endif |
114 | 22.4k | NEED_IP(1); |
115 | 1.93M | while (*ip == 0) |
116 | 1.91M | { |
117 | 1.91M | t += 255; |
118 | 1.91M | ip++; |
119 | 1.91M | TEST_OV(t); |
120 | 1.91M | NEED_IP(1); |
121 | 1.90M | } |
122 | 1.64k | t += *ip++; |
123 | 1.64k | } |
124 | 99.1k | else |
125 | 99.1k | { |
126 | 99.1k | #if defined(LZO_EOF_CODE) |
127 | 99.1k | if (m_pos == op) |
128 | 695 | goto eof_found; |
129 | 98.4k | #endif |
130 | 98.4k | t += 2; |
131 | 98.4k | } |
132 | 120k | assert(m_pos >= out); assert(m_pos < op); |
133 | 120k | TEST_LB(m_pos); |
134 | 120k | NEED_OP(t); |
135 | 120k | MEMCPY_DS(op,m_pos,t); |
136 | 10.2k | } |
137 | | |
138 | | |
139 | 70 | #if defined(LZO_EOF_CODE) |
140 | | #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) |
141 | | /* no EOF code was found */ |
142 | 70 | *out_len = pd(op, out); |
143 | 70 | return LZO_E_EOF_NOT_FOUND; |
144 | 0 | #endif |
145 | | |
146 | 695 | eof_found: |
147 | 695 | assert(t == 1); |
148 | 695 | #endif |
149 | 695 | *out_len = pd(op, out); |
150 | 695 | return (ip == ip_end ? LZO_E_OK : |
151 | 695 | (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); |
152 | | |
153 | | |
154 | | #if defined(HAVE_NEED_IP) |
155 | 46 | input_overrun: |
156 | 46 | *out_len = pd(op, out); |
157 | 46 | return LZO_E_INPUT_OVERRUN; |
158 | 0 | #endif |
159 | | |
160 | | #if defined(HAVE_NEED_OP) |
161 | 11 | output_overrun: |
162 | 11 | *out_len = pd(op, out); |
163 | 11 | return LZO_E_OUTPUT_OVERRUN; |
164 | 0 | #endif |
165 | | |
166 | | #if defined(LZO_TEST_OVERRUN_LOOKBEHIND) |
167 | 69 | lookbehind_overrun: |
168 | 69 | *out_len = pd(op, out); |
169 | 69 | return LZO_E_LOOKBEHIND_OVERRUN; |
170 | | #endif |
171 | 891 | } Line | Count | Source | 43 | 689 | { | 44 | 689 | lzo_bytep op; | 45 | 689 | const lzo_bytep ip; | 46 | 689 | const lzo_bytep m_pos; | 47 | | | 48 | 689 | lzo_uint t; | 49 | 689 | const lzo_bytep const ip_end = in + in_len; | 50 | | #if defined(HAVE_ANY_OP) | 51 | | lzo_bytep const op_end = out + *out_len; | 52 | | #endif | 53 | | | 54 | 689 | lzo_uint32_t b = 0; /* bit buffer */ | 55 | 689 | unsigned k = 0; /* bits in bit buffer */ | 56 | | | 57 | 689 | LZO_UNUSED(wrkmem); | 58 | | | 59 | 689 | op = out; | 60 | 689 | ip = in; | 61 | | | 62 | 5.76M | while (TEST_IP_AND_TEST_OP) | 63 | 5.76M | { | 64 | 5.76M | NEEDBITS(1); | 65 | 5.76M | if (MASKBITS(1) == 0) | 66 | 4.90M | { | 67 | 4.90M | DUMPBITS(1); | 68 | | /* a literal */ | 69 | 4.90M | NEED_IP(1); NEED_OP(1); | 70 | 4.90M | *op++ = *ip++; | 71 | 4.90M | continue; | 72 | 4.90M | } | 73 | 864k | DUMPBITS(1); | 74 | | | 75 | 864k | NEEDBITS(1); | 76 | 864k | if (MASKBITS(1) == 0) | 77 | 753k | { | 78 | 753k | DUMPBITS(1); | 79 | | /* a M1 match */ | 80 | 753k | NEEDBITS(2); | 81 | 753k | t = M1_MIN_LEN + (lzo_uint) MASKBITS(2); | 82 | 753k | DUMPBITS(2); | 83 | 753k | NEED_IP(1); NEED_OP(t); | 84 | 753k | m_pos = op - 1 - *ip++; | 85 | 753k | assert(m_pos >= out); assert(m_pos < op); | 86 | 753k | TEST_LB(m_pos); | 87 | 753k | MEMCPY_DS(op,m_pos,t); | 88 | 753k | continue; | 89 | 753k | } | 90 | 111k | DUMPBITS(1); | 91 | | | 92 | 111k | NEED_IP(2); | 93 | 111k | t = *ip++; | 94 | 111k | m_pos = op; | 95 | 111k | m_pos -= (t & 31) | (((lzo_uint) *ip++) << 5); | 96 | 111k | t >>= 5; | 97 | 111k | if (t == 0) | 98 | 20.7k | { | 99 | | #if (SWD_N >= 8192) | 100 | | NEEDBITS(1); | 101 | | t = MASKBITS(1); | 102 | | DUMPBITS(1); | 103 | | if (t == 0) | 104 | | t = 10 - 1; | 105 | | else | 106 | | { | 107 | | /* a M3 match */ | 108 | | m_pos -= 8192; /* t << 13 */ | 109 | | t = M3_MIN_LEN - 1; | 110 | | } | 111 | | #else | 112 | 20.7k | t = 10 - 1; | 113 | 20.7k | #endif | 114 | 20.7k | NEED_IP(1); | 115 | 35.5k | while (*ip == 0) | 116 | 14.8k | { | 117 | 14.8k | t += 255; | 118 | 14.8k | ip++; | 119 | 14.8k | TEST_OV(t); | 120 | 14.8k | NEED_IP(1); | 121 | 14.8k | } | 122 | 20.7k | t += *ip++; | 123 | 20.7k | } | 124 | 90.5k | else | 125 | 90.5k | { | 126 | 90.5k | #if defined(LZO_EOF_CODE) | 127 | 90.5k | if (m_pos == op) | 128 | 689 | goto eof_found; | 129 | 89.8k | #endif | 130 | 89.8k | t += 2; | 131 | 89.8k | } | 132 | 111k | assert(m_pos >= out); assert(m_pos < op); | 133 | 110k | TEST_LB(m_pos); | 134 | 110k | NEED_OP(t); | 135 | 110k | MEMCPY_DS(op,m_pos,t); | 136 | 110k | } | 137 | | | 138 | | | 139 | 0 | #if defined(LZO_EOF_CODE) | 140 | | #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) | 141 | | /* no EOF code was found */ | 142 | | *out_len = pd(op, out); | 143 | | return LZO_E_EOF_NOT_FOUND; | 144 | | #endif | 145 | | | 146 | 689 | eof_found: | 147 | 689 | assert(t == 1); | 148 | 689 | #endif | 149 | 689 | *out_len = pd(op, out); | 150 | 689 | return (ip == ip_end ? LZO_E_OK : | 151 | 689 | (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); | 152 | | | 153 | | | 154 | | #if defined(HAVE_NEED_IP) | 155 | | input_overrun: | 156 | | *out_len = pd(op, out); | 157 | | return LZO_E_INPUT_OVERRUN; | 158 | | #endif | 159 | | | 160 | | #if defined(HAVE_NEED_OP) | 161 | | output_overrun: | 162 | | *out_len = pd(op, out); | 163 | | return LZO_E_OUTPUT_OVERRUN; | 164 | | #endif | 165 | | | 166 | | #if defined(LZO_TEST_OVERRUN_LOOKBEHIND) | 167 | | lookbehind_overrun: | 168 | | *out_len = pd(op, out); | 169 | | return LZO_E_LOOKBEHIND_OVERRUN; | 170 | | #endif | 171 | 689 | } |
Line | Count | Source | 43 | 202 | { | 44 | 202 | lzo_bytep op; | 45 | 202 | const lzo_bytep ip; | 46 | 202 | const lzo_bytep m_pos; | 47 | | | 48 | 202 | lzo_uint t; | 49 | 202 | const lzo_bytep const ip_end = in + in_len; | 50 | 202 | #if defined(HAVE_ANY_OP) | 51 | 202 | lzo_bytep const op_end = out + *out_len; | 52 | 202 | #endif | 53 | | | 54 | 202 | lzo_uint32_t b = 0; /* bit buffer */ | 55 | 202 | unsigned k = 0; /* bits in bit buffer */ | 56 | | | 57 | 202 | LZO_UNUSED(wrkmem); | 58 | | | 59 | 202 | op = out; | 60 | 202 | ip = in; | 61 | | | 62 | 202 | while (TEST_IP_AND_TEST_OP) | 63 | 384k | { | 64 | 384k | NEEDBITS(1); | 65 | 384k | if (MASKBITS(1) == 0) | 66 | 362k | { | 67 | 362k | DUMPBITS(1); | 68 | | /* a literal */ | 69 | 362k | NEED_IP(1); NEED_OP(1); | 70 | 362k | *op++ = *ip++; | 71 | 362k | continue; | 72 | 362k | } | 73 | 21.8k | DUMPBITS(1); | 74 | | | 75 | 21.8k | NEEDBITS(1); | 76 | 21.8k | if (MASKBITS(1) == 0) | 77 | 11.5k | { | 78 | 11.5k | DUMPBITS(1); | 79 | | /* a M1 match */ | 80 | 11.5k | NEEDBITS(2); | 81 | 11.5k | t = M1_MIN_LEN + (lzo_uint) MASKBITS(2); | 82 | 11.5k | DUMPBITS(2); | 83 | 11.5k | NEED_IP(1); NEED_OP(t); | 84 | 11.5k | m_pos = op - 1 - *ip++; | 85 | 11.5k | assert(m_pos >= out); assert(m_pos < op); | 86 | 11.5k | TEST_LB(m_pos); | 87 | 11.5k | MEMCPY_DS(op,m_pos,t); | 88 | 11.5k | continue; | 89 | 11.5k | } | 90 | 10.3k | DUMPBITS(1); | 91 | | | 92 | 10.3k | NEED_IP(2); | 93 | 10.3k | t = *ip++; | 94 | 10.3k | m_pos = op; | 95 | 10.3k | m_pos -= (t & 31) | (((lzo_uint) *ip++) << 5); | 96 | 10.3k | t >>= 5; | 97 | 10.3k | if (t == 0) | 98 | 1.66k | { | 99 | | #if (SWD_N >= 8192) | 100 | | NEEDBITS(1); | 101 | | t = MASKBITS(1); | 102 | | DUMPBITS(1); | 103 | | if (t == 0) | 104 | | t = 10 - 1; | 105 | | else | 106 | | { | 107 | | /* a M3 match */ | 108 | | m_pos -= 8192; /* t << 13 */ | 109 | | t = M3_MIN_LEN - 1; | 110 | | } | 111 | | #else | 112 | 1.66k | t = 10 - 1; | 113 | 1.66k | #endif | 114 | 1.66k | NEED_IP(1); | 115 | 1.90M | while (*ip == 0) | 116 | 1.90M | { | 117 | 1.90M | t += 255; | 118 | 1.90M | ip++; | 119 | 1.90M | TEST_OV(t); | 120 | 1.90M | NEED_IP(1); | 121 | 1.90M | } | 122 | 1.64k | t += *ip++; | 123 | 1.64k | } | 124 | 8.63k | else | 125 | 8.63k | { | 126 | 8.63k | #if defined(LZO_EOF_CODE) | 127 | 8.63k | if (m_pos == op) | 128 | 6 | goto eof_found; | 129 | 8.63k | #endif | 130 | 8.63k | t += 2; | 131 | 8.63k | } | 132 | 10.3k | assert(m_pos >= out); assert(m_pos < op); | 133 | 10.2k | TEST_LB(m_pos); | 134 | 10.2k | NEED_OP(t); | 135 | 10.2k | MEMCPY_DS(op,m_pos,t); | 136 | 10.2k | } | 137 | | | 138 | | | 139 | 70 | #if defined(LZO_EOF_CODE) | 140 | 70 | #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) | 141 | | /* no EOF code was found */ | 142 | 70 | *out_len = pd(op, out); | 143 | 70 | return LZO_E_EOF_NOT_FOUND; | 144 | 0 | #endif | 145 | | | 146 | 6 | eof_found: | 147 | 6 | assert(t == 1); | 148 | 6 | #endif | 149 | 6 | *out_len = pd(op, out); | 150 | 6 | return (ip == ip_end ? LZO_E_OK : | 151 | 6 | (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); | 152 | | | 153 | | | 154 | 0 | #if defined(HAVE_NEED_IP) | 155 | 46 | input_overrun: | 156 | 46 | *out_len = pd(op, out); | 157 | 46 | return LZO_E_INPUT_OVERRUN; | 158 | 0 | #endif | 159 | | | 160 | 0 | #if defined(HAVE_NEED_OP) | 161 | 11 | output_overrun: | 162 | 11 | *out_len = pd(op, out); | 163 | 11 | return LZO_E_OUTPUT_OVERRUN; | 164 | 0 | #endif | 165 | | | 166 | 0 | #if defined(LZO_TEST_OVERRUN_LOOKBEHIND) | 167 | 69 | lookbehind_overrun: | 168 | 69 | *out_len = pd(op, out); | 169 | 69 | return LZO_E_LOOKBEHIND_OVERRUN; | 170 | 202 | #endif | 171 | 202 | } |
|
172 | | |
173 | | |
174 | | /* vim:set ts=4 sw=4 et: */ |