zopfli 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/main.yml +35 -0
- data/.github/workflows/publish.yml +34 -0
- data/.gitmodules +1 -1
- data/Gemfile +4 -0
- data/README.md +6 -1
- data/Rakefile +14 -10
- data/ext/extconf.rb +36 -32
- data/ext/zopfli.c +52 -20
- data/lib/zopfli/version.rb +1 -1
- data/smoke.sh +9 -0
- data/test/test_helper.rb +7 -0
- data/test/zopfli_test.rb +63 -0
- data/vendor/zopfli/src/zopfli/blocksplitter.c +41 -53
- data/vendor/zopfli/src/zopfli/blocksplitter.h +2 -6
- data/vendor/zopfli/src/zopfli/cache.c +6 -0
- data/vendor/zopfli/src/zopfli/deflate.c +613 -381
- data/vendor/zopfli/src/zopfli/deflate.h +8 -2
- data/vendor/zopfli/src/zopfli/gzip_container.c +54 -47
- data/vendor/zopfli/src/zopfli/hash.c +18 -10
- data/vendor/zopfli/src/zopfli/hash.h +10 -7
- data/vendor/zopfli/src/zopfli/katajainen.c +73 -62
- data/vendor/zopfli/src/zopfli/katajainen.h +1 -1
- data/vendor/zopfli/src/zopfli/lz77.c +190 -42
- data/vendor/zopfli/src/zopfli/lz77.h +39 -23
- data/vendor/zopfli/src/zopfli/squeeze.c +75 -61
- data/vendor/zopfli/src/zopfli/squeeze.h +1 -0
- data/vendor/zopfli/src/zopfli/symbols.h +239 -0
- data/vendor/zopfli/src/zopfli/util.c +0 -178
- data/vendor/zopfli/src/zopfli/util.h +6 -23
- data/vendor/zopfli/src/zopfli/zlib_container.c +1 -1
- data/vendor/zopfli/src/zopfli/zopfli.h +1 -4
- data/vendor/zopfli/src/zopfli/zopfli_bin.c +31 -15
- data/zopfli.gemspec +12 -32
- metadata +20 -68
- data/test/fixtures/alice29.txt +0 -3609
- data/test/test_zopfli_deflate.rb +0 -47
- data/vendor/zopfli/CONTRIBUTORS +0 -7
- data/vendor/zopfli/README +0 -32
- data/vendor/zopfli/README.zopflipng +0 -35
- data/vendor/zopfli/makefile +0 -37
- data/vendor/zopfli/src/zopflipng/lodepng/lodepng.cpp +0 -6253
- data/vendor/zopfli/src/zopflipng/lodepng/lodepng.h +0 -1705
- data/vendor/zopfli/src/zopflipng/lodepng/lodepng_util.cpp +0 -656
- data/vendor/zopfli/src/zopflipng/lodepng/lodepng_util.h +0 -151
- data/vendor/zopfli/src/zopflipng/zopflipng_bin.cc +0 -407
- data/vendor/zopfli/src/zopflipng/zopflipng_lib.cc +0 -376
- data/vendor/zopfli/src/zopflipng/zopflipng_lib.h +0 -79
@@ -0,0 +1,239 @@
|
|
1
|
+
/*
|
2
|
+
Copyright 2016 Google Inc. All Rights Reserved.
|
3
|
+
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
See the License for the specific language governing permissions and
|
14
|
+
limitations under the License.
|
15
|
+
|
16
|
+
Author: lode.vandevenne@gmail.com (Lode Vandevenne)
|
17
|
+
Author: jyrki.alakuijala@gmail.com (Jyrki Alakuijala)
|
18
|
+
*/
|
19
|
+
|
20
|
+
/*
|
21
|
+
Utilities for using the lz77 symbols of the deflate spec.
|
22
|
+
*/
|
23
|
+
|
24
|
+
#ifndef ZOPFLI_SYMBOLS_H_
|
25
|
+
#define ZOPFLI_SYMBOLS_H_
|
26
|
+
|
27
|
+
/* __has_builtin available in clang */
|
28
|
+
#ifdef __has_builtin
|
29
|
+
# if __has_builtin(__builtin_clz)
|
30
|
+
# define ZOPFLI_HAS_BUILTIN_CLZ
|
31
|
+
# endif
|
32
|
+
/* __builtin_clz available beginning with GCC 3.4 */
|
33
|
+
#elif __GNUC__ * 100 + __GNUC_MINOR__ >= 304
|
34
|
+
# define ZOPFLI_HAS_BUILTIN_CLZ
|
35
|
+
#endif
|
36
|
+
|
37
|
+
/* Gets the amount of extra bits for the given dist, cfr. the DEFLATE spec. */
|
38
|
+
static int ZopfliGetDistExtraBits(int dist) {
|
39
|
+
#ifdef ZOPFLI_HAS_BUILTIN_CLZ
|
40
|
+
if (dist < 5) return 0;
|
41
|
+
return (31 ^ __builtin_clz(dist - 1)) - 1; /* log2(dist - 1) - 1 */
|
42
|
+
#else
|
43
|
+
if (dist < 5) return 0;
|
44
|
+
else if (dist < 9) return 1;
|
45
|
+
else if (dist < 17) return 2;
|
46
|
+
else if (dist < 33) return 3;
|
47
|
+
else if (dist < 65) return 4;
|
48
|
+
else if (dist < 129) return 5;
|
49
|
+
else if (dist < 257) return 6;
|
50
|
+
else if (dist < 513) return 7;
|
51
|
+
else if (dist < 1025) return 8;
|
52
|
+
else if (dist < 2049) return 9;
|
53
|
+
else if (dist < 4097) return 10;
|
54
|
+
else if (dist < 8193) return 11;
|
55
|
+
else if (dist < 16385) return 12;
|
56
|
+
else return 13;
|
57
|
+
#endif
|
58
|
+
}
|
59
|
+
|
60
|
+
/* Gets value of the extra bits for the given dist, cfr. the DEFLATE spec. */
|
61
|
+
static int ZopfliGetDistExtraBitsValue(int dist) {
|
62
|
+
#ifdef ZOPFLI_HAS_BUILTIN_CLZ
|
63
|
+
if (dist < 5) {
|
64
|
+
return 0;
|
65
|
+
} else {
|
66
|
+
int l = 31 ^ __builtin_clz(dist - 1); /* log2(dist - 1) */
|
67
|
+
return (dist - (1 + (1 << l))) & ((1 << (l - 1)) - 1);
|
68
|
+
}
|
69
|
+
#else
|
70
|
+
if (dist < 5) return 0;
|
71
|
+
else if (dist < 9) return (dist - 5) & 1;
|
72
|
+
else if (dist < 17) return (dist - 9) & 3;
|
73
|
+
else if (dist < 33) return (dist - 17) & 7;
|
74
|
+
else if (dist < 65) return (dist - 33) & 15;
|
75
|
+
else if (dist < 129) return (dist - 65) & 31;
|
76
|
+
else if (dist < 257) return (dist - 129) & 63;
|
77
|
+
else if (dist < 513) return (dist - 257) & 127;
|
78
|
+
else if (dist < 1025) return (dist - 513) & 255;
|
79
|
+
else if (dist < 2049) return (dist - 1025) & 511;
|
80
|
+
else if (dist < 4097) return (dist - 2049) & 1023;
|
81
|
+
else if (dist < 8193) return (dist - 4097) & 2047;
|
82
|
+
else if (dist < 16385) return (dist - 8193) & 4095;
|
83
|
+
else return (dist - 16385) & 8191;
|
84
|
+
#endif
|
85
|
+
}
|
86
|
+
|
87
|
+
/* Gets the symbol for the given dist, cfr. the DEFLATE spec. */
|
88
|
+
static int ZopfliGetDistSymbol(int dist) {
|
89
|
+
#ifdef ZOPFLI_HAS_BUILTIN_CLZ
|
90
|
+
if (dist < 5) {
|
91
|
+
return dist - 1;
|
92
|
+
} else {
|
93
|
+
int l = (31 ^ __builtin_clz(dist - 1)); /* log2(dist - 1) */
|
94
|
+
int r = ((dist - 1) >> (l - 1)) & 1;
|
95
|
+
return l * 2 + r;
|
96
|
+
}
|
97
|
+
#else
|
98
|
+
if (dist < 193) {
|
99
|
+
if (dist < 13) { /* dist 0..13. */
|
100
|
+
if (dist < 5) return dist - 1;
|
101
|
+
else if (dist < 7) return 4;
|
102
|
+
else if (dist < 9) return 5;
|
103
|
+
else return 6;
|
104
|
+
} else { /* dist 13..193. */
|
105
|
+
if (dist < 17) return 7;
|
106
|
+
else if (dist < 25) return 8;
|
107
|
+
else if (dist < 33) return 9;
|
108
|
+
else if (dist < 49) return 10;
|
109
|
+
else if (dist < 65) return 11;
|
110
|
+
else if (dist < 97) return 12;
|
111
|
+
else if (dist < 129) return 13;
|
112
|
+
else return 14;
|
113
|
+
}
|
114
|
+
} else {
|
115
|
+
if (dist < 2049) { /* dist 193..2049. */
|
116
|
+
if (dist < 257) return 15;
|
117
|
+
else if (dist < 385) return 16;
|
118
|
+
else if (dist < 513) return 17;
|
119
|
+
else if (dist < 769) return 18;
|
120
|
+
else if (dist < 1025) return 19;
|
121
|
+
else if (dist < 1537) return 20;
|
122
|
+
else return 21;
|
123
|
+
} else { /* dist 2049..32768. */
|
124
|
+
if (dist < 3073) return 22;
|
125
|
+
else if (dist < 4097) return 23;
|
126
|
+
else if (dist < 6145) return 24;
|
127
|
+
else if (dist < 8193) return 25;
|
128
|
+
else if (dist < 12289) return 26;
|
129
|
+
else if (dist < 16385) return 27;
|
130
|
+
else if (dist < 24577) return 28;
|
131
|
+
else return 29;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
#endif
|
135
|
+
}
|
136
|
+
|
137
|
+
/* Gets the amount of extra bits for the given length, cfr. the DEFLATE spec. */
|
138
|
+
static int ZopfliGetLengthExtraBits(int l) {
|
139
|
+
static const int table[259] = {
|
140
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
|
141
|
+
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
142
|
+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
143
|
+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
144
|
+
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
145
|
+
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
146
|
+
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
147
|
+
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
148
|
+
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
149
|
+
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
150
|
+
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
151
|
+
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
152
|
+
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
153
|
+
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
154
|
+
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
155
|
+
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0
|
156
|
+
};
|
157
|
+
return table[l];
|
158
|
+
}
|
159
|
+
|
160
|
+
/* Gets value of the extra bits for the given length, cfr. the DEFLATE spec. */
|
161
|
+
static int ZopfliGetLengthExtraBitsValue(int l) {
|
162
|
+
static const int table[259] = {
|
163
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 0,
|
164
|
+
1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5,
|
165
|
+
6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6,
|
166
|
+
7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
|
167
|
+
13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2,
|
168
|
+
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
169
|
+
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
|
170
|
+
29, 30, 31, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
171
|
+
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 0, 1, 2, 3, 4, 5, 6,
|
172
|
+
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
|
173
|
+
27, 28, 29, 30, 31, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
174
|
+
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 0
|
175
|
+
};
|
176
|
+
return table[l];
|
177
|
+
}
|
178
|
+
|
179
|
+
/*
|
180
|
+
Gets the symbol for the given length, cfr. the DEFLATE spec.
|
181
|
+
Returns the symbol in the range [257-285] (inclusive)
|
182
|
+
*/
|
183
|
+
static int ZopfliGetLengthSymbol(int l) {
|
184
|
+
static const int table[259] = {
|
185
|
+
0, 0, 0, 257, 258, 259, 260, 261, 262, 263, 264,
|
186
|
+
265, 265, 266, 266, 267, 267, 268, 268,
|
187
|
+
269, 269, 269, 269, 270, 270, 270, 270,
|
188
|
+
271, 271, 271, 271, 272, 272, 272, 272,
|
189
|
+
273, 273, 273, 273, 273, 273, 273, 273,
|
190
|
+
274, 274, 274, 274, 274, 274, 274, 274,
|
191
|
+
275, 275, 275, 275, 275, 275, 275, 275,
|
192
|
+
276, 276, 276, 276, 276, 276, 276, 276,
|
193
|
+
277, 277, 277, 277, 277, 277, 277, 277,
|
194
|
+
277, 277, 277, 277, 277, 277, 277, 277,
|
195
|
+
278, 278, 278, 278, 278, 278, 278, 278,
|
196
|
+
278, 278, 278, 278, 278, 278, 278, 278,
|
197
|
+
279, 279, 279, 279, 279, 279, 279, 279,
|
198
|
+
279, 279, 279, 279, 279, 279, 279, 279,
|
199
|
+
280, 280, 280, 280, 280, 280, 280, 280,
|
200
|
+
280, 280, 280, 280, 280, 280, 280, 280,
|
201
|
+
281, 281, 281, 281, 281, 281, 281, 281,
|
202
|
+
281, 281, 281, 281, 281, 281, 281, 281,
|
203
|
+
281, 281, 281, 281, 281, 281, 281, 281,
|
204
|
+
281, 281, 281, 281, 281, 281, 281, 281,
|
205
|
+
282, 282, 282, 282, 282, 282, 282, 282,
|
206
|
+
282, 282, 282, 282, 282, 282, 282, 282,
|
207
|
+
282, 282, 282, 282, 282, 282, 282, 282,
|
208
|
+
282, 282, 282, 282, 282, 282, 282, 282,
|
209
|
+
283, 283, 283, 283, 283, 283, 283, 283,
|
210
|
+
283, 283, 283, 283, 283, 283, 283, 283,
|
211
|
+
283, 283, 283, 283, 283, 283, 283, 283,
|
212
|
+
283, 283, 283, 283, 283, 283, 283, 283,
|
213
|
+
284, 284, 284, 284, 284, 284, 284, 284,
|
214
|
+
284, 284, 284, 284, 284, 284, 284, 284,
|
215
|
+
284, 284, 284, 284, 284, 284, 284, 284,
|
216
|
+
284, 284, 284, 284, 284, 284, 284, 285
|
217
|
+
};
|
218
|
+
return table[l];
|
219
|
+
}
|
220
|
+
|
221
|
+
/* Gets the amount of extra bits for the given length symbol. */
|
222
|
+
static int ZopfliGetLengthSymbolExtraBits(int s) {
|
223
|
+
static const int table[29] = {
|
224
|
+
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
225
|
+
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0
|
226
|
+
};
|
227
|
+
return table[s - 257];
|
228
|
+
}
|
229
|
+
|
230
|
+
/* Gets the amount of extra bits for the given distance symbol. */
|
231
|
+
static int ZopfliGetDistSymbolExtraBits(int s) {
|
232
|
+
static const int table[30] = {
|
233
|
+
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8,
|
234
|
+
9, 9, 10, 10, 11, 11, 12, 12, 13, 13
|
235
|
+
};
|
236
|
+
return table[s];
|
237
|
+
}
|
238
|
+
|
239
|
+
#endif /* ZOPFLI_SYMBOLS_H_ */
|
@@ -25,184 +25,6 @@ Author: jyrki.alakuijala@gmail.com (Jyrki Alakuijala)
|
|
25
25
|
#include <stdio.h>
|
26
26
|
#include <stdlib.h>
|
27
27
|
|
28
|
-
int ZopfliGetDistExtraBits(int dist) {
|
29
|
-
#ifdef __GNUC__
|
30
|
-
if (dist < 5) return 0;
|
31
|
-
return (31 ^ __builtin_clz(dist - 1)) - 1; /* log2(dist - 1) - 1 */
|
32
|
-
#else
|
33
|
-
if (dist < 5) return 0;
|
34
|
-
else if (dist < 9) return 1;
|
35
|
-
else if (dist < 17) return 2;
|
36
|
-
else if (dist < 33) return 3;
|
37
|
-
else if (dist < 65) return 4;
|
38
|
-
else if (dist < 129) return 5;
|
39
|
-
else if (dist < 257) return 6;
|
40
|
-
else if (dist < 513) return 7;
|
41
|
-
else if (dist < 1025) return 8;
|
42
|
-
else if (dist < 2049) return 9;
|
43
|
-
else if (dist < 4097) return 10;
|
44
|
-
else if (dist < 8193) return 11;
|
45
|
-
else if (dist < 16385) return 12;
|
46
|
-
else return 13;
|
47
|
-
#endif
|
48
|
-
}
|
49
|
-
|
50
|
-
int ZopfliGetDistExtraBitsValue(int dist) {
|
51
|
-
#ifdef __GNUC__
|
52
|
-
if (dist < 5) {
|
53
|
-
return 0;
|
54
|
-
} else {
|
55
|
-
int l = 31 ^ __builtin_clz(dist - 1); /* log2(dist - 1) */
|
56
|
-
return (dist - (1 + (1 << l))) & ((1 << (l - 1)) - 1);
|
57
|
-
}
|
58
|
-
#else
|
59
|
-
if (dist < 5) return 0;
|
60
|
-
else if (dist < 9) return (dist - 5) & 1;
|
61
|
-
else if (dist < 17) return (dist - 9) & 3;
|
62
|
-
else if (dist < 33) return (dist - 17) & 7;
|
63
|
-
else if (dist < 65) return (dist - 33) & 15;
|
64
|
-
else if (dist < 129) return (dist - 65) & 31;
|
65
|
-
else if (dist < 257) return (dist - 129) & 63;
|
66
|
-
else if (dist < 513) return (dist - 257) & 127;
|
67
|
-
else if (dist < 1025) return (dist - 513) & 255;
|
68
|
-
else if (dist < 2049) return (dist - 1025) & 511;
|
69
|
-
else if (dist < 4097) return (dist - 2049) & 1023;
|
70
|
-
else if (dist < 8193) return (dist - 4097) & 2047;
|
71
|
-
else if (dist < 16385) return (dist - 8193) & 4095;
|
72
|
-
else return (dist - 16385) & 8191;
|
73
|
-
#endif
|
74
|
-
}
|
75
|
-
|
76
|
-
int ZopfliGetDistSymbol(int dist) {
|
77
|
-
#ifdef __GNUC__
|
78
|
-
if (dist < 5) {
|
79
|
-
return dist - 1;
|
80
|
-
} else {
|
81
|
-
int l = (31 ^ __builtin_clz(dist - 1)); /* log2(dist - 1) */
|
82
|
-
int r = ((dist - 1) >> (l - 1)) & 1;
|
83
|
-
return l * 2 + r;
|
84
|
-
}
|
85
|
-
#else
|
86
|
-
if (dist < 193) {
|
87
|
-
if (dist < 13) { /* dist 0..13. */
|
88
|
-
if (dist < 5) return dist - 1;
|
89
|
-
else if (dist < 7) return 4;
|
90
|
-
else if (dist < 9) return 5;
|
91
|
-
else return 6;
|
92
|
-
} else { /* dist 13..193. */
|
93
|
-
if (dist < 17) return 7;
|
94
|
-
else if (dist < 25) return 8;
|
95
|
-
else if (dist < 33) return 9;
|
96
|
-
else if (dist < 49) return 10;
|
97
|
-
else if (dist < 65) return 11;
|
98
|
-
else if (dist < 97) return 12;
|
99
|
-
else if (dist < 129) return 13;
|
100
|
-
else return 14;
|
101
|
-
}
|
102
|
-
} else {
|
103
|
-
if (dist < 2049) { /* dist 193..2049. */
|
104
|
-
if (dist < 257) return 15;
|
105
|
-
else if (dist < 385) return 16;
|
106
|
-
else if (dist < 513) return 17;
|
107
|
-
else if (dist < 769) return 18;
|
108
|
-
else if (dist < 1025) return 19;
|
109
|
-
else if (dist < 1537) return 20;
|
110
|
-
else return 21;
|
111
|
-
} else { /* dist 2049..32768. */
|
112
|
-
if (dist < 3073) return 22;
|
113
|
-
else if (dist < 4097) return 23;
|
114
|
-
else if (dist < 6145) return 24;
|
115
|
-
else if (dist < 8193) return 25;
|
116
|
-
else if (dist < 12289) return 26;
|
117
|
-
else if (dist < 16385) return 27;
|
118
|
-
else if (dist < 24577) return 28;
|
119
|
-
else return 29;
|
120
|
-
}
|
121
|
-
}
|
122
|
-
#endif
|
123
|
-
}
|
124
|
-
|
125
|
-
int ZopfliGetLengthExtraBits(int l) {
|
126
|
-
static const int table[259] = {
|
127
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
|
128
|
-
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
129
|
-
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
130
|
-
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
131
|
-
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
132
|
-
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
133
|
-
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
134
|
-
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
135
|
-
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
136
|
-
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
137
|
-
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
138
|
-
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
139
|
-
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
140
|
-
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
141
|
-
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
142
|
-
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0
|
143
|
-
};
|
144
|
-
return table[l];
|
145
|
-
}
|
146
|
-
|
147
|
-
int ZopfliGetLengthExtraBitsValue(int l) {
|
148
|
-
static const int table[259] = {
|
149
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 0,
|
150
|
-
1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5,
|
151
|
-
6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6,
|
152
|
-
7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
|
153
|
-
13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2,
|
154
|
-
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
155
|
-
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
|
156
|
-
29, 30, 31, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
157
|
-
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 0, 1, 2, 3, 4, 5, 6,
|
158
|
-
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
|
159
|
-
27, 28, 29, 30, 31, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
160
|
-
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 0
|
161
|
-
};
|
162
|
-
return table[l];
|
163
|
-
}
|
164
|
-
|
165
|
-
/*
|
166
|
-
Returns symbol in range [257-285] (inclusive).
|
167
|
-
*/
|
168
|
-
int ZopfliGetLengthSymbol(int l) {
|
169
|
-
static const int table[259] = {
|
170
|
-
0, 0, 0, 257, 258, 259, 260, 261, 262, 263, 264,
|
171
|
-
265, 265, 266, 266, 267, 267, 268, 268,
|
172
|
-
269, 269, 269, 269, 270, 270, 270, 270,
|
173
|
-
271, 271, 271, 271, 272, 272, 272, 272,
|
174
|
-
273, 273, 273, 273, 273, 273, 273, 273,
|
175
|
-
274, 274, 274, 274, 274, 274, 274, 274,
|
176
|
-
275, 275, 275, 275, 275, 275, 275, 275,
|
177
|
-
276, 276, 276, 276, 276, 276, 276, 276,
|
178
|
-
277, 277, 277, 277, 277, 277, 277, 277,
|
179
|
-
277, 277, 277, 277, 277, 277, 277, 277,
|
180
|
-
278, 278, 278, 278, 278, 278, 278, 278,
|
181
|
-
278, 278, 278, 278, 278, 278, 278, 278,
|
182
|
-
279, 279, 279, 279, 279, 279, 279, 279,
|
183
|
-
279, 279, 279, 279, 279, 279, 279, 279,
|
184
|
-
280, 280, 280, 280, 280, 280, 280, 280,
|
185
|
-
280, 280, 280, 280, 280, 280, 280, 280,
|
186
|
-
281, 281, 281, 281, 281, 281, 281, 281,
|
187
|
-
281, 281, 281, 281, 281, 281, 281, 281,
|
188
|
-
281, 281, 281, 281, 281, 281, 281, 281,
|
189
|
-
281, 281, 281, 281, 281, 281, 281, 281,
|
190
|
-
282, 282, 282, 282, 282, 282, 282, 282,
|
191
|
-
282, 282, 282, 282, 282, 282, 282, 282,
|
192
|
-
282, 282, 282, 282, 282, 282, 282, 282,
|
193
|
-
282, 282, 282, 282, 282, 282, 282, 282,
|
194
|
-
283, 283, 283, 283, 283, 283, 283, 283,
|
195
|
-
283, 283, 283, 283, 283, 283, 283, 283,
|
196
|
-
283, 283, 283, 283, 283, 283, 283, 283,
|
197
|
-
283, 283, 283, 283, 283, 283, 283, 283,
|
198
|
-
284, 284, 284, 284, 284, 284, 284, 284,
|
199
|
-
284, 284, 284, 284, 284, 284, 284, 284,
|
200
|
-
284, 284, 284, 284, 284, 284, 284, 284,
|
201
|
-
284, 284, 284, 284, 284, 284, 284, 285
|
202
|
-
};
|
203
|
-
return table[l];
|
204
|
-
}
|
205
|
-
|
206
28
|
void ZopfliInitOptions(ZopfliOptions* options) {
|
207
29
|
options->verbose = 0;
|
208
30
|
options->verbose_more = 0;
|
@@ -32,6 +32,10 @@ basic deflate specification values and generic program options.
|
|
32
32
|
#define ZOPFLI_MAX_MATCH 258
|
33
33
|
#define ZOPFLI_MIN_MATCH 3
|
34
34
|
|
35
|
+
/* Number of distinct literal/length and distance symbols in DEFLATE */
|
36
|
+
#define ZOPFLI_NUM_LL 288
|
37
|
+
#define ZOPFLI_NUM_D 32
|
38
|
+
|
35
39
|
/*
|
36
40
|
The window size for deflate. Must be a power of two. This should be 32768, the
|
37
41
|
maximum possible by the deflate spec. Anything less hurts compression more than
|
@@ -51,9 +55,9 @@ operating on huge files without exceeding memory, such as the 1GB wiki9 corpus.
|
|
51
55
|
The whole compression algorithm, including the smarter block splitting, will
|
52
56
|
be executed independently on each huge block.
|
53
57
|
Dividing into huge blocks hurts compression, but not much relative to the size.
|
54
|
-
Set
|
58
|
+
Set it to 0 to disable master blocks.
|
55
59
|
*/
|
56
|
-
#define ZOPFLI_MASTER_BLOCK_SIZE
|
60
|
+
#define ZOPFLI_MASTER_BLOCK_SIZE 1000000
|
57
61
|
|
58
62
|
/*
|
59
63
|
Used to initialize costs for example
|
@@ -116,27 +120,6 @@ varies from file to file.
|
|
116
120
|
*/
|
117
121
|
#define ZOPFLI_LAZY_MATCHING
|
118
122
|
|
119
|
-
/*
|
120
|
-
Gets the symbol for the given length, cfr. the DEFLATE spec.
|
121
|
-
Returns the symbol in the range [257-285] (inclusive)
|
122
|
-
*/
|
123
|
-
int ZopfliGetLengthSymbol(int l);
|
124
|
-
|
125
|
-
/* Gets the amount of extra bits for the given length, cfr. the DEFLATE spec. */
|
126
|
-
int ZopfliGetLengthExtraBits(int l);
|
127
|
-
|
128
|
-
/* Gets value of the extra bits for the given length, cfr. the DEFLATE spec. */
|
129
|
-
int ZopfliGetLengthExtraBitsValue(int l);
|
130
|
-
|
131
|
-
/* Gets the symbol for the given dist, cfr. the DEFLATE spec. */
|
132
|
-
int ZopfliGetDistSymbol(int dist);
|
133
|
-
|
134
|
-
/* Gets the amount of extra bits for the given dist, cfr. the DEFLATE spec. */
|
135
|
-
int ZopfliGetDistExtraBits(int dist);
|
136
|
-
|
137
|
-
/* Gets value of the extra bits for the given dist, cfr. the DEFLATE spec. */
|
138
|
-
int ZopfliGetDistExtraBitsValue(int dist);
|
139
|
-
|
140
123
|
/*
|
141
124
|
Appends value to dynamically allocated memory, doubling its allocation size
|
142
125
|
whenever needed.
|