81 #define NMSEDEC_BITS 7 
   82 #define NMSEDEC_FRACBITS (NMSEDEC_BITS-1) 
   83 #define WMSEDEC_SHIFT 13  
   84 #define LAMBDA_SCALE (100000000LL << (WMSEDEC_SHIFT - 13))
 
   95     {{10000, 19650, 41770,  84030, 169000, 338400,  676900, 1353000, 2706000, 5409000},
 
   96      {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
 
   97      {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
 
   98      {20800, 38650, 83070, 171800, 347100, 695900, 1393000, 2786000, 5572000}},
 
  100     {{10000, 15000, 27500, 53750, 106800, 213400, 426700, 853300, 1707000, 3413000},
 
  101      {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
 
  102      {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
 
  103      { 7186,  9218, 15860, 30430,  60190, 120100, 240000, 479700,  959300}}
 
  118     uint8_t comp_remap[4];
 
  136     int layer_rates[100];
 
  154 static void nspaces(FILE *fd, 
int n)
 
  156     while(n--) putc(
' ', fd);
 
  168     int tileno, compno, reslevelno, bandno, precno;
 
  169     fprintf(fd, 
"XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n" 
  170                 "numXtiles = %d, numYtiles = %d, ncomponents = %d\n" 
  172             s->width, 
s->height, 
s->tile_width, 
s->tile_height,
 
  173             s->numXtiles, 
s->numYtiles, 
s->ncomponents);
 
  174     for (tileno = 0; tileno < 
s->numXtiles * 
s->numYtiles; tileno++){
 
  177         fprintf(fd, 
"tile %d:\n", tileno);
 
  178         for(compno = 0; compno < 
s->ncomponents; compno++){
 
  181             fprintf(fd, 
"component %d:\n", compno);
 
  183             fprintf(fd, 
"x0 = %d, x1 = %d, y0 = %d, y1 = %d\n",
 
  185             for(reslevelno = 0; reslevelno < 
s->nreslevels; reslevelno++){
 
  188                 fprintf(fd, 
"reslevel %d:\n", reslevelno);
 
  190                 fprintf(fd, 
"x0 = %d, x1 = %d, y0 = %d, y1 = %d, nbands = %d\n",
 
  191                         reslevel->x0, reslevel->x1, reslevel->y0,
 
  192                         reslevel->y1, reslevel->
nbands);
 
  193                 for(bandno = 0; bandno < reslevel->
nbands; bandno++){
 
  196                     fprintf(fd, 
"band %d:\n", bandno);
 
  198                     fprintf(fd, 
"x0 = %d, x1 = %d, y0 = %d, y1 = %d," 
  199                                 "codeblock_width = %d, codeblock_height = %d cblknx = %d cblkny = %d\n",
 
  202                                 band->codeblock_width, band->codeblock_height,
 
  203                                 band->cblknx, band->cblkny);
 
  207                         fprintf(fd, 
"prec %d:\n", precno);
 
  209                         fprintf(fd, 
"xi0 = %d, xi1 = %d, yi0 = %d, yi1 = %d\n",
 
  210                                      prec->xi0, prec->xi1, prec->yi0, prec->yi1);
 
  225         if (
s->bit_index == 8)
 
  227             s->bit_index = *
s->buf == 0xff;
 
  230         *
s->buf |= 
val << (7 - 
s->bit_index++);
 
  256     int sp = -1, curval = 0;
 
  270         if (node->
val >= threshold) {
 
  304     if (
s->buf_end - 
s->buf < 40 + 3 * 
s->ncomponents)
 
  308     bytestream_put_be16(&
s->buf, 38 + 3 * 
s->ncomponents); 
 
  309     bytestream_put_be16(&
s->buf, 0); 
 
  310     bytestream_put_be32(&
s->buf, 
s->width); 
 
  311     bytestream_put_be32(&
s->buf, 
s->height); 
 
  312     bytestream_put_be32(&
s->buf, 0); 
 
  313     bytestream_put_be32(&
s->buf, 0); 
 
  315     bytestream_put_be32(&
s->buf, 
s->tile_width); 
 
  316     bytestream_put_be32(&
s->buf, 
s->tile_height); 
 
  317     bytestream_put_be32(&
s->buf, 0); 
 
  318     bytestream_put_be32(&
s->buf, 0); 
 
  319     bytestream_put_be16(&
s->buf, 
s->ncomponents); 
 
  321     for (
i = 0; 
i < 
s->ncomponents; 
i++){ 
 
  322         bytestream_put_byte(&
s->buf, 
s->cbps[
i] - 1);
 
  323         bytestream_put_byte(&
s->buf, (
i+1&2)?1<<
s->chroma_shift[0]:1);
 
  324         bytestream_put_byte(&
s->buf, (
i+1&2)?1<<
s->chroma_shift[1]:1);
 
  334     if (
s->buf_end - 
s->buf < 14)
 
  338     bytestream_put_be16(&
s->buf, 12); 
 
  343     bytestream_put_byte(&
s->buf, scod);  
 
  345     bytestream_put_byte(&
s->buf, 
s->prog); 
 
  346     bytestream_put_be16(&
s->buf, 
s->nlayers); 
 
  348         bytestream_put_byte(&
s->buf, 0); 
 
  350         bytestream_put_byte(&
s->buf, 0); 
 
  353     bytestream_put_byte(&
s->buf, codsty->
nreslevels - 1); 
 
  356     bytestream_put_byte(&
s->buf, 0); 
 
  372     if (
s->buf_end - 
s->buf < 
size + 2)
 
  376     bytestream_put_be16(&
s->buf, 
size);  
 
  380             bytestream_put_byte(&
s->buf, qntsty->
expn[
i] << 3);
 
  383             bytestream_put_be16(&
s->buf, (qntsty->
expn[
i] << 11) | qntsty->
mant[
i]);
 
  394     if (
s->buf_end - 
s->buf < 
size + 2)
 
  398     bytestream_put_be16(&
s->buf, 
size);
 
  399     bytestream_put_be16(&
s->buf, 1); 
 
  410     if (
s->buf_end - 
s->buf < 12)
 
  414     bytestream_put_be16(&
s->buf, 10); 
 
  415     bytestream_put_be16(&
s->buf, tileno); 
 
  418     bytestream_put_be32(&
s->buf, 0); 
 
  420     bytestream_put_byte(&
s->buf, 0); 
 
  421     bytestream_put_byte(&
s->buf, 1); 
 
  429     for (
i = 0; 
i < 
s->numYtiles; 
i++) {
 
  430         for (j = 0; j < 
s->numXtiles; j++) {
 
  432             for (compno = 0; compno < 
s->ncomponents; compno++) {
 
  435                 int scale = ((compno+1&2)?1 << 
s->chroma_shift[0]:1) * ((compno+1&2)?1 << 
s->chroma_shift[1]:1);
 
  436                 for (layno = 0; layno < 
s->nlayers; layno++) {
 
  437                     if (
s->layer_rates[layno] > 0) {
 
  457     int tileno, tilex, tiley, compno;
 
  467     for (tileno = 0, tiley = 0; tiley < 
s->numYtiles; tiley++)
 
  468         for (tilex = 0; tilex < 
s->numXtiles; tilex++, tileno++){
 
  479             for (compno = 0; compno < 
s->ncomponents; compno++){
 
  483                 comp->coord[0][0] = 
comp->coord_o[0][0] = tilex * 
s->tile_width;
 
  484                 comp->coord[0][1] = 
comp->coord_o[0][1] = 
FFMIN((tilex+1)*
s->tile_width, 
s->width);
 
  485                 comp->coord[1][0] = 
comp->coord_o[1][0] = tiley * 
s->tile_height;
 
  486                 comp->coord[1][1] = 
comp->coord_o[1][1] = 
FFMIN((tiley+1)*
s->tile_height, 
s->height);
 
  488                     for (
i = 0; 
i < 2; 
i++)
 
  489                         for (j = 0; j < 2; j++)
 
  496                                                 (compno+1&2)?1<<
s->chroma_shift[0]:1,
 
  497                                                 (compno+1&2)?1<<
s->chroma_shift[1]:1,
 
  507 #define COPY_FRAME(D, PIXEL)                                                                                                \ 
  508     static void copy_frame_ ##D(Jpeg2000EncoderContext *s)                                                                  \ 
  510         int tileno, compno, i, y, x;                                                                                        \ 
  512         for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){                                                   \ 
  513             Jpeg2000Tile *tile = s->tile + tileno;                                                                          \ 
  515                 for (compno = 0; compno < s->ncomponents; compno++){                                                        \ 
  516                     int icompno = s->comp_remap[compno];                                                                    \ 
  517                     Jpeg2000Component *comp = tile->comp + compno;                                                          \ 
  518                     int *dst = comp->i_data;                                                                                \ 
  519                     int cbps = s->cbps[compno];                                                                             \ 
  520                     line = (const PIXEL*)s->picture->data[icompno]                                                           \ 
  521                            + comp->coord[1][0] * (s->picture->linesize[icompno] / sizeof(PIXEL))                             \ 
  522                            + comp->coord[0][0];                                                                             \ 
  523                     for (y = comp->coord[1][0]; y < comp->coord[1][1]; y++){                                                \ 
  524                         const PIXEL *ptr = line;                                                                            \ 
  525                         for (x = comp->coord[0][0]; x < comp->coord[0][1]; x++)                                             \ 
  526                             *dst++ = *ptr++ - (1 << (cbps - 1));                                                            \ 
  527                         line += s->picture->linesize[icompno] / sizeof(PIXEL);                                               \ 
  531                 line = (const PIXEL*)(s->picture->data[0] + tile->comp[0].coord[1][0] * s->picture->linesize[0])            \ 
  532                        + tile->comp[0].coord[0][0] * s->ncomponents;                                                        \ 
  535                 for (y = tile->comp[0].coord[1][0]; y < tile->comp[0].coord[1][1]; y++){                                    \ 
  536                     const PIXEL *ptr = line;                                                                                \ 
  537                     for (x = tile->comp[0].coord[0][0]; x < tile->comp[0].coord[0][1]; x++, i++){                           \ 
  538                         for (compno = 0; compno < s->ncomponents; compno++){                                                \ 
  539                             int cbps = s->cbps[compno];                                                                     \ 
  540                             tile->comp[compno].i_data[i] = *ptr++  - (1 << (cbps - 1));                                     \ 
  543                     line += s->picture->linesize[0] / sizeof(PIXEL);                                                        \ 
  554     int compno, reslevelno, bandno;
 
  558     for (compno = 0; compno < 
s->ncomponents; compno++){
 
  560         for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
 
  562             nbands = reslevelno ? 3 : 1;
 
  563             for (bandno = 0; bandno < nbands; bandno++, gbandno++){
 
  567                     int bandpos = bandno + (reslevelno>0),
 
  570                     mant = (11 - log < 0 ? ss >> 
log - 11 : 
ss << 11 - 
log) & 0x7ff;
 
  571                     expn = 
s->cbps[compno] - 
log + 13;
 
  573                     expn = ((bandno&2)>>1) + (reslevelno>0) + 
s->cbps[compno];
 
  575                 qntsty->
expn[gbandno] = expn;
 
  576                 qntsty->
mant[gbandno] = mant;
 
  593                                     (1 << 13) - (
a * 
a << 11), 0);
 
  618     for (y0 = 0; y0 < 
height; y0 += 4)
 
  619         for (x = 0; x < 
width; x++)
 
  620             for (y = y0; y < 
height && y < y0+4; y++){
 
  623                         bit = 
t1->data[(y) * 
t1->stride + x] & 
mask ? 1 : 0;
 
  628                         ff_mqc_encode(&
t1->mqc, 
t1->mqc.cx_states + ctxno, (
t1->flags[(y+1) * 
t1->stride + x+1] >> 15) ^ xorbit);
 
  640     for (y0 = 0; y0 < 
height; y0 += 4)
 
  641         for (x = 0; x < 
width; x++)
 
  642             for (y = y0; y < 
height && y < y0+4; y++)
 
  654     for (y0 = 0; y0 < 
height; y0 += 4)
 
  655         for (x = 0; x < 
width; x++){
 
  664                 for (rlen = 0; rlen < 4; rlen++)
 
  665                     if (
t1->data[(y0+rlen) * 
t1->stride + x] & 
mask)
 
  672                 for (y = y0 + rlen; y < y0 + 4; y++){
 
  677                         if (
t1->data[(y) * 
t1->stride + x] & 
mask){ 
 
  681                             ff_mqc_encode(&
t1->mqc, 
t1->mqc.cx_states + ctxno, (
t1->flags[(y+1) * 
t1->stride + x+1] >> 15) ^ xorbit);
 
  688                 for (y = y0; y < y0 + 4 && y < 
height; y++){
 
  692                         if (
t1->data[(y) * 
t1->stride + x] & 
mask){ 
 
  696                             ff_mqc_encode(&
t1->mqc, 
t1->mqc.cx_states + ctxno, (
t1->flags[(y+1) * 
t1->stride + x+1] >> 15) ^ xorbit);
 
  709     int pass_t = 2, passno, x, y, 
max=0, nmsedec, bpno;
 
  712     memset(
t1->flags, 0, 
t1->stride * (
height + 2) * 
sizeof(*
t1->flags));
 
  714     for (y = 0; y < 
height; y++){
 
  715         for (x = 0; x < 
width; x++){
 
  716             if (
t1->data[(y) * 
t1->stride + x] < 0){
 
  718                 t1->data[(y) * 
t1->stride + x] = -
t1->data[(y) * 
t1->stride + x];
 
  734     for (passno = 0; bpno >= 0; passno++){
 
  749         wmsedec += (
int64_t)nmsedec << (2*bpno);
 
  784                          int precno, 
const uint8_t *expn, 
int numgbits, 
int packetno,
 
  787     int bandno, empty = 1;
 
  795         bytestream_put_be16(&
s->buf, 4);
 
  796         bytestream_put_be16(&
s->buf, packetno);
 
  801         for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
 
  816                     for (
i = 0; 
i < nlayers; 
i++) {
 
  831     for (bandno = 0; bandno < rlevel->
nbands; bandno++){
 
  858     for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
 
  870                 int llen = 0, length;
 
  873                 if (
s->buf_end - 
s->buf < 20) 
 
  916     for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
 
  922             for (
xi = 0; 
xi < cblknw; 
xi++){
 
  941     int compno, reslevelno, layno, 
ret;
 
  947     int tile_coord[2][2];
 
  948     int col = tileno % 
s->numXtiles;
 
  949     int row = tileno / 
s->numXtiles;
 
  951     tile_coord[0][0] = col * 
s->tile_width;
 
  952     tile_coord[0][1] = 
FFMIN(tile_coord[0][0] + 
s->tile_width, 
s->width);
 
  953     tile_coord[1][0] = row * 
s->tile_height;
 
  954     tile_coord[1][1] = 
FFMIN(tile_coord[1][0] + 
s->tile_height, 
s->height);
 
  960     for (layno = 0; layno < nlayers; layno++) {
 
  961         for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
 
  962             for (compno = 0; compno < 
s->ncomponents; compno++){
 
  966                     if ((
ret = 
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
 
  967                                 qntsty->
nguardbits, packetno++, nlayers)) < 0)
 
  975     for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
 
  976         for (layno = 0; layno < nlayers; layno++) {
 
  977             for (compno = 0; compno < 
s->ncomponents; compno++){
 
  981                     if ((
ret = 
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
 
  982                                 qntsty->
nguardbits, packetno++, nlayers)) < 0)
 
  990     for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
 
  994         for (compno = 0; compno < 
s->ncomponents; compno++) {
 
  996             if (reslevelno < codsty->nreslevels) {
 
  997                 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno; 
 
 1006         for (y = tile_coord[1][0]; y < tile_coord[1][1]; y = (y/step_y + 1)*step_y) {
 
 1007             for (x = tile_coord[0][0]; x < tile_coord[0][1]; x = (x/step_x + 1)*step_x) {
 
 1008                 for (compno = 0; compno < 
s->ncomponents; compno++) {
 
 1010                     uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno; 
 
 1012                     int log_subsampling[2] = { (compno+1&2)?
s->chroma_shift[0]:0, (compno+1&2)?
s->chroma_shift[1]:0};
 
 1013                     unsigned prcx, prcy;
 
 1019                     if (!(y % ((uint64_t)1 << (reslevel->
log2_prec_height + reducedresno + log_subsampling[1])) == 0 ||
 
 1020                         (y == tile_coord[1][0] && (try0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_height)))))
 
 1023                     if (!(x % ((uint64_t)1 << (reslevel->
log2_prec_width + reducedresno + log_subsampling[0])) == 0 ||
 
 1024                         (x == tile_coord[0][0] && (trx0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_width)))))
 
 1039                     for (layno = 0; layno < nlayers; layno++) {
 
 1040                         if ((
ret = 
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
 
 1041                                 qntsty->
nguardbits, packetno++, nlayers)) < 0)
 
 1052         for (compno = 0; compno < 
s->ncomponents; compno++) {
 
 1055             for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
 
 1056                 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno; 
 
 1062         if (step_x >= 31 || step_y >= 31){
 
 1069         for (y = tile_coord[1][0]; y < tile_coord[1][1]; y = (y/step_y + 1)*step_y) {
 
 1070             for (x = tile_coord[0][0]; x < tile_coord[0][1]; x = (x/step_x + 1)*step_x) {
 
 1071                 for (compno = 0; compno < 
s->ncomponents; compno++) {
 
 1073                     int log_subsampling[2] = { (compno+1&2)?
s->chroma_shift[0]:0, (compno+1&2)?
s->chroma_shift[1]:0};
 
 1075                     for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
 
 1076                         unsigned prcx, prcy;
 
 1078                         uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno; 
 
 1085                         if (!(y % ((uint64_t)1 << (reslevel->
log2_prec_height + reducedresno + log_subsampling[1])) == 0 ||
 
 1086                             (y == tile_coord[1][0] && (try0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_height)))))
 
 1089                         if (!(x % ((uint64_t)1 << (reslevel->
log2_prec_width + reducedresno + log_subsampling[0])) == 0 ||
 
 1090                             (x == tile_coord[0][0] && (trx0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_width)))))
 
 1106                         for (layno = 0; layno < nlayers; layno++) {
 
 1107                             if ((
ret = 
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
 
 1108                                     qntsty->
nguardbits, packetno++, nlayers)) < 0)
 
 1117         for (compno = 0; compno < 
s->ncomponents; compno++) {
 
 1119             int log_subsampling[2] = { (compno+1&2)?
s->chroma_shift[0]:0, (compno+1&2)?
s->chroma_shift[1]:0};
 
 1123             for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
 
 1124                 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno; 
 
 1129             if (step_x >= 31 || step_y >= 31){
 
 1136             for (y = tile_coord[1][0]; y < tile_coord[1][1]; y = (y/step_y + 1)*step_y) {
 
 1137                 for (x = tile_coord[0][0]; x < tile_coord[0][1]; x = (x/step_x + 1)*step_x) {
 
 1138                     for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
 
 1139                         unsigned prcx, prcy;
 
 1142                         uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno; 
 
 1148                         if (!(y % ((uint64_t)1 << (reslevel->
log2_prec_height + reducedresno + log_subsampling[1])) == 0 ||
 
 1149                             (y == tile_coord[1][0] && (try0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_height)))))
 
 1152                         if (!(x % ((uint64_t)1 << (reslevel->
log2_prec_width + reducedresno + log_subsampling[0])) == 0 ||
 
 1153                             (x == tile_coord[0][0] && (trx0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_width)))))
 
 1169                         for (layno = 0; layno < nlayers; layno++) {
 
 1170                             if ((
ret = 
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
 
 1171                                     qntsty->
nguardbits, packetno++, nlayers)) < 0)
 
 1187     int compno, resno, bandno, precno, cblkno;
 
 1190     for (compno = 0; compno < 
s->ncomponents; compno++) {
 
 1193         for (resno = 0; resno < 
s->codsty.nreslevels; resno++) {
 
 1197                 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
 
 1215                             for (passno = cblk->
ninclpasses; passno < cblk->npasses; passno++) {
 
 1235                                 if (thresh - (dd / dr) < DBL_EPSILON)
 
 1270     int precno, compno, reslevelno, bandno, cblkno, 
lev, passno, layno;
 
 1272     double min = DBL_MAX;
 
 1278     for (compno = 0; compno < 
s->ncomponents; compno++){
 
 1281         for (reslevelno = 0, 
lev = codsty->
nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++, 
lev--){
 
 1285                 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
 
 1291                         for (passno = 0; passno < cblk->
npasses; passno++) {
 
 1320     for (layno = 0; layno < 
s->nlayers; layno++) {
 
 1323         double stable_thresh = 0.0;
 
 1324         double good_thresh = 0.0;
 
 1325         if (!
s->layer_rates[layno]) {
 
 1328             for (
i = 0; 
i < 128; 
i++) {
 
 1329                 uint8_t *stream_pos = 
s->buf;
 
 1331                 thresh = (lo + hi) / 2;
 
 1334                 memset(stream_pos, 0, 
s->buf - stream_pos);
 
 1337                     s->buf = stream_pos;
 
 1341                 stable_thresh = thresh;
 
 1342                 s->buf = stream_pos;
 
 1345         if (good_thresh >= 0.0)
 
 1346             good_thresh = stable_thresh == 0.0 ? thresh : stable_thresh;
 
 1353     int passno, res = 0;
 
 1354     for (passno = 0; passno < cblk->
npasses; passno++){
 
 1363         if (dd  >= dr * lambda)
 
 1371     int precno, compno, reslevelno, bandno, cblkno, 
lev;
 
 1374     for (compno = 0; compno < 
s->ncomponents; compno++){
 
 1377         for (reslevelno = 0, 
lev = codsty->
nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++, 
lev--){
 
 1381                 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
 
 1382                     int bandpos = bandno + (reslevelno > 0);
 
 1406     int compno, reslevelno, bandno, 
ret;
 
 1409     for (compno = 0; compno < 
s->ncomponents; compno++){
 
 1419         for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
 
 1422             for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
 
 1425                 int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos;
 
 1426                 yy0 = bandno == 0 ? 0 : 
comp->reslevel[reslevelno-1].coord[1][1] - 
comp->reslevel[reslevelno-1].coord[1][0];
 
 1429                             band->
coord[1][1]) - band->
coord[1][0] + yy0;
 
 1434                 bandpos = bandno + (reslevelno > 0);
 
 1437                     if (reslevelno == 0 || bandno == 1)
 
 1440                         xx0 = 
comp->reslevel[reslevelno-1].coord[0][1] - 
comp->reslevel[reslevelno-1].coord[0][0];
 
 1443                                 band->
coord[0][1]) - band->
coord[0][0] + xx0;
 
 1448                             for (y = yy0; y < yy1; y++){
 
 1449                                 int *ptr = 
t1.data + (y-yy0)*
t1.stride;
 
 1450                                 for (x = xx0; x < xx1; x++){
 
 1455                             for (y = yy0; y < yy1; y++){
 
 1456                                 int *ptr = 
t1.data + (y-yy0)*
t1.stride;
 
 1457                                 for (x = xx0; x < xx1; x++){
 
 1458                                     *ptr = (
comp->i_data[(
comp->coord[0][1] - 
comp->coord[0][0]) * y + x]);
 
 1471                                     bandpos, codsty->
nreslevels - reslevelno - 1);
 
 1484     if (
s->compression_rate_enc)
 
 1502     for (tileno = 0; tileno < 
s->numXtiles * 
s->numYtiles; tileno++){
 
 1503         if (
s->tile[tileno].comp) {
 
 1504             for (compno = 0; compno < 
s->ncomponents; compno++){
 
 1518     for (tileno = 0; tileno < 
s->numXtiles * 
s->numYtiles; tileno++){
 
 1520         for (compno = 0; compno < 
s->ncomponents; compno++)
 
 1531                         const AVFrame *pict, 
int *got_packet)
 
 1535     uint8_t *chunkstart, *jp2cstart, *jp2hstart;
 
 1559         bytestream_put_be32(&
s->buf, 0x0000000C);
 
 1560         bytestream_put_be32(&
s->buf, 0x6A502020);
 
 1561         bytestream_put_be32(&
s->buf, 0x0D0A870A);
 
 1563         chunkstart = 
s->buf;
 
 1564         bytestream_put_be32(&
s->buf, 0);
 
 1567         bytestream_put_be32(&
s->buf, 0);
 
 1572         bytestream_put_be32(&
s->buf, 0);
 
 1575         chunkstart = 
s->buf;
 
 1576         bytestream_put_be32(&
s->buf, 0);
 
 1578         bytestream_put_be32(&
s->buf, avctx->
height);
 
 1579         bytestream_put_be32(&
s->buf, avctx->
width);
 
 1580         bytestream_put_be16(&
s->buf, 
s->ncomponents);
 
 1581         bytestream_put_byte(&
s->buf, 
s->cbps[0]);
 
 1582         bytestream_put_byte(&
s->buf, 7);
 
 1583         bytestream_put_byte(&
s->buf, 0);
 
 1584         bytestream_put_byte(&
s->buf, 0);
 
 1587         chunkstart = 
s->buf;
 
 1588         bytestream_put_be32(&
s->buf, 0);
 
 1590         bytestream_put_byte(&
s->buf, 1);
 
 1591         bytestream_put_byte(&
s->buf, 0);
 
 1592         bytestream_put_byte(&
s->buf, 0);
 
 1594             bytestream_put_be32(&
s->buf, 16);
 
 1595         } 
else if (
s->ncomponents == 1) {
 
 1596             bytestream_put_be32(&
s->buf, 17);
 
 1598             bytestream_put_be32(&
s->buf, 18);
 
 1603             const uint8_t *palette = pict->
data[1];
 
 1604             chunkstart = 
s->buf;
 
 1605             bytestream_put_be32(&
s->buf, 0);
 
 1608             bytestream_put_byte(&
s->buf, 3); 
 
 1609             bytestream_put_be24(&
s->buf, 0x070707); 
 
 1611                 bytestream_put_be24(&
s->buf, HAVE_BIGENDIAN ? 
AV_RB24(palette + 1) : 
AV_RL24(palette));
 
 1615             chunkstart = 
s->buf;
 
 1616             bytestream_put_be32(&
s->buf, 0);
 
 1618             for (
i = 0; 
i < 3; 
i++) {
 
 1619                 bytestream_put_be16(&
s->buf, 0); 
 
 1620                 bytestream_put_byte(&
s->buf, 1); 
 
 1621                 bytestream_put_byte(&
s->buf, 
i); 
 
 1628         bytestream_put_be32(&
s->buf, 0);
 
 1632     if (
s->buf_end - 
s->buf < 2)
 
 1644     for (tileno = 0; tileno < 
s->numXtiles * 
s->numYtiles; tileno++){
 
 1646         if (!(psotptr = 
put_sot(
s, tileno)))
 
 1648         if (
s->buf_end - 
s->buf < 2)
 
 1653         bytestream_put_be32(&psotptr, 
s->buf - psotptr + 6);
 
 1655     if (
s->buf_end - 
s->buf < 2)
 
 1673     char *saveptr = 
NULL;
 
 1678         s->layer_rates[0] = 0;
 
 1679         s->compression_rate_enc = 0;
 
 1684     if (token && (rate = strtol(token, 
NULL, 10))) {
 
 1685             s->layer_rates[0] = rate <= 1 ? 0:rate;
 
 1695         if (rate = strtol(token, 
NULL, 10)) {
 
 1696             if (nlayers >= 100) {
 
 1699             s->layer_rates[nlayers] = rate <= 1 ? 0:rate;
 
 1706     for (
i = 1; 
i < nlayers; 
i++) {
 
 1707         if (
s->layer_rates[
i] >= 
s->layer_rates[
i-1]) {
 
 1711     s->nlayers = nlayers;
 
 1712     s->compression_rate_enc = 1;
 
 1730         s->layer_rates[0] = 0;
 
 1731         s->compression_rate_enc = 0;
 
 1753     if ((
s->tile_width  & (
s->tile_width -1)) ||
 
 1754         (
s->tile_height & (
s->tile_height-1))) {
 
 1766     s->ncomponents = 
desc->nb_components;
 
 1767     for (
i = 0; 
i < 4; 
i++) {
 
 1768         s->cbps[
i] = 
desc->comp[
i].depth;
 
 1769         s->comp_remap[
i] = 
i; 
 
 1775                                                s->chroma_shift, 
s->chroma_shift + 1);
 
 1779             s->comp_remap[0] = 2;
 
 1780             s->comp_remap[1] = 0;
 
 1781             s->comp_remap[2] = 1;
 
 1806 #define OFFSET(x) offsetof(Jpeg2000EncoderContext, x) 
 1807 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM 
 1837     .
p.
name         = 
"jpeg2000",