35 #define NMSEDEC_BITS 7
36 #define NMSEDEC_FRACBITS (NMSEDEC_BITS-1)
37 #define WMSEDEC_SHIFT 13
38 #define LAMBDA_SCALE (100000000LL << (WMSEDEC_SHIFT - 13))
46 {{10000, 19650, 41770, 84030, 169000, 338400, 676900, 1353000, 2706000, 5409000},
47 {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
48 {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
49 {20800, 38650, 83070, 171800, 347100, 695900, 1393000, 2786000, 5572000}},
51 {{10000, 15000, 27500, 53750, 106800, 213400, 426700, 853300, 1707000, 3413000},
52 {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
53 {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
54 { 7186, 9218, 15860, 30430, 60190, 120100, 240000, 479700, 959300}}
92 static void nspaces(FILE *fd,
int n)
94 while(n--) putc(
' ', fd);
100 for (i = 0; i < comp->y1 - comp->y0; i++)
101 ff_jpeg2000_printv(comp->
i_data + i * (comp->x1 - comp->x0), comp->x1 - comp->x0);
106 int tileno, compno, reslevelno, bandno, precno;
107 fprintf(fd,
"XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n"
108 "numXtiles = %d, numYtiles = %d, ncomponents = %d\n"
115 fprintf(fd,
"tile %d:\n", tileno);
116 for(compno = 0; compno < s->
ncomponents; compno++){
119 fprintf(fd,
"component %d:\n", compno);
121 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d\n",
122 comp->x0, comp->x1, comp->y0, comp->y1);
123 for(reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){
126 fprintf(fd,
"reslevel %d:\n", reslevelno);
128 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d, nbands = %d\n",
129 reslevel->x0, reslevel->x1, reslevel->y0,
130 reslevel->y1, reslevel->
nbands);
131 for(bandno = 0; bandno < reslevel->
nbands; bandno++){
134 fprintf(fd,
"band %d:\n", bandno);
136 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d,"
137 "codeblock_width = %d, codeblock_height = %d cblknx = %d cblkny = %d\n",
140 band->codeblock_width, band->codeblock_height,
141 band->cblknx, band->cblkny);
145 fprintf(fd,
"prec %d:\n", precno);
147 fprintf(fd,
"xi0 = %d, xi1 = %d, yi0 = %d, yi1 = %d\n",
148 prec->xi0, prec->xi1, prec->yi0, prec->yi1);
194 int sp = 1, curval = 0;
208 if (stack[sp]->
val >= threshold){
214 curval = stack[
sp]->
val;
240 bytestream_put_be16(&s->
buf, 0);
241 bytestream_put_be32(&s->
buf, s->
width);
243 bytestream_put_be32(&s->
buf, 0);
244 bytestream_put_be32(&s->
buf, 0);
248 bytestream_put_be32(&s->
buf, 0);
249 bytestream_put_be32(&s->
buf, 0);
253 bytestream_put_byte(&s->
buf, 7);
268 bytestream_put_be16(&s->
buf, 12);
269 bytestream_put_byte(&s->
buf, 0);
271 bytestream_put_byte(&s->
buf, 0);
272 bytestream_put_be16(&s->
buf, 1);
274 bytestream_put_byte(&s->
buf, 2);
276 bytestream_put_byte(&s->
buf, 0);
282 bytestream_put_byte(&s->
buf, 0);
302 bytestream_put_be16(&s->
buf, size);
305 for (i = 0; i < codsty->
nreslevels * 3 - 2; i++)
306 bytestream_put_byte(&s->
buf, qntsty->
expn[i] << 3);
308 for (i = 0; i < codsty->
nreslevels * 3 - 2; i++)
309 bytestream_put_be16(&s->
buf, (qntsty->
expn[i] << 11) | qntsty->
mant[i]);
321 bytestream_put_be16(&s->
buf, 10);
322 bytestream_put_be16(&s->
buf, tileno);
325 bytestream_put_be32(&s->
buf, 0);
327 bytestream_put_byte(&s->
buf, 0);
328 bytestream_put_byte(&s->
buf, 1);
339 int tileno, tilex, tiley, compno;
349 for (tileno = 0, tiley = 0; tiley < s->
numYtiles; tiley++)
350 for (tilex = 0; tilex < s->
numXtiles; tilex++, tileno++){
356 for (compno = 0; compno < s->
ncomponents; compno++){
365 for (i = 0; i < 2; i++)
366 for (j = 0; j < 2; j++)
385 int tileno, compno, i,
y, x;
390 for (compno = 0; compno < s->
ncomponents; compno++){
396 for (y = comp->
coord[1][0]; y < comp->coord[1][1]; y++){
398 for (x = comp->
coord[0][0]; x < comp->coord[0][1]; x++)
399 *dst++ = *ptr++ - (1 << 7);
408 for (y = tile->
comp[0].
coord[1][0]; y < tile->comp[0].
coord[1][1]; y++){
410 for (x = tile->
comp[0].
coord[0][0]; x < tile->comp[0].
coord[0][1]; x++, i++){
411 for (compno = 0; compno < s->
ncomponents; compno++){
412 tile->
comp[compno].
i_data[i] = *ptr++ - (1 << 7);
423 int compno, reslevelno, bandno;
427 for (compno = 0; compno < s->
ncomponents; compno++){
429 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
430 int nbands, lev = codsty->
nreslevels - reslevelno - 1;
431 nbands = reslevelno ? 3 : 1;
432 for (bandno = 0; bandno < nbands; bandno++, gbandno++){
436 int bandpos = bandno + (reslevelno>0),
437 ss = 81920000 /
dwt_norms[0][bandpos][lev],
439 mant = (11 - log < 0 ? ss >> log - 11 : ss << 11 - log) & 0x7ff;
440 expn = s->
cbps[compno] - log + 13;
442 expn = ((bandno&2)>>1) + (reslevelno>0) + s->
cbps[compno];
444 qntsty->
expn[gbandno] = expn;
445 qntsty->
mant[gbandno] = mant;
486 for (y0 = 0; y0 <
height; y0 += 4)
487 for (x = 0; x <
width; x++)
488 for (y = y0; y < height && y < y0+4; y++){
491 bit = t1->
data[
y][x] & mask ? 1 : 0;
508 for (y0 = 0; y0 <
height; y0 += 4)
509 for (x = 0; x <
width; x++)
510 for (y = y0; y < height && y < y0+4; y++)
522 for (y0 = 0; y0 <
height; y0 += 4)
523 for (x = 0; x <
width; x++){
524 if (y0 + 3 < height && !(
532 for (rlen = 0; rlen < 4; rlen++)
533 if (t1->
data[y0+rlen][x] & mask)
540 for (y = y0 + rlen; y < y0 + 4; y++){
545 if (t1->
data[y][x] & mask){
556 for (y = y0; y < y0 + 4 && y <
height; y++){
560 if (t1->
data[y][x] & mask){
577 int pass_t = 2, passno, x,
y, max=0, nmsedec, bpno;
580 for (y = 0; y < height+2; y++)
581 memset(t1->
flags[y], 0, (width+2)*
sizeof(
int));
583 for (y = 0; y <
height; y++){
584 for (x = 0; x <
width; x++){
585 if (t1->
data[y][x] < 0){
603 for (passno = 0; bpno >= 0; passno++){
607 case 0:
encode_sigpass(t1, width, height, bandpos, &nmsedec, bpno);
611 case 2:
encode_clnpass(t1, width, height, bandpos, &nmsedec, bpno);
616 wmsedec += (int64_t)nmsedec << (2*bpno);
644 put_num(s, 0xff80 | (n-37), 16);
651 int bandno, empty = 1;
660 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
674 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
685 for (xi = 0; xi < cblknw; xi++, pos++){
694 for (xi = 0; xi < cblknw; xi++, pos++){
695 int pad = 0, llen,
length;
724 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
730 for (xi = 0; xi < cblknw; xi++){
745 int compno, reslevelno,
ret;
751 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
752 for (compno = 0; compno < s->
ncomponents; compno++){
756 if (ret =
encode_packet(s, reslevel, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
769 for (passno = 0; passno < cblk->
npasses; passno++){
778 if (((dd * dwt_norm) >>
WMSEDEC_SHIFT) * dwt_norm >= dr * lambda)
786 int precno, compno, reslevelno, bandno, cblkno, lev;
789 for (compno = 0; compno < s->
ncomponents; compno++){
792 for (reslevelno = 0, lev = codsty->
nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++, lev--){
796 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
797 int bandpos = bandno + (reslevelno > 0);
815 int compno, reslevelno, bandno,
ret;
818 for (compno = 0; compno < s->
ncomponents; compno++){
826 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
829 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
832 int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos;
841 bandpos = bandno + (reslevelno > 0);
844 if (reslevelno == 0 || bandno == 1)
855 for (y = yy0; y < yy1; y++){
856 int *ptr = t1.
data[y-yy0];
857 for (x = xx0; x < xx1; x++){
862 for (y = yy0; y < yy1; y++){
863 int *ptr = t1.
data[y-yy0];
864 for (x = xx0; x < xx1; x++){
872 bandpos, codsty->
nreslevels - reslevelno - 1);
898 for (compno = 0; compno < s->
ncomponents; compno++){
912 for (compno = 0; compno < s->
ncomponents; compno++)
918 const AVFrame *pict,
int *got_packet)
949 if (!(psotptr =
put_sot(s, tileno)))
956 bytestream_put_be32(&psotptr, s->
buf - psotptr + 6);
1003 for (i = 0; i < 3; i++)