Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Michael A. (Mike) Iovine
p1
Commits
27b5e31d
Commit
27b5e31d
authored
5 years ago
by
Mike Iovine
Browse files
Options
Download
Email Patches
Plain Diff
Add tests for reading fixed Huffman codes
parent
a6d2f914
master
No related merge requests found
Pipeline
#30569
failed with stage
in 0 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/inflate.h
+5
-2
include/inflate.h
src/inflate/inflate.c
+32
-33
src/inflate/inflate.c
tests/inflate_test.cpp
+53
-2
tests/inflate_test.cpp
with
90 additions
and
37 deletions
+90
-37
include/inflate.h
View file @
27b5e31d
#ifndef _INFLATE_
C
_
#define _INFLATE_
C
_
#ifndef _INFLATE_
H
_
#define _INFLATE_
H
_
/* Maximum length for any Huffman code */
#define MAX_LENGTH 15
...
...
@@ -22,6 +22,9 @@ typedef struct huffman {
}
huffman_t
;
extern
huffman_t
HUFFMAN_FIXED_DISTS
;
extern
huffman_t
HUFFMAN_FIXED
;
/* Reset the position state variable */
void
reset_pos
();
...
...
This diff is collapsed.
Click to expand it.
src/inflate/inflate.c
View file @
27b5e31d
...
...
@@ -7,6 +7,37 @@
#include <inflate.h>
/* Conversion tables for lengths
* To index into lengths, use (value_read - LENGTH_OFFSET)
* We may have to read additional bits; check LEN_ADDITIONAL for how many
*/
#define LENGTH_OFFSET 257
int
LEN_TABLE
[
29
]
=
{
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
13
,
15
,
17
,
19
,
23
,
27
,
31
,
35
,
43
,
51
,
59
,
67
,
83
,
99
,
115
,
131
,
163
,
195
,
227
,
258
};
int
LEN_ADDITIONAL
[
29
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
,
1
,
1
,
1
,
2
,
2
,
2
,
2
,
3
,
3
,
3
,
3
,
4
,
4
,
4
,
4
,
5
,
5
,
5
,
5
,
0
};
/* Conversion tables for distance codes
* This can be indexed into directly with the distance code.
* Again, we may have to read additional bits to get the distance.
*/
int
DIST_TABLE
[
30
]
=
{
1
,
2
,
3
,
4
,
5
,
7
,
9
,
13
,
17
,
25
,
33
,
49
,
65
,
97
,
129
,
193
,
257
,
385
,
513
,
769
,
1025
,
1537
,
2049
,
3073
,
4097
,
6145
,
8193
,
12289
,
16385
,
24577
};
int
DIST_ADDITIONAL
[
30
]
=
{
0
,
0
,
0
,
0
,
1
,
1
,
2
,
2
,
3
,
3
,
4
,
4
,
5
,
5
,
6
,
6
,
7
,
7
,
8
,
8
,
9
,
9
,
10
,
10
,
11
,
11
,
12
,
12
,
13
,
13
};
/* Types of huffman codes */
#define FIXED 1
#define DYNAMIC 2
...
...
@@ -48,8 +79,7 @@ int _FIXED_9[112] = {144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
221
,
222
,
223
,
224
,
225
,
226
,
227
,
228
,
229
,
230
,
231
,
232
,
233
,
234
,
235
,
236
,
237
,
238
,
239
,
240
,
241
,
242
,
243
,
244
,
245
,
246
,
247
,
248
,
249
,
250
,
251
,
252
,
253
,
254
,
255
};
254
,
255
};
/* Note that we only have codes of length 7, 8, 9 */
huffman_t
HUFFMAN_FIXED
=
{
...
...
@@ -87,37 +117,6 @@ huffman_t HUFFMAN_FIXED_DISTS = {
NO_CODE
,
NO_CODE
,
NO_CODE
,
NO_CODE
}
};
/* Conversion tables for lengths
* To index into lengths, use (value_read - LENGTH_OFFSET)
* We may have to read additional bits; check LEN_ADDITIONAL for how many
*/
#define LENGTH_OFFSET 257
int
LEN_TABLE
[
29
]
=
{
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
13
,
15
,
17
,
19
,
23
,
27
,
31
,
35
,
43
,
51
,
59
,
67
,
83
,
99
,
115
,
131
,
163
,
195
,
227
,
258
};
int
LEN_ADDITIONAL
[
29
]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
,
1
,
1
,
1
,
2
,
2
,
2
,
2
,
3
,
3
,
3
,
3
,
4
,
4
,
4
,
4
,
5
,
5
,
5
,
5
,
0
};
/* Conversion tables for distance codes
* This can be indexed into directly with the distance code.
* Again, we may have to read additional bits to get the distance.
*/
int
DIST_TABLE
[
30
]
=
{
1
,
2
,
3
,
4
,
5
,
7
,
9
,
13
,
17
,
25
,
33
,
49
,
65
,
97
,
129
,
193
,
257
,
385
,
513
,
769
,
1025
,
1537
,
2049
,
3073
,
4097
,
6145
,
8193
,
12289
,
16385
,
24577
};
int
DIST_ADDITIONAL
[
30
]
=
{
0
,
0
,
0
,
0
,
1
,
1
,
2
,
2
,
3
,
3
,
4
,
4
,
5
,
5
,
6
,
6
,
7
,
7
,
8
,
8
,
9
,
9
,
10
,
10
,
11
,
11
,
12
,
12
,
13
,
13
};
/*
* Constants for DYNAMIC code type
*/
...
...
This diff is collapsed.
Click to expand it.
tests/inflate_test.cpp
View file @
27b5e31d
...
...
@@ -147,11 +147,62 @@ TEST (HuffmanTests, TestMakeHuffmanZeroLens) {
destroy_huffman
(
hf
);
}
// TODO
TEST
(
HuffmanTests
,
TestReadChunk
)
{
/*
* Test reading a sequence of literals/distances from a buffer.
* In this test, the FIXED Huffman codes are used.
*/
TEST
(
HuffmanTests
,
TestReadChunkFixed
)
{
/*
* This is the mapping of literal or length -> code.
* The DEFLATE specification defines how to map the literals
* (0, 1, ..., 287) to their codes. However, these codes are to
* be interpreted in stream order. The numbers below are the actual
* memory representation of each code, not their stream-order
* numerical value.
*/
int
codes
[
288
]
=
{
12
,
140
,
76
,
204
,
44
,
172
,
108
,
236
,
28
,
156
,
92
,
220
,
60
,
188
,
124
,
252
,
2
,
130
,
66
,
194
,
34
,
162
,
98
,
226
,
18
,
146
,
82
,
210
,
50
,
178
,
114
,
242
,
10
,
138
,
74
,
202
,
42
,
170
,
106
,
234
,
26
,
154
,
90
,
218
,
58
,
186
,
122
,
250
,
6
,
134
,
70
,
198
,
38
,
166
,
102
,
230
,
22
,
150
,
86
,
214
,
54
,
182
,
118
,
246
,
14
,
142
,
78
,
206
,
46
,
174
,
110
,
238
,
30
,
158
,
94
,
222
,
62
,
190
,
126
,
254
,
1
,
129
,
65
,
193
,
33
,
161
,
97
,
225
,
17
,
145
,
81
,
209
,
49
,
177
,
113
,
241
,
9
,
137
,
73
,
201
,
41
,
169
,
105
,
233
,
25
,
153
,
89
,
217
,
57
,
185
,
121
,
249
,
5
,
133
,
69
,
197
,
37
,
165
,
101
,
229
,
21
,
149
,
85
,
213
,
53
,
181
,
117
,
245
,
13
,
141
,
77
,
205
,
45
,
173
,
109
,
237
,
29
,
157
,
93
,
221
,
61
,
189
,
125
,
253
,
19
,
275
,
147
,
403
,
83
,
339
,
211
,
467
,
51
,
307
,
179
,
435
,
115
,
371
,
243
,
499
,
11
,
267
,
139
,
395
,
75
,
331
,
203
,
459
,
43
,
299
,
171
,
427
,
107
,
363
,
235
,
491
,
27
,
283
,
155
,
411
,
91
,
347
,
219
,
475
,
59
,
315
,
187
,
443
,
123
,
379
,
251
,
507
,
7
,
263
,
135
,
391
,
71
,
327
,
199
,
455
,
39
,
295
,
167
,
423
,
103
,
359
,
231
,
487
,
23
,
279
,
151
,
407
,
87
,
343
,
215
,
471
,
55
,
311
,
183
,
439
,
119
,
375
,
247
,
503
,
15
,
271
,
143
,
399
,
79
,
335
,
207
,
463
,
47
,
303
,
175
,
431
,
111
,
367
,
239
,
495
,
31
,
287
,
159
,
415
,
95
,
351
,
223
,
479
,
63
,
319
,
191
,
447
,
127
,
383
,
255
,
511
,
0
,
64
,
32
,
96
,
16
,
80
,
48
,
112
,
8
,
72
,
40
,
104
,
24
,
88
,
56
,
120
,
4
,
68
,
36
,
100
,
20
,
84
,
52
,
116
,
3
,
131
,
67
,
195
,
35
,
163
,
99
,
227
};
/* Test reading all possible literal-lengths */
for
(
int
i
=
0
;
i
<
288
;
i
++
)
{
reset_pos
();
int
code
=
codes
[
i
];
unsigned
char
buf
[
2
];
buf
[
0
]
=
code
&
255
;
buf
[
1
]
=
code
>>
8
;
ASSERT_EQ
(
read_chunk
((
char
*
)
buf
,
HUFFMAN_FIXED
),
i
);
}
// TODO test fixed distance codes as well?
}
// TODO
TEST
(
HuffmanTests
,
TestReadLens
)
{}
int
main
(
int
argc
,
char
**
argv
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help