78 #define NMSEDEC_BITS 7
79 #define NMSEDEC_FRACBITS (NMSEDEC_BITS-1)
80 #define WMSEDEC_SHIFT 13
81 #define LAMBDA_SCALE (100000000LL << (WMSEDEC_SHIFT - 13))
92 {{10000, 19650, 41770, 84030, 169000, 338400, 676900, 1353000, 2706000, 5409000},
93 {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
94 {20220, 39890, 83550, 170400, 342700, 686300, 1373000, 2746000, 5490000},
95 {20800, 38650, 83070, 171800, 347100, 695900, 1393000, 2786000, 5572000}},
97 {{10000, 15000, 27500, 53750, 106800, 213400, 426700, 853300, 1707000, 3413000},
98 {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
99 {10380, 15920, 29190, 57030, 113300, 226400, 452500, 904800, 1809000},
100 { 7186, 9218, 15860, 30430, 60190, 120100, 240000, 479700, 959300}}
132 int layer_rates[100];
150 static void nspaces(FILE *fd,
int n)
152 while(n--) putc(
' ', fd);
164 int tileno, compno, reslevelno, bandno, precno;
165 fprintf(fd,
"XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n"
166 "numXtiles = %d, numYtiles = %d, ncomponents = %d\n"
168 s->width,
s->height,
s->tile_width,
s->tile_height,
169 s->numXtiles,
s->numYtiles,
s->ncomponents);
170 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++){
173 fprintf(fd,
"tile %d:\n", tileno);
174 for(compno = 0; compno <
s->ncomponents; compno++){
177 fprintf(fd,
"component %d:\n", compno);
179 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d\n",
181 for(reslevelno = 0; reslevelno <
s->nreslevels; reslevelno++){
184 fprintf(fd,
"reslevel %d:\n", reslevelno);
186 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d, nbands = %d\n",
187 reslevel->x0, reslevel->x1, reslevel->y0,
188 reslevel->y1, reslevel->
nbands);
189 for(bandno = 0; bandno < reslevel->
nbands; bandno++){
192 fprintf(fd,
"band %d:\n", bandno);
194 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d,"
195 "codeblock_width = %d, codeblock_height = %d cblknx = %d cblkny = %d\n",
198 band->codeblock_width, band->codeblock_height,
199 band->cblknx, band->cblkny);
203 fprintf(fd,
"prec %d:\n", precno);
205 fprintf(fd,
"xi0 = %d, xi1 = %d, yi0 = %d, yi1 = %d\n",
206 prec->xi0, prec->xi1, prec->yi0, prec->yi1);
221 if (
s->bit_index == 8)
223 s->bit_index = *
s->buf == 0xff;
226 *
s->buf |=
val << (7 -
s->bit_index++);
254 int sp = -1, curval = 0;
268 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<<
s->chroma_shift[0]:1);
324 bytestream_put_byte(&
s->buf,
i?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 <<
s->chroma_shift[0]:1) * (compno?1 <<
s->chroma_shift[1]:1);
436 for (layno = 0; layno <
s->nlayers; layno++) {
437 if (
s->layer_rates[layno] > 0) {
438 tile->
layer_rates[layno] += (double)(tilew * tileh) *
s->ncomponents *
s->cbps[compno] /
439 (double)(
s->layer_rates[layno] * 8 * scale);
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<<
s->chroma_shift[0]:1,
497 compno?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 Jpeg2000Component *comp = tile->comp + compno; \
517 int *dst = comp->i_data; \
518 int cbps = s->cbps[compno]; \
519 line = (PIXEL*)s->picture->data[compno] \
520 + comp->coord[1][0] * (s->picture->linesize[compno] / sizeof(PIXEL)) \
521 + comp->coord[0][0]; \
522 for (y = comp->coord[1][0]; y < comp->coord[1][1]; y++){ \
524 for (x = comp->coord[0][0]; x < comp->coord[0][1]; x++) \
525 *dst++ = *ptr++ - (1 << (cbps - 1)); \
526 line += s->picture->linesize[compno] / sizeof(PIXEL); \
530 line = (PIXEL*)s->picture->data[0] + tile->comp[0].coord[1][0] * (s->picture->linesize[0] / sizeof(PIXEL)) \
531 + tile->comp[0].coord[0][0] * s->ncomponents; \
534 for (y = tile->comp[0].coord[1][0]; y < tile->comp[0].coord[1][1]; y++){ \
536 for (x = tile->comp[0].coord[0][0]; x < tile->comp[0].coord[0][1]; x++, i++){ \
537 for (compno = 0; compno < s->ncomponents; compno++){ \
538 int cbps = s->cbps[compno]; \
539 tile->comp[compno].i_data[i] = *ptr++ - (1 << (cbps - 1)); \
542 line += s->picture->linesize[0] / sizeof(PIXEL); \
553 int compno, reslevelno, bandno;
557 for (compno = 0; compno <
s->ncomponents; compno++){
559 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
561 nbands = reslevelno ? 3 : 1;
562 for (bandno = 0; bandno < nbands; bandno++, gbandno++){
566 int bandpos = bandno + (reslevelno>0),
569 mant = (11 - log < 0 ? ss >> log - 11 :
ss << 11 - log) & 0x7ff;
570 expn =
s->cbps[compno] - log + 13;
572 expn = ((bandno&2)>>1) + (reslevelno>0) +
s->cbps[compno];
574 qntsty->
expn[gbandno] = expn;
575 qntsty->
mant[gbandno] = mant;
592 (1 << 13) - (
a *
a << 11), 0);
616 for (y0 = 0; y0 <
height; y0 += 4)
617 for (x = 0; x <
width; x++)
618 for (y = y0; y <
height && y < y0+4; y++){
621 bit =
t1->data[(y) *
t1->stride + x] &
mask ? 1 : 0;
626 ff_mqc_encode(&
t1->mqc,
t1->mqc.cx_states + ctxno, (
t1->flags[(y+1) *
t1->stride + x+1] >> 15) ^ xorbit);
638 for (y0 = 0; y0 <
height; y0 += 4)
639 for (x = 0; x <
width; x++)
640 for (y = y0; y <
height && y < y0+4; y++)
652 for (y0 = 0; y0 <
height; y0 += 4)
653 for (x = 0; x <
width; x++){
662 for (rlen = 0; rlen < 4; rlen++)
663 if (
t1->data[(y0+rlen) *
t1->stride + x] &
mask)
670 for (y = y0 + rlen; y < y0 + 4; y++){
675 if (
t1->data[(y) *
t1->stride + x] &
mask){
679 ff_mqc_encode(&
t1->mqc,
t1->mqc.cx_states + ctxno, (
t1->flags[(y+1) *
t1->stride + x+1] >> 15) ^ xorbit);
686 for (y = y0; y < y0 + 4 && y <
height; y++){
690 if (
t1->data[(y) *
t1->stride + x] &
mask){
694 ff_mqc_encode(&
t1->mqc,
t1->mqc.cx_states + ctxno, (
t1->flags[(y+1) *
t1->stride + x+1] >> 15) ^ xorbit);
707 int pass_t = 2, passno, x, y,
max=0, nmsedec, bpno;
710 memset(
t1->flags, 0,
t1->stride * (
height + 2) *
sizeof(*
t1->flags));
712 for (y = 0; y <
height; y++){
713 for (x = 0; x <
width; x++){
714 if (
t1->data[(y) *
t1->stride + x] < 0){
716 t1->data[(y) *
t1->stride + x] = -
t1->data[(y) *
t1->stride + x];
732 for (passno = 0; bpno >= 0; passno++){
747 wmsedec += (
int64_t)nmsedec << (2*bpno);
782 int precno,
uint8_t *expn,
int numgbits,
int packetno,
785 int bandno, empty = 1;
789 bytestream_put_be16(&
s->buf, 4);
790 bytestream_put_be16(&
s->buf, packetno);
800 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
815 for (
i = 0;
i < nlayers;
i++) {
830 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
849 if (
s->buf_end -
s->buf < 3)
860 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
872 int llen = 0, length;
875 if (
s->buf_end -
s->buf < 20)
914 if (
s->buf_end -
s->buf < 2 + 2 *
s->eph)
922 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
928 for (
xi = 0;
xi < cblknw;
xi++){
947 int compno, reslevelno, layno, ret;
953 int tile_coord[2][2];
954 int col = tileno %
s->numXtiles;
955 int row = tileno /
s->numXtiles;
957 tile_coord[0][0] = col *
s->tile_width;
958 tile_coord[0][1] =
FFMIN(tile_coord[0][0] +
s->tile_width,
s->width);
959 tile_coord[1][0] = row *
s->tile_height;
960 tile_coord[1][1] =
FFMIN(tile_coord[1][0] +
s->tile_height,
s->height);
966 for (layno = 0; layno < nlayers; layno++) {
967 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
968 for (compno = 0; compno <
s->ncomponents; compno++){
972 if ((ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
973 qntsty->
nguardbits, packetno++, nlayers)) < 0)
981 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
982 for (layno = 0; layno < nlayers; layno++) {
983 for (compno = 0; compno <
s->ncomponents; compno++){
987 if ((ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
988 qntsty->
nguardbits, packetno++, nlayers)) < 0)
996 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1000 for (compno = 0; compno <
s->ncomponents; compno++) {
1002 if (reslevelno < codsty->nreslevels) {
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++) {
1018 int log_subsampling[2] = { compno?
s->chroma_shift[0]:0, compno?
s->chroma_shift[1]:0};
1019 unsigned prcx, prcy;
1025 if (!(y % ((uint64_t)1 << (reslevel->
log2_prec_height + reducedresno + log_subsampling[1])) == 0 ||
1026 (y == tile_coord[1][0] && (try0 << reducedresno) % (1U << (reducedresno + reslevel->
log2_prec_height)))))
1029 if (!(x % ((uint64_t)1 << (reslevel->
log2_prec_width + reducedresno + log_subsampling[0])) == 0 ||
1030 (x == tile_coord[0][0] && (trx0 << reducedresno) % (1U << (reducedresno + reslevel->
log2_prec_width)))))
1045 for (layno = 0; layno < nlayers; layno++) {
1046 if ((ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
1047 qntsty->
nguardbits, packetno++, nlayers)) < 0)
1058 for (compno = 0; compno <
s->ncomponents; compno++) {
1061 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1068 if (step_x >= 31 || step_y >= 31){
1075 for (y = tile_coord[1][0]; y < tile_coord[1][1]; y = (y/step_y + 1)*step_y) {
1076 for (x = tile_coord[0][0]; x < tile_coord[0][1]; x = (x/step_x + 1)*step_x) {
1077 for (compno = 0; compno <
s->ncomponents; compno++) {
1079 int log_subsampling[2] = { compno?
s->chroma_shift[0]:0, compno?
s->chroma_shift[1]:0};
1081 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1082 unsigned prcx, prcy;
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)
1123 for (compno = 0; compno <
s->ncomponents; compno++) {
1125 int log_subsampling[2] = { compno?
s->chroma_shift[0]:0, compno?
s->chroma_shift[1]:0};
1129 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1135 if (step_x >= 31 || step_y >= 31){
1142 for (y = tile_coord[1][0]; y < tile_coord[1][1]; y = (y/step_y + 1)*step_y) {
1143 for (x = tile_coord[0][0]; x < tile_coord[0][1]; x = (x/step_x + 1)*step_x) {
1144 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1145 unsigned prcx, prcy;
1154 if (!(y % ((uint64_t)1 << (reslevel->
log2_prec_height + reducedresno + log_subsampling[1])) == 0 ||
1155 (y == tile_coord[1][0] && (try0 << reducedresno) % (1U << (reducedresno + reslevel->
log2_prec_height)))))
1158 if (!(x % ((uint64_t)1 << (reslevel->
log2_prec_width + reducedresno + log_subsampling[0])) == 0 ||
1159 (x == tile_coord[0][0] && (trx0 << reducedresno) % (1U << (reducedresno + reslevel->
log2_prec_width)))))
1175 for (layno = 0; layno < nlayers; layno++) {
1176 if ((ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
1177 qntsty->
nguardbits, packetno++, nlayers)) < 0)
1193 int compno, resno, bandno, precno, cblkno;
1196 for (compno = 0; compno <
s->ncomponents; compno++) {
1199 for (resno = 0; resno <
s->codsty.nreslevels; resno++) {
1203 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1221 for (passno = cblk->
ninclpasses; passno < cblk->npasses; passno++) {
1241 if (thresh - (dd / dr) < DBL_EPSILON)
1276 int precno, compno, reslevelno, bandno, cblkno,
lev, passno, layno;
1278 double min = DBL_MAX;
1285 for (compno = 0; compno <
s->ncomponents; compno++){
1288 for (reslevelno = 0,
lev = codsty->
nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++,
lev--){
1292 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1298 for (passno = 0; passno < cblk->
npasses; passno++) {
1303 tile_disto +=
pass->disto;
1328 for (layno = 0; layno <
s->nlayers; layno++) {
1331 double stable_thresh = 0.0;
1332 double good_thresh = 0.0;
1333 if (!
s->layer_rates[layno]) {
1336 for (
i = 0;
i < 128;
i++) {
1339 thresh = (lo + hi) / 2;
1342 memset(stream_pos, 0,
s->buf - stream_pos);
1345 s->buf = stream_pos;
1349 stable_thresh = thresh;
1350 s->buf = stream_pos;
1353 if (good_thresh >= 0.0)
1354 good_thresh = stable_thresh == 0.0 ? thresh : stable_thresh;
1361 int passno, res = 0;
1362 for (passno = 0; passno < cblk->
npasses; passno++){
1371 if (((dd * dwt_norm) >>
WMSEDEC_SHIFT) * dwt_norm >= dr * lambda)
1379 int precno, compno, reslevelno, bandno, cblkno,
lev;
1382 for (compno = 0; compno <
s->ncomponents; compno++){
1385 for (reslevelno = 0,
lev = codsty->
nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++,
lev--){
1389 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1390 int bandpos = bandno + (reslevelno > 0);
1413 int compno, reslevelno, bandno, ret;
1416 for (compno = 0; compno <
s->ncomponents; compno++){
1426 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
1429 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1432 int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos;
1433 yy0 = bandno == 0 ? 0 :
comp->reslevel[reslevelno-1].coord[1][1] -
comp->reslevel[reslevelno-1].coord[1][0];
1436 band->
coord[1][1]) - band->
coord[1][0] + yy0;
1441 bandpos = bandno + (reslevelno > 0);
1444 if (reslevelno == 0 || bandno == 1)
1447 xx0 =
comp->reslevel[reslevelno-1].coord[0][1] -
comp->reslevel[reslevelno-1].coord[0][0];
1450 band->
coord[0][1]) - band->
coord[0][0] + xx0;
1455 for (y = yy0; y < yy1; y++){
1456 int *ptr =
t1.data + (y-yy0)*
t1.stride;
1457 for (x = xx0; x < xx1; x++){
1462 for (y = yy0; y < yy1; y++){
1463 int *ptr =
t1.data + (y-yy0)*
t1.stride;
1464 for (x = xx0; x < xx1; x++){
1465 *ptr = (
comp->i_data[(
comp->coord[0][1] -
comp->coord[0][0]) * y + x]);
1478 bandpos, codsty->
nreslevels - reslevelno - 1);
1491 if (
s->compression_rate_enc)
1509 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++){
1510 if (
s->tile[tileno].comp) {
1511 for (compno = 0; compno <
s->ncomponents; compno++){
1525 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++){
1527 for (compno = 0; compno <
s->ncomponents; compno++)
1538 const AVFrame *pict,
int *got_packet)
1542 uint8_t *chunkstart, *jp2cstart, *jp2hstart;
1566 bytestream_put_be32(&
s->buf, 0x0000000C);
1567 bytestream_put_be32(&
s->buf, 0x6A502020);
1568 bytestream_put_be32(&
s->buf, 0x0D0A870A);
1570 chunkstart =
s->buf;
1571 bytestream_put_be32(&
s->buf, 0);
1574 bytestream_put_be32(&
s->buf, 0);
1579 bytestream_put_be32(&
s->buf, 0);
1582 chunkstart =
s->buf;
1583 bytestream_put_be32(&
s->buf, 0);
1585 bytestream_put_be32(&
s->buf, avctx->
height);
1586 bytestream_put_be32(&
s->buf, avctx->
width);
1587 bytestream_put_be16(&
s->buf,
s->ncomponents);
1588 bytestream_put_byte(&
s->buf,
s->cbps[0]);
1589 bytestream_put_byte(&
s->buf, 7);
1590 bytestream_put_byte(&
s->buf, 0);
1591 bytestream_put_byte(&
s->buf, 0);
1594 chunkstart =
s->buf;
1595 bytestream_put_be32(&
s->buf, 0);
1597 bytestream_put_byte(&
s->buf, 1);
1598 bytestream_put_byte(&
s->buf, 0);
1599 bytestream_put_byte(&
s->buf, 0);
1601 bytestream_put_be32(&
s->buf, 16);
1602 }
else if (
s->ncomponents == 1) {
1603 bytestream_put_be32(&
s->buf, 17);
1605 bytestream_put_be32(&
s->buf, 18);
1611 chunkstart =
s->buf;
1612 bytestream_put_be32(&
s->buf, 0);
1615 bytestream_put_byte(&
s->buf, 3);
1616 bytestream_put_be24(&
s->buf, 0x070707);
1622 chunkstart =
s->buf;
1623 bytestream_put_be32(&
s->buf, 0);
1625 for (
i = 0;
i < 3;
i++) {
1626 bytestream_put_be16(&
s->buf, 0);
1627 bytestream_put_byte(&
s->buf, 1);
1628 bytestream_put_byte(&
s->buf,
i);
1635 bytestream_put_be32(&
s->buf, 0);
1639 if (
s->buf_end -
s->buf < 2)
1651 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++){
1653 if (!(psotptr =
put_sot(
s, tileno)))
1655 if (
s->buf_end -
s->buf < 2)
1660 bytestream_put_be32(&psotptr,
s->buf - psotptr + 6);
1662 if (
s->buf_end -
s->buf < 2)
1681 char *saveptr =
NULL;
1686 s->layer_rates[0] = 0;
1687 s->compression_rate_enc = 0;
1692 if (token && (rate = strtol(token,
NULL, 10))) {
1693 s->layer_rates[0] = rate <= 1 ? 0:rate;
1703 if (rate = strtol(token,
NULL, 10)) {
1704 if (nlayers >= 100) {
1707 s->layer_rates[nlayers] = rate <= 1 ? 0:rate;
1714 for (
i = 1;
i < nlayers;
i++) {
1715 if (
s->layer_rates[
i] >=
s->layer_rates[
i-1]) {
1719 s->nlayers = nlayers;
1720 s->compression_rate_enc = 1;
1737 s->layer_rates[0] = 0;
1738 s->compression_rate_enc = 0;
1741 #if FF_API_PRIVATE_OPT
1767 if ((
s->tile_width & (
s->tile_width -1)) ||
1768 (
s->tile_height & (
s->tile_height-1))) {
1780 s->ncomponents =
desc->nb_components;
1781 for (
i = 0;
i < 3;
i++) {
1782 s->cbps[
i] =
desc->comp[
i].depth;
1788 s->chroma_shift,
s->chroma_shift + 1);
1816 #define OFFSET(x) offsetof(Jpeg2000EncoderContext, x)
1817 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
static double val(void *priv, double ch)
static const char *const format[]
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
#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]
common internal and external API header
static __device__ float ceil(float a)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define AV_INPUT_BUFFER_MIN_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#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.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
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 int init_tiles(Jpeg2000EncoderContext *s)
compute the sizes of tiles, resolution levels, bands, etc.
static int put_com(Jpeg2000EncoderContext *s, int compno)
static int parse_layer_rates(Jpeg2000EncoderContext *s)
static uint8_t * put_sot(Jpeg2000EncoderContext *s, int tileno)
#define WMSEDEC_SHIFT
must be >= 13
static void update_size(uint8_t *size, const uint8_t *end)
static void makelayers(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile)
AVCodec ff_jpeg2000_encoder
static void makelayer(Jpeg2000EncoderContext *s, int layno, double thresh, Jpeg2000Tile *tile, int final)
static void truncpasses(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile)
static void init_luts(void)
static const AVOption options[]
static void putnumpasses(Jpeg2000EncoderContext *s, int n)
static int encode_tile(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno)
static int encode_packet(Jpeg2000EncoderContext *s, Jpeg2000ResLevel *rlevel, int layno, int precno, uint8_t *expn, int numgbits, int packetno, int nlayers)
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 int getcut(Jpeg2000Cblk *cblk, int64_t lambda, int dwt_norm)
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)
int ff_jpeg2000_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, int cbps, int dx, int dy, AVCodecContext *avctx)
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)
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)
#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 API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
static enum AVPixelFormat pix_fmts[]
static const uint16_t mask[17]
void av_cold ff_mqc_init_context_tables(void)
MQ-coder Initialize context tables (QE, NLPS, NMPS)
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)
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.
AVPixelFormat
Pixel format.
@ 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_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ 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_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
#define AV_PIX_FMT_GRAY16
static const float pred[4]
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
attribute_deprecated int prediction_method
const char * name
Name of the codec implementation.
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.
int flags
A combination of AV_PKT_FLAG values.
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
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(...)