83 #define NMSEDEC_BITS 7
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}}
120 uint8_t comp_remap[4];
138 int layer_rates[100];
156 static void nspaces(FILE *fd,
int n)
158 while(n--) putc(
' ', fd);
170 int tileno, compno, reslevelno, bandno, precno;
171 fprintf(fd,
"XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n"
172 "numXtiles = %d, numYtiles = %d, ncomponents = %d\n"
174 s->width,
s->height,
s->tile_width,
s->tile_height,
175 s->numXtiles,
s->numYtiles,
s->ncomponents);
176 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++){
179 fprintf(fd,
"tile %d:\n", tileno);
180 for(compno = 0; compno <
s->ncomponents; compno++){
183 fprintf(fd,
"component %d:\n", compno);
185 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d\n",
187 for(reslevelno = 0; reslevelno <
s->nreslevels; reslevelno++){
190 fprintf(fd,
"reslevel %d:\n", reslevelno);
192 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d, nbands = %d\n",
193 reslevel->x0, reslevel->x1, reslevel->y0,
194 reslevel->y1, reslevel->
nbands);
195 for(bandno = 0; bandno < reslevel->
nbands; bandno++){
198 fprintf(fd,
"band %d:\n", bandno);
200 fprintf(fd,
"x0 = %d, x1 = %d, y0 = %d, y1 = %d,"
201 "codeblock_width = %d, codeblock_height = %d cblknx = %d cblkny = %d\n",
204 band->codeblock_width, band->codeblock_height,
205 band->cblknx, band->cblkny);
209 fprintf(fd,
"prec %d:\n", precno);
211 fprintf(fd,
"xi0 = %d, xi1 = %d, yi0 = %d, yi1 = %d\n",
212 prec->xi0, prec->xi1, prec->yi0, prec->yi1);
227 if (
s->bit_index == 8)
229 s->bit_index = *
s->buf == 0xff;
232 *
s->buf |=
val << (7 -
s->bit_index++);
258 int sp = -1, curval = 0;
272 if (node->
val >= threshold) {
306 if (
s->buf_end -
s->buf < 40 + 3 *
s->ncomponents)
310 bytestream_put_be16(&
s->buf, 38 + 3 *
s->ncomponents);
311 bytestream_put_be16(&
s->buf, 0);
312 bytestream_put_be32(&
s->buf,
s->width);
313 bytestream_put_be32(&
s->buf,
s->height);
314 bytestream_put_be32(&
s->buf, 0);
315 bytestream_put_be32(&
s->buf, 0);
317 bytestream_put_be32(&
s->buf,
s->tile_width);
318 bytestream_put_be32(&
s->buf,
s->tile_height);
319 bytestream_put_be32(&
s->buf, 0);
320 bytestream_put_be32(&
s->buf, 0);
321 bytestream_put_be16(&
s->buf,
s->ncomponents);
323 for (
i = 0;
i <
s->ncomponents;
i++){
324 bytestream_put_byte(&
s->buf,
s->cbps[
i] - 1);
325 bytestream_put_byte(&
s->buf, (
i+1&2)?1<<
s->chroma_shift[0]:1);
326 bytestream_put_byte(&
s->buf, (
i+1&2)?1<<
s->chroma_shift[1]:1);
336 if (
s->buf_end -
s->buf < 14)
340 bytestream_put_be16(&
s->buf, 12);
345 bytestream_put_byte(&
s->buf, scod);
347 bytestream_put_byte(&
s->buf,
s->prog);
348 bytestream_put_be16(&
s->buf,
s->nlayers);
350 bytestream_put_byte(&
s->buf, 0);
352 bytestream_put_byte(&
s->buf, 0);
355 bytestream_put_byte(&
s->buf, codsty->
nreslevels - 1);
358 bytestream_put_byte(&
s->buf, 0);
374 if (
s->buf_end -
s->buf <
size + 2)
378 bytestream_put_be16(&
s->buf,
size);
382 bytestream_put_byte(&
s->buf, qntsty->
expn[
i] << 3);
385 bytestream_put_be16(&
s->buf, (qntsty->
expn[
i] << 11) | qntsty->
mant[
i]);
396 if (
s->buf_end -
s->buf <
size + 2)
400 bytestream_put_be16(&
s->buf,
size);
401 bytestream_put_be16(&
s->buf, 1);
412 if (
s->buf_end -
s->buf < 12)
416 bytestream_put_be16(&
s->buf, 10);
417 bytestream_put_be16(&
s->buf, tileno);
420 bytestream_put_be32(&
s->buf, 0);
422 bytestream_put_byte(&
s->buf, 0);
423 bytestream_put_byte(&
s->buf, 1);
431 for (
i = 0;
i <
s->numYtiles;
i++) {
432 for (j = 0; j <
s->numXtiles; j++) {
434 for (compno = 0; compno <
s->ncomponents; compno++) {
435 int tilew =
tile->comp[compno].coord[0][1] -
tile->comp[compno].coord[0][0];
436 int tileh =
tile->comp[compno].coord[1][1] -
tile->comp[compno].coord[1][0];
437 int scale = ((compno+1&2)?1 <<
s->chroma_shift[0]:1) * ((compno+1&2)?1 <<
s->chroma_shift[1]:1);
438 for (layno = 0; layno <
s->nlayers; layno++) {
439 if (
s->layer_rates[layno] > 0) {
440 tile->layer_rates[layno] += (
double)(tilew * tileh) *
s->ncomponents *
s->cbps[compno] /
443 tile->layer_rates[layno] = 0.0;
459 int tileno, tilex, tiley, compno;
469 for (tileno = 0, tiley = 0; tiley <
s->numYtiles; tiley++)
470 for (tilex = 0; tilex <
s->numXtiles; tilex++, tileno++){
478 if (!
tile->layer_rates)
481 for (compno = 0; compno <
s->ncomponents; compno++){
485 comp->coord[0][0] =
comp->coord_o[0][0] = tilex *
s->tile_width;
486 comp->coord[0][1] =
comp->coord_o[0][1] =
FFMIN((tilex+1)*
s->tile_width,
s->width);
487 comp->coord[1][0] =
comp->coord_o[1][0] = tiley *
s->tile_height;
488 comp->coord[1][1] =
comp->coord_o[1][1] =
FFMIN((tiley+1)*
s->tile_height,
s->height);
490 for (
i = 0;
i < 2;
i++)
491 for (j = 0; j < 2; j++)
498 (compno+1&2)?1<<
s->chroma_shift[0]:1,
499 (compno+1&2)?1<<
s->chroma_shift[1]:1,
509 #define COPY_FRAME(D, PIXEL) \
510 static void copy_frame_ ##D(Jpeg2000EncoderContext *s) \
512 int tileno, compno, i, y, x; \
514 for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){ \
515 Jpeg2000Tile *tile = s->tile + tileno; \
517 for (compno = 0; compno < s->ncomponents; compno++){ \
518 int icompno = s->comp_remap[compno]; \
519 Jpeg2000Component *comp = tile->comp + compno; \
520 int *dst = comp->i_data; \
521 int cbps = s->cbps[compno]; \
522 line = (const PIXEL*)s->picture->data[icompno] \
523 + comp->coord[1][0] * (s->picture->linesize[icompno] / sizeof(PIXEL)) \
524 + comp->coord[0][0]; \
525 for (y = comp->coord[1][0]; y < comp->coord[1][1]; y++){ \
526 const PIXEL *ptr = line; \
527 for (x = comp->coord[0][0]; x < comp->coord[0][1]; x++) \
528 *dst++ = *ptr++ - (1 << (cbps - 1)); \
529 line += s->picture->linesize[icompno] / sizeof(PIXEL); \
533 line = (const PIXEL*)(s->picture->data[0] + tile->comp[0].coord[1][0] * s->picture->linesize[0]) \
534 + tile->comp[0].coord[0][0] * s->ncomponents; \
537 for (y = tile->comp[0].coord[1][0]; y < tile->comp[0].coord[1][1]; y++){ \
538 const PIXEL *ptr = line; \
539 for (x = tile->comp[0].coord[0][0]; x < tile->comp[0].coord[0][1]; x++, i++){ \
540 for (compno = 0; compno < s->ncomponents; compno++){ \
541 int cbps = s->cbps[compno]; \
542 tile->comp[compno].i_data[i] = *ptr++ - (1 << (cbps - 1)); \
545 line += s->picture->linesize[0] / sizeof(PIXEL); \
556 int compno, reslevelno, bandno;
560 for (compno = 0; compno <
s->ncomponents; compno++){
562 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
564 nbands = reslevelno ? 3 : 1;
565 for (bandno = 0; bandno < nbands; bandno++, gbandno++){
569 int bandpos = bandno + (reslevelno>0),
572 mant = (11 - log < 0 ? ss >>
log - 11 :
ss << 11 -
log) & 0x7ff;
573 expn =
s->cbps[compno] -
log + 13;
575 expn = ((bandno&2)>>1) + (reslevelno>0) +
s->cbps[compno];
577 qntsty->
expn[gbandno] = expn;
578 qntsty->
mant[gbandno] = mant;
595 (1 << 13) - (
a *
a << 11), 0);
620 for (y0 = 0; y0 <
height; y0 += 4)
621 for (x = 0; x <
width; x++)
622 for (y = y0; y <
height && y < y0+4; y++){
642 for (y0 = 0; y0 <
height; y0 += 4)
643 for (x = 0; x <
width; x++)
644 for (y = y0; y <
height && y < y0+4; y++)
656 for (y0 = 0; y0 <
height; y0 += 4)
657 for (x = 0; x <
width; x++){
666 for (rlen = 0; rlen < 4; rlen++)
674 for (y = y0 + rlen; y < y0 + 4; y++){
690 for (y = y0; y < y0 + 4 && y <
height; y++){
711 int pass_t = 2, passno, x, y,
max=0, nmsedec, bpno;
716 for (y = 0; y <
height; y++){
717 for (x = 0; x <
width; x++){
736 for (passno = 0; bpno >= 0; passno++){
751 wmsedec += (
int64_t)nmsedec << (2*bpno);
786 int precno,
const uint8_t *expn,
int numgbits,
int packetno,
789 int bandno, empty = 1;
797 bytestream_put_be16(&
s->buf, 4);
798 bytestream_put_be16(&
s->buf, packetno);
803 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
818 for (
i = 0;
i < nlayers;
i++) {
833 for (bandno = 0; bandno < rlevel->
nbands; bandno++){
860 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
872 int llen = 0, length;
875 if (
s->buf_end -
s->buf < 20)
918 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
924 for (
xi = 0;
xi < cblknw;
xi++){
943 int compno, reslevelno, layno,
ret;
949 int tile_coord[2][2];
950 int col = tileno %
s->numXtiles;
951 int row = tileno /
s->numXtiles;
953 tile_coord[0][0] = col *
s->tile_width;
954 tile_coord[0][1] =
FFMIN(tile_coord[0][0] +
s->tile_width,
s->width);
955 tile_coord[1][0] = row *
s->tile_height;
956 tile_coord[1][1] =
FFMIN(tile_coord[1][0] +
s->tile_height,
s->height);
962 for (layno = 0; layno < nlayers; layno++) {
963 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
964 for (compno = 0; compno <
s->ncomponents; compno++){
968 if ((
ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
969 qntsty->
nguardbits, packetno++, nlayers)) < 0)
977 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
978 for (layno = 0; layno < nlayers; layno++) {
979 for (compno = 0; compno <
s->ncomponents; compno++){
983 if ((
ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
984 qntsty->
nguardbits, packetno++, nlayers)) < 0)
992 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
996 for (compno = 0; compno <
s->ncomponents; compno++) {
998 if (reslevelno < codsty->nreslevels) {
999 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1008 for (y = tile_coord[1][0]; y < tile_coord[1][1]; y = (y/step_y + 1)*step_y) {
1009 for (x = tile_coord[0][0]; x < tile_coord[0][1]; x = (x/step_x + 1)*step_x) {
1010 for (compno = 0; compno <
s->ncomponents; compno++) {
1012 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1014 int log_subsampling[2] = { (compno+1&2)?
s->chroma_shift[0]:0, (compno+1&2)?
s->chroma_shift[1]:0};
1015 unsigned prcx, prcy;
1021 if (!(y % ((uint64_t)1 << (reslevel->
log2_prec_height + reducedresno + log_subsampling[1])) == 0 ||
1022 (y == tile_coord[1][0] && (try0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_height)))))
1025 if (!(x % ((uint64_t)1 << (reslevel->
log2_prec_width + reducedresno + log_subsampling[0])) == 0 ||
1026 (x == tile_coord[0][0] && (trx0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_width)))))
1041 for (layno = 0; layno < nlayers; layno++) {
1042 if ((
ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
1043 qntsty->
nguardbits, packetno++, nlayers)) < 0)
1054 for (compno = 0; compno <
s->ncomponents; compno++) {
1057 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1058 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1064 if (step_x >= 31 || step_y >= 31){
1071 for (y = tile_coord[1][0]; y < tile_coord[1][1]; y = (y/step_y + 1)*step_y) {
1072 for (x = tile_coord[0][0]; x < tile_coord[0][1]; x = (x/step_x + 1)*step_x) {
1073 for (compno = 0; compno <
s->ncomponents; compno++) {
1075 int log_subsampling[2] = { (compno+1&2)?
s->chroma_shift[0]:0, (compno+1&2)?
s->chroma_shift[1]:0};
1077 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1078 unsigned prcx, prcy;
1080 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1087 if (!(y % ((uint64_t)1 << (reslevel->
log2_prec_height + reducedresno + log_subsampling[1])) == 0 ||
1088 (y == tile_coord[1][0] && (try0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_height)))))
1091 if (!(x % ((uint64_t)1 << (reslevel->
log2_prec_width + reducedresno + log_subsampling[0])) == 0 ||
1092 (x == tile_coord[0][0] && (trx0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_width)))))
1108 for (layno = 0; layno < nlayers; layno++) {
1109 if ((
ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
1110 qntsty->
nguardbits, packetno++, nlayers)) < 0)
1119 for (compno = 0; compno <
s->ncomponents; compno++) {
1121 int log_subsampling[2] = { (compno+1&2)?
s->chroma_shift[0]:0, (compno+1&2)?
s->chroma_shift[1]:0};
1125 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1126 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1131 if (step_x >= 31 || step_y >= 31){
1138 for (y = tile_coord[1][0]; y < tile_coord[1][1]; y = (y/step_y + 1)*step_y) {
1139 for (x = tile_coord[0][0]; x < tile_coord[0][1]; x = (x/step_x + 1)*step_x) {
1140 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++) {
1141 unsigned prcx, prcy;
1144 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1150 if (!(y % ((uint64_t)1 << (reslevel->
log2_prec_height + reducedresno + log_subsampling[1])) == 0 ||
1151 (y == tile_coord[1][0] && (try0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_height)))))
1154 if (!(x % ((uint64_t)1 << (reslevel->
log2_prec_width + reducedresno + log_subsampling[0])) == 0 ||
1155 (x == tile_coord[0][0] && (trx0 << reducedresno) % (1
U << (reducedresno + reslevel->
log2_prec_width)))))
1171 for (layno = 0; layno < nlayers; layno++) {
1172 if ((
ret =
encode_packet(
s, reslevel, layno, precno, qntsty->
expn + (reslevelno ? 3*reslevelno-2 : 0),
1173 qntsty->
nguardbits, packetno++, nlayers)) < 0)
1189 int compno, resno, bandno, precno, cblkno;
1192 for (compno = 0; compno <
s->ncomponents; compno++) {
1195 for (resno = 0; resno <
s->codsty.nreslevels; resno++) {
1199 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1217 for (passno = cblk->
ninclpasses; passno < cblk->npasses; passno++) {
1237 if (thresh - (dd / dr) < DBL_EPSILON)
1272 int precno, compno, reslevelno, bandno, cblkno, passno, layno;
1274 double min = DBL_MAX;
1280 for (compno = 0; compno <
s->ncomponents; compno++){
1283 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
1287 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1293 for (passno = 0; passno < cblk->
npasses; passno++) {
1322 for (layno = 0; layno <
s->nlayers; layno++) {
1325 double stable_thresh = 0.0;
1326 double good_thresh = 0.0;
1327 if (!
s->layer_rates[layno]) {
1330 for (
i = 0;
i < 128;
i++) {
1331 uint8_t *stream_pos =
s->buf;
1333 thresh = (lo + hi) / 2;
1336 memset(stream_pos, 0,
s->buf - stream_pos);
1337 if ((
s->buf - stream_pos >
ceil(
tile->layer_rates[layno])) ||
ret < 0) {
1339 s->buf = stream_pos;
1343 stable_thresh = thresh;
1344 s->buf = stream_pos;
1347 if (good_thresh >= 0.0)
1348 good_thresh = stable_thresh == 0.0 ? thresh : stable_thresh;
1355 int passno, res = 0;
1356 for (passno = 0; passno < cblk->
npasses; passno++){
1365 if (dd >= dr * lambda)
1373 int precno, compno, reslevelno, bandno, cblkno,
lev;
1376 for (compno = 0; compno <
s->ncomponents; compno++){
1379 for (reslevelno = 0,
lev = codsty->
nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++,
lev--){
1383 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1384 int bandpos = bandno + (reslevelno > 0);
1408 int compno, reslevelno, bandno,
ret;
1411 for (compno = 0; compno <
s->ncomponents; compno++){
1421 for (reslevelno = 0; reslevelno < codsty->
nreslevels; reslevelno++){
1424 for (bandno = 0; bandno < reslevel->
nbands ; bandno++){
1427 int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos;
1428 yy0 = bandno == 0 ? 0 :
comp->reslevel[reslevelno-1].coord[1][1] -
comp->reslevel[reslevelno-1].coord[1][0];
1431 band->
coord[1][1]) - band->
coord[1][0] + yy0;
1436 bandpos = bandno + (reslevelno > 0);
1439 if (reslevelno == 0 || bandno == 1)
1442 xx0 =
comp->reslevel[reslevelno-1].coord[0][1] -
comp->reslevel[reslevelno-1].coord[0][0];
1445 band->
coord[0][1]) - band->
coord[0][0] + xx0;
1450 for (y = yy0; y < yy1; y++){
1452 for (x = xx0; x < xx1; x++){
1457 for (y = yy0; y < yy1; y++){
1459 for (x = xx0; x < xx1; x++){
1460 *ptr = (
comp->i_data[(
comp->coord[0][1] -
comp->coord[0][0]) * y + x]);
1473 bandpos, codsty->
nreslevels - reslevelno - 1);
1486 if (
s->compression_rate_enc)
1504 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++){
1505 if (
s->tile[tileno].comp) {
1506 for (compno = 0; compno <
s->ncomponents; compno++){
1520 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++){
1522 for (compno = 0; compno <
s->ncomponents; compno++)
1533 const AVFrame *pict,
int *got_packet)
1537 uint8_t *chunkstart, *jp2cstart, *jp2hstart;
1561 bytestream_put_be32(&
s->buf, 0x0000000C);
1562 bytestream_put_be32(&
s->buf, 0x6A502020);
1563 bytestream_put_be32(&
s->buf, 0x0D0A870A);
1565 chunkstart =
s->buf;
1566 bytestream_put_be32(&
s->buf, 0);
1569 bytestream_put_be32(&
s->buf, 0);
1574 bytestream_put_be32(&
s->buf, 0);
1577 chunkstart =
s->buf;
1578 bytestream_put_be32(&
s->buf, 0);
1580 bytestream_put_be32(&
s->buf, avctx->
height);
1581 bytestream_put_be32(&
s->buf, avctx->
width);
1582 bytestream_put_be16(&
s->buf,
s->ncomponents);
1583 bytestream_put_byte(&
s->buf,
s->cbps[0]);
1584 bytestream_put_byte(&
s->buf, 7);
1585 bytestream_put_byte(&
s->buf, 0);
1586 bytestream_put_byte(&
s->buf, 0);
1589 chunkstart =
s->buf;
1590 bytestream_put_be32(&
s->buf, 0);
1592 bytestream_put_byte(&
s->buf, 1);
1593 bytestream_put_byte(&
s->buf, 0);
1594 bytestream_put_byte(&
s->buf, 0);
1596 bytestream_put_be32(&
s->buf, 16);
1597 }
else if (
s->ncomponents == 1) {
1598 bytestream_put_be32(&
s->buf, 17);
1600 bytestream_put_be32(&
s->buf, 18);
1605 const uint8_t *palette = pict->
data[1];
1606 chunkstart =
s->buf;
1607 bytestream_put_be32(&
s->buf, 0);
1610 bytestream_put_byte(&
s->buf, 3);
1611 bytestream_put_be24(&
s->buf, 0x070707);
1613 bytestream_put_be24(&
s->buf, HAVE_BIGENDIAN ?
AV_RB24(palette + 1) :
AV_RL24(palette));
1617 chunkstart =
s->buf;
1618 bytestream_put_be32(&
s->buf, 0);
1620 for (
i = 0;
i < 3;
i++) {
1621 bytestream_put_be16(&
s->buf, 0);
1622 bytestream_put_byte(&
s->buf, 1);
1623 bytestream_put_byte(&
s->buf,
i);
1630 bytestream_put_be32(&
s->buf, 0);
1634 if (
s->buf_end -
s->buf < 2)
1646 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++){
1648 if (!(psotptr =
put_sot(
s, tileno)))
1650 if (
s->buf_end -
s->buf < 2)
1655 bytestream_put_be32(&psotptr,
s->buf - psotptr + 6);
1657 if (
s->buf_end -
s->buf < 2)
1675 char *saveptr =
NULL;
1680 s->layer_rates[0] = 0;
1681 s->compression_rate_enc = 0;
1686 if (token && (rate = strtol(token,
NULL, 10))) {
1687 s->layer_rates[0] = rate <= 1 ? 0:rate;
1697 if (rate = strtol(token,
NULL, 10)) {
1698 if (nlayers >= 100) {
1701 s->layer_rates[nlayers] = rate <= 1 ? 0:rate;
1708 for (
i = 1;
i < nlayers;
i++) {
1709 if (
s->layer_rates[
i] >=
s->layer_rates[
i-1]) {
1713 s->nlayers = nlayers;
1714 s->compression_rate_enc = 1;
1730 av_log(avctx,
AV_LOG_WARNING,
"Layer rates invalid. Encoding with 1 layer based on quality metric.\n");
1732 s->layer_rates[0] = 0;
1733 s->compression_rate_enc = 0;
1755 if ((
s->tile_width & (
s->tile_width -1)) ||
1756 (
s->tile_height & (
s->tile_height-1))) {
1768 s->ncomponents =
desc->nb_components;
1769 for (
i = 0;
i < 4;
i++) {
1770 s->cbps[
i] =
desc->comp[
i].depth;
1771 s->comp_remap[
i] =
i;
1777 s->chroma_shift,
s->chroma_shift + 1);
1781 s->comp_remap[0] = 2;
1782 s->comp_remap[1] = 0;
1783 s->comp_remap[2] = 1;
1808 #define OFFSET(x) offsetof(Jpeg2000EncoderContext, x)
1809 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1839 .
p.
name =
"jpeg2000",