84#define NMSEDEC_FRACBITS (NMSEDEC_BITS-1)
85#define WMSEDEC_SHIFT 13
86#define LAMBDA_SCALE (100000000LL << (WMSEDEC_SHIFT - 13))
97 {{10000, 19650, 41770, 84030, 169000, 338400, 676900, 1353000, 2706000, 5409000},
98 {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
99 {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
100 {20800, 38650, 83070, 171800, 347100, 695900, 1393000, 2786000, 5572000}},
102 {{10000, 15000, 27500, 53750, 106800, 213400, 426700, 853300, 1707000, 3413000},
103 {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
104 {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
105 { 7186, 9218, 15860, 30430, 60190, 120100, 240000, 479700, 959300}}
158 if (
s->bit_index == 8)
160 s->bit_index = *
s->buf == 0xff;
163 *
s->buf |=
val >>
s->bit_index++;
191 int sp = -1, curval = 0;
205 if (node->
val >= threshold) {
239 if (
s->buf_end -
s->buf < 40 + 3 *
s->ncomponents)
243 bytestream_put_be16(&
s->buf, 38 + 3 *
s->ncomponents);
244 bytestream_put_be16(&
s->buf, 0);
245 bytestream_put_be32(&
s->buf,
s->width);
246 bytestream_put_be32(&
s->buf,
s->height);
247 bytestream_put_be32(&
s->buf, 0);
248 bytestream_put_be32(&
s->buf, 0);
250 bytestream_put_be32(&
s->buf,
s->tile_width);
251 bytestream_put_be32(&
s->buf,
s->tile_height);
252 bytestream_put_be32(&
s->buf, 0);
253 bytestream_put_be32(&
s->buf, 0);
254 bytestream_put_be16(&
s->buf,
s->ncomponents);
256 for (
i = 0;
i <
s->ncomponents;
i++){
257 bytestream_put_byte(&
s->buf,
s->cbps[
i] - 1);
258 bytestream_put_byte(&
s->buf, (
i+1&2)?1<<
s->chroma_shift[0]:1);
259 bytestream_put_byte(&
s->buf, (
i+1&2)?1<<
s->chroma_shift[1]:1);
269 if (
s->buf_end -
s->buf < 14)
273 bytestream_put_be16(&
s->buf, 12);
278 bytestream_put_byte(&
s->buf, scod);
280 bytestream_put_byte(&
s->buf,
s->prog);
281 bytestream_put_be16(&
s->buf,
s->nlayers);
283 bytestream_put_byte(&
s->buf, 0);
285 bytestream_put_byte(&
s->buf, 0);
288 bytestream_put_byte(&
s->buf, codsty->
nreslevels - 1);
291 bytestream_put_byte(&
s->buf, 0);
307 if (
s->buf_end -
s->buf <
size + 2)
311 bytestream_put_be16(&
s->buf,
size);
315 bytestream_put_byte(&
s->buf, qntsty->
expn[
i] << 3);
318 bytestream_put_be16(&
s->buf, (qntsty->
expn[
i] << 11) | qntsty->
mant[
i]);
329 if (
s->buf_end -
s->buf <
size + 2)
333 bytestream_put_be16(&
s->buf,
size);
334 bytestream_put_be16(&
s->buf, 1);
345 if (
s->buf_end -
s->buf < 12)
349 bytestream_put_be16(&
s->buf, 10);
350 bytestream_put_be16(&
s->buf, tileno);
353 bytestream_put_be32(&
s->buf, 0);
355 bytestream_put_byte(&
s->buf, 0);
356 bytestream_put_byte(&
s->buf, 1);
364 for (
i = 0;
i <
s->numYtiles;
i++) {
365 for (j = 0; j <
s->numXtiles; j++) {
367 for (compno = 0; compno <
s->ncomponents; compno++) {
368 int tilew =
tile->comp[compno].coord[0][1] -
tile->comp[compno].coord[0][0];
369 int tileh =
tile->comp[compno].coord[1][1] -
tile->comp[compno].coord[1][0];
370 int scale = ((compno+1&2)?1 <<
s->chroma_shift[0]:1) * ((compno+1&2)?1 <<
s->chroma_shift[1]:1);
371 for (layno = 0; layno <
s->nlayers; layno++) {
372 if (
s->layer_rates[layno] > 0) {
373 tile->layer_rates[layno] += (
double)(tilew * tileh) *
s->ncomponents *
s->cbps[compno] /
376 tile->layer_rates[layno] = 0.0;
392 int tileno, tilex, tiley, compno;
402 for (tileno = 0, tiley = 0; tiley <
s->numYtiles; tiley++)
403 for (tilex = 0; tilex <
s->numXtiles; tilex++, tileno++){
411 if (!
tile->layer_rates)
414 for (compno = 0; compno <
s->ncomponents; compno++){
418 comp->coord[0][0] =
comp->coord_o[0][0] = tilex *
s->tile_width;
419 comp->coord[0][1] =
comp->coord_o[0][1] =
FFMIN((tilex+1)*
s->tile_width,
s->width);
420 comp->coord[1][0] =
comp->coord_o[1][0] = tiley *
s->tile_height;
421 comp->coord[1][1] =
comp->coord_o[1][1] =
FFMIN((tiley+1)*
s->tile_height,
s->height);
423 for (
i = 0;
i < 2;
i++)
424 for (j = 0; j < 2; j++)
431 (compno+1&2)?1<<
s->chroma_shift[0]:1,
432 (compno+1&2)?1<<
s->chroma_shift[1]:1,
442#define COPY_FRAME(D, PIXEL) \
443 static void copy_frame_ ##D(Jpeg2000EncoderContext *s) \
445 int tileno, compno, i, y, x; \
447 for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){ \
448 Jpeg2000Tile *tile = s->tile + tileno; \
450 for (compno = 0; compno < s->ncomponents; compno++){ \
451 int icompno = s->comp_remap[compno]; \
452 Jpeg2000Component *comp = tile->comp + compno; \
453 int *dst = comp->i_data; \
454 int cbps = s->cbps[compno]; \
455 line = (const PIXEL*)s->picture->data[icompno] \
456 + comp->coord[1][0] * (s->picture->linesize[icompno] / sizeof(PIXEL)) \
457 + comp->coord[0][0]; \
458 for (y = comp->coord[1][0]; y < comp->coord[1][1]; y++){ \
459 const PIXEL *ptr = line; \
460 for (x = comp->coord[0][0]; x < comp->coord[0][1]; x++) \
461 *dst++ = *ptr++ - (1 << (cbps - 1)); \
462 line += s->picture->linesize[icompno] / sizeof(PIXEL); \
466 line = (const PIXEL*)(s->picture->data[0] + tile->comp[0].coord[1][0] * s->picture->linesize[0]) \
467 + tile->comp[0].coord[0][0] * s->ncomponents; \
470 for (y = tile->comp[0].coord[1][0]; y < tile->comp[0].coord[1][1]; y++){ \
471 const PIXEL *ptr = line; \
472 for (x = tile->comp[0].coord[0][0]; x < tile->comp[0].coord[0][1]; x++, i++){ \
473 for (compno = 0; compno < s->ncomponents; compno++){ \
474 int cbps = s->cbps[compno]; \
475 tile->comp[compno].i_data[i] = *ptr++ - (1 << (cbps - 1)); \
478 line += s->picture->linesize[0] / sizeof(PIXEL); \
489 int compno, reslevelno, bandno;
493 for (compno = 0; compno <
s->ncomponents; compno++){
495 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
497 nbands = reslevelno ? 3 : 1;
498 for (bandno = 0; bandno < nbands; bandno++, gbandno++){
502 int bandpos = bandno + (reslevelno>0),
505 mant = (11 - log < 0 ? ss >> log - 11 :
ss << 11 - log) & 0x7ff;
506 expn =
s->cbps[compno] - log + 13;
508 expn = ((bandno&2)>>1) + (reslevelno>0) +
s->cbps[compno];
510 qntsty->
expn[gbandno] = expn;
511 qntsty->
mant[gbandno] = mant;
528 (1 << 13) - (
a *
a << 11), 0);
553 for (y0 = 0; y0 <
height; y0 += 4)
554 for (x = 0; x <
width; x++)
555 for (y = y0; y <
height && y < y0+4; y++){
575 for (y0 = 0; y0 <
height; y0 += 4)
576 for (x = 0; x <
width; x++)
577 for (y = y0; y <
height && y < y0+4; y++)
589 for (y0 = 0; y0 <
height; y0 += 4)
590 for (x = 0; x <
width; x++){
599 for (rlen = 0; rlen < 4; rlen++)
607 for (y = y0 + rlen; y < y0 + 4; y++){
623 for (y = y0; y < y0 + 4 && y <
height; y++){
644 int pass_t = 2, passno, x, y,
max=0, nmsedec, bpno;
649 for (y = 0; y <
height; y++){
650 for (x = 0; x <
width; x++){
669 for (passno = 0; bpno >= 0; passno++){
684 wmsedec += (
int64_t)nmsedec << (2*bpno);
719 int precno,
const uint8_t *expn,
int numgbits,
int packetno,
722 int bandno, empty = 1;
726 bytestream_put_be16(&
s->buf, 4);
727 bytestream_put_be16(&
s->buf, packetno);
737 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
752 for (
i = 0;
i < nlayers;
i++) {
767 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
786 if (
s->buf_end -
s->buf < 3)
797 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
809 int llen = 0, length;
812 if (
s->buf_end -
s->buf < 20)
851 if (
s->buf_end -
s->buf < 2 + 2 *
s->eph)
859 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
865 for (
xi = 0;
xi < cblknw;
xi++){
884 int compno, reslevelno, layno, ret;
890 int tile_coord[2][2];
891 int col = tileno %
s->numXtiles;
892 int row = tileno /
s->numXtiles;
894 tile_coord[0][0] = col *
s->tile_width;
895 tile_coord[0][1] =
FFMIN(tile_coord[0][0] +
s->tile_width,
s->width);
896 tile_coord[1][0] = row *
s->tile_height;
897 tile_coord[1][1] =
FFMIN(tile_coord[1][0] +
s->tile_height,
s->height);
903 for (layno = 0; layno < nlayers; layno++) {
904 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
905 for (compno = 0; compno <
s->ncomponents; compno++){
909 if ((ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
910 qntsty->
nguardbits, packetno++, nlayers)) < 0)
918 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
919 for (layno = 0; layno < nlayers; layno++) {
920 for (compno = 0; compno <
s->ncomponents; compno++){
924 if ((ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
925 qntsty->
nguardbits, packetno++, nlayers)) < 0)
933 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
937 for (compno = 0; compno <
s->ncomponents; compno++) {
939 if (reslevelno < codsty->nreslevels) {
940 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
949 for (y = tile_coord[1][0]; y < tile_coord[1][1]; y = (y/step_y + 1)*step_y) {
950 for (x = tile_coord[0][0]; x < tile_coord[0][1]; x = (x/step_x + 1)*step_x) {
951 for (compno = 0; compno <
s->ncomponents; compno++) {
953 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
955 int log_subsampling[2] = { (compno+1&2)?
s->chroma_shift[0]:0, (compno+1&2)?
s->chroma_shift[1]:0};
962 if (!(y % ((uint64_t)1 << (reslevel->
log2_prec_height + reducedresno + log_subsampling[1])) == 0 ||
963 (y == tile_coord[1][0] && (try0 << reducedresno) % (1U << (reducedresno + reslevel->
log2_prec_height)))))
966 if (!(x % ((uint64_t)1 << (reslevel->
log2_prec_width + reducedresno + log_subsampling[0])) == 0 ||
967 (x == tile_coord[0][0] && (trx0 << reducedresno) % (1U << (reducedresno + reslevel->
log2_prec_width)))))
982 for (layno = 0; layno < nlayers; layno++) {
983 if ((ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
984 qntsty->
nguardbits, packetno++, nlayers)) < 0)
995 for (compno = 0; compno <
s->ncomponents; compno++) {
998 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
999 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1005 if (step_x >= 31 || step_y >= 31){
1012 for (y = tile_coord[1][0]; y < tile_coord[1][1]; y = (y/step_y + 1)*step_y) {
1013 for (x = tile_coord[0][0]; x < tile_coord[0][1]; x = (x/step_x + 1)*step_x) {
1014 for (compno = 0; compno <
s->ncomponents; compno++) {
1016 int log_subsampling[2] = { (compno+1&2)?
s->chroma_shift[0]:0, (compno+1&2)?
s->chroma_shift[1]:0};
1018 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1019 unsigned prcx, prcy;
1021 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1028 if (!(y % ((uint64_t)1 << (reslevel->
log2_prec_height + reducedresno + log_subsampling[1])) == 0 ||
1029 (y == tile_coord[1][0] && (try0 << reducedresno) % (1U << (reducedresno + reslevel->
log2_prec_height)))))
1032 if (!(x % ((uint64_t)1 << (reslevel->
log2_prec_width + reducedresno + log_subsampling[0])) == 0 ||
1033 (x == tile_coord[0][0] && (trx0 << reducedresno) % (1U << (reducedresno + reslevel->
log2_prec_width)))))
1049 for (layno = 0; layno < nlayers; layno++) {
1050 if ((ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
1051 qntsty->
nguardbits, packetno++, nlayers)) < 0)
1060 for (compno = 0; compno <
s->ncomponents; compno++) {
1062 int log_subsampling[2] = { (compno+1&2)?
s->chroma_shift[0]:0, (compno+1&2)?
s->chroma_shift[1]:0};
1066 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1067 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1072 if (step_x >= 31 || step_y >= 31){
1079 for (y = tile_coord[1][0]; y < tile_coord[1][1]; y = (y/step_y + 1)*step_y) {
1080 for (x = tile_coord[0][0]; x < tile_coord[0][1]; x = (x/step_x + 1)*step_x) {
1081 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1082 unsigned prcx, prcy;
1085 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1091 if (!(y % ((uint64_t)1 << (reslevel->
log2_prec_height + reducedresno + log_subsampling[1])) == 0 ||
1092 (y == tile_coord[1][0] && (try0 << reducedresno) % (1U << (reducedresno + reslevel->
log2_prec_height)))))
1095 if (!(x % ((uint64_t)1 << (reslevel->
log2_prec_width + reducedresno + log_subsampling[0])) == 0 ||
1096 (x == tile_coord[0][0] && (trx0 << reducedresno) % (1U << (reducedresno + reslevel->
log2_prec_width)))))
1112 for (layno = 0; layno < nlayers; layno++) {
1113 if ((ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
1114 qntsty->
nguardbits, packetno++, nlayers)) < 0)
1130 int compno, resno, bandno, precno, cblkno;
1133 for (compno = 0; compno <
s->ncomponents; compno++) {
1136 for (resno = 0; resno <
s->codsty.nreslevels; resno++) {
1140 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1158 for (passno = cblk->
ninclpasses; passno < cblk->npasses; passno++) {
1178 if (thresh - (dd / dr) < DBL_EPSILON)
1213 int precno, compno, reslevelno, bandno, cblkno, passno, layno;
1215 double min = DBL_MAX;
1221 for (compno = 0; compno <
s->ncomponents; compno++){
1224 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
1228 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1234 for (passno = 0; passno < cblk->
npasses; passno++) {
1263 for (layno = 0; layno <
s->nlayers; layno++) {
1266 double stable_thresh = 0.0;
1267 double good_thresh = 0.0;
1268 if (!
s->layer_rates[layno]) {
1271 for (
i = 0;
i < 128;
i++) {
1272 uint8_t *stream_pos =
s->buf;
1274 thresh = (lo + hi) / 2;
1277 memset(stream_pos, 0,
s->buf - stream_pos);
1278 if ((
s->buf - stream_pos >
ceil(
tile->layer_rates[layno])) || ret < 0) {
1280 s->buf = stream_pos;
1284 stable_thresh = thresh;
1285 s->buf = stream_pos;
1288 if (good_thresh >= 0.0)
1289 good_thresh = stable_thresh == 0.0 ? thresh : stable_thresh;
1296 int passno, res = 0;
1297 for (passno = 0; passno < cblk->
npasses; passno++){
1306 if (dd >= dr * lambda)
1314 int precno, compno, reslevelno, bandno, cblkno,
lev;
1317 for (compno = 0; compno <
s->ncomponents; compno++){
1320 for (reslevelno = 0,
lev = codsty->
nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++,
lev--){
1324 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1325 int bandpos = bandno + (reslevelno > 0);
1349 int compno, reslevelno, bandno, ret;
1352 for (compno = 0; compno <
s->ncomponents; compno++){
1362 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
1365 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1368 int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos;
1369 yy0 = bandno == 0 ? 0 :
comp->reslevel[reslevelno-1].coord[1][1] -
comp->reslevel[reslevelno-1].coord[1][0];
1372 band->
coord[1][1]) - band->
coord[1][0] + yy0;
1377 bandpos = bandno + (reslevelno > 0);
1380 if (reslevelno == 0 || bandno == 1)
1383 xx0 =
comp->reslevel[reslevelno-1].coord[0][1] -
comp->reslevel[reslevelno-1].coord[0][0];
1386 band->
coord[0][1]) - band->
coord[0][0] + xx0;
1391 for (y = yy0; y < yy1; y++){
1393 for (x = xx0; x < xx1; x++){
1399 for (y = yy0; y < yy1; y++){
1401 for (x = xx0; x < xx1; x++){
1402 *ptr = (
comp->i_data[(
comp->coord[0][1] -
comp->coord[0][0]) * y + x]);
1415 bandpos, codsty->
nreslevels - reslevelno - 1);
1428 if (
s->compression_rate_enc)
1446 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++){
1447 if (
s->tile[tileno].comp) {
1448 for (compno = 0; compno <
s->ncomponents; compno++){
1462 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++){
1464 for (compno = 0; compno <
s->ncomponents; compno++)
1475 const AVFrame *pict,
int *got_packet)
1479 uint8_t *chunkstart, *jp2cstart, *jp2hstart;
1486 s->buf =
s->buf_start =
pkt->data;
1487 s->buf_end =
pkt->data +
pkt->size;
1503 bytestream_put_be32(&
s->buf, 0x0000000C);
1504 bytestream_put_be32(&
s->buf, 0x6A502020);
1505 bytestream_put_be32(&
s->buf, 0x0D0A870A);
1507 chunkstart =
s->buf;
1508 bytestream_put_be32(&
s->buf, 0);
1511 bytestream_put_be32(&
s->buf, 0);
1516 bytestream_put_be32(&
s->buf, 0);
1519 chunkstart =
s->buf;
1520 bytestream_put_be32(&
s->buf, 0);
1522 bytestream_put_be32(&
s->buf, avctx->
height);
1523 bytestream_put_be32(&
s->buf, avctx->
width);
1524 bytestream_put_be16(&
s->buf,
s->ncomponents);
1525 bytestream_put_byte(&
s->buf,
s->cbps[0]);
1526 bytestream_put_byte(&
s->buf, 7);
1527 bytestream_put_byte(&
s->buf, 0);
1528 bytestream_put_byte(&
s->buf, 0);
1531 chunkstart =
s->buf;
1532 bytestream_put_be32(&
s->buf, 0);
1534 bytestream_put_byte(&
s->buf, 1);
1535 bytestream_put_byte(&
s->buf, 0);
1536 bytestream_put_byte(&
s->buf, 0);
1538 bytestream_put_be32(&
s->buf, 16);
1539 }
else if (
s->ncomponents == 1) {
1540 bytestream_put_be32(&
s->buf, 17);
1542 bytestream_put_be32(&
s->buf, 18);
1547 const uint8_t *palette = pict->
data[1];
1548 chunkstart =
s->buf;
1549 bytestream_put_be32(&
s->buf, 0);
1552 bytestream_put_byte(&
s->buf, 3);
1553 bytestream_put_be24(&
s->buf, 0x070707);
1555 bytestream_put_be24(&
s->buf, HAVE_BIGENDIAN ?
AV_RB24(palette + 1) :
AV_RL24(palette));
1559 chunkstart =
s->buf;
1560 bytestream_put_be32(&
s->buf, 0);
1562 for (
i = 0;
i < 3;
i++) {
1563 bytestream_put_be16(&
s->buf, 0);
1564 bytestream_put_byte(&
s->buf, 1);
1565 bytestream_put_byte(&
s->buf,
i);
1572 bytestream_put_be32(&
s->buf, 0);
1576 if (
s->buf_end -
s->buf < 2)
1588 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++){
1590 if (!(psotptr =
put_sot(
s, tileno)))
1592 if (
s->buf_end -
s->buf < 2)
1597 bytestream_put_be32(&psotptr,
s->buf - psotptr + 6);
1599 if (
s->buf_end -
s->buf < 2)
1607 pkt->size =
s->buf -
s->buf_start;
1617 char *saveptr =
NULL;
1622 s->layer_rates[0] = 0;
1623 s->compression_rate_enc = 0;
1628 if (token && (rate = strtol(token,
NULL, 10))) {
1629 s->layer_rates[0] = rate <= 1 ? 0:rate;
1639 if (rate = strtol(token,
NULL, 10)) {
1640 if (nlayers >= 100) {
1643 s->layer_rates[nlayers] = rate <= 1 ? 0:rate;
1650 for (
i = 1;
i < nlayers;
i++) {
1651 if (
s->layer_rates[
i] >=
s->layer_rates[
i-1]) {
1655 s->nlayers = nlayers;
1656 s->compression_rate_enc = 1;
1672 av_log(avctx,
AV_LOG_WARNING,
"Layer rates invalid. Encoding with 1 layer based on quality metric.\n");
1674 s->layer_rates[0] = 0;
1675 s->compression_rate_enc = 0;
1697 if ((
s->tile_width & (
s->tile_width -1)) ||
1698 (
s->tile_height & (
s->tile_height-1))) {
1710 s->ncomponents =
desc->nb_components;
1711 for (
i = 0;
i < 4;
i++) {
1712 s->cbps[
i] =
desc->comp[
i].depth;
1713 s->comp_remap[
i] =
i;
1719 s->chroma_shift,
s->chroma_shift + 1);
1723 s->comp_remap[0] = 2;
1724 s->comp_remap[1] = 0;
1725 s->comp_remap[2] = 1;
1750#define OFFSET(x) offsetof(Jpeg2000EncoderContext, x)
1751#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1774 .class_name =
"jpeg 2000 encoder",
1781 .p.name =
"jpeg2000",
static double val(void *priv, double ch)
static const char *const format[]
const FFCodec ff_jpeg2000_encoder
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
static int FUNC tile(CodedBitstreamContext *ctx, RWContext *rw, APVRawTile *current, int tile_idx, uint32_t tile_size)
#define i(width, name, range_min, range_max)
#define xi(width, name, var, range_min, range_max, subs,...)
#define bit(string, value)
#define ss(width, name, subs,...)
static LevelCodes lev[4+3+3]
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal and external API header
static __device__ float ceil(float a)
int(* init)(AVBSFContext *ctx)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
#define FF_INPUT_BUFFER_MIN_SIZE
Used by some encoders as upper bound for the length of headers.
static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, AVPacket *pkt)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
#define LIBAVUTIL_VERSION_INT
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static int init_tiles(Jpeg2000EncoderContext *s)
compute the sizes of tiles, resolution levels, bands, etc.
static int encode_packet(Jpeg2000EncoderContext *s, Jpeg2000ResLevel *rlevel, int layno, int precno, const uint8_t *expn, int numgbits, int packetno, int nlayers)
static int put_com(Jpeg2000EncoderContext *s, int compno)
static int parse_layer_rates(Jpeg2000EncoderContext *s)
#define WMSEDEC_SHIFT
must be >= 13
static void update_size(uint8_t *size, const uint8_t *end)
static void makelayers(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile)
static int getcut(Jpeg2000Cblk *cblk, uint64_t lambda)
static void makelayer(Jpeg2000EncoderContext *s, int layno, double thresh, Jpeg2000Tile *tile, int final)
static av_cold void init_luts(void)
static void truncpasses(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile)
static void putnumpasses(Jpeg2000EncoderContext *s, int n)
static int encode_tile(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno)
static uint8_t * put_sot(Jpeg2000EncoderContext *s, int tileno)
static void encode_refpass(Jpeg2000T1Context *t1, int width, int height, int *nmsedec, int bpno)
static void reinit(Jpeg2000EncoderContext *s)
static int encode_packets(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno, int nlayers)
static av_cold int j2kenc_init(AVCodecContext *avctx)
static int j2kenc_destroy(AVCodecContext *avctx)
static void encode_sigpass(Jpeg2000T1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)
static void init_quantization(Jpeg2000EncoderContext *s)
static int lut_nmsedec_sig0[1<< NMSEDEC_BITS]
static void compute_rates(Jpeg2000EncoderContext *s)
static void tag_tree_update(Jpeg2000TgtNode *node)
update the value in node
static void cleanup(Jpeg2000EncoderContext *s)
static void put_num(Jpeg2000EncoderContext *s, int num, int n)
put n least significant bits of a number num
static void j2k_flush(Jpeg2000EncoderContext *s)
flush the bitstream
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
static int lut_nmsedec_sig[1<< NMSEDEC_BITS]
static int lut_nmsedec_ref0[1<< NMSEDEC_BITS]
static void encode_cblk(Jpeg2000EncoderContext *s, Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk, Jpeg2000Tile *tile, int width, int height, int bandpos, int lev)
static int lut_nmsedec_ref[1<< NMSEDEC_BITS]
static int put_qcd(Jpeg2000EncoderContext *s, int compno)
static int getnmsedec_sig(int x, int bpno)
static int getnmsedec_ref(int x, int bpno)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static void tag_tree_code(Jpeg2000EncoderContext *s, Jpeg2000TgtNode *node, int threshold)
code the value stored in node
static const int dwt_norms[2][4][10]
static const AVClass j2k_class
static void encode_clnpass(Jpeg2000T1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno)
static int put_siz(Jpeg2000EncoderContext *s)
#define COPY_FRAME(D, PIXEL)
static int put_cod(Jpeg2000EncoderContext *s)
void ff_tag_tree_zero(Jpeg2000TgtNode *t, int w, int h, int val)
void av_cold ff_jpeg2000_init_tier1_luts(void)
void ff_jpeg2000_reinit(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
int ff_jpeg2000_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, const int cbps, int dx, int dy, AVCodecContext *avctx)
void ff_jpeg2000_set_significance(Jpeg2000T1Context *t1, int x, int y, int negative)
JPEG 2000 structures and defines common to encoder and decoder.
#define JPEG2000_T1_SIG_NB
#define JPEG2000_CSTY_SOP
static int ff_jpeg2000_ceildivpow2(int a, int b)
#define JPEG2000_PGOD_PCRL
static int ff_jpeg2000_ceildiv(int a, int64_t b)
#define JPEG2000_CSTY_EPH
#define JPEG2000_PGOD_CPRL
#define JPEG2000_PGOD_RPCL
#define JPEG2000_MAX_PASSES
#define JPEG2000_PGOD_RLCP
static int ff_jpeg2000_getsgnctxno(int flag, int *xorbit)
static int ff_jpeg2000_getrefctxno(int flag)
static int ff_jpeg2000_getsigctxno(int flag, int bandno)
#define JPEG2000_PGOD_LRCP
int ff_dwt_encode(DWTContext *s, void *t)
Libavcodec version macros.
Macro definitions for various function/variable attributes.
static int ff_thread_once(char *control, void(*routine)(void))
static const uint16_t mask[17]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
void ff_mqc_encode(MqcState *mqc, uint8_t *cxstate, int d)
code bit d with context cx
int ff_mqc_flush_to(MqcState *mqc, uint8_t *dst, int *dst_len)
flush the encoder [returns number of bytes encoded]
void ff_mqc_initenc(MqcState *mqc, uint8_t *bp)
initialize the encoder
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
#define AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_YUV422P9
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
#define AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUV420P14
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10
static const float pred[4]
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This structure stores compressed data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
uint16_t log2_cblk_height
uint8_t log2_prec_widths[JPEG2000_MAX_RESLEVELS]
uint8_t log2_prec_heights[JPEG2000_MAX_RESLEVELS]
Jpeg2000CodingStyle codsty
uint8_t cbps[4]
bits per sample in particular components
Jpeg2000QuantStyle qntsty
int height
image width and height
uint8_t compression_rate_enc
Is compression done using compression ratio?
Jpeg2000TgtNode * zerobits
Jpeg2000TgtNode * cblkincl
uint16_t mant[JPEG2000_MAX_DECLEVELS *3]
uint8_t expn[JPEG2000_MAX_DECLEVELS *3]
struct Jpeg2000TgtNode * parent
#define av_malloc_array(a, b)
#define avpriv_request_sample(...)