82 #define NMSEDEC_BITS 7
83 #define NMSEDEC_FRACBITS (NMSEDEC_BITS-1)
84 #define WMSEDEC_SHIFT 13
85 #define LAMBDA_SCALE (100000000LL << (WMSEDEC_SHIFT - 13))
96 {{10000, 19650, 41770, 84030, 169000, 338400, 676900, 1353000, 2706000, 5409000},
97 {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
98 {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
99 {20800, 38650, 83070, 171800, 347100, 695900, 1393000, 2786000, 5572000}},
101 {{10000, 15000, 27500, 53750, 106800, 213400, 426700, 853300, 1707000, 3413000},
102 {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
103 {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
104 { 7186, 9218, 15860, 30430, 60190, 120100, 240000, 479700, 959300}}
119 uint8_t comp_remap[4];
137 int layer_rates[100];
155 static void nspaces(FILE *fd,
int n)
157 while(n--) putc(
' ', fd);
169 int tileno, compno, reslevelno, bandno, precno;
170 fprintf(fd,
"XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n"
171 "numXtiles = %d, numYtiles = %d, ncomponents = %d\n"
173 s->width,
s->height,
s->tile_width,
s->tile_height,
174 s->numXtiles,
s->numYtiles,
s->ncomponents);
175 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++){
178 fprintf(fd,
"tile %d:\n", tileno);
179 for(compno = 0; compno <
s->ncomponents; compno++){
182 fprintf(fd,
"component %d:\n", compno);
184 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d\n",
186 for(reslevelno = 0; reslevelno <
s->nreslevels; reslevelno++){
189 fprintf(fd,
"reslevel %d:\n", reslevelno);
191 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d, nbands = %d\n",
192 reslevel->x0, reslevel->x1, reslevel->y0,
193 reslevel->y1, reslevel->
nbands);
194 for(bandno = 0; bandno < reslevel->
nbands; bandno++){
197 fprintf(fd,
"band %d:\n", bandno);
199 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d,"
200 "codeblock_width = %d, codeblock_height = %d cblknx = %d cblkny = %d\n",
203 band->codeblock_width, band->codeblock_height,
204 band->cblknx, band->cblkny);
208 fprintf(fd,
"prec %d:\n", precno);
210 fprintf(fd,
"xi0 = %d, xi1 = %d, yi0 = %d, yi1 = %d\n",
211 prec->xi0, prec->xi1, prec->yi0, prec->yi1);
226 if (
s->bit_index == 8)
228 s->bit_index = *
s->buf == 0xff;
231 *
s->buf |=
val << (7 -
s->bit_index++);
257 int sp = -1, curval = 0;
271 if (node->
val >= threshold) {
305 if (
s->buf_end -
s->buf < 40 + 3 *
s->ncomponents)
309 bytestream_put_be16(&
s->buf, 38 + 3 *
s->ncomponents);
310 bytestream_put_be16(&
s->buf, 0);
311 bytestream_put_be32(&
s->buf,
s->width);
312 bytestream_put_be32(&
s->buf,
s->height);
313 bytestream_put_be32(&
s->buf, 0);
314 bytestream_put_be32(&
s->buf, 0);
316 bytestream_put_be32(&
s->buf,
s->tile_width);
317 bytestream_put_be32(&
s->buf,
s->tile_height);
318 bytestream_put_be32(&
s->buf, 0);
319 bytestream_put_be32(&
s->buf, 0);
320 bytestream_put_be16(&
s->buf,
s->ncomponents);
322 for (
i = 0;
i <
s->ncomponents;
i++){
323 bytestream_put_byte(&
s->buf,
s->cbps[
i] - 1);
324 bytestream_put_byte(&
s->buf, (
i+1&2)?1<<
s->chroma_shift[0]:1);
325 bytestream_put_byte(&
s->buf, (
i+1&2)?1<<
s->chroma_shift[1]:1);
335 if (
s->buf_end -
s->buf < 14)
339 bytestream_put_be16(&
s->buf, 12);
344 bytestream_put_byte(&
s->buf, scod);
346 bytestream_put_byte(&
s->buf,
s->prog);
347 bytestream_put_be16(&
s->buf,
s->nlayers);
349 bytestream_put_byte(&
s->buf, 0);
351 bytestream_put_byte(&
s->buf, 0);
354 bytestream_put_byte(&
s->buf, codsty->
nreslevels - 1);
357 bytestream_put_byte(&
s->buf, 0);
373 if (
s->buf_end -
s->buf <
size + 2)
377 bytestream_put_be16(&
s->buf,
size);
381 bytestream_put_byte(&
s->buf, qntsty->
expn[
i] << 3);
384 bytestream_put_be16(&
s->buf, (qntsty->
expn[
i] << 11) | qntsty->
mant[
i]);
395 if (
s->buf_end -
s->buf <
size + 2)
399 bytestream_put_be16(&
s->buf,
size);
400 bytestream_put_be16(&
s->buf, 1);
411 if (
s->buf_end -
s->buf < 12)
415 bytestream_put_be16(&
s->buf, 10);
416 bytestream_put_be16(&
s->buf, tileno);
419 bytestream_put_be32(&
s->buf, 0);
421 bytestream_put_byte(&
s->buf, 0);
422 bytestream_put_byte(&
s->buf, 1);
430 for (
i = 0;
i <
s->numYtiles;
i++) {
431 for (j = 0; j <
s->numXtiles; j++) {
433 for (compno = 0; compno <
s->ncomponents; compno++) {
436 int scale = ((compno+1&2)?1 <<
s->chroma_shift[0]:1) * ((compno+1&2)?1 <<
s->chroma_shift[1]:1);
437 for (layno = 0; layno <
s->nlayers; layno++) {
438 if (
s->layer_rates[layno] > 0) {
458 int tileno, tilex, tiley, compno;
468 for (tileno = 0, tiley = 0; tiley <
s->numYtiles; tiley++)
469 for (tilex = 0; tilex <
s->numXtiles; tilex++, tileno++){
480 for (compno = 0; compno <
s->ncomponents; compno++){
484 comp->coord[0][0] =
comp->coord_o[0][0] = tilex *
s->tile_width;
485 comp->coord[0][1] =
comp->coord_o[0][1] =
FFMIN((tilex+1)*
s->tile_width,
s->width);
486 comp->coord[1][0] =
comp->coord_o[1][0] = tiley *
s->tile_height;
487 comp->coord[1][1] =
comp->coord_o[1][1] =
FFMIN((tiley+1)*
s->tile_height,
s->height);
489 for (
i = 0;
i < 2;
i++)
490 for (j = 0; j < 2; j++)
497 (compno+1&2)?1<<
s->chroma_shift[0]:1,
498 (compno+1&2)?1<<
s->chroma_shift[1]:1,
508 #define COPY_FRAME(D, PIXEL) \
509 static void copy_frame_ ##D(Jpeg2000EncoderContext *s) \
511 int tileno, compno, i, y, x; \
513 for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){ \
514 Jpeg2000Tile *tile = s->tile + tileno; \
516 for (compno = 0; compno < s->ncomponents; compno++){ \
517 int icompno = s->comp_remap[compno]; \
518 Jpeg2000Component *comp = tile->comp + compno; \
519 int *dst = comp->i_data; \
520 int cbps = s->cbps[compno]; \
521 line = (const PIXEL*)s->picture->data[icompno] \
522 + comp->coord[1][0] * (s->picture->linesize[icompno] / sizeof(PIXEL)) \
523 + comp->coord[0][0]; \
524 for (y = comp->coord[1][0]; y < comp->coord[1][1]; y++){ \
525 const PIXEL *ptr = line; \
526 for (x = comp->coord[0][0]; x < comp->coord[0][1]; x++) \
527 *dst++ = *ptr++ - (1 << (cbps - 1)); \
528 line += s->picture->linesize[icompno] / sizeof(PIXEL); \
532 line = (const PIXEL*)(s->picture->data[0] + tile->comp[0].coord[1][0] * s->picture->linesize[0]) \
533 + tile->comp[0].coord[0][0] * s->ncomponents; \
536 for (y = tile->comp[0].coord[1][0]; y < tile->comp[0].coord[1][1]; y++){ \
537 const PIXEL *ptr = line; \
538 for (x = tile->comp[0].coord[0][0]; x < tile->comp[0].coord[0][1]; x++, i++){ \
539 for (compno = 0; compno < s->ncomponents; compno++){ \
540 int cbps = s->cbps[compno]; \
541 tile->comp[compno].i_data[i] = *ptr++ - (1 << (cbps - 1)); \
544 line += s->picture->linesize[0] / sizeof(PIXEL); \
555 int compno, reslevelno, bandno;
559 for (compno = 0; compno <
s->ncomponents; compno++){
561 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
563 nbands = reslevelno ? 3 : 1;
564 for (bandno = 0; bandno < nbands; bandno++, gbandno++){
568 int bandpos = bandno + (reslevelno>0),
571 mant = (11 - log < 0 ? ss >>
log - 11 :
ss << 11 -
log) & 0x7ff;
572 expn =
s->cbps[compno] -
log + 13;
574 expn = ((bandno&2)>>1) + (reslevelno>0) +
s->cbps[compno];
576 qntsty->
expn[gbandno] = expn;
577 qntsty->
mant[gbandno] = mant;
594 (1 << 13) - (
a *
a << 11), 0);
619 for (y0 = 0; y0 <
height; y0 += 4)
620 for (x = 0; x <
width; x++)
621 for (y = y0; y <
height && y < y0+4; y++){
641 for (y0 = 0; y0 <
height; y0 += 4)
642 for (x = 0; x <
width; x++)
643 for (y = y0; y <
height && y < y0+4; y++)
655 for (y0 = 0; y0 <
height; y0 += 4)
656 for (x = 0; x <
width; x++){
665 for (rlen = 0; rlen < 4; rlen++)
673 for (y = y0 + rlen; y < y0 + 4; y++){
689 for (y = y0; y < y0 + 4 && y <
height; y++){
710 int pass_t = 2, passno, x, y,
max=0, nmsedec, bpno;
715 for (y = 0; y <
height; y++){
716 for (x = 0; x <
width; x++){
735 for (passno = 0; bpno >= 0; passno++){
750 wmsedec += (
int64_t)nmsedec << (2*bpno);
785 int precno,
const uint8_t *expn,
int numgbits,
int packetno,
788 int bandno, empty = 1;
796 bytestream_put_be16(&
s->buf, 4);
797 bytestream_put_be16(&
s->buf, packetno);
802 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
817 for (
i = 0;
i < nlayers;
i++) {
832 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
859 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
871 int llen = 0, length;
874 if (
s->buf_end -
s->buf < 20)
917 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
923 for (
xi = 0;
xi < cblknw;
xi++){
942 int compno, reslevelno, layno,
ret;
948 int tile_coord[2][2];
949 int col = tileno %
s->numXtiles;
950 int row = tileno /
s->numXtiles;
952 tile_coord[0][0] = col *
s->tile_width;
953 tile_coord[0][1] =
FFMIN(tile_coord[0][0] +
s->tile_width,
s->width);
954 tile_coord[1][0] = row *
s->tile_height;
955 tile_coord[1][1] =
FFMIN(tile_coord[1][0] +
s->tile_height,
s->height);
961 for (layno = 0; layno < nlayers; layno++) {
962 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
963 for (compno = 0; compno <
s->ncomponents; compno++){
967 if ((
ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
968 qntsty->
nguardbits, packetno++, nlayers)) < 0)
976 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
977 for (layno = 0; layno < nlayers; layno++) {
978 for (compno = 0; compno <
s->ncomponents; compno++){
982 if ((
ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
983 qntsty->
nguardbits, packetno++, nlayers)) < 0)
991 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
995 for (compno = 0; compno <
s->ncomponents; compno++) {
997 if (reslevelno < codsty->nreslevels) {
998 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1007 for (y = tile_coord[1][0]; y < tile_coord[1][1]; y = (y/step_y + 1)*step_y) {
1008 for (x = tile_coord[0][0]; x < tile_coord[0][1]; x = (x/step_x + 1)*step_x) {
1009 for (compno = 0; compno <
s->ncomponents; compno++) {
1011 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1013 int log_subsampling[2] = { (compno+1&2)?
s->chroma_shift[0]:0, (compno+1&2)?
s->chroma_shift[1]:0};
1014 unsigned prcx, prcy;
1020 if (!(y % ((uint64_t)1 << (reslevel->
log2_prec_height + reducedresno + log_subsampling[1])) == 0 ||
1021 (y == tile_coord[1][0] && (try0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_height)))))
1024 if (!(x % ((uint64_t)1 << (reslevel->
log2_prec_width + reducedresno + log_subsampling[0])) == 0 ||
1025 (x == tile_coord[0][0] && (trx0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_width)))))
1040 for (layno = 0; layno < nlayers; layno++) {
1041 if ((
ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
1042 qntsty->
nguardbits, packetno++, nlayers)) < 0)
1053 for (compno = 0; compno <
s->ncomponents; compno++) {
1056 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1057 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1063 if (step_x >= 31 || step_y >= 31){
1070 for (y = tile_coord[1][0]; y < tile_coord[1][1]; y = (y/step_y + 1)*step_y) {
1071 for (x = tile_coord[0][0]; x < tile_coord[0][1]; x = (x/step_x + 1)*step_x) {
1072 for (compno = 0; compno <
s->ncomponents; compno++) {
1074 int log_subsampling[2] = { (compno+1&2)?
s->chroma_shift[0]:0, (compno+1&2)?
s->chroma_shift[1]:0};
1076 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1077 unsigned prcx, prcy;
1079 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1086 if (!(y % ((uint64_t)1 << (reslevel->
log2_prec_height + reducedresno + log_subsampling[1])) == 0 ||
1087 (y == tile_coord[1][0] && (try0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_height)))))
1090 if (!(x % ((uint64_t)1 << (reslevel->
log2_prec_width + reducedresno + log_subsampling[0])) == 0 ||
1091 (x == tile_coord[0][0] && (trx0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_width)))))
1107 for (layno = 0; layno < nlayers; layno++) {
1108 if ((
ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
1109 qntsty->
nguardbits, packetno++, nlayers)) < 0)
1118 for (compno = 0; compno <
s->ncomponents; compno++) {
1120 int log_subsampling[2] = { (compno+1&2)?
s->chroma_shift[0]:0, (compno+1&2)?
s->chroma_shift[1]:0};
1124 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1125 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1130 if (step_x >= 31 || step_y >= 31){
1137 for (y = tile_coord[1][0]; y < tile_coord[1][1]; y = (y/step_y + 1)*step_y) {
1138 for (x = tile_coord[0][0]; x < tile_coord[0][1]; x = (x/step_x + 1)*step_x) {
1139 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1140 unsigned prcx, prcy;
1143 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1149 if (!(y % ((uint64_t)1 << (reslevel->
log2_prec_height + reducedresno + log_subsampling[1])) == 0 ||
1150 (y == tile_coord[1][0] && (try0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_height)))))
1153 if (!(x % ((uint64_t)1 << (reslevel->
log2_prec_width + reducedresno + log_subsampling[0])) == 0 ||
1154 (x == tile_coord[0][0] && (trx0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_width)))))
1170 for (layno = 0; layno < nlayers; layno++) {
1171 if ((
ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
1172 qntsty->
nguardbits, packetno++, nlayers)) < 0)
1188 int compno, resno, bandno, precno, cblkno;
1191 for (compno = 0; compno <
s->ncomponents; compno++) {
1194 for (resno = 0; resno <
s->codsty.nreslevels; resno++) {
1198 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1216 for (passno = cblk->
ninclpasses; passno < cblk->npasses; passno++) {
1236 if (thresh - (dd / dr) < DBL_EPSILON)
1271 int precno, compno, reslevelno, bandno, cblkno,
lev, passno, layno;
1273 double min = DBL_MAX;
1279 for (compno = 0; compno <
s->ncomponents; compno++){
1282 for (reslevelno = 0,
lev = codsty->
nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++,
lev--){
1286 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1292 for (passno = 0; passno < cblk->
npasses; passno++) {
1321 for (layno = 0; layno <
s->nlayers; layno++) {
1324 double stable_thresh = 0.0;
1325 double good_thresh = 0.0;
1326 if (!
s->layer_rates[layno]) {
1329 for (
i = 0;
i < 128;
i++) {
1330 uint8_t *stream_pos =
s->buf;
1332 thresh = (lo + hi) / 2;
1335 memset(stream_pos, 0,
s->buf - stream_pos);
1338 s->buf = stream_pos;
1342 stable_thresh = thresh;
1343 s->buf = stream_pos;
1346 if (good_thresh >= 0.0)
1347 good_thresh = stable_thresh == 0.0 ? thresh : stable_thresh;
1354 int passno, res = 0;
1355 for (passno = 0; passno < cblk->
npasses; passno++){
1364 if (dd >= dr * lambda)
1372 int precno, compno, reslevelno, bandno, cblkno,
lev;
1375 for (compno = 0; compno <
s->ncomponents; compno++){
1378 for (reslevelno = 0,
lev = codsty->
nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++,
lev--){
1382 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1383 int bandpos = bandno + (reslevelno > 0);
1407 int compno, reslevelno, bandno,
ret;
1410 for (compno = 0; compno <
s->ncomponents; compno++){
1420 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
1423 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1426 int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos;
1427 yy0 = bandno == 0 ? 0 :
comp->reslevel[reslevelno-1].coord[1][1] -
comp->reslevel[reslevelno-1].coord[1][0];
1430 band->
coord[1][1]) - band->
coord[1][0] + yy0;
1435 bandpos = bandno + (reslevelno > 0);
1438 if (reslevelno == 0 || bandno == 1)
1441 xx0 =
comp->reslevel[reslevelno-1].coord[0][1] -
comp->reslevel[reslevelno-1].coord[0][0];
1444 band->
coord[0][1]) - band->
coord[0][0] + xx0;
1449 for (y = yy0; y < yy1; y++){
1451 for (x = xx0; x < xx1; x++){
1456 for (y = yy0; y < yy1; y++){
1458 for (x = xx0; x < xx1; x++){
1459 *ptr = (
comp->i_data[(
comp->coord[0][1] -
comp->coord[0][0]) * y + x]);
1472 bandpos, codsty->
nreslevels - reslevelno - 1);
1485 if (
s->compression_rate_enc)
1503 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++){
1504 if (
s->tile[tileno].comp) {
1505 for (compno = 0; compno <
s->ncomponents; compno++){
1519 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++){
1521 for (compno = 0; compno <
s->ncomponents; compno++)
1532 const AVFrame *pict,
int *got_packet)
1536 uint8_t *chunkstart, *jp2cstart, *jp2hstart;
1560 bytestream_put_be32(&
s->buf, 0x0000000C);
1561 bytestream_put_be32(&
s->buf, 0x6A502020);
1562 bytestream_put_be32(&
s->buf, 0x0D0A870A);
1564 chunkstart =
s->buf;
1565 bytestream_put_be32(&
s->buf, 0);
1568 bytestream_put_be32(&
s->buf, 0);
1573 bytestream_put_be32(&
s->buf, 0);
1576 chunkstart =
s->buf;
1577 bytestream_put_be32(&
s->buf, 0);
1579 bytestream_put_be32(&
s->buf, avctx->
height);
1580 bytestream_put_be32(&
s->buf, avctx->
width);
1581 bytestream_put_be16(&
s->buf,
s->ncomponents);
1582 bytestream_put_byte(&
s->buf,
s->cbps[0]);
1583 bytestream_put_byte(&
s->buf, 7);
1584 bytestream_put_byte(&
s->buf, 0);
1585 bytestream_put_byte(&
s->buf, 0);
1588 chunkstart =
s->buf;
1589 bytestream_put_be32(&
s->buf, 0);
1591 bytestream_put_byte(&
s->buf, 1);
1592 bytestream_put_byte(&
s->buf, 0);
1593 bytestream_put_byte(&
s->buf, 0);
1595 bytestream_put_be32(&
s->buf, 16);
1596 }
else if (
s->ncomponents == 1) {
1597 bytestream_put_be32(&
s->buf, 17);
1599 bytestream_put_be32(&
s->buf, 18);
1604 const uint8_t *palette = pict->
data[1];
1605 chunkstart =
s->buf;
1606 bytestream_put_be32(&
s->buf, 0);
1609 bytestream_put_byte(&
s->buf, 3);
1610 bytestream_put_be24(&
s->buf, 0x070707);
1612 bytestream_put_be24(&
s->buf, HAVE_BIGENDIAN ?
AV_RB24(palette + 1) :
AV_RL24(palette));
1616 chunkstart =
s->buf;
1617 bytestream_put_be32(&
s->buf, 0);
1619 for (
i = 0;
i < 3;
i++) {
1620 bytestream_put_be16(&
s->buf, 0);
1621 bytestream_put_byte(&
s->buf, 1);
1622 bytestream_put_byte(&
s->buf,
i);
1629 bytestream_put_be32(&
s->buf, 0);
1633 if (
s->buf_end -
s->buf < 2)
1645 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++){
1647 if (!(psotptr =
put_sot(
s, tileno)))
1649 if (
s->buf_end -
s->buf < 2)
1654 bytestream_put_be32(&psotptr,
s->buf - psotptr + 6);
1656 if (
s->buf_end -
s->buf < 2)
1674 char *saveptr =
NULL;
1679 s->layer_rates[0] = 0;
1680 s->compression_rate_enc = 0;
1685 if (token && (rate = strtol(token,
NULL, 10))) {
1686 s->layer_rates[0] = rate <= 1 ? 0:rate;
1696 if (rate = strtol(token,
NULL, 10)) {
1697 if (nlayers >= 100) {
1700 s->layer_rates[nlayers] = rate <= 1 ? 0:rate;
1707 for (
i = 1;
i < nlayers;
i++) {
1708 if (
s->layer_rates[
i] >=
s->layer_rates[
i-1]) {
1712 s->nlayers = nlayers;
1713 s->compression_rate_enc = 1;
1731 s->layer_rates[0] = 0;
1732 s->compression_rate_enc = 0;
1754 if ((
s->tile_width & (
s->tile_width -1)) ||
1755 (
s->tile_height & (
s->tile_height-1))) {
1767 s->ncomponents =
desc->nb_components;
1768 for (
i = 0;
i < 4;
i++) {
1769 s->cbps[
i] =
desc->comp[
i].depth;
1770 s->comp_remap[
i] =
i;
1776 s->chroma_shift,
s->chroma_shift + 1);
1780 s->comp_remap[0] = 2;
1781 s->comp_remap[1] = 0;
1782 s->comp_remap[2] = 1;
1807 #define OFFSET(x) offsetof(Jpeg2000EncoderContext, x)
1808 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1838 .
p.
name =
"jpeg2000",