32 #define SHL(a, n) ((n)>=0 ? (a) << (n) : (a) >> -(n))
35 void ff_j2k_printv(
int *
tab,
int l)
38 for (i = 0; i < l; i++)
46 for (i = 0; i < l; i++)
59 while (w > 1 || h > 1){
77 while (w > 1 || h > 1){
86 for (i = 0; i < ph; i++)
87 for (j = 0; j < pw; j++){
88 t[i*pw + j].
parent = &t2[(i>>1)*w + (j>>1)];
100 for (i = 0; i < siz; i++){
108 static int getnbctxno(
int flag,
int bandno,
int vert_causal_ctx_csty_symbol)
115 if (!vert_causal_ctx_csty_symbol)
119 if (!vert_causal_ctx_csty_symbol)
125 if (h == 2)
return 8;
127 if (v >= 1)
return 7;
128 if (d >= 1)
return 6;
131 if (v == 2)
return 4;
132 if (v == 1)
return 3;
133 if (d >= 2)
return 2;
134 if (d == 1)
return 1;
137 if (d >= 3)
return 8;
139 if (h+v >= 1)
return 7;
143 if (h+v >= 2)
return 5;
144 if (h+v == 1)
return 4;
147 if (h+v >= 2)
return 2;
148 if (h+v == 1)
return 1;
157 int vcontrib, hcontrib;
158 static const int contribtab[3][3] = {{0, -1, 1}, {-1, -1, 0}, {1, 0, 1}};
159 static const int ctxlbltab[3][3] = {{13, 12, 11}, {10, 9, 10}, {11, 12, 13}};
160 static const int xorbittab[3][3] = {{1, 1, 1,}, {1, 0, 0}, {0, 0, 0}};
166 *xorbit = xorbittab[hcontrib][vcontrib];
167 return ctxlbltab[hcontrib][vcontrib];
173 for (i = 0; i < 256; i++)
174 for (j = 0; j < 4; j++)
175 ff_j2k_nbctxno_lut[i][j] =
getnbctxno(i, j, 0);
176 for (i = 0; i < 16; i++)
177 for (j = 0; j < 16; j++)
178 ff_j2k_sgnctxno_lut[i][j] =
getsgnctxno(i + (j << 8), &ff_j2k_xorbit_lut[i][j]);
204 int reslevelno, bandno, gbandno = 0, ret, i, j, csize = 1;
208 for (i = 0; i < 2; i++)
209 csize *= comp->
coord[i][1] - comp->
coord[i][0];
218 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
222 for (i = 0; i < 2; i++)
223 for (j = 0; j < 2; j++)
224 reslevel->
coord[i][j] =
232 if (reslevel->
coord[0][1] == reslevel->
coord[0][0])
238 if (reslevel->
coord[1][1] == reslevel->
coord[1][0])
247 for (bandno = 0; bandno < reslevel->
nbands; bandno++, gbandno++){
249 int cblkno, precx, precy, precno;
251 int xi0, yi0, xi1, yi1;
252 int cblkperprecw, cblkperprech;
255 static const uint8_t lut_gain[2][4] = {{0, 0, 0, 0}, {0, 1, 1, 2}};
258 numbps = cbps + lut_gain[codsty->
transform][bandno + reslevelno>0];
263 if (reslevelno == 0){
266 for (i = 0; i < 2; i++)
267 for (j = 0; j < 2; j++)
273 for (i = 0; i < 2; i++)
274 for (j = 0; j < 2; j++)
280 for (j = 0; j < 2; j++)
282 for (j = 0; j < 2; j++)
295 for (cblkno = 0; cblkno < band->
cblknx * band->
cblkny; cblkno++){
304 y0 = band->
coord[1][0];
310 for (precy = 0, precno = 0; precy < reslevel->
num_precincts_y; precy++){
316 yi0 = yi1 - cblkperprech;
319 x0 = band->
coord[0][0];
326 for (precx = 0, precno = 0; precx < reslevel->
num_precincts_x; precx++){
327 for (precy = 0; precy < reslevel->
num_precincts_y; precy++, precno = 0){
340 xi0 = xi1 - cblkperprecw;
350 int reslevelno, bandno, cblkno, precno;
351 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
353 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
360 for (cblkno = 0; cblkno < band->
cblknx * band->
cblkny; cblkno++){
371 int reslevelno, bandno, precno;
372 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
375 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){