lzoruby 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE.txt +339 -0
- data/README.txt +57 -0
- data/ext/compr1b.h +81 -0
- data/ext/compr1c.h +81 -0
- data/ext/config1.h +61 -0
- data/ext/config1a.h +196 -0
- data/ext/config1b.h +140 -0
- data/ext/config1c.h +145 -0
- data/ext/config1f.h +97 -0
- data/ext/config1x.h +118 -0
- data/ext/config1y.h +66 -0
- data/ext/config1z.h +65 -0
- data/ext/config2a.h +155 -0
- data/ext/extconf.rb +2 -0
- data/ext/lzo/lzo1.h +96 -0
- data/ext/lzo/lzo1a.h +96 -0
- data/ext/lzo/lzo1b.h +160 -0
- data/ext/lzo/lzo1c.h +160 -0
- data/ext/lzo/lzo1f.h +108 -0
- data/ext/lzo/lzo1x.h +177 -0
- data/ext/lzo/lzo1y.h +145 -0
- data/ext/lzo/lzo1z.h +150 -0
- data/ext/lzo/lzo2a.h +92 -0
- data/ext/lzo/lzo_asm.h +139 -0
- data/ext/lzo/lzoconf.h +417 -0
- data/ext/lzo/lzodefs.h +1807 -0
- data/ext/lzo/lzoutil.h +73 -0
- data/ext/lzo1.c +635 -0
- data/ext/lzo1_99.c +130 -0
- data/ext/lzo1_cm.ch +52 -0
- data/ext/lzo1_d.ch +155 -0
- data/ext/lzo1a.c +657 -0
- data/ext/lzo1a_99.c +130 -0
- data/ext/lzo1a_cm.ch +242 -0
- data/ext/lzo1a_cr.ch +128 -0
- data/ext/lzo1a_de.h +158 -0
- data/ext/lzo1b_1.c +46 -0
- data/ext/lzo1b_2.c +46 -0
- data/ext/lzo1b_3.c +46 -0
- data/ext/lzo1b_4.c +46 -0
- data/ext/lzo1b_5.c +46 -0
- data/ext/lzo1b_6.c +46 -0
- data/ext/lzo1b_7.c +46 -0
- data/ext/lzo1b_8.c +46 -0
- data/ext/lzo1b_9.c +46 -0
- data/ext/lzo1b_99.c +49 -0
- data/ext/lzo1b_9x.c +365 -0
- data/ext/lzo1b_c.ch +270 -0
- data/ext/lzo1b_cc.c +167 -0
- data/ext/lzo1b_cc.h +93 -0
- data/ext/lzo1b_cm.ch +294 -0
- data/ext/lzo1b_cr.ch +126 -0
- data/ext/lzo1b_d.ch +282 -0
- data/ext/lzo1b_d1.c +46 -0
- data/ext/lzo1b_d2.c +46 -0
- data/ext/lzo1b_de.h +344 -0
- data/ext/lzo1b_r.ch +117 -0
- data/ext/lzo1b_rr.c +43 -0
- data/ext/lzo1b_sm.ch +210 -0
- data/ext/lzo1b_tm.ch +99 -0
- data/ext/lzo1b_xx.c +98 -0
- data/ext/lzo1c_1.c +46 -0
- data/ext/lzo1c_2.c +46 -0
- data/ext/lzo1c_3.c +46 -0
- data/ext/lzo1c_4.c +46 -0
- data/ext/lzo1c_5.c +46 -0
- data/ext/lzo1c_6.c +46 -0
- data/ext/lzo1c_7.c +46 -0
- data/ext/lzo1c_8.c +46 -0
- data/ext/lzo1c_9.c +46 -0
- data/ext/lzo1c_99.c +49 -0
- data/ext/lzo1c_9x.c +379 -0
- data/ext/lzo1c_cc.c +167 -0
- data/ext/lzo1c_cc.h +93 -0
- data/ext/lzo1c_d1.c +46 -0
- data/ext/lzo1c_d2.c +46 -0
- data/ext/lzo1c_rr.c +43 -0
- data/ext/lzo1c_xx.c +98 -0
- data/ext/lzo1f_1.c +312 -0
- data/ext/lzo1f_9x.c +345 -0
- data/ext/lzo1f_d.ch +223 -0
- data/ext/lzo1f_d1.c +46 -0
- data/ext/lzo1f_d2.c +46 -0
- data/ext/lzo1x_1.c +50 -0
- data/ext/lzo1x_1k.c +50 -0
- data/ext/lzo1x_1l.c +50 -0
- data/ext/lzo1x_1o.c +50 -0
- data/ext/lzo1x_9x.c +881 -0
- data/ext/lzo1x_c.ch +351 -0
- data/ext/lzo1x_d.ch +466 -0
- data/ext/lzo1x_d1.c +46 -0
- data/ext/lzo1x_d2.c +46 -0
- data/ext/lzo1x_d3.c +108 -0
- data/ext/lzo1x_o.c +45 -0
- data/ext/lzo1x_oo.ch +366 -0
- data/ext/lzo1y_1.c +50 -0
- data/ext/lzo1y_9x.c +42 -0
- data/ext/lzo1y_d1.c +46 -0
- data/ext/lzo1y_d2.c +46 -0
- data/ext/lzo1y_d3.c +45 -0
- data/ext/lzo1y_o.c +45 -0
- data/ext/lzo1z_9x.c +42 -0
- data/ext/lzo1z_d1.c +46 -0
- data/ext/lzo1z_d2.c +46 -0
- data/ext/lzo1z_d3.c +45 -0
- data/ext/lzo2a_9x.c +357 -0
- data/ext/lzo2a_d.ch +188 -0
- data/ext/lzo2a_d1.c +46 -0
- data/ext/lzo2a_d2.c +46 -0
- data/ext/lzo_conf.h +323 -0
- data/ext/lzo_crc.c +167 -0
- data/ext/lzo_dict.h +316 -0
- data/ext/lzo_dll.ch +64 -0
- data/ext/lzo_init.c +176 -0
- data/ext/lzo_mchw.ch +242 -0
- data/ext/lzo_ptr.c +92 -0
- data/ext/lzo_ptr.h +154 -0
- data/ext/lzo_str.c +71 -0
- data/ext/lzo_swd.ch +707 -0
- data/ext/lzo_util.c +165 -0
- data/ext/lzoruby.c +149 -0
- data/ext/miniacc.h +6553 -0
- data/ext/stats1a.h +137 -0
- data/ext/stats1b.h +142 -0
- data/ext/stats1c.h +61 -0
- metadata +180 -0
data/ext/lzo1b_9x.c
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/* lzo1b_9x.c -- implementation of the LZO1B-999 compression 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
|
+
#include "config1b.h"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/***********************************************************************
|
|
45
|
+
//
|
|
46
|
+
************************************************************************/
|
|
47
|
+
|
|
48
|
+
#define N 0xffffL /* size of ring buffer */
|
|
49
|
+
#define THRESHOLD 2 /* lower limit for match length */
|
|
50
|
+
#define F 2048 /* upper limit for match length */
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
#define LZO1B
|
|
54
|
+
#define LZO_COMPRESS_T lzo1b_999_t
|
|
55
|
+
#define lzo_swd_t lzo1b_999_swd_t
|
|
56
|
+
#include "lzo_mchw.ch"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
/***********************************************************************
|
|
61
|
+
//
|
|
62
|
+
************************************************************************/
|
|
63
|
+
|
|
64
|
+
static lzo_bytep
|
|
65
|
+
code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
|
|
66
|
+
{
|
|
67
|
+
if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
|
|
68
|
+
{
|
|
69
|
+
assert(m_len >= M2_MIN_LEN);
|
|
70
|
+
assert(m_off >= M2_MIN_OFFSET);
|
|
71
|
+
|
|
72
|
+
m_off -= M2_MIN_OFFSET;
|
|
73
|
+
/* code match len + low offset bits */
|
|
74
|
+
*op++ = LZO_BYTE(((m_len - (M2_MIN_LEN - 2)) << M2O_BITS) |
|
|
75
|
+
(m_off & M2O_MASK));
|
|
76
|
+
/* code high offset bits */
|
|
77
|
+
*op++ = LZO_BYTE(m_off >> M2O_BITS);
|
|
78
|
+
c->m2_m++;
|
|
79
|
+
}
|
|
80
|
+
else
|
|
81
|
+
{
|
|
82
|
+
assert(m_len >= M3_MIN_LEN);
|
|
83
|
+
assert(m_off <= M3_MAX_OFFSET);
|
|
84
|
+
|
|
85
|
+
m_off -= M3_MIN_OFFSET - M3_EOF_OFFSET;
|
|
86
|
+
/* code match len */
|
|
87
|
+
if (m_len <= M3_MAX_LEN)
|
|
88
|
+
*op++ = LZO_BYTE(M3_MARKER | (m_len - (M3_MIN_LEN - 1)));
|
|
89
|
+
else
|
|
90
|
+
{
|
|
91
|
+
assert(m_len >= M4_MIN_LEN);
|
|
92
|
+
/* code M4 match len flag */
|
|
93
|
+
*op++ = M4_MARKER;
|
|
94
|
+
/* code match len */
|
|
95
|
+
m_len -= M4_MIN_LEN - 1;
|
|
96
|
+
while (m_len > 255)
|
|
97
|
+
{
|
|
98
|
+
m_len -= 255;
|
|
99
|
+
*op++ = 0;
|
|
100
|
+
}
|
|
101
|
+
assert(m_len > 0);
|
|
102
|
+
*op++ = LZO_BYTE(m_len);
|
|
103
|
+
}
|
|
104
|
+
/* code low offset bits */
|
|
105
|
+
*op++ = LZO_BYTE(m_off & M3O_MASK);
|
|
106
|
+
/* code high offset bits */
|
|
107
|
+
*op++ = LZO_BYTE(m_off >> M3O_BITS);
|
|
108
|
+
|
|
109
|
+
c->r1_m_len = 0;
|
|
110
|
+
c->m3_m++;
|
|
111
|
+
}
|
|
112
|
+
return op;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
/***********************************************************************
|
|
117
|
+
// this is a public function, but there is no prototype in a header file
|
|
118
|
+
************************************************************************/
|
|
119
|
+
|
|
120
|
+
LZO_EXTERN(int)
|
|
121
|
+
lzo1b_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
|
|
122
|
+
lzo_bytep out, lzo_uintp out_len,
|
|
123
|
+
lzo_voidp wrkmem,
|
|
124
|
+
lzo_callback_p cb,
|
|
125
|
+
lzo_uint max_chain );
|
|
126
|
+
|
|
127
|
+
LZO_PUBLIC(int)
|
|
128
|
+
lzo1b_999_compress_callback ( const lzo_bytep in , lzo_uint in_len,
|
|
129
|
+
lzo_bytep out, lzo_uintp out_len,
|
|
130
|
+
lzo_voidp wrkmem,
|
|
131
|
+
lzo_callback_p cb,
|
|
132
|
+
lzo_uint max_chain )
|
|
133
|
+
{
|
|
134
|
+
lzo_bytep op;
|
|
135
|
+
const lzo_bytep ii;
|
|
136
|
+
lzo_uint lit;
|
|
137
|
+
lzo_uint m_len, m_off;
|
|
138
|
+
LZO_COMPRESS_T cc;
|
|
139
|
+
LZO_COMPRESS_T * const c = &cc;
|
|
140
|
+
lzo_swd_p const swd = (lzo_swd_p) wrkmem;
|
|
141
|
+
int r;
|
|
142
|
+
|
|
143
|
+
/* sanity check */
|
|
144
|
+
LZO_COMPILE_TIME_ASSERT(LZO1B_999_MEM_COMPRESS >= SIZEOF_LZO_SWD_T)
|
|
145
|
+
|
|
146
|
+
c->init = 0;
|
|
147
|
+
c->ip = c->in = in;
|
|
148
|
+
c->in_end = in + in_len;
|
|
149
|
+
c->cb = cb;
|
|
150
|
+
c->r1_r = c->m3_r = c->m2_m = c->m3_m = 0;
|
|
151
|
+
|
|
152
|
+
op = out;
|
|
153
|
+
ii = c->ip; /* point to start of literal run */
|
|
154
|
+
lit = 0;
|
|
155
|
+
c->r1_m_len = 0;
|
|
156
|
+
|
|
157
|
+
r = init_match(c,swd,NULL,0,0);
|
|
158
|
+
if (r != 0)
|
|
159
|
+
return r;
|
|
160
|
+
if (max_chain > 0)
|
|
161
|
+
swd->max_chain = max_chain;
|
|
162
|
+
|
|
163
|
+
r = find_match(c,swd,0,0);
|
|
164
|
+
if (r != 0)
|
|
165
|
+
return r;
|
|
166
|
+
while (c->look > 0)
|
|
167
|
+
{
|
|
168
|
+
int lazy_match_min_gain = -1;
|
|
169
|
+
lzo_uint ahead = 0;
|
|
170
|
+
|
|
171
|
+
m_len = c->m_len;
|
|
172
|
+
m_off = c->m_off;
|
|
173
|
+
|
|
174
|
+
#if 0
|
|
175
|
+
printf("%5ld: %5d len:%3d off:%5d\n", (c->ip-c->look)-in, c->look,
|
|
176
|
+
m_len, m_off);
|
|
177
|
+
#endif
|
|
178
|
+
|
|
179
|
+
assert(c->ip - c->look >= in);
|
|
180
|
+
if (lit == 0)
|
|
181
|
+
ii = c->ip - c->look;
|
|
182
|
+
assert(ii + lit == c->ip - c->look);
|
|
183
|
+
assert(swd->b_char == *(c->ip - c->look));
|
|
184
|
+
|
|
185
|
+
if ((m_len < M2_MIN_LEN) ||
|
|
186
|
+
(m_len < M3_MIN_LEN && m_off > M2_MAX_OFFSET))
|
|
187
|
+
{
|
|
188
|
+
m_len = 0;
|
|
189
|
+
}
|
|
190
|
+
else
|
|
191
|
+
{
|
|
192
|
+
assert(c->ip - c->look - m_off >= in);
|
|
193
|
+
assert(c->ip - c->look - m_off + m_len < c->ip);
|
|
194
|
+
assert(lzo_memcmp(c->ip - c->look, c->ip - c->look - m_off,
|
|
195
|
+
m_len) == 0);
|
|
196
|
+
|
|
197
|
+
if (lit > 0)
|
|
198
|
+
{
|
|
199
|
+
/* we have a current literal run: do not try a lazy match,
|
|
200
|
+
if the literal could be coded into a r1 match */
|
|
201
|
+
if (lit == 1 && c->r1_m_len == M2_MIN_LEN)
|
|
202
|
+
lazy_match_min_gain = -1;
|
|
203
|
+
else
|
|
204
|
+
lazy_match_min_gain = 1;
|
|
205
|
+
|
|
206
|
+
#if (M2_MIN_LEN == 2)
|
|
207
|
+
if (m_len == 2)
|
|
208
|
+
{
|
|
209
|
+
/* don't code a match of len 2 if we have to
|
|
210
|
+
code a literal run. Code a literal instead. */
|
|
211
|
+
m_len = 0;
|
|
212
|
+
}
|
|
213
|
+
#endif
|
|
214
|
+
#if (M2_MIN_LEN == M3_MIN_LEN)
|
|
215
|
+
if (m_len == M2_MIN_LEN && m_off > M2_MAX_OFFSET)
|
|
216
|
+
{
|
|
217
|
+
/* don't code a M3 match of len 3 if we have to
|
|
218
|
+
code a literal run. Code a literal instead. */
|
|
219
|
+
m_len = 0;
|
|
220
|
+
}
|
|
221
|
+
#endif
|
|
222
|
+
}
|
|
223
|
+
else
|
|
224
|
+
{
|
|
225
|
+
/* no current literal run: only try a lazy match,
|
|
226
|
+
if the literal could be coded into a r1 match */
|
|
227
|
+
if (c->r1_m_len == M2_MIN_LEN)
|
|
228
|
+
lazy_match_min_gain = 0;
|
|
229
|
+
else
|
|
230
|
+
lazy_match_min_gain = -1;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
/* try a lazy match */
|
|
236
|
+
if (m_len == 0)
|
|
237
|
+
lazy_match_min_gain = -1;
|
|
238
|
+
if (lazy_match_min_gain >= 0 && c->look > m_len)
|
|
239
|
+
{
|
|
240
|
+
assert(m_len > 0);
|
|
241
|
+
|
|
242
|
+
r = find_match(c,swd,1,0);
|
|
243
|
+
assert(r == 0);
|
|
244
|
+
assert(c->look > 0);
|
|
245
|
+
|
|
246
|
+
if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET &&
|
|
247
|
+
c->m_off > M2_MAX_OFFSET)
|
|
248
|
+
lazy_match_min_gain += 1;
|
|
249
|
+
|
|
250
|
+
if (c->m_len >= m_len + lazy_match_min_gain)
|
|
251
|
+
{
|
|
252
|
+
c->lazy++;
|
|
253
|
+
#if !defined(NDEBUG)
|
|
254
|
+
m_len = c->m_len;
|
|
255
|
+
m_off = c->m_off;
|
|
256
|
+
assert(lzo_memcmp(c->ip - c->look, c->ip - c->look - m_off,
|
|
257
|
+
m_len) == 0);
|
|
258
|
+
#endif
|
|
259
|
+
lit++;
|
|
260
|
+
assert(ii + lit == c->ip - c->look);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
else
|
|
264
|
+
{
|
|
265
|
+
ahead = 1;
|
|
266
|
+
assert(ii + lit + 1 == c->ip - c->look);
|
|
267
|
+
}
|
|
268
|
+
assert(m_len > 0);
|
|
269
|
+
}
|
|
270
|
+
assert(ii + lit + ahead == c->ip - c->look);
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
if (m_len == 0)
|
|
274
|
+
{
|
|
275
|
+
/* a literal */
|
|
276
|
+
lit++;
|
|
277
|
+
r = find_match(c,swd,1,0);
|
|
278
|
+
assert(r == 0);
|
|
279
|
+
}
|
|
280
|
+
else
|
|
281
|
+
{
|
|
282
|
+
/* 1 - store run */
|
|
283
|
+
if (lit > 0)
|
|
284
|
+
{
|
|
285
|
+
/* code current literal run */
|
|
286
|
+
if (lit == 1 && c->r1_m_len == M2_MIN_LEN)
|
|
287
|
+
{
|
|
288
|
+
/* Code a context sensitive R1 match. */
|
|
289
|
+
assert((op[-2] >> M2O_BITS) == (M2_MARKER >> M2O_BITS));
|
|
290
|
+
op[-2] &= M2O_MASK;
|
|
291
|
+
assert((op[-2] >> M2O_BITS) == 0);
|
|
292
|
+
/* copy 1 literal */
|
|
293
|
+
*op++ = *ii++;
|
|
294
|
+
assert(ii + ahead == c->ip - c->look);
|
|
295
|
+
c->r1_r++;
|
|
296
|
+
}
|
|
297
|
+
else
|
|
298
|
+
{
|
|
299
|
+
op = STORE_RUN(op,ii,lit);
|
|
300
|
+
}
|
|
301
|
+
if (lit < R0FAST)
|
|
302
|
+
c->r1_m_len = m_len;
|
|
303
|
+
else
|
|
304
|
+
c->r1_m_len = 0;
|
|
305
|
+
lit = 0;
|
|
306
|
+
}
|
|
307
|
+
else
|
|
308
|
+
c->r1_m_len = 0;
|
|
309
|
+
|
|
310
|
+
/* 2 - code match */
|
|
311
|
+
op = code_match(c,op,m_len,m_off);
|
|
312
|
+
r = find_match(c,swd,m_len,1+ahead);
|
|
313
|
+
assert(r == 0);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
c->codesize = pd(op, out);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
/* store final run */
|
|
321
|
+
if (lit > 0)
|
|
322
|
+
op = STORE_RUN(op,ii,lit);
|
|
323
|
+
|
|
324
|
+
#if defined(LZO_EOF_CODE)
|
|
325
|
+
*op++ = M3_MARKER | 1;
|
|
326
|
+
*op++ = 0;
|
|
327
|
+
*op++ = 0;
|
|
328
|
+
#endif
|
|
329
|
+
|
|
330
|
+
c->codesize = pd(op, out);
|
|
331
|
+
assert(c->textsize == in_len);
|
|
332
|
+
|
|
333
|
+
*out_len = pd(op, out);
|
|
334
|
+
|
|
335
|
+
if (c->cb && c->cb->nprogress)
|
|
336
|
+
(*c->cb->nprogress)(c->cb, c->textsize, c->codesize, 0);
|
|
337
|
+
|
|
338
|
+
#if 0
|
|
339
|
+
printf("%ld %ld -> %ld: %ld %ld %ld %ld %ld\n",
|
|
340
|
+
(long) c->textsize, (long)in_len, (long) c->codesize,
|
|
341
|
+
c->r1_r, c->m3_r, c->m2_m, c->m3_m, c->lazy);
|
|
342
|
+
#endif
|
|
343
|
+
return LZO_E_OK;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
/***********************************************************************
|
|
349
|
+
//
|
|
350
|
+
************************************************************************/
|
|
351
|
+
|
|
352
|
+
LZO_PUBLIC(int)
|
|
353
|
+
lzo1b_999_compress ( const lzo_bytep in , lzo_uint in_len,
|
|
354
|
+
lzo_bytep out, lzo_uintp out_len,
|
|
355
|
+
lzo_voidp wrkmem )
|
|
356
|
+
{
|
|
357
|
+
return lzo1b_999_compress_callback(in,in_len,out,out_len,wrkmem,
|
|
358
|
+
(lzo_callback_p) 0, 0);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
/*
|
|
363
|
+
vi:ts=4:et
|
|
364
|
+
*/
|
|
365
|
+
|
data/ext/lzo1b_c.ch
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/* lzo1b_c.ch -- implementation of the LZO1B compression 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
|
+
/***********************************************************************
|
|
43
|
+
//
|
|
44
|
+
************************************************************************/
|
|
45
|
+
|
|
46
|
+
#if !defined(LZO_HAVE_R1) && !defined(LZO_NO_R1)
|
|
47
|
+
# define LZO_HAVE_R1
|
|
48
|
+
#endif
|
|
49
|
+
|
|
50
|
+
#if !defined(LZO_HAVE_M3) && !defined(LZO_NO_M3)
|
|
51
|
+
# if (M3O_BITS < 8)
|
|
52
|
+
# define LZO_HAVE_M3
|
|
53
|
+
# endif
|
|
54
|
+
#endif
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
#define MI
|
|
58
|
+
#define SI MI
|
|
59
|
+
#if (DD_BITS > 0)
|
|
60
|
+
#define DI ++ii; DVAL_NEXT(dv,ii); UPDATE_D(dict,drun,dv,ii,in); MI
|
|
61
|
+
#define XI assert(ii < ip); ii = ip; DVAL_FIRST(dv,(ip));
|
|
62
|
+
#else
|
|
63
|
+
#define DI ++ii; DINDEX1(dindex,ii); UPDATE_I(dict,0,dindex,ii,in); MI
|
|
64
|
+
#define XI assert(ii < ip); ii = ip;
|
|
65
|
+
#endif
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
/***********************************************************************
|
|
69
|
+
// compress a block of data.
|
|
70
|
+
//
|
|
71
|
+
// I really apologize for this spaghetti code.
|
|
72
|
+
************************************************************************/
|
|
73
|
+
|
|
74
|
+
LZO_PRIVATE(int)
|
|
75
|
+
do_compress ( const lzo_bytep in , lzo_uint in_len,
|
|
76
|
+
lzo_bytep out, lzo_uintp out_len,
|
|
77
|
+
lzo_voidp wrkmem )
|
|
78
|
+
{
|
|
79
|
+
register const lzo_bytep ip;
|
|
80
|
+
#if (DD_BITS > 0)
|
|
81
|
+
#if defined(__LZO_HASH_INCREMENTAL)
|
|
82
|
+
lzo_xint dv;
|
|
83
|
+
#endif
|
|
84
|
+
unsigned drun = 0;
|
|
85
|
+
#endif
|
|
86
|
+
lzo_bytep op;
|
|
87
|
+
const lzo_bytep const in_end = in + in_len;
|
|
88
|
+
const lzo_bytep const ip_end = in + in_len - MIN_LOOKAHEAD;
|
|
89
|
+
const lzo_bytep ii;
|
|
90
|
+
#if defined(LZO_HAVE_R1)
|
|
91
|
+
const lzo_bytep r1 = ip_end; /* pointer for R1 match (none yet) */
|
|
92
|
+
#endif
|
|
93
|
+
#if defined(LZO_HAVE_M3)
|
|
94
|
+
lzo_bytep m3 = out + 1; /* pointer after last m3/m4 match */
|
|
95
|
+
#endif
|
|
96
|
+
|
|
97
|
+
lzo_dict_p const dict = (lzo_dict_p) wrkmem;
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
#if defined(LZO_COLLECT_STATS)
|
|
101
|
+
lzo_stats->r_bits = R_BITS;
|
|
102
|
+
lzo_stats->m3o_bits = M3O_BITS;
|
|
103
|
+
lzo_stats->dd_bits = DD_BITS;
|
|
104
|
+
lzo_stats->clevel = CLEVEL;
|
|
105
|
+
lzo_stats->d_bits = D_BITS;
|
|
106
|
+
lzo_stats->min_lookahead = MIN_LOOKAHEAD;
|
|
107
|
+
lzo_stats->max_lookbehind = MAX_LOOKBEHIND;
|
|
108
|
+
lzo_stats->compress_id = LZO_CPP_MACRO_EXPAND(COMPRESS_ID);
|
|
109
|
+
#endif
|
|
110
|
+
|
|
111
|
+
/* init dictionary */
|
|
112
|
+
#if defined(LZO_DETERMINISTIC)
|
|
113
|
+
BZERO8_PTR(wrkmem,sizeof(lzo_dict_t),D_SIZE);
|
|
114
|
+
#endif
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
op = out;
|
|
118
|
+
ip = in;
|
|
119
|
+
ii = ip; /* point to start of current literal run */
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
#if (DD_BITS > 0)
|
|
123
|
+
DVAL_FIRST(dv,ip);
|
|
124
|
+
UPDATE_D(dict,drun,dv,ip,in);
|
|
125
|
+
ip++;
|
|
126
|
+
DVAL_NEXT(dv,ip);
|
|
127
|
+
#else
|
|
128
|
+
ip++;
|
|
129
|
+
#endif
|
|
130
|
+
|
|
131
|
+
assert(ip < ip_end);
|
|
132
|
+
for (;;)
|
|
133
|
+
{
|
|
134
|
+
const lzo_bytep m_pos;
|
|
135
|
+
#if !defined(NDEBUG)
|
|
136
|
+
const lzo_bytep m_pos_sav = NULL;
|
|
137
|
+
#endif
|
|
138
|
+
lzo_uint m_off;
|
|
139
|
+
#if (DD_BITS == 0)
|
|
140
|
+
lzo_uint dindex;
|
|
141
|
+
#endif
|
|
142
|
+
lzo_uint m_len;
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
/***********************************************************************
|
|
146
|
+
// search for a match
|
|
147
|
+
************************************************************************/
|
|
148
|
+
|
|
149
|
+
#if !defined(LZO_SEARCH_MATCH_INCLUDE_FILE)
|
|
150
|
+
# define LZO_SEARCH_MATCH_INCLUDE_FILE "lzo1b_sm.ch"
|
|
151
|
+
#endif
|
|
152
|
+
|
|
153
|
+
#include LZO_SEARCH_MATCH_INCLUDE_FILE
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
#if !defined(LZO_TEST_MATCH_INCLUDE_FILE)
|
|
157
|
+
# define LZO_TEST_MATCH_INCLUDE_FILE "lzo1b_tm.ch"
|
|
158
|
+
#endif
|
|
159
|
+
|
|
160
|
+
#include LZO_TEST_MATCH_INCLUDE_FILE
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
/***********************************************************************
|
|
165
|
+
// found a literal
|
|
166
|
+
************************************************************************/
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
/* a literal */
|
|
170
|
+
literal:
|
|
171
|
+
#if (DD_BITS == 0)
|
|
172
|
+
UPDATE_I(dict,0,dindex,ip,in);
|
|
173
|
+
#endif
|
|
174
|
+
if (++ip >= ip_end)
|
|
175
|
+
break;
|
|
176
|
+
#if (DD_BITS > 0)
|
|
177
|
+
DVAL_NEXT(dv,ip);
|
|
178
|
+
#endif
|
|
179
|
+
continue;
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
/***********************************************************************
|
|
184
|
+
// found a match
|
|
185
|
+
************************************************************************/
|
|
186
|
+
|
|
187
|
+
match:
|
|
188
|
+
#if (DD_BITS == 0)
|
|
189
|
+
UPDATE_I(dict,0,dindex,ip,in);
|
|
190
|
+
#endif
|
|
191
|
+
/* we have found a match of at least M2_MIN_LEN */
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
#if !defined(LZO_CODE_RUN_INCLUDE_FILE)
|
|
195
|
+
# define LZO_CODE_RUN_INCLUDE_FILE "lzo1b_cr.ch"
|
|
196
|
+
#endif
|
|
197
|
+
|
|
198
|
+
#include LZO_CODE_RUN_INCLUDE_FILE
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
/* ii now points to the start of the current match */
|
|
202
|
+
assert(ii == ip);
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
/***********************************************************************
|
|
206
|
+
// code the match
|
|
207
|
+
************************************************************************/
|
|
208
|
+
|
|
209
|
+
#if !defined(LZO_CODE_MATCH_INCLUDE_FILE)
|
|
210
|
+
# define LZO_CODE_MATCH_INCLUDE_FILE "lzo1b_cm.ch"
|
|
211
|
+
#endif
|
|
212
|
+
|
|
213
|
+
#include LZO_CODE_MATCH_INCLUDE_FILE
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
/* ii now points to the start of the next literal run */
|
|
217
|
+
assert(ii == ip);
|
|
218
|
+
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
/***********************************************************************
|
|
223
|
+
// end of block
|
|
224
|
+
************************************************************************/
|
|
225
|
+
|
|
226
|
+
assert(ip <= in_end);
|
|
227
|
+
|
|
228
|
+
#if defined(LZO_COLLECT_STATS)
|
|
229
|
+
{
|
|
230
|
+
lzo_uint i;
|
|
231
|
+
const lzo_bytep p;
|
|
232
|
+
|
|
233
|
+
for (i = 0; i < D_SIZE; i++)
|
|
234
|
+
{
|
|
235
|
+
p = dict[i];
|
|
236
|
+
if (BOUNDS_CHECKING_OFF_IN_EXPR(p == NULL || p < in || p > in_end))
|
|
237
|
+
lzo_stats->unused_dict_entries++;
|
|
238
|
+
}
|
|
239
|
+
lzo_stats->unused_dict_entries_percent =
|
|
240
|
+
100.0 * lzo_stats->unused_dict_entries / D_SIZE;
|
|
241
|
+
}
|
|
242
|
+
#endif
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
#if defined(LZO_RETURN_IF_NOT_COMPRESSIBLE)
|
|
246
|
+
/* return if op == out to indicate that we
|
|
247
|
+
* couldn't compress and didn't copy anything.
|
|
248
|
+
*/
|
|
249
|
+
if (op == out)
|
|
250
|
+
{
|
|
251
|
+
*out_len = 0;
|
|
252
|
+
return LZO_E_NOT_COMPRESSIBLE;
|
|
253
|
+
}
|
|
254
|
+
#endif
|
|
255
|
+
|
|
256
|
+
/* store the final literal run */
|
|
257
|
+
if (pd(in_end,ii) > 0)
|
|
258
|
+
{
|
|
259
|
+
lzo_uint t = pd(in_end,ii);
|
|
260
|
+
op = STORE_RUN(op,ii,t);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
*out_len = pd(op, out);
|
|
264
|
+
return LZO_E_OK; /* compression went ok */
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
/*
|
|
269
|
+
vi:ts=4:et
|
|
270
|
+
*/
|