73 #define NMSEDEC_BITS 7
74 #define NMSEDEC_FRACBITS (NMSEDEC_BITS-1)
75 #define WMSEDEC_SHIFT 13
76 #define LAMBDA_SCALE (100000000LL << (WMSEDEC_SHIFT - 13))
84 {{10000, 19650, 41770, 84030, 169000, 338400, 676900, 1353000, 2706000, 5409000},
85 {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
86 {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
87 {20800, 38650, 83070, 171800, 347100, 695900, 1393000, 2786000, 5572000}},
89 {{10000, 15000, 27500, 53750, 106800, 213400, 426700, 853300, 1707000, 3413000},
90 {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
91 {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
92 { 7186, 9218, 15860, 30430, 60190, 120100, 240000, 479700, 959300}}
130 static void nspaces(FILE *fd,
int n)
132 while(n--) putc(
' ', fd);
138 for (i = 0; i < comp->y1 - comp->y0; i++)
139 ff_jpeg2000_printv(comp->
i_data + i * (comp->x1 - comp->x0), comp->x1 - comp->x0);
144 int tileno, compno, reslevelno, bandno, precno;
145 fprintf(fd,
"XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n"
146 "numXtiles = %d, numYtiles = %d, ncomponents = %d\n"
153 fprintf(fd,
"tile %d:\n", tileno);
154 for(compno = 0; compno < s->
ncomponents; compno++){
157 fprintf(fd,
"component %d:\n", compno);
159 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d\n",
160 comp->x0, comp->x1, comp->y0, comp->y1);
161 for(reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){
164 fprintf(fd,
"reslevel %d:\n", reslevelno);
166 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d, nbands = %d\n",
167 reslevel->x0, reslevel->x1, reslevel->y0,
168 reslevel->y1, reslevel->
nbands);
169 for(bandno = 0; bandno < reslevel->
nbands; bandno++){
172 fprintf(fd,
"band %d:\n", bandno);
174 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d,"
175 "codeblock_width = %d, codeblock_height = %d cblknx = %d cblkny = %d\n",
178 band->codeblock_width, band->codeblock_height,
179 band->cblknx, band->cblkny);
183 fprintf(fd,
"prec %d:\n", precno);
185 fprintf(fd,
"xi0 = %d, xi1 = %d, yi0 = %d, yi1 = %d\n",
186 prec->xi0, prec->xi1, prec->yi0, prec->yi1);
232 int sp = 1, curval = 0;
246 if (stack[sp]->
val >= threshold){
252 curval = stack[
sp]->
val;
278 bytestream_put_be16(&s->
buf, 0);
279 bytestream_put_be32(&s->
buf, s->
width);
281 bytestream_put_be32(&s->
buf, 0);
282 bytestream_put_be32(&s->
buf, 0);
286 bytestream_put_be32(&s->
buf, 0);
287 bytestream_put_be32(&s->
buf, 0);
291 bytestream_put_byte(&s->
buf, 7);
306 bytestream_put_be16(&s->
buf, 12);
307 bytestream_put_byte(&s->
buf, 0);
309 bytestream_put_byte(&s->
buf, 0);
310 bytestream_put_be16(&s->
buf, 1);
312 bytestream_put_byte(&s->
buf, 2);
314 bytestream_put_byte(&s->
buf, 0);
320 bytestream_put_byte(&s->
buf, 0);
340 bytestream_put_be16(&s->
buf, size);
343 for (i = 0; i < codsty->
nreslevels * 3 - 2; i++)
344 bytestream_put_byte(&s->
buf, qntsty->
expn[i] << 3);
346 for (i = 0; i < codsty->
nreslevels * 3 - 2; i++)
347 bytestream_put_be16(&s->
buf, (qntsty->
expn[i] << 11) | qntsty->
mant[i]);
359 bytestream_put_be16(&s->
buf, 10);
360 bytestream_put_be16(&s->
buf, tileno);
363 bytestream_put_be32(&s->
buf, 0);
365 bytestream_put_byte(&s->
buf, 0);
366 bytestream_put_byte(&s->
buf, 1);
377 int tileno, tilex, tiley, compno;
387 for (tileno = 0, tiley = 0; tiley < s->
numYtiles; tiley++)
388 for (tilex = 0; tilex < s->
numXtiles; tilex++, tileno++){
394 for (compno = 0; compno < s->
ncomponents; compno++){
403 for (i = 0; i < 2; i++)
404 for (j = 0; j < 2; j++)
423 int tileno, compno, i,
y, x;
428 for (compno = 0; compno < s->
ncomponents; compno++){
434 for (y = comp->
coord[1][0]; y < comp->coord[1][1]; y++){
436 for (x = comp->
coord[0][0]; x < comp->coord[0][1]; x++)
437 *dst++ = *ptr++ - (1 << 7);
446 for (y = tile->
comp[0].
coord[1][0]; y < tile->comp[0].
coord[1][1]; y++){
448 for (x = tile->
comp[0].
coord[0][0]; x < tile->comp[0].
coord[0][1]; x++, i++){
449 for (compno = 0; compno < s->
ncomponents; compno++){
450 tile->
comp[compno].
i_data[i] = *ptr++ - (1 << 7);
461 int compno, reslevelno, bandno;
465 for (compno = 0; compno < s->
ncomponents; compno++){
467 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
468 int nbands, lev = codsty->
nreslevels - reslevelno - 1;
469 nbands = reslevelno ? 3 : 1;
470 for (bandno = 0; bandno < nbands; bandno++, gbandno++){
474 int bandpos = bandno + (reslevelno>0),
475 ss = 81920000 /
dwt_norms[0][bandpos][lev],
477 mant = (11 - log < 0 ? ss >> log - 11 : ss << 11 - log) & 0x7ff;
478 expn = s->
cbps[compno] - log + 13;
480 expn = ((bandno&2)>>1) + (reslevelno>0) + s->
cbps[compno];
482 qntsty->
expn[gbandno] = expn;
483 qntsty->
mant[gbandno] = mant;
524 for (y0 = 0; y0 <
height; y0 += 4)
525 for (x = 0; x <
width; x++)
526 for (y = y0; y < height && y < y0+4; y++){
529 bit = t1->
data[
y][x] & mask ? 1 : 0;
546 for (y0 = 0; y0 <
height; y0 += 4)
547 for (x = 0; x <
width; x++)
548 for (y = y0; y < height && y < y0+4; y++)
560 for (y0 = 0; y0 <
height; y0 += 4)
561 for (x = 0; x <
width; x++){
562 if (y0 + 3 < height && !(
570 for (rlen = 0; rlen < 4; rlen++)
571 if (t1->
data[y0+rlen][x] & mask)
578 for (y = y0 + rlen; y < y0 + 4; y++){
583 if (t1->
data[y][x] & mask){
594 for (y = y0; y < y0 + 4 && y <
height; y++){
598 if (t1->
data[y][x] & mask){
615 int pass_t = 2, passno, x,
y, max=0, nmsedec, bpno;
618 for (y = 0; y < height+2; y++)
619 memset(t1->
flags[y], 0, (width+2)*
sizeof(
int));
621 for (y = 0; y <
height; y++){
622 for (x = 0; x <
width; x++){
623 if (t1->
data[y][x] < 0){
641 for (passno = 0; bpno >= 0; passno++){
645 case 0:
encode_sigpass(t1, width, height, bandpos, &nmsedec, bpno);
649 case 2:
encode_clnpass(t1, width, height, bandpos, &nmsedec, bpno);
654 wmsedec += (int64_t)nmsedec << (2*bpno);
682 put_num(s, 0xff80 | (n-37), 16);
689 int bandno, empty = 1;
698 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
712 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
723 for (xi = 0; xi < cblknw; xi++, pos++){
732 for (xi = 0; xi < cblknw; xi++, pos++){
733 int pad = 0, llen,
length;
762 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
768 for (xi = 0; xi < cblknw; xi++){
783 int compno, reslevelno,
ret;
789 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
790 for (compno = 0; compno < s->
ncomponents; compno++){
794 if (ret =
encode_packet(s, reslevel, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
807 for (passno = 0; passno < cblk->
npasses; passno++){
816 if (((dd * dwt_norm) >>
WMSEDEC_SHIFT) * dwt_norm >= dr * lambda)
824 int precno, compno, reslevelno, bandno, cblkno, lev;
827 for (compno = 0; compno < s->
ncomponents; compno++){
830 for (reslevelno = 0, lev = codsty->
nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++, lev--){
834 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
835 int bandpos = bandno + (reslevelno > 0);
853 int compno, reslevelno, bandno,
ret;
856 for (compno = 0; compno < s->
ncomponents; compno++){
864 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
867 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
870 int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos;
879 bandpos = bandno + (reslevelno > 0);
882 if (reslevelno == 0 || bandno == 1)
893 for (y = yy0; y < yy1; y++){
894 int *ptr = t1.
data[y-yy0];
895 for (x = xx0; x < xx1; x++){
900 for (y = yy0; y < yy1; y++){
901 int *ptr = t1.
data[y-yy0];
902 for (x = xx0; x < xx1; x++){
910 bandpos, codsty->
nreslevels - reslevelno - 1);
936 for (compno = 0; compno < s->
ncomponents; compno++){
950 for (compno = 0; compno < s->
ncomponents; compno++)
956 const AVFrame *pict,
int *got_packet)
987 if (!(psotptr =
put_sot(s, tileno)))
994 bytestream_put_be32(&psotptr, s->
buf - psotptr + 6);
1041 for (i = 0; i < 3; i++)