35 #define SHL(a, n) ((n) >= 0 ? (a) << (n) : (a) >> -(n))
43 while (w > 1 || h > 1) {
64 while (w > 1 || h > 1) {
73 for (i = 0; i < ph; i++)
74 for (j = 0; j < pw; j++)
75 t[i * pw + j].parent = &t2[(i >> 1) * w + (j >> 1)];
87 for (i = 0; i < siz; i++) {
111 if (h == 2)
return 8;
113 if (v >= 1)
return 7;
114 if (d >= 1)
return 6;
117 if (v == 2)
return 4;
118 if (v == 1)
return 3;
119 if (d >= 2)
return 2;
120 if (d == 1)
return 1;
122 if (d >= 3)
return 8;
124 if (h+v >= 1)
return 7;
128 if (h+v >= 2)
return 5;
129 if (h+v == 1)
return 4;
132 if (h+v >= 2)
return 2;
133 if (h+v == 1)
return 1;
140 static const int contribtab[3][3] = { { 0, -1, 1 }, { -1, -1, 0 }, { 1, 0, 1 } };
141 static const int ctxlbltab[3][3] = { { 13, 12, 11 }, { 10, 9, 10 }, { 11, 12, 13 } };
142 static const int xorbittab[3][3] = { { 1, 1, 1 }, { 1, 0, 0 }, { 0, 0, 0 } };
146 int vcontrib, hcontrib;
160 for (i = 0; i < 256; i++)
161 for (j = 0; j < 4; j++)
163 for (i = 0; i < 16; i++)
164 for (j = 0; j < 16; j++)
197 int cbps,
int dx,
int dy,
200 uint8_t log2_band_prec_width, log2_band_prec_height;
201 int reslevelno, bandno, gbandno = 0,
ret, i, j;
214 csize = (comp->
coord[0][1] - comp->
coord[0][0]) *
232 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
239 for (i = 0; i < 2; i++)
240 for (j = 0; j < 2; j++)
241 reslevel->
coord[i][j] =
260 if (reslevel->
coord[0][1] == reslevel->
coord[0][0])
268 if (reslevel->
coord[1][1] == reslevel->
coord[1][0])
280 for (bandno = 0; bandno < reslevel->
nbands; bandno++, gbandno++) {
299 2 + numbps - qntsty->
expn[gbandno]);
330 if (reslevelno == 0) {
332 for (i = 0; i < 2; i++)
333 for (j = 0; j < 2; j++)
347 for (i = 0; i < 2; i++)
348 for (j = 0; j < 2; j++)
352 (((bandno + 1 >> i) & 1) << declvl - 1),
367 for (j = 0; j < 2; j++)
369 for (j = 0; j < 2; j++)
381 for (precno = 0; precno < nb_precincts; precno++) {
390 (1 << log2_band_prec_width);
395 (1 << log2_band_prec_height);
400 (1 << log2_band_prec_width);
405 (1 << log2_band_prec_height);
438 for (cblkno = 0; cblkno < nb_codeblocks; cblkno++) {
461 if ((bandno + !!reslevelno) & 1) {
467 if ((bandno + !!reslevelno) & 2) {
488 int reslevelno, bandno, cblkno, precno;
489 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
491 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
509 int reslevelno, bandno, precno;
518 reslevel = comp->
reslevel + reslevelno;
519 for (bandno = 0; bandno < reslevel->
nbands; bandno++) {
525 band = reslevel->
band + bandno;