line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
/*-------------------------------------------------------------*/ |
3
|
|
|
|
|
|
|
/*--- Compression machinery (not incl block sorting) ---*/ |
4
|
|
|
|
|
|
|
/*--- compress.c ---*/ |
5
|
|
|
|
|
|
|
/*-------------------------------------------------------------*/ |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ |
8
|
|
|
|
|
|
|
This file is part of bzip2/libbzip2, a program and library for |
9
|
|
|
|
|
|
|
lossless, block-sorting data compression. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
bzip2/libbzip2 version 1.0.8 of 13 July 2019 |
12
|
|
|
|
|
|
|
Copyright (C) 1996-2019 Julian Seward |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Please read the WARNING, DISCLAIMER and PATENTS sections in the |
15
|
|
|
|
|
|
|
README file. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
This program is released under the terms of the license contained |
18
|
|
|
|
|
|
|
in the file LICENSE. |
19
|
|
|
|
|
|
|
------------------------------------------------------------------ */ |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
/* CHANGES |
23
|
|
|
|
|
|
|
0.9.0 -- original version. |
24
|
|
|
|
|
|
|
0.9.0a/b -- no changes in this file. |
25
|
|
|
|
|
|
|
0.9.0c -- changed setting of nGroups in sendMTFValues() |
26
|
|
|
|
|
|
|
so as to do a bit better on small files |
27
|
|
|
|
|
|
|
*/ |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#include "bzlib_private.h" |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
/* |
32
|
|
|
|
|
|
|
Perl-specific change to allow building with C++ |
33
|
|
|
|
|
|
|
The 'register' keyword not allowed from C++17 |
34
|
|
|
|
|
|
|
see https://github.com/pmqs/Compress-Raw-Bzip2/issues/11 |
35
|
|
|
|
|
|
|
*/ |
36
|
|
|
|
|
|
|
#define register |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
/*---------------------------------------------------*/ |
39
|
|
|
|
|
|
|
/*--- Bit stream I/O ---*/ |
40
|
|
|
|
|
|
|
/*---------------------------------------------------*/ |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
/*---------------------------------------------------*/ |
43
|
21
|
|
|
|
|
|
void BZ2_bsInitWrite ( EState* s ) |
44
|
|
|
|
|
|
|
{ |
45
|
21
|
|
|
|
|
|
s->bsLive = 0; |
46
|
21
|
|
|
|
|
|
s->bsBuff = 0; |
47
|
21
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
/*---------------------------------------------------*/ |
51
|
|
|
|
|
|
|
static |
52
|
21
|
|
|
|
|
|
void bsFinishWrite ( EState* s ) |
53
|
|
|
|
|
|
|
{ |
54
|
63
|
100
|
|
|
|
|
while (s->bsLive > 0) { |
55
|
42
|
|
|
|
|
|
s->zbits[s->numZ] = (UChar)(s->bsBuff >> 24); |
56
|
42
|
|
|
|
|
|
s->numZ++; |
57
|
42
|
|
|
|
|
|
s->bsBuff <<= 8; |
58
|
42
|
|
|
|
|
|
s->bsLive -= 8; |
59
|
|
|
|
|
|
|
} |
60
|
21
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
/*---------------------------------------------------*/ |
64
|
|
|
|
|
|
|
#define bsNEEDW(nz) \ |
65
|
|
|
|
|
|
|
{ \ |
66
|
|
|
|
|
|
|
while (s->bsLive >= 8) { \ |
67
|
|
|
|
|
|
|
s->zbits[s->numZ] \ |
68
|
|
|
|
|
|
|
= (UChar)(s->bsBuff >> 24); \ |
69
|
|
|
|
|
|
|
s->numZ++; \ |
70
|
|
|
|
|
|
|
s->bsBuff <<= 8; \ |
71
|
|
|
|
|
|
|
s->bsLive -= 8; \ |
72
|
|
|
|
|
|
|
} \ |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
/*---------------------------------------------------*/ |
77
|
|
|
|
|
|
|
static |
78
|
|
|
|
|
|
|
__inline__ |
79
|
76709
|
|
|
|
|
|
void bsW ( EState* s, Int32 n, UInt32 v ) |
80
|
|
|
|
|
|
|
{ |
81
|
139377
|
100
|
|
|
|
|
bsNEEDW ( n ); |
82
|
76709
|
|
|
|
|
|
s->bsBuff |= (v << (32 - s->bsLive - n)); |
83
|
76709
|
|
|
|
|
|
s->bsLive += n; |
84
|
76709
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
/*---------------------------------------------------*/ |
88
|
|
|
|
|
|
|
static |
89
|
42
|
|
|
|
|
|
void bsPutUInt32 ( EState* s, UInt32 u ) |
90
|
|
|
|
|
|
|
{ |
91
|
42
|
|
|
|
|
|
bsW ( s, 8, (u >> 24) & 0xffL ); |
92
|
42
|
|
|
|
|
|
bsW ( s, 8, (u >> 16) & 0xffL ); |
93
|
42
|
|
|
|
|
|
bsW ( s, 8, (u >> 8) & 0xffL ); |
94
|
42
|
|
|
|
|
|
bsW ( s, 8, u & 0xffL ); |
95
|
42
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
/*---------------------------------------------------*/ |
99
|
|
|
|
|
|
|
static |
100
|
336
|
|
|
|
|
|
void bsPutUChar ( EState* s, UChar c ) |
101
|
|
|
|
|
|
|
{ |
102
|
336
|
|
|
|
|
|
bsW( s, 8, (UInt32)c ); |
103
|
336
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
/*---------------------------------------------------*/ |
107
|
|
|
|
|
|
|
/*--- The back end proper ---*/ |
108
|
|
|
|
|
|
|
/*---------------------------------------------------*/ |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
/*---------------------------------------------------*/ |
111
|
|
|
|
|
|
|
static |
112
|
21
|
|
|
|
|
|
void makeMaps_e ( EState* s ) |
113
|
|
|
|
|
|
|
{ |
114
|
|
|
|
|
|
|
Int32 i; |
115
|
21
|
|
|
|
|
|
s->nInUse = 0; |
116
|
5397
|
100
|
|
|
|
|
for (i = 0; i < 256; i++) |
117
|
5376
|
100
|
|
|
|
|
if (s->inUse[i]) { |
118
|
1033
|
|
|
|
|
|
s->unseqToSeq[i] = s->nInUse; |
119
|
1033
|
|
|
|
|
|
s->nInUse++; |
120
|
|
|
|
|
|
|
} |
121
|
21
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
/*---------------------------------------------------*/ |
125
|
|
|
|
|
|
|
static |
126
|
21
|
|
|
|
|
|
void generateMTFValues ( EState* s ) |
127
|
|
|
|
|
|
|
{ |
128
|
|
|
|
|
|
|
UChar yy[256]; |
129
|
|
|
|
|
|
|
Int32 i, j; |
130
|
|
|
|
|
|
|
Int32 zPend; |
131
|
|
|
|
|
|
|
Int32 wr; |
132
|
|
|
|
|
|
|
Int32 EOB; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
/* |
135
|
|
|
|
|
|
|
After sorting (eg, here), |
136
|
|
|
|
|
|
|
s->arr1 [ 0 .. s->nblock-1 ] holds sorted order, |
137
|
|
|
|
|
|
|
and |
138
|
|
|
|
|
|
|
((UChar*)s->arr2) [ 0 .. s->nblock-1 ] |
139
|
|
|
|
|
|
|
holds the original block data. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
The first thing to do is generate the MTF values, |
142
|
|
|
|
|
|
|
and put them in |
143
|
|
|
|
|
|
|
((UInt16*)s->arr1) [ 0 .. s->nblock-1 ]. |
144
|
|
|
|
|
|
|
Because there are strictly fewer or equal MTF values |
145
|
|
|
|
|
|
|
than block values, ptr values in this area are overwritten |
146
|
|
|
|
|
|
|
with MTF values only when they are no longer needed. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
The final compressed bitstream is generated into the |
149
|
|
|
|
|
|
|
area starting at |
150
|
|
|
|
|
|
|
(UChar*) (&((UChar*)s->arr2)[s->nblock]) |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
These storage aliases are set up in bzCompressInit(), |
153
|
|
|
|
|
|
|
except for the last one, which is arranged in |
154
|
|
|
|
|
|
|
compressBlock(). |
155
|
|
|
|
|
|
|
*/ |
156
|
21
|
|
|
|
|
|
UInt32* ptr = s->ptr; |
157
|
21
|
|
|
|
|
|
UChar* block = s->block; |
158
|
21
|
|
|
|
|
|
UInt16* mtfv = s->mtfv; |
159
|
|
|
|
|
|
|
|
160
|
21
|
|
|
|
|
|
makeMaps_e ( s ); |
161
|
21
|
|
|
|
|
|
EOB = s->nInUse+1; |
162
|
|
|
|
|
|
|
|
163
|
1096
|
100
|
|
|
|
|
for (i = 0; i <= EOB; i++) s->mtfFreq[i] = 0; |
164
|
|
|
|
|
|
|
|
165
|
21
|
|
|
|
|
|
wr = 0; |
166
|
21
|
|
|
|
|
|
zPend = 0; |
167
|
1054
|
100
|
|
|
|
|
for (i = 0; i < s->nInUse; i++) yy[i] = (UChar) i; |
168
|
|
|
|
|
|
|
|
169
|
125416
|
100
|
|
|
|
|
for (i = 0; i < s->nblock; i++) { |
170
|
|
|
|
|
|
|
UChar ll_i; |
171
|
|
|
|
|
|
|
AssertD ( wr <= i, "generateMTFValues(1)" ); |
172
|
125395
|
100
|
|
|
|
|
j = ptr[i]-1; if (j < 0) j += s->nblock; |
173
|
125395
|
|
|
|
|
|
ll_i = s->unseqToSeq[block[j]]; |
174
|
|
|
|
|
|
|
AssertD ( ll_i < s->nInUse, "generateMTFValues(2a)" ); |
175
|
|
|
|
|
|
|
|
176
|
125395
|
100
|
|
|
|
|
if (yy[0] == ll_i) { |
177
|
65272
|
|
|
|
|
|
zPend++; |
178
|
|
|
|
|
|
|
} else { |
179
|
|
|
|
|
|
|
|
180
|
60123
|
100
|
|
|
|
|
if (zPend > 0) { |
181
|
298
|
|
|
|
|
|
zPend--; |
182
|
|
|
|
|
|
|
while (True) { |
183
|
609
|
100
|
|
|
|
|
if (zPend & 1) { |
184
|
229
|
|
|
|
|
|
mtfv[wr] = BZ_RUNB; wr++; |
185
|
229
|
|
|
|
|
|
s->mtfFreq[BZ_RUNB]++; |
186
|
|
|
|
|
|
|
} else { |
187
|
380
|
|
|
|
|
|
mtfv[wr] = BZ_RUNA; wr++; |
188
|
380
|
|
|
|
|
|
s->mtfFreq[BZ_RUNA]++; |
189
|
|
|
|
|
|
|
} |
190
|
609
|
100
|
|
|
|
|
if (zPend < 2) break; |
191
|
311
|
|
|
|
|
|
zPend = (zPend - 2) / 2; |
192
|
311
|
|
|
|
|
|
}; |
193
|
298
|
|
|
|
|
|
zPend = 0; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
{ |
196
|
|
|
|
|
|
|
register UChar rtmp; |
197
|
|
|
|
|
|
|
register UChar* ryy_j; |
198
|
|
|
|
|
|
|
register UChar rll_i; |
199
|
60123
|
|
|
|
|
|
rtmp = yy[1]; |
200
|
60123
|
|
|
|
|
|
yy[1] = yy[0]; |
201
|
60123
|
|
|
|
|
|
ryy_j = &(yy[1]); |
202
|
60123
|
|
|
|
|
|
rll_i = ll_i; |
203
|
7617965
|
100
|
|
|
|
|
while ( rll_i != rtmp ) { |
204
|
|
|
|
|
|
|
register UChar rtmp2; |
205
|
7557842
|
|
|
|
|
|
ryy_j++; |
206
|
7557842
|
|
|
|
|
|
rtmp2 = rtmp; |
207
|
7557842
|
|
|
|
|
|
rtmp = *ryy_j; |
208
|
7557842
|
|
|
|
|
|
*ryy_j = rtmp2; |
209
|
|
|
|
|
|
|
}; |
210
|
60123
|
|
|
|
|
|
yy[0] = rtmp; |
211
|
60123
|
|
|
|
|
|
j = ryy_j - &(yy[0]); |
212
|
60123
|
|
|
|
|
|
mtfv[wr] = j+1; wr++; s->mtfFreq[j+1]++; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
21
|
100
|
|
|
|
|
if (zPend > 0) { |
219
|
1
|
|
|
|
|
|
zPend--; |
220
|
|
|
|
|
|
|
while (True) { |
221
|
10
|
100
|
|
|
|
|
if (zPend & 1) { |
222
|
6
|
|
|
|
|
|
mtfv[wr] = BZ_RUNB; wr++; |
223
|
6
|
|
|
|
|
|
s->mtfFreq[BZ_RUNB]++; |
224
|
|
|
|
|
|
|
} else { |
225
|
4
|
|
|
|
|
|
mtfv[wr] = BZ_RUNA; wr++; |
226
|
4
|
|
|
|
|
|
s->mtfFreq[BZ_RUNA]++; |
227
|
|
|
|
|
|
|
} |
228
|
10
|
100
|
|
|
|
|
if (zPend < 2) break; |
229
|
9
|
|
|
|
|
|
zPend = (zPend - 2) / 2; |
230
|
9
|
|
|
|
|
|
}; |
231
|
1
|
|
|
|
|
|
zPend = 0; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
21
|
|
|
|
|
|
mtfv[wr] = EOB; wr++; s->mtfFreq[EOB]++; |
235
|
|
|
|
|
|
|
|
236
|
21
|
|
|
|
|
|
s->nMTF = wr; |
237
|
21
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
/*---------------------------------------------------*/ |
241
|
|
|
|
|
|
|
#define BZ_LESSER_ICOST 0 |
242
|
|
|
|
|
|
|
#define BZ_GREATER_ICOST 15 |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
static |
245
|
21
|
|
|
|
|
|
void sendMTFValues ( EState* s ) |
246
|
|
|
|
|
|
|
{ |
247
|
|
|
|
|
|
|
Int32 v, t, i, j, gs, ge, totc, bt, bc, iter; |
248
|
|
|
|
|
|
|
Int32 nSelectors, alphaSize, minLen, maxLen, selCtr; |
249
|
|
|
|
|
|
|
Int32 nGroups; |
250
|
21
|
|
|
|
|
|
Int32 nBytes = 0; |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
/*-- |
253
|
|
|
|
|
|
|
UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; |
254
|
|
|
|
|
|
|
is a global since the decoder also needs it. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Int32 code[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; |
257
|
|
|
|
|
|
|
Int32 rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; |
258
|
|
|
|
|
|
|
are also globals only used in this proc. |
259
|
|
|
|
|
|
|
Made global to keep stack frame size small. |
260
|
|
|
|
|
|
|
--*/ |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
|
263
|
21
|
|
|
|
|
|
UInt16 cost[BZ_N_GROUPS] = {0, 0, 0, 0, 0, 0}; |
264
|
21
|
|
|
|
|
|
Int32 fave[BZ_N_GROUPS] = {0, 0, 0, 0, 0, 0}; |
265
|
|
|
|
|
|
|
|
266
|
21
|
|
|
|
|
|
UInt16* mtfv = s->mtfv; |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
((void)nBytes); /* Silence variable ‘nBytes’ set but not used warning */ |
269
|
21
|
|
|
|
|
|
if (s->verbosity >= 3) |
270
|
|
|
|
|
|
|
VPrintf3( " %d in block, %d after MTF & 1-2 coding, " |
271
|
|
|
|
|
|
|
"%d+2 syms in use\n", |
272
|
|
|
|
|
|
|
s->nblock, s->nMTF, s->nInUse ); |
273
|
|
|
|
|
|
|
|
274
|
21
|
|
|
|
|
|
alphaSize = s->nInUse+2; |
275
|
147
|
100
|
|
|
|
|
for (t = 0; t < BZ_N_GROUPS; t++) |
276
|
6576
|
100
|
|
|
|
|
for (v = 0; v < alphaSize; v++) |
277
|
6450
|
|
|
|
|
|
s->len[t][v] = BZ_GREATER_ICOST; |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
/*--- Decide how many coding tables to use ---*/ |
280
|
21
|
50
|
|
|
|
|
AssertH ( s->nMTF > 0, 3001 ); |
281
|
21
|
100
|
|
|
|
|
if (s->nMTF < 200) nGroups = 2; else |
282
|
4
|
100
|
|
|
|
|
if (s->nMTF < 600) nGroups = 3; else |
283
|
3
|
50
|
|
|
|
|
if (s->nMTF < 1200) nGroups = 4; else |
284
|
3
|
50
|
|
|
|
|
if (s->nMTF < 2400) nGroups = 5; else |
285
|
3
|
|
|
|
|
|
nGroups = 6; |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
/*--- Generate an initial set of coding tables ---*/ |
288
|
|
|
|
|
|
|
{ |
289
|
|
|
|
|
|
|
Int32 nPart, remF, tFreq, aFreq; |
290
|
|
|
|
|
|
|
|
291
|
21
|
|
|
|
|
|
nPart = nGroups; |
292
|
21
|
|
|
|
|
|
remF = s->nMTF; |
293
|
21
|
|
|
|
|
|
gs = 0; |
294
|
76
|
100
|
|
|
|
|
while (nPart > 0) { |
295
|
55
|
|
|
|
|
|
tFreq = remF / nPart; |
296
|
55
|
|
|
|
|
|
ge = gs-1; |
297
|
55
|
|
|
|
|
|
aFreq = 0; |
298
|
1136
|
100
|
|
|
|
|
while (aFreq < tFreq && ge < alphaSize-1) { |
|
|
50
|
|
|
|
|
|
299
|
1081
|
|
|
|
|
|
ge++; |
300
|
1081
|
|
|
|
|
|
aFreq += s->mtfFreq[ge]; |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
|
303
|
55
|
100
|
|
|
|
|
if (ge > gs |
304
|
53
|
100
|
|
|
|
|
&& nPart != nGroups && nPart != 1 |
|
|
100
|
|
|
|
|
|
305
|
12
|
100
|
|
|
|
|
&& ((nGroups-nPart) % 2 == 1)) { |
306
|
6
|
|
|
|
|
|
aFreq -= s->mtfFreq[ge]; |
307
|
6
|
|
|
|
|
|
ge--; |
308
|
|
|
|
|
|
|
} |
309
|
|
|
|
|
|
|
|
310
|
55
|
|
|
|
|
|
if (s->verbosity >= 3) |
311
|
|
|
|
|
|
|
VPrintf5( " initial group %d, [%d .. %d], " |
312
|
|
|
|
|
|
|
"has %d syms (%4.1f%%)\n", |
313
|
|
|
|
|
|
|
nPart, gs, ge, aFreq, |
314
|
|
|
|
|
|
|
(100.0 * (float)aFreq) / (float)(s->nMTF) ); |
315
|
|
|
|
|
|
|
|
316
|
5307
|
100
|
|
|
|
|
for (v = 0; v < alphaSize; v++) |
317
|
5252
|
100
|
|
|
|
|
if (v >= gs && v <= ge) |
|
|
100
|
|
|
|
|
|
318
|
1075
|
|
|
|
|
|
s->len[nPart-1][v] = BZ_LESSER_ICOST; else |
319
|
4177
|
|
|
|
|
|
s->len[nPart-1][v] = BZ_GREATER_ICOST; |
320
|
|
|
|
|
|
|
|
321
|
55
|
|
|
|
|
|
nPart--; |
322
|
55
|
|
|
|
|
|
gs = ge+1; |
323
|
55
|
|
|
|
|
|
remF -= aFreq; |
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
/*--- |
328
|
|
|
|
|
|
|
Iterate up to BZ_N_ITERS times to improve the tables. |
329
|
|
|
|
|
|
|
---*/ |
330
|
105
|
100
|
|
|
|
|
for (iter = 0; iter < BZ_N_ITERS; iter++) { |
331
|
|
|
|
|
|
|
|
332
|
304
|
100
|
|
|
|
|
for (t = 0; t < nGroups; t++) fave[t] = 0; |
333
|
|
|
|
|
|
|
|
334
|
304
|
100
|
|
|
|
|
for (t = 0; t < nGroups; t++) |
335
|
21228
|
100
|
|
|
|
|
for (v = 0; v < alphaSize; v++) |
336
|
21008
|
|
|
|
|
|
s->rfreq[t][v] = 0; |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
/*--- |
339
|
|
|
|
|
|
|
Set up an auxiliary length table which is used to fast-track |
340
|
|
|
|
|
|
|
the common case (nGroups == 6). |
341
|
|
|
|
|
|
|
---*/ |
342
|
84
|
100
|
|
|
|
|
if (nGroups == 6) { |
343
|
3096
|
100
|
|
|
|
|
for (v = 0; v < alphaSize; v++) { |
344
|
3084
|
|
|
|
|
|
s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v]; |
345
|
3084
|
|
|
|
|
|
s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v]; |
346
|
3084
|
|
|
|
|
|
s->len_pack[v][2] = (s->len[5][v] << 16) | s->len[4][v]; |
347
|
|
|
|
|
|
|
} |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
|
350
|
84
|
|
|
|
|
|
nSelectors = 0; |
351
|
84
|
|
|
|
|
|
totc = 0; |
352
|
84
|
|
|
|
|
|
gs = 0; |
353
|
|
|
|
|
|
|
while (True) { |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
/*--- Set group start & end marks. --*/ |
356
|
4996
|
100
|
|
|
|
|
if (gs >= s->nMTF) break; |
357
|
4912
|
|
|
|
|
|
ge = gs + BZ_G_SIZE - 1; |
358
|
4912
|
100
|
|
|
|
|
if (ge >= s->nMTF) ge = s->nMTF-1; |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
/*-- |
361
|
|
|
|
|
|
|
Calculate the cost of this group as coded |
362
|
|
|
|
|
|
|
by each of the coding tables. |
363
|
|
|
|
|
|
|
--*/ |
364
|
34004
|
100
|
|
|
|
|
for (t = 0; t < nGroups; t++) cost[t] = 0; |
365
|
|
|
|
|
|
|
|
366
|
4912
|
100
|
|
|
|
|
if (nGroups == 6 && 50 == ge-gs+1) { |
|
|
100
|
|
|
|
|
|
367
|
|
|
|
|
|
|
/*--- fast track the common case ---*/ |
368
|
|
|
|
|
|
|
register UInt32 cost01, cost23, cost45; |
369
|
|
|
|
|
|
|
register UInt16 icv; |
370
|
4800
|
|
|
|
|
|
cost01 = cost23 = cost45 = 0; |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
# define BZ_ITER(nn) \ |
373
|
|
|
|
|
|
|
icv = mtfv[gs+(nn)]; \ |
374
|
|
|
|
|
|
|
cost01 += s->len_pack[icv][0]; \ |
375
|
|
|
|
|
|
|
cost23 += s->len_pack[icv][1]; \ |
376
|
|
|
|
|
|
|
cost45 += s->len_pack[icv][2]; \ |
377
|
|
|
|
|
|
|
|
378
|
4800
|
|
|
|
|
|
BZ_ITER(0); BZ_ITER(1); BZ_ITER(2); BZ_ITER(3); BZ_ITER(4); |
379
|
4800
|
|
|
|
|
|
BZ_ITER(5); BZ_ITER(6); BZ_ITER(7); BZ_ITER(8); BZ_ITER(9); |
380
|
4800
|
|
|
|
|
|
BZ_ITER(10); BZ_ITER(11); BZ_ITER(12); BZ_ITER(13); BZ_ITER(14); |
381
|
4800
|
|
|
|
|
|
BZ_ITER(15); BZ_ITER(16); BZ_ITER(17); BZ_ITER(18); BZ_ITER(19); |
382
|
4800
|
|
|
|
|
|
BZ_ITER(20); BZ_ITER(21); BZ_ITER(22); BZ_ITER(23); BZ_ITER(24); |
383
|
4800
|
|
|
|
|
|
BZ_ITER(25); BZ_ITER(26); BZ_ITER(27); BZ_ITER(28); BZ_ITER(29); |
384
|
4800
|
|
|
|
|
|
BZ_ITER(30); BZ_ITER(31); BZ_ITER(32); BZ_ITER(33); BZ_ITER(34); |
385
|
4800
|
|
|
|
|
|
BZ_ITER(35); BZ_ITER(36); BZ_ITER(37); BZ_ITER(38); BZ_ITER(39); |
386
|
4800
|
|
|
|
|
|
BZ_ITER(40); BZ_ITER(41); BZ_ITER(42); BZ_ITER(43); BZ_ITER(44); |
387
|
4800
|
|
|
|
|
|
BZ_ITER(45); BZ_ITER(46); BZ_ITER(47); BZ_ITER(48); BZ_ITER(49); |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
# undef BZ_ITER |
390
|
|
|
|
|
|
|
|
391
|
4800
|
|
|
|
|
|
cost[0] = cost01 & 0xffff; cost[1] = cost01 >> 16; |
392
|
4800
|
|
|
|
|
|
cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16; |
393
|
4800
|
|
|
|
|
|
cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16; |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
} else { |
396
|
|
|
|
|
|
|
/*--- slow version which correctly handles all situations ---*/ |
397
|
3164
|
100
|
|
|
|
|
for (i = gs; i <= ge; i++) { |
398
|
3052
|
|
|
|
|
|
UInt16 icv = mtfv[i]; |
399
|
10104
|
100
|
|
|
|
|
for (t = 0; t < nGroups; t++) cost[t] += s->len[t][icv]; |
400
|
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
|
} |
402
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
/*-- |
404
|
|
|
|
|
|
|
Find the coding table which is best for this group, |
405
|
|
|
|
|
|
|
and record its identity in the selector table. |
406
|
|
|
|
|
|
|
--*/ |
407
|
4912
|
|
|
|
|
|
bc = 999999999; bt = -1; |
408
|
34004
|
100
|
|
|
|
|
for (t = 0; t < nGroups; t++) |
409
|
29092
|
100
|
|
|
|
|
if (cost[t] < bc) { bc = cost[t]; bt = t; }; |
410
|
4912
|
|
|
|
|
|
totc += bc; |
411
|
4912
|
|
|
|
|
|
fave[bt]++; |
412
|
4912
|
|
|
|
|
|
s->selector[nSelectors] = bt; |
413
|
4912
|
|
|
|
|
|
nSelectors++; |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
/*-- |
416
|
|
|
|
|
|
|
Increment the symbol frequencies for the selected table. |
417
|
|
|
|
|
|
|
--*/ |
418
|
4912
|
100
|
|
|
|
|
if (nGroups == 6 && 50 == ge-gs+1) { |
|
|
100
|
|
|
|
|
|
419
|
|
|
|
|
|
|
/*--- fast track the common case ---*/ |
420
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
# define BZ_ITUR(nn) s->rfreq[bt][ mtfv[gs+(nn)] ]++ |
422
|
|
|
|
|
|
|
|
423
|
4800
|
|
|
|
|
|
BZ_ITUR(0); BZ_ITUR(1); BZ_ITUR(2); BZ_ITUR(3); BZ_ITUR(4); |
424
|
4800
|
|
|
|
|
|
BZ_ITUR(5); BZ_ITUR(6); BZ_ITUR(7); BZ_ITUR(8); BZ_ITUR(9); |
425
|
4800
|
|
|
|
|
|
BZ_ITUR(10); BZ_ITUR(11); BZ_ITUR(12); BZ_ITUR(13); BZ_ITUR(14); |
426
|
4800
|
|
|
|
|
|
BZ_ITUR(15); BZ_ITUR(16); BZ_ITUR(17); BZ_ITUR(18); BZ_ITUR(19); |
427
|
4800
|
|
|
|
|
|
BZ_ITUR(20); BZ_ITUR(21); BZ_ITUR(22); BZ_ITUR(23); BZ_ITUR(24); |
428
|
4800
|
|
|
|
|
|
BZ_ITUR(25); BZ_ITUR(26); BZ_ITUR(27); BZ_ITUR(28); BZ_ITUR(29); |
429
|
4800
|
|
|
|
|
|
BZ_ITUR(30); BZ_ITUR(31); BZ_ITUR(32); BZ_ITUR(33); BZ_ITUR(34); |
430
|
4800
|
|
|
|
|
|
BZ_ITUR(35); BZ_ITUR(36); BZ_ITUR(37); BZ_ITUR(38); BZ_ITUR(39); |
431
|
4800
|
|
|
|
|
|
BZ_ITUR(40); BZ_ITUR(41); BZ_ITUR(42); BZ_ITUR(43); BZ_ITUR(44); |
432
|
4800
|
|
|
|
|
|
BZ_ITUR(45); BZ_ITUR(46); BZ_ITUR(47); BZ_ITUR(48); BZ_ITUR(49); |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
# undef BZ_ITUR |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
} else { |
437
|
|
|
|
|
|
|
/*--- slow version which correctly handles all situations ---*/ |
438
|
3164
|
100
|
|
|
|
|
for (i = gs; i <= ge; i++) |
439
|
3052
|
|
|
|
|
|
s->rfreq[bt][ mtfv[i] ]++; |
440
|
|
|
|
|
|
|
} |
441
|
|
|
|
|
|
|
|
442
|
4912
|
|
|
|
|
|
gs = ge+1; |
443
|
4912
|
|
|
|
|
|
} |
444
|
84
|
50
|
|
|
|
|
if (s->verbosity >= 3) { |
445
|
|
|
|
|
|
|
VPrintf2 ( " pass %d: size is %d, grp uses are ", |
446
|
|
|
|
|
|
|
iter+1, totc/8 ); |
447
|
0
|
0
|
|
|
|
|
for (t = 0; t < nGroups; t++) |
448
|
|
|
|
|
|
|
VPrintf1 ( "%d ", fave[t] ); |
449
|
|
|
|
|
|
|
VPrintf0 ( "\n" ); |
450
|
|
|
|
|
|
|
} |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
/*-- |
453
|
|
|
|
|
|
|
Recompute the tables based on the accumulated frequencies. |
454
|
|
|
|
|
|
|
--*/ |
455
|
|
|
|
|
|
|
/* maxLen was changed from 20 to 17 in bzip2-1.0.3. See |
456
|
|
|
|
|
|
|
comment in huffman.c for details. */ |
457
|
304
|
100
|
|
|
|
|
for (t = 0; t < nGroups; t++) |
458
|
220
|
|
|
|
|
|
BZ2_hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]), |
459
|
|
|
|
|
|
|
alphaSize, 17 /*20*/ ); |
460
|
|
|
|
|
|
|
} |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
|
463
|
21
|
50
|
|
|
|
|
AssertH( nGroups < 8, 3002 ); |
464
|
21
|
50
|
|
|
|
|
AssertH( nSelectors < 32768 && |
|
|
50
|
|
|
|
|
|
465
|
|
|
|
|
|
|
nSelectors <= BZ_MAX_SELECTORS, |
466
|
|
|
|
|
|
|
3003 ); |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
/*--- Compute MTF values for the selectors. ---*/ |
470
|
|
|
|
|
|
|
{ |
471
|
|
|
|
|
|
|
UChar pos[BZ_N_GROUPS], ll_i, tmp2, tmp; |
472
|
76
|
100
|
|
|
|
|
for (i = 0; i < nGroups; i++) pos[i] = i; |
473
|
1249
|
100
|
|
|
|
|
for (i = 0; i < nSelectors; i++) { |
474
|
1228
|
|
|
|
|
|
ll_i = s->selector[i]; |
475
|
1228
|
|
|
|
|
|
j = 0; |
476
|
1228
|
|
|
|
|
|
tmp = pos[j]; |
477
|
4102
|
100
|
|
|
|
|
while ( ll_i != tmp ) { |
478
|
2874
|
|
|
|
|
|
j++; |
479
|
2874
|
|
|
|
|
|
tmp2 = tmp; |
480
|
2874
|
|
|
|
|
|
tmp = pos[j]; |
481
|
2874
|
|
|
|
|
|
pos[j] = tmp2; |
482
|
|
|
|
|
|
|
}; |
483
|
1228
|
|
|
|
|
|
pos[0] = tmp; |
484
|
1228
|
|
|
|
|
|
s->selectorMtf[i] = j; |
485
|
|
|
|
|
|
|
} |
486
|
|
|
|
|
|
|
}; |
487
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
/*--- Assign actual codes for the tables. --*/ |
489
|
76
|
100
|
|
|
|
|
for (t = 0; t < nGroups; t++) { |
490
|
55
|
|
|
|
|
|
minLen = 32; |
491
|
55
|
|
|
|
|
|
maxLen = 0; |
492
|
5307
|
100
|
|
|
|
|
for (i = 0; i < alphaSize; i++) { |
493
|
5252
|
100
|
|
|
|
|
if (s->len[t][i] > maxLen) maxLen = s->len[t][i]; |
494
|
5252
|
100
|
|
|
|
|
if (s->len[t][i] < minLen) minLen = s->len[t][i]; |
495
|
|
|
|
|
|
|
} |
496
|
55
|
50
|
|
|
|
|
AssertH ( !(maxLen > 17 /*20*/ ), 3004 ); |
497
|
55
|
50
|
|
|
|
|
AssertH ( !(minLen < 1), 3005 ); |
498
|
55
|
|
|
|
|
|
BZ2_hbAssignCodes ( &(s->code[t][0]), &(s->len[t][0]), |
499
|
|
|
|
|
|
|
minLen, maxLen, alphaSize ); |
500
|
|
|
|
|
|
|
} |
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
/*--- Transmit the mapping table. ---*/ |
503
|
|
|
|
|
|
|
{ |
504
|
|
|
|
|
|
|
Bool inUse16[16]; |
505
|
357
|
100
|
|
|
|
|
for (i = 0; i < 16; i++) { |
506
|
336
|
|
|
|
|
|
inUse16[i] = False; |
507
|
5712
|
100
|
|
|
|
|
for (j = 0; j < 16; j++) |
508
|
5376
|
100
|
|
|
|
|
if (s->inUse[i * 16 + j]) inUse16[i] = True; |
509
|
|
|
|
|
|
|
} |
510
|
|
|
|
|
|
|
|
511
|
21
|
|
|
|
|
|
nBytes = s->numZ; |
512
|
357
|
100
|
|
|
|
|
for (i = 0; i < 16; i++) |
513
|
336
|
100
|
|
|
|
|
if (inUse16[i]) bsW(s,1,1); else bsW(s,1,0); |
514
|
|
|
|
|
|
|
|
515
|
357
|
100
|
|
|
|
|
for (i = 0; i < 16; i++) |
516
|
336
|
100
|
|
|
|
|
if (inUse16[i]) |
517
|
2193
|
100
|
|
|
|
|
for (j = 0; j < 16; j++) { |
518
|
2064
|
100
|
|
|
|
|
if (s->inUse[i * 16 + j]) bsW(s,1,1); else bsW(s,1,0); |
519
|
|
|
|
|
|
|
} |
520
|
|
|
|
|
|
|
|
521
|
21
|
|
|
|
|
|
if (s->verbosity >= 3) |
522
|
|
|
|
|
|
|
VPrintf1( " bytes: mapping %d, ", s->numZ-nBytes ); |
523
|
|
|
|
|
|
|
} |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
/*--- Now the selectors. ---*/ |
526
|
21
|
|
|
|
|
|
nBytes = s->numZ; |
527
|
21
|
|
|
|
|
|
bsW ( s, 3, nGroups ); |
528
|
21
|
|
|
|
|
|
bsW ( s, 15, nSelectors ); |
529
|
1249
|
100
|
|
|
|
|
for (i = 0; i < nSelectors; i++) { |
530
|
4102
|
100
|
|
|
|
|
for (j = 0; j < s->selectorMtf[i]; j++) bsW(s,1,1); |
531
|
1228
|
|
|
|
|
|
bsW(s,1,0); |
532
|
|
|
|
|
|
|
} |
533
|
21
|
|
|
|
|
|
if (s->verbosity >= 3) |
534
|
|
|
|
|
|
|
VPrintf1( "selectors %d, ", s->numZ-nBytes ); |
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
/*--- Now the coding tables. ---*/ |
537
|
21
|
|
|
|
|
|
nBytes = s->numZ; |
538
|
|
|
|
|
|
|
|
539
|
76
|
100
|
|
|
|
|
for (t = 0; t < nGroups; t++) { |
540
|
55
|
|
|
|
|
|
Int32 curr = s->len[t][0]; |
541
|
55
|
|
|
|
|
|
bsW ( s, 5, curr ); |
542
|
5307
|
100
|
|
|
|
|
for (i = 0; i < alphaSize; i++) { |
543
|
7051
|
100
|
|
|
|
|
while (curr < s->len[t][i]) { bsW(s,2,2); curr++; /* 10 */ }; |
544
|
7002
|
100
|
|
|
|
|
while (curr > s->len[t][i]) { bsW(s,2,3); curr--; /* 11 */ }; |
545
|
5252
|
|
|
|
|
|
bsW ( s, 1, 0 ); |
546
|
|
|
|
|
|
|
} |
547
|
|
|
|
|
|
|
} |
548
|
|
|
|
|
|
|
|
549
|
21
|
|
|
|
|
|
if (s->verbosity >= 3) |
550
|
|
|
|
|
|
|
VPrintf1 ( "code lengths %d, ", s->numZ-nBytes ); |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
/*--- And finally, the block data proper ---*/ |
553
|
21
|
|
|
|
|
|
nBytes = s->numZ; |
554
|
21
|
|
|
|
|
|
selCtr = 0; |
555
|
21
|
|
|
|
|
|
gs = 0; |
556
|
|
|
|
|
|
|
while (True) { |
557
|
1249
|
100
|
|
|
|
|
if (gs >= s->nMTF) break; |
558
|
1228
|
|
|
|
|
|
ge = gs + BZ_G_SIZE - 1; |
559
|
1228
|
100
|
|
|
|
|
if (ge >= s->nMTF) ge = s->nMTF-1; |
560
|
1228
|
50
|
|
|
|
|
AssertH ( s->selector[selCtr] < nGroups, 3006 ); |
561
|
|
|
|
|
|
|
|
562
|
2428
|
100
|
|
|
|
|
if (nGroups == 6 && 50 == ge-gs+1) { |
|
|
100
|
|
|
|
|
|
563
|
|
|
|
|
|
|
/*--- fast track the common case ---*/ |
564
|
|
|
|
|
|
|
UInt16 mtfv_i; |
565
|
1200
|
|
|
|
|
|
UChar* s_len_sel_selCtr |
566
|
1200
|
|
|
|
|
|
= &(s->len[s->selector[selCtr]][0]); |
567
|
1200
|
|
|
|
|
|
Int32* s_code_sel_selCtr |
568
|
1200
|
|
|
|
|
|
= &(s->code[s->selector[selCtr]][0]); |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
# define BZ_ITAH(nn) \ |
571
|
|
|
|
|
|
|
mtfv_i = mtfv[gs+(nn)]; \ |
572
|
|
|
|
|
|
|
bsW ( s, \ |
573
|
|
|
|
|
|
|
s_len_sel_selCtr[mtfv_i], \ |
574
|
|
|
|
|
|
|
s_code_sel_selCtr[mtfv_i] ) |
575
|
|
|
|
|
|
|
|
576
|
1200
|
|
|
|
|
|
BZ_ITAH(0); BZ_ITAH(1); BZ_ITAH(2); BZ_ITAH(3); BZ_ITAH(4); |
577
|
1200
|
|
|
|
|
|
BZ_ITAH(5); BZ_ITAH(6); BZ_ITAH(7); BZ_ITAH(8); BZ_ITAH(9); |
578
|
1200
|
|
|
|
|
|
BZ_ITAH(10); BZ_ITAH(11); BZ_ITAH(12); BZ_ITAH(13); BZ_ITAH(14); |
579
|
1200
|
|
|
|
|
|
BZ_ITAH(15); BZ_ITAH(16); BZ_ITAH(17); BZ_ITAH(18); BZ_ITAH(19); |
580
|
1200
|
|
|
|
|
|
BZ_ITAH(20); BZ_ITAH(21); BZ_ITAH(22); BZ_ITAH(23); BZ_ITAH(24); |
581
|
1200
|
|
|
|
|
|
BZ_ITAH(25); BZ_ITAH(26); BZ_ITAH(27); BZ_ITAH(28); BZ_ITAH(29); |
582
|
1200
|
|
|
|
|
|
BZ_ITAH(30); BZ_ITAH(31); BZ_ITAH(32); BZ_ITAH(33); BZ_ITAH(34); |
583
|
1200
|
|
|
|
|
|
BZ_ITAH(35); BZ_ITAH(36); BZ_ITAH(37); BZ_ITAH(38); BZ_ITAH(39); |
584
|
1200
|
|
|
|
|
|
BZ_ITAH(40); BZ_ITAH(41); BZ_ITAH(42); BZ_ITAH(43); BZ_ITAH(44); |
585
|
1200
|
|
|
|
|
|
BZ_ITAH(45); BZ_ITAH(46); BZ_ITAH(47); BZ_ITAH(48); BZ_ITAH(49); |
586
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
# undef BZ_ITAH |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
} else { |
590
|
|
|
|
|
|
|
/*--- slow version which correctly handles all situations ---*/ |
591
|
791
|
100
|
|
|
|
|
for (i = gs; i <= ge; i++) { |
592
|
763
|
|
|
|
|
|
bsW ( s, |
593
|
763
|
|
|
|
|
|
s->len [s->selector[selCtr]] [mtfv[i]], |
594
|
763
|
|
|
|
|
|
s->code [s->selector[selCtr]] [mtfv[i]] ); |
595
|
|
|
|
|
|
|
} |
596
|
|
|
|
|
|
|
} |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
|
599
|
1228
|
|
|
|
|
|
gs = ge+1; |
600
|
1228
|
|
|
|
|
|
selCtr++; |
601
|
1228
|
|
|
|
|
|
} |
602
|
21
|
50
|
|
|
|
|
AssertH( selCtr == nSelectors, 3007 ); |
603
|
|
|
|
|
|
|
|
604
|
21
|
|
|
|
|
|
if (s->verbosity >= 3) |
605
|
|
|
|
|
|
|
VPrintf1( "codes %d\n", s->numZ-nBytes ); |
606
|
21
|
|
|
|
|
|
} |
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
/*---------------------------------------------------*/ |
610
|
23
|
|
|
|
|
|
void BZ2_compressBlock ( EState* s, Bool is_last_block ) |
611
|
|
|
|
|
|
|
{ |
612
|
23
|
100
|
|
|
|
|
if (s->nblock > 0) { |
613
|
|
|
|
|
|
|
|
614
|
21
|
|
|
|
|
|
BZ_FINALISE_CRC ( s->blockCRC ); |
615
|
21
|
|
|
|
|
|
s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31); |
616
|
21
|
|
|
|
|
|
s->combinedCRC ^= s->blockCRC; |
617
|
21
|
50
|
|
|
|
|
if (s->blockNo > 1) s->numZ = 0; |
618
|
|
|
|
|
|
|
|
619
|
21
|
|
|
|
|
|
if (s->verbosity >= 2) |
620
|
|
|
|
|
|
|
VPrintf4( " block %d: crc = 0x%08x, " |
621
|
|
|
|
|
|
|
"combined CRC = 0x%08x, size = %d\n", |
622
|
|
|
|
|
|
|
s->blockNo, s->blockCRC, s->combinedCRC, s->nblock ); |
623
|
|
|
|
|
|
|
|
624
|
21
|
|
|
|
|
|
BZ2_blockSort ( s ); |
625
|
|
|
|
|
|
|
} |
626
|
|
|
|
|
|
|
|
627
|
23
|
|
|
|
|
|
s->zbits = (UChar*) (&((UChar*)s->arr2)[s->nblock]); |
628
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
/*-- If this is the first block, create the stream header. --*/ |
630
|
23
|
100
|
|
|
|
|
if (s->blockNo == 1) { |
631
|
21
|
|
|
|
|
|
BZ2_bsInitWrite ( s ); |
632
|
21
|
|
|
|
|
|
bsPutUChar ( s, BZ_HDR_B ); |
633
|
21
|
|
|
|
|
|
bsPutUChar ( s, BZ_HDR_Z ); |
634
|
21
|
|
|
|
|
|
bsPutUChar ( s, BZ_HDR_h ); |
635
|
21
|
|
|
|
|
|
bsPutUChar ( s, (UChar)(BZ_HDR_0 + s->blockSize100k) ); |
636
|
|
|
|
|
|
|
} |
637
|
|
|
|
|
|
|
|
638
|
23
|
100
|
|
|
|
|
if (s->nblock > 0) { |
639
|
|
|
|
|
|
|
|
640
|
21
|
|
|
|
|
|
bsPutUChar ( s, 0x31 ); bsPutUChar ( s, 0x41 ); |
641
|
21
|
|
|
|
|
|
bsPutUChar ( s, 0x59 ); bsPutUChar ( s, 0x26 ); |
642
|
21
|
|
|
|
|
|
bsPutUChar ( s, 0x53 ); bsPutUChar ( s, 0x59 ); |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
/*-- Now the block's CRC, so it is in a known place. --*/ |
645
|
21
|
|
|
|
|
|
bsPutUInt32 ( s, s->blockCRC ); |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
/*-- |
648
|
|
|
|
|
|
|
Now a single bit indicating (non-)randomisation. |
649
|
|
|
|
|
|
|
As of version 0.9.5, we use a better sorting algorithm |
650
|
|
|
|
|
|
|
which makes randomisation unnecessary. So always set |
651
|
|
|
|
|
|
|
the randomised bit to 'no'. Of course, the decoder |
652
|
|
|
|
|
|
|
still needs to be able to handle randomised blocks |
653
|
|
|
|
|
|
|
so as to maintain backwards compatibility with |
654
|
|
|
|
|
|
|
older versions of bzip2. |
655
|
|
|
|
|
|
|
--*/ |
656
|
21
|
|
|
|
|
|
bsW(s,1,0); |
657
|
|
|
|
|
|
|
|
658
|
21
|
|
|
|
|
|
bsW ( s, 24, s->origPtr ); |
659
|
21
|
|
|
|
|
|
generateMTFValues ( s ); |
660
|
21
|
|
|
|
|
|
sendMTFValues ( s ); |
661
|
|
|
|
|
|
|
} |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
/*-- If this is the last block, add the stream trailer. --*/ |
665
|
23
|
100
|
|
|
|
|
if (is_last_block) { |
666
|
|
|
|
|
|
|
|
667
|
21
|
|
|
|
|
|
bsPutUChar ( s, 0x17 ); bsPutUChar ( s, 0x72 ); |
668
|
21
|
|
|
|
|
|
bsPutUChar ( s, 0x45 ); bsPutUChar ( s, 0x38 ); |
669
|
21
|
|
|
|
|
|
bsPutUChar ( s, 0x50 ); bsPutUChar ( s, 0x90 ); |
670
|
21
|
|
|
|
|
|
bsPutUInt32 ( s, s->combinedCRC ); |
671
|
21
|
|
|
|
|
|
if (s->verbosity >= 2) |
672
|
|
|
|
|
|
|
VPrintf1( " final combined CRC = 0x%08x\n ", s->combinedCRC ); |
673
|
21
|
|
|
|
|
|
bsFinishWrite ( s ); |
674
|
|
|
|
|
|
|
} |
675
|
23
|
|
|
|
|
|
} |
676
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
/*-------------------------------------------------------------*/ |
679
|
|
|
|
|
|
|
/*--- end compress.c ---*/ |
680
|
|
|
|
|
|
|
/*-------------------------------------------------------------*/ |