63 while (s->bsLive >= 8) { \
65 = (UChar)(s->bsBuff >> 24); \
88 bsW ( s, 8, (u >> 24) & 0xffL );
89 bsW ( s, 8, (u >> 16) & 0xffL );
90 bsW ( s, 8, (u >> 8) & 0xffL );
91 bsW ( s, 8, u & 0xffL );
113 for (i = 0; i < 256; i++)
160 for (i = 0; i <= EOB; i++) s->
mtfFreq[i] = 0;
166 for (i = 0; i < s->
nblock; i++) {
168 AssertD ( wr <= i,
"generateMTFValues(1)" );
169 j = ptr[i]-1;
if (j < 0) j += s->
nblock;
171 AssertD ( ll_i < s->nInUse,
"generateMTFValues(2a)" );
187 if (zPend < 2)
break;
188 zPend = (zPend - 2) / 2;
194 register UChar* ryy_j;
195 register UChar rll_i;
200 while ( rll_i != rtmp ) {
201 register UChar rtmp2;
208 j = ryy_j - &(yy[0]);
209 mtfv[wr] = j+1; wr++; s->
mtfFreq[j+1]++;
225 if (zPend < 2)
break;
226 zPend = (zPend - 2) / 2;
231 mtfv[wr] = EOB; wr++; s->
mtfFreq[EOB]++;
238 #define BZ_LESSER_ICOST 0
239 #define BZ_GREATER_ICOST 15
244 Int32 v, t, i, j, gs, ge, totc, bt, bc, iter;
245 Int32 nSelectors, alphaSize, minLen, maxLen, selCtr;
246 Int32 nGroups, nBytes;
265 VPrintf3(
" %d in block, %d after MTF & 1-2 coding, "
266 "%d+2 syms in use\n",
271 for (v = 0; v < alphaSize; v++)
276 if (s->
nMTF < 200) nGroups = 2;
else
277 if (s->
nMTF < 600) nGroups = 3;
else
278 if (s->
nMTF < 1200) nGroups = 4;
else
279 if (s->
nMTF < 2400) nGroups = 5;
else
284 Int32 nPart, remF, tFreq, aFreq;
290 tFreq = remF / nPart;
293 while (aFreq < tFreq && ge < alphaSize-1) {
299 && nPart != nGroups && nPart != 1
300 && ((nGroups-nPart) % 2 == 1)) {
306 VPrintf5(
" initial group %d, [%d .. %d], "
307 "has %d syms (%4.1f%%)\n",
308 nPart, gs, ge, aFreq,
309 (100.0 * (
float)aFreq) / (
float)(s->
nMTF) );
311 for (v = 0; v < alphaSize; v++)
312 if (v >= gs && v <= ge)
327 for (t = 0; t < nGroups; t++) fave[t] = 0;
329 for (t = 0; t < nGroups; t++)
330 for (v = 0; v < alphaSize; v++)
338 for (v = 0; v < alphaSize; v++) {
351 if (gs >= s->
nMTF)
break;
359 for (t = 0; t < nGroups; t++) cost[t] = 0;
361 if (nGroups == 6 && 50 == ge-gs+1) {
363 register UInt32 cost01, cost23, cost45;
365 cost01 = cost23 = cost45 = 0;
367 # define BZ_ITER(nn) \
368 icv = mtfv[gs+(nn)]; \
369 cost01 += s->len_pack[icv][0]; \
370 cost23 += s->len_pack[icv][1]; \
371 cost45 += s->len_pack[icv][2]; \
386 cost[0] = cost01 & 0xffff; cost[1] = cost01 >> 16;
387 cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16;
388 cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16;
392 for (i = gs; i <= ge; i++) {
394 for (t = 0; t < nGroups; t++) cost[t] += s->
len[t][icv];
402 bc = 999999999; bt = -1;
403 for (t = 0; t < nGroups; t++)
404 if (cost[t] < bc) { bc = cost[t]; bt = t; };
413 if (nGroups == 6 && 50 == ge-gs+1) {
416 # define BZ_ITUR(nn) s->rfreq[bt][ mtfv[gs+(nn)] ]++
433 for (i = gs; i <= ge; i++)
434 s->
rfreq[bt][ mtfv[i] ]++;
440 VPrintf2 (
" pass %d: size is %d, grp uses are ",
442 for (t = 0; t < nGroups; t++)
452 for (t = 0; t < nGroups; t++)
460 nSelectors <= (2 + (900000 /
BZ_G_SIZE)),
467 for (i = 0; i < nGroups; i++) pos[i] = i;
468 for (i = 0; i < nSelectors; i++) {
472 while ( ll_i != tmp ) {
484 for (t = 0; t < nGroups; t++) {
487 for (i = 0; i < alphaSize; i++) {
488 if (s->
len[t][i] > maxLen) maxLen = s->
len[t][i];
489 if (s->
len[t][i] < minLen) minLen = s->
len[t][i];
491 AssertH ( !(maxLen > 17 ), 3004 );
492 AssertH ( !(minLen < 1), 3005 );
494 minLen, maxLen, alphaSize );
500 for (i = 0; i < 16; i++) {
502 for (j = 0; j < 16; j++)
503 if (s->
inUse[i * 16 + j]) inUse16[i] =
True;
507 for (i = 0; i < 16; i++)
508 if (inUse16[i])
bsW(s,1,1);
else bsW(s,1,0);
510 for (i = 0; i < 16; i++)
512 for (j = 0; j < 16; j++) {
513 if (s->
inUse[i * 16 + j])
bsW(s,1,1);
else bsW(s,1,0);
522 bsW ( s, 3, nGroups );
523 bsW ( s, 15, nSelectors );
524 for (i = 0; i < nSelectors; i++) {
534 for (t = 0; t < nGroups; t++) {
537 for (i = 0; i < alphaSize; i++) {
538 while (curr < s->len[t][i]) {
bsW(s,2,2); curr++; };
539 while (curr > s->
len[t][i]) {
bsW(s,2,3); curr--; };
552 if (gs >= s->
nMTF)
break;
557 if (nGroups == 6 && 50 == ge-gs+1) {
560 UChar* s_len_sel_selCtr
562 Int32* s_code_sel_selCtr
565 # define BZ_ITAH(nn) \
566 mtfv_i = mtfv[gs+(nn)]; \
568 s_len_sel_selCtr[mtfv_i], \
569 s_code_sel_selCtr[mtfv_i] )
586 for (i = gs; i <= ge; i++) {
597 AssertH( selCtr == nSelectors, 3007 );
615 VPrintf4(
" block %d: crc = 0x%08x, "
616 "combined CRC = 0x%08x, size = %d\n",
static void makeMaps_e(EState *s)
#define BZ_FINALISE_CRC(crcVar)
void BZ2_compressBlock(EState *s, Bool is_last_block)
#define VPrintf1(zf, za1)
void BZ2_hbMakeCodeLengths(UChar *, Int32 *, Int32, Int32)
#define VPrintf2(zf, za1, za2)
for(p=first;p->value< newval;p=p->next)
ABC_NAMESPACE_IMPL_START void BZ2_bsInitWrite(EState *s)
UChar selectorMtf[BZ_MAX_SELECTORS]
#define AssertH(cond, errcode)
Int32 rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]
UChar selector[BZ_MAX_SELECTORS]
void BZ2_blockSort(EState *s)
static void bsFinishWrite(EState *s)
#define ABC_NAMESPACE_IMPL_END
static void sendMTFValues(EState *s)
UInt32 len_pack[BZ_MAX_ALPHA_SIZE][4]
#define ABC_NAMESPACE_IMPL_START
#define VPrintf3(zf, za1, za2, za3)
Int32 mtfFreq[BZ_MAX_ALPHA_SIZE]
void BZ2_hbAssignCodes(Int32 *, UChar *, Int32, Int32, Int32)
#define AssertD(cond, msg)
Int32 code[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]
static void bsPutUInt32(EState *s, UInt32 u)
static __inline__ void bsW(EState *s, Int32 n, UInt32 v)
#define VPrintf4(zf, za1, za2, za3, za4)
UChar len[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]
static void generateMTFValues(EState *s)
#define VPrintf5(zf, za1, za2, za3, za4, za5)
static void bsPutUChar(EState *s, UChar c)