46 #define JP2_SIG_TYPE 0x6A502020 47 #define JP2_SIG_VALUE 0x0D0A870A 48 #define JP2_CODESTREAM 0x6A703263 49 #define JP2_HEADER 0x6A703268 117 uint32_t palette[256];
152 s->
bit_index = 7 + (bytestream2_get_byte(&s->
g) != 0xFF
u);
155 res |= (bytestream2_peek_byte(&s->
g) >> s->
bit_index) & 1;
162 if (bytestream2_get_byte(&s->
g) == 0xff)
172 int sp = -1, curval = 0;
179 while (node && !node->
vis) {
187 curval = stack[
sp]->
val;
189 while (curval < threshold && sp >= 0) {
190 if (curval < stack[sp]->
val)
191 curval = stack[
sp]->
val;
192 while (curval < threshold) {
202 stack[
sp]->
val = curval;
209 int bpc, uint32_t log2_chroma_wh,
int pal8)
220 switch (components) {
222 match = match && desc->
comp[3].
depth >= bpc &&
223 (log2_chroma_wh >> 14 & 3) == 0 &&
224 (log2_chroma_wh >> 12 & 3) == 0;
226 match = match && desc->
comp[2].
depth >= bpc &&
230 match = match && desc->
comp[1].
depth >= bpc &&
235 match = match && desc->
comp[0].
depth >= bpc &&
236 (log2_chroma_wh >> 2 & 3) == 0 &&
237 (log2_chroma_wh & 3) == 0 &&
245 #define RGB_PIXEL_FORMATS AV_PIX_FMT_PAL8,AV_PIX_FMT_RGB24,AV_PIX_FMT_RGBA,AV_PIX_FMT_RGB48,AV_PIX_FMT_RGBA64 246 #define GRAY_PIXEL_FORMATS AV_PIX_FMT_GRAY8,AV_PIX_FMT_GRAY8A,AV_PIX_FMT_GRAY16,AV_PIX_FMT_YA16 247 #define YUV_PIXEL_FORMATS AV_PIX_FMT_YUV410P,AV_PIX_FMT_YUV411P,AV_PIX_FMT_YUVA420P, \ 248 AV_PIX_FMT_YUV420P,AV_PIX_FMT_YUV422P,AV_PIX_FMT_YUVA422P, \ 249 AV_PIX_FMT_YUV440P,AV_PIX_FMT_YUV444P,AV_PIX_FMT_YUVA444P, \ 250 AV_PIX_FMT_YUV420P9,AV_PIX_FMT_YUV422P9,AV_PIX_FMT_YUV444P9, \ 251 AV_PIX_FMT_YUVA420P9,AV_PIX_FMT_YUVA422P9,AV_PIX_FMT_YUVA444P9, \ 252 AV_PIX_FMT_YUV420P10,AV_PIX_FMT_YUV422P10,AV_PIX_FMT_YUV444P10, \ 253 AV_PIX_FMT_YUVA420P10,AV_PIX_FMT_YUVA422P10,AV_PIX_FMT_YUVA444P10, \ 254 AV_PIX_FMT_YUV420P12,AV_PIX_FMT_YUV422P12,AV_PIX_FMT_YUV444P12, \ 255 AV_PIX_FMT_YUV420P14,AV_PIX_FMT_YUV422P14,AV_PIX_FMT_YUV444P14, \ 256 AV_PIX_FMT_YUV420P16,AV_PIX_FMT_YUV422P16,AV_PIX_FMT_YUV444P16, \ 257 AV_PIX_FMT_YUVA420P16,AV_PIX_FMT_YUVA422P16,AV_PIX_FMT_YUVA444P16 258 #define XYZ_PIXEL_FORMATS AV_PIX_FMT_XYZ12 276 uint32_t log2_chroma_wh = 0;
278 int possible_fmts_nb = 0;
289 s->
width = bytestream2_get_be32u(&s->
g);
290 s->
height = bytestream2_get_be32u(&s->
g);
297 ncomponents = bytestream2_get_be16u(&s->
g);
304 if (ncomponents <= 0) {
310 if (ncomponents > 4) {
340 uint8_t x = bytestream2_get_byteu(&s->
g);
341 s->
cbps[
i] = (x & 0x7f) + 1;
343 s->
sgnd[
i] = !!(x & 0x80);
344 s->
cdx[
i] = bytestream2_get_byteu(&s->
g);
345 s->
cdy[
i] = bytestream2_get_byteu(&s->
g);
346 if ( !s->
cdx[i] || s->
cdx[i] == 3 || s->
cdx[i] > 4
347 || !s->
cdy[i] || s->
cdy[i] == 3 || s->
cdy[i] > 4) {
351 log2_chroma_wh |= s->
cdy[
i] >> 1 << i * 4 | s->
cdx[
i] >> 1 << i * 4 + 2;
423 for (i = 0; i < possible_fmts_nb; ++
i) {
430 if (i == possible_fmts_nb) {
431 if (ncomponents == 4 &&
432 s->
cdy[0] == 1 && s->
cdx[0] == 1 &&
433 s->
cdy[1] == 1 && s->
cdx[1] == 1 &&
443 }
else if (ncomponents == 3 && s->
precision == 8 &&
448 }
else if (ncomponents == 2 && s->
precision == 8 &&
452 }
else if (ncomponents == 1 && s->
precision == 8) {
459 if (i == possible_fmts_nb) {
461 "Unknown pix_fmt, profile: %d, colour_space: %d, " 462 "components: %d, precision: %d\n" 463 "cdx[0]: %d, cdy[0]: %d\n" 464 "cdx[1]: %d, cdy[1]: %d\n" 465 "cdx[2]: %d, cdy[2]: %d\n" 466 "cdx[3]: %d, cdy[3]: %d\n",
470 ncomponents > 1 ? s->
cdx[1] : 0,
471 ncomponents > 1 ? s->
cdy[1] : 0,
472 ncomponents > 2 ? s->
cdx[2] : 0,
473 ncomponents > 2 ? s->
cdy[2] : 0,
474 ncomponents > 3 ? s->
cdx[3] : 0,
475 ncomponents > 3 ? s->
cdy[3] : 0);
539 byte = bytestream2_get_byte(&s->
g);
569 tmp.
csty = bytestream2_get_byteu(&s->
g);
574 tmp.
nlayers = bytestream2_get_be16u(&s->
g);
575 tmp.
mct = bytestream2_get_byteu(&s->
g);
579 "MCT %"PRIu8
" with too few components (%d)\n",
584 if ((ret =
get_cox(s, &tmp)) < 0)
587 for (compno = 0; compno < s->
ncomponents; compno++)
588 if (!(properties[compno] &
HAD_COC))
589 memcpy(c + compno, &tmp,
sizeof(tmp));
606 compno = bytestream2_get_byteu(&s->
g);
610 "Invalid compno %d. There are %d components in the image.\n",
618 c->
csty = bytestream2_get_byteu(&s->
g);
633 compno = (s->
ncomponents < 257)? bytestream2_get_byte(&s->
g):
634 bytestream2_get_be16u(&s->
g);
635 if (bytestream2_get_byte(&s->
g)) {
642 if (compno < s->ncomponents) {
645 v = bytestream2_get_byte(&s->
g);
652 v = bytestream2_get_byte(&s->
g);
670 x = bytestream2_get_byteu(&s->
g);
680 for (i = 0; i < n; i++)
681 q->
expn[i] = bytestream2_get_byteu(&s->
g) >> 3;
685 x = bytestream2_get_be16u(&s->
g);
686 q->
expn[0] = x >> 11;
687 q->
mant[0] = x & 0x7ff;
689 int curexpn =
FFMAX(0, q->
expn[0] - (i - 1) / 3);
690 q->
expn[
i] = curexpn;
698 for (i = 0; i < n; i++) {
699 x = bytestream2_get_be16u(&s->
g);
700 q->
expn[
i] = x >> 11;
701 q->
mant[
i] = x & 0x7ff;
714 memset(&tmp, 0,
sizeof(tmp));
716 if ((ret =
get_qcx(s, n, &tmp)) < 0)
718 for (compno = 0; compno < s->
ncomponents; compno++)
719 if (!(properties[compno] &
HAD_QCC))
720 memcpy(q + compno, &tmp,
sizeof(tmp));
734 compno = bytestream2_get_byteu(&s->
g);
738 "Invalid compno %d. There are %d components in the image.\n",
744 return get_qcx(s, n - 1, q + compno);
763 tmp.
nb_poc = (size - 2) / elem_size;
769 for (i = 0; i<tmp.
nb_poc; i++) {
771 e->
RSpoc = bytestream2_get_byteu(&s->
g);
772 e->
CSpoc = bytestream2_get_byteu(&s->
g);
773 e->
LYEpoc = bytestream2_get_be16u(&s->
g);
774 e->
REpoc = bytestream2_get_byteu(&s->
g);
775 e->
CEpoc = bytestream2_get_byteu(&s->
g);
776 e->
Ppoc = bytestream2_get_byteu(&s->
g);
820 Isot = bytestream2_get_be16u(&s->
g);
825 Psot = bytestream2_get_be32u(&s->
g);
826 TPsot = bytestream2_get_byteu(&s->
g);
829 bytestream2_get_byteu(&s->
g);
855 memcpy(&tile->
poc , &s->
poc ,
sizeof(tile->
poc));
882 bytestream2_get_byte(&s->
g);
883 Stlm = bytestream2_get_byte(&s->
g);
886 ST = (Stlm >> 4) & 0x03;
892 SP = (Stlm >> 6) & 0x01;
893 tile_tlm = (n - 4) / ((SP + 1) * 2 + ST);
894 for (i = 0; i < tile_tlm; i++) {
899 bytestream2_get_byte(&s->
g);
902 bytestream2_get_be16(&s->
g);
905 bytestream2_get_be32(&s->
g);
909 bytestream2_get_be16(&s->
g);
911 bytestream2_get_be32(&s->
g);
928 bytestream2_get_byte(&s->
g);
930 for (i = 0; i < n - 3; i++) {
931 v = bytestream2_get_byte(&s->
g);
947 bytestream2_get_byte(&s->
g);
978 "PPT marker can occur only on first tile part of a tile.\n");
983 bytestream2_get_byte(&s->
g);
1014 for (compno = 0; compno < s->
ncomponents; compno++) {
1040 s->
cbps[compno], s->
cdx[compno],
1056 return num < 0 ? num : 3 + num;
1058 return num < 0 ? num : 6 + num;
1060 return num < 0 ? num : 37 + num;
1105 int layno,
uint8_t *expn,
int numgbits)
1107 int bandno, cblkno,
ret, nb_code_blocks;
1110 if (layno < rlevel->band[0].prec[precno].decoded_layers)
1127 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
1131 if (band->
coord[0][0] == band->
coord[0][1] ||
1136 for (cblkno = 0; cblkno < nb_code_blocks; cblkno++) {
1138 int incl, newpasses, llen;
1151 int v = expn[bandno] + numgbits - 1 -
1153 if (v < 0 || v > 30) {
1155 "nonzerobits %d invalid or unsupported\n", v);
1171 "Block with length beyond 16 bits");
1190 while (newpasses1 < newpasses) {
1216 newpasses -= newpasses1;
1237 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
1242 for (cblkno = 0; cblkno < nb_code_blocks; cblkno++) {
1246 for (cwsno = 0; cwsno < cblk->
nb_lengthinc; cwsno ++) {
1259 "Block length %"PRIu16
" or lengthinc %d is too large, left %d\n",
1303 int Ppoc,
int *tp_index)
1306 int layno, reslevelno, compno, precno, ok_reslevel;
1314 for (reslevelno = RSpoc; ok_reslevel && reslevelno <
REpoc; reslevelno++) {
1316 for (layno = 0; layno <
LYEpoc; layno++) {
1317 for (compno = CSpoc; compno <
CEpoc; compno++) {
1320 if (reslevelno < codsty->nreslevels) {
1328 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
1339 for (layno = 0; layno <
LYEpoc; layno++) {
1341 for (reslevelno = RSpoc; ok_reslevel && reslevelno <
REpoc; reslevelno++) {
1343 for (compno = CSpoc; compno <
CEpoc; compno++) {
1346 if (reslevelno < codsty->nreslevels) {
1354 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
1365 for (compno = CSpoc; compno <
CEpoc; compno++) {
1375 for (reslevelno = RSpoc; reslevelno <
FFMIN(codsty->
nreslevels, REpoc); reslevelno++) {
1381 if (step_x >= 31 || step_y >= 31){
1388 for (y = tile->
coord[1][0]; y < tile->coord[1][1]; y = (y/step_y + 1)*step_y) {
1389 for (x = tile->
coord[0][0]; x < tile->coord[0][1]; x = (x/step_x + 1)*step_x) {
1390 for (reslevelno = RSpoc; reslevelno <
FFMIN(codsty->
nreslevels, REpoc); reslevelno++) {
1391 unsigned prcx, prcy;
1394 int xc = x / s->
cdx[compno];
1395 int yc = y / s->
cdy[compno];
1417 for (layno = 0; layno <
LYEpoc; layno++) {
1420 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
1433 for (reslevelno = RSpoc; ok_reslevel && reslevelno <
REpoc; reslevelno++) {
1437 for (compno = CSpoc; compno <
CEpoc; compno++) {
1441 if (reslevelno < codsty->nreslevels) {
1451 for (y = tile->
coord[1][0]; y < tile->coord[1][1]; y = (y/step_y + 1)*step_y) {
1452 for (x = tile->
coord[0][0]; x < tile->coord[0][1]; x = (x/step_x + 1)*step_x) {
1453 for (compno = CSpoc; compno <
CEpoc; compno++) {
1459 unsigned prcx, prcy;
1462 if (!s->
cdx[compno] || !s->
cdy[compno])
1472 (y == tile->
coord[1][0] && ((int64_t)try0 << reducedresno) % (1ULL << (reducedresno + rlevel->
log2_prec_height)))))
1475 if (!(x % ((uint64_t)s->
cdx[compno] << (rlevel->
log2_prec_width + reducedresno)) == 0 ||
1476 (x == tile->
coord[0][0] && ((int64_t)trx0 << reducedresno) % (1ULL << (reducedresno + rlevel->
log2_prec_width)))))
1494 for (layno = 0; layno <
LYEpoc; layno++) {
1498 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
1512 for (compno = CSpoc; compno <
CEpoc; compno++) {
1516 for (reslevelno = RSpoc; reslevelno <
FFMIN(codsty->
nreslevels, REpoc); reslevelno++) {
1523 if (step_x >= 31 || step_y >= 31){
1530 for (y = tile->
coord[1][0]; y < tile->coord[1][1]; y = (y/step_y + 1)*step_y) {
1531 for (x = tile->
coord[0][0]; x < tile->coord[0][1]; x = (x/step_x + 1)*step_x) {
1532 for (compno = CSpoc; compno <
CEpoc; compno++) {
1537 if (!s->
cdx[compno] || !s->
cdy[compno])
1540 for (reslevelno = RSpoc; reslevelno <
FFMIN(codsty->
nreslevels, REpoc); reslevelno++) {
1541 unsigned prcx, prcy;
1550 (y == tile->
coord[1][0] && ((int64_t)try0 << reducedresno) % (1ULL << (reducedresno + rlevel->
log2_prec_height)))))
1553 if (!(x % ((uint64_t)s->
cdx[compno] << (rlevel->
log2_prec_width + reducedresno)) == 0 ||
1554 (x == tile->
coord[0][0] && ((int64_t)trx0 << reducedresno) % (1ULL << (reducedresno + rlevel->
log2_prec_width)))))
1571 for (layno = 0; layno <
LYEpoc; layno++) {
1574 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
1629 int bpno,
int bandno,
1630 int vert_causal_ctx_csty_symbol)
1632 int mask = 3 << (bpno - 1), y0, x, y;
1634 for (y0 = 0; y0 <
height; y0 += 4)
1635 for (x = 0; x <
width; x++)
1636 for (y = y0; y < height && y < y0 + 4; y++) {
1637 int flags_mask = -1;
1638 if (vert_causal_ctx_csty_symbol && y == y0 + 3)
1659 int bpno,
int vert_causal_ctx_csty_symbol)
1664 phalf = 1 << (bpno - 1);
1667 for (y0 = 0; y0 <
height; y0 += 4)
1668 for (x = 0; x <
width; x++)
1669 for (y = y0; y < height && y < y0 + 4; y++)
1671 int flags_mask = (vert_causal_ctx_csty_symbol && y == y0 + 3) ?
1684 int seg_symbols,
int vert_causal_ctx_csty_symbol)
1686 int mask = 3 << (bpno - 1), y0, x, y, runlen, dec;
1688 for (y0 = 0; y0 <
height; y0 += 4) {
1689 for (x = 0; x <
width; x++) {
1690 int flags_mask = -1;
1691 if (vert_causal_ctx_csty_symbol)
1693 if (y0 + 3 < height &&
1711 for (y = y0 + runlen; y < y0 + 4 && y <
height; y++) {
1712 int flags_mask = -1;
1713 if (vert_causal_ctx_csty_symbol && y == y0 + 3)
1744 "Segmentation symbol value incorrect\n");
1774 if (bpno < 0 || bpno > 29) {
1781 vert_causal_ctx_csty_symbol);
1784 decode_refpass(t1, width, height, bpno + 1, vert_causal_ctx_csty_symbol);
1790 vert_causal_ctx_csty_symbol);
1836 val = (quan_parameter < 0)?-quan_parameter:quan_parameter;
1838 if (val > (1 << roi_shift))
1839 return (quan_parameter < 0)?-(val >> roi_shift):(val >> roi_shift);
1840 return quan_parameter;
1856 for (j = 0; j < (cblk->
coord[1][1] - cblk->
coord[1][0]); ++j) {
1857 float *datap = &comp->
f_data[(comp->
coord[0][1] - comp->
coord[0][0]) * (y + j) + x];
1859 for (i = 0; i <
w; ++
i)
1871 for (j = 0; j < (cblk->
coord[1][1] - cblk->
coord[1][0]); ++j) {
1875 for (i = 0; i <
w; ++
i)
1876 datap[i] = src[i] / 2;
1879 for (i = 0; i <
w; ++
i)
1880 datap[i] = (src[i] * (int64_t)band->
i_stepsize) / 65536;
1891 for (j = 0; j < (cblk->
coord[1][1] - cblk->
coord[1][0]); ++j) {
1894 for (i = 0; i <
w; ++
i)
1895 datap[i] = (src[i] * (int64_t)band->
i_stepsize + (1<<15)) >> 16;
1904 for (i = 1; i < 3; i++) {
1915 for (i = 0; i < 3; i++)
1921 for (i = 0; i < 2; i++)
1933 for (j = 0; j < (cblk->
coord[1][1] - cblk->
coord[1][0]); ++j) {
1935 for (i = 0; i <
w; ++
i)
1944 int compno, reslevelno, bandno;
1947 for (compno = 0; compno < s->
ncomponents; compno++) {
1958 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
1959 int nb_precincts, precno;
1961 int cblkno = 0, bandpos;
1963 bandpos = bandno + (reslevelno > 0);
1965 if (band->
coord[0][0] == band->
coord[0][1] ||
1971 for (precno = 0; precno < nb_precincts; precno++) {
2011 #define WRITE_FRAME(D, PIXEL) \ 2012 static inline void write_frame_ ## D(Jpeg2000DecoderContext * s, Jpeg2000Tile * tile, \ 2013 AVFrame * picture, int precision) \ 2015 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(s->avctx->pix_fmt); \ 2016 int planar = !!(pixdesc->flags & AV_PIX_FMT_FLAG_PLANAR); \ 2017 int pixelsize = planar ? 1 : pixdesc->nb_components; \ 2022 for (compno = 0; compno < s->ncomponents; compno++) { \ 2023 Jpeg2000Component *comp = tile->comp + compno; \ 2024 Jpeg2000CodingStyle *codsty = tile->codsty + compno; \ 2026 float *datap = comp->f_data; \ 2027 int32_t *i_datap = comp->i_data; \ 2028 int cbps = s->cbps[compno]; \ 2029 int w = tile->comp[compno].coord[0][1] - \ 2030 ff_jpeg2000_ceildiv(s->image_offset_x, s->cdx[compno]); \ 2031 int h = tile->comp[compno].coord[1][1] - \ 2032 ff_jpeg2000_ceildiv(s->image_offset_y, s->cdy[compno]); \ 2036 plane = s->cdef[compno] ? s->cdef[compno]-1 : (s->ncomponents-1); \ 2038 y = tile->comp[compno].coord[1][0] - \ 2039 ff_jpeg2000_ceildiv(s->image_offset_y, s->cdy[compno]); \ 2040 line = (PIXEL *)picture->data[plane] + y * (picture->linesize[plane] / sizeof(PIXEL));\ 2041 for (; y < h; y++) { \ 2044 x = tile->comp[compno].coord[0][0] - \ 2045 ff_jpeg2000_ceildiv(s->image_offset_x, s->cdx[compno]); \ 2046 dst = line + x * pixelsize + compno*!planar; \ 2048 if (codsty->transform == FF_DWT97) { \ 2049 for (; x < w; x++) { \ 2050 int val = lrintf(*datap) + (1 << (cbps - 1)); \ 2052 val = av_clip(val, 0, (1 << cbps) - 1); \ 2053 *dst = val << (precision - cbps); \ 2058 for (; x < w; x++) { \ 2059 int val = *i_datap + (1 << (cbps - 1)); \ 2061 val = av_clip(val, 0, (1 << cbps) - 1); \ 2062 *dst = val << (precision - cbps); \ 2067 line += picture->linesize[plane] / sizeof(PIXEL); \ 2079 int jobnr,
int threadnr)
2093 if (s->
cdef[x] < 0) {
2104 write_frame_8(s, tile, picture, 8);
2111 write_frame_16(s, tile, picture, precision);
2122 for (compno = 0; compno < s->
ncomponents; compno++) {
2140 memset(&s->
poc , 0,
sizeof(s->
poc));
2162 marker = bytestream2_get_be16u(&s->
g);
2164 if (marker >= 0xFF30 && marker <= 0xFF3F)
2205 len = bytestream2_get_be16(&s->
g);
2226 ret =
get_coc(s, codsty, properties);
2229 ret =
get_cod(s, codsty, properties);
2235 ret =
get_qcc(s, len, qntsty, properties);
2238 ret =
get_qcd(s, len, qntsty, properties);
2250 if (!(ret =
get_sot(s, len))) {
2287 "Cannot have both PPT and PPM marker.\n");
2295 "unsupported marker 0x%.4"PRIX16
" at pos 0x%X\n",
2302 "error during processing marker segment %.4"PRIx16
"\n",
2304 return ret ? ret : -1;
2331 uint32_t atom_size, atom, atom_end;
2332 int search_range = 10;
2337 atom_size = bytestream2_get_be32u(&s->
g);
2338 atom = bytestream2_get_be32u(&s->
g);
2339 if (atom_size == 1) {
2340 if (bytestream2_get_be32u(&s->
g)) {
2344 atom_size = bytestream2_get_be32u(&s->
g);
2345 if (atom_size < 16 || (int64_t)
bytestream2_tell(&s->
g) + atom_size - 16 > INT_MAX)
2349 if (atom_size < 8 || (int64_t)
bytestream2_tell(&s->
g) + atom_size - 8 > INT_MAX)
2362 uint32_t atom2_size, atom2, atom2_end;
2364 atom2_size = bytestream2_get_be32u(&s->
g);
2365 atom2 = bytestream2_get_be32u(&s->
g);
2367 if (atom2_size < 8 || atom2_end > atom_end || atom2_end < atom2_size)
2372 }
else if (atom2 ==
MKBETAG(
'c',
'o',
'l',
'r') && atom2_size >= 7) {
2373 int method = bytestream2_get_byteu(&s->
g);
2378 }
else if (atom2 ==
MKBETAG(
'p',
'c',
'l',
'r') && atom2_size >= 6) {
2379 int i,
size, colour_count, colour_channels, colour_depth[3];
2380 colour_count = bytestream2_get_be16u(&s->
g);
2381 colour_channels = bytestream2_get_byteu(&s->
g);
2383 colour_depth[0] = (bytestream2_get_byteu(&s->
g) & 0x7f) + 1;
2384 colour_depth[1] = (bytestream2_get_byteu(&s->
g) & 0x7f) + 1;
2385 colour_depth[2] = (bytestream2_get_byteu(&s->
g) & 0x7f) + 1;
2386 size = (colour_depth[0] + 7 >> 3) * colour_count +
2387 (colour_depth[1] + 7 >> 3) * colour_count +
2388 (colour_depth[2] + 7 >> 3) * colour_count;
2390 colour_channels != 3 ||
2391 colour_depth[0] > 16 ||
2392 colour_depth[1] > 16 ||
2393 colour_depth[2] > 16 ||
2394 atom2_size < size) {
2400 for (i = 0; i < colour_count; i++) {
2402 if (colour_depth[0] <= 8) {
2403 r = bytestream2_get_byteu(&s->
g) << 8 - colour_depth[0];
2404 r |= r >> colour_depth[0];
2406 r = bytestream2_get_be16u(&s->
g) >> colour_depth[0] - 8;
2408 if (colour_depth[1] <= 8) {
2409 g = bytestream2_get_byteu(&s->
g) << 8 - colour_depth[1];
2410 g |= g >> colour_depth[1];
2412 g = bytestream2_get_be16u(&s->
g) >> colour_depth[1] - 8;
2414 if (colour_depth[2] <= 8) {
2415 b = bytestream2_get_byteu(&s->
g) << 8 - colour_depth[2];
2416 b |= b >> colour_depth[2];
2418 b = bytestream2_get_be16u(&s->
g) >> colour_depth[2] - 8;
2420 s->
palette[
i] = 0xff
u << 24 | r << 16 | g << 8 |
b;
2422 }
else if (atom2 ==
MKBETAG(
'c',
'd',
'e',
'f') && atom2_size >= 2) {
2423 int n = bytestream2_get_be16u(&s->
g);
2425 int cn = bytestream2_get_be16(&s->
g);
2426 int av_unused typ = bytestream2_get_be16(&s->
g);
2427 int asoc = bytestream2_get_be16(&s->
g);
2428 if (cn < 4 && asoc < 4)
2431 }
else if (atom2 ==
MKBETAG(
'r',
'e',
's',
' ') && atom2_size >= 18) {
2432 int64_t vnum, vden, hnum, hden, vexp, hexp;
2435 resx = bytestream2_get_be32u(&s->
g);
2436 if (resx !=
MKBETAG(
'r',
'e',
's',
'c') && resx !=
MKBETAG(
'r',
'e',
's',
'd')) {
2440 vnum = bytestream2_get_be16u(&s->
g);
2441 vden = bytestream2_get_be16u(&s->
g);
2442 hnum = bytestream2_get_be16u(&s->
g);
2443 hden = bytestream2_get_be16u(&s->
g);
2444 vexp = bytestream2_get_byteu(&s->
g);
2445 hexp = bytestream2_get_byteu(&s->
g);
2446 if (!vnum || !vden || !hnum || !hden) {
2458 if ( INT64_MAX / (hnum * vden) > pow(10, hexp)
2459 && INT64_MAX / (vnum * hden) > pow(10, vexp))
2461 hnum * vden * pow(10, hexp),
2462 vnum * hden * pow(10, vexp),
2466 }
while (atom_end - atom2_end >= 8);
2504 memset(s->
cdef, -1,
sizeof(s->
cdef));
2513 (bytestream2_get_be32u(&s->
g) == 12) &&
2518 "Could not find Jpeg2000 codestream atom.\n");
2553 memcpy(picture->
data[1], s->
palette, 256 *
sizeof(uint32_t));
2565 #define OFFSET(x) offsetof(Jpeg2000DecoderContext, x) 2566 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM 2569 {
"lowres",
"Lower the decoding resolution by a power of two",
2590 .priv_class = &jpeg2000_class,
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1, int width, int height, int bpno, int bandno, int seg_symbols, int vert_causal_ctx_csty_symbol)
void ff_mqc_initdec(MqcState *mqc, uint8_t *bp, int raw, int reset)
Initialize MQ-decoder.
#define JPEG2000_CBLK_VSC
void(* mct_decode[FF_DWT_NB])(void *src0, void *src1, void *src2, int csize)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_cold ff_jpeg2000_init_tier1_luts(void)
static enum AVPixelFormat pix_fmt
static void select_header(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile, int *tp_index)
void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
ptrdiff_t const GLvoid * data
Jpeg2000TgtNode * cblkincl
static enum AVPixelFormat xyz_pix_fmts[]
av_cold void ff_jpeg2000dsp_init(Jpeg2000DSPContext *c)
8 bits gray, 8 bits alpha
#define JPEG2000_T1_SIG_NB
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
packed RGB 8:8:8, 24bpp, RGBRGB...
#define RGB_PIXEL_FORMATS
#define JPEG2000_PGOD_PCRL
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
static enum AVPixelFormat all_pix_fmts[]
static av_cold int init(AVCodecContext *avctx)
static uint64_t SP[8][256]
#define AV_PIX_FMT_RGBA64
static void decode_refpass(Jpeg2000T1Context *t1, int width, int height, int bpno, int vert_causal_ctx_csty_symbol)
#define JPEG2000_PGOD_RLCP
#define avpriv_request_sample(...)
static void jpeg2000_flush(Jpeg2000DecoderContext *s)
static int get_qcc(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, uint8_t *properties)
static int roi_shift_param(Jpeg2000Component *comp, int quan_parameter)
Jpeg2000QuantStyle qntsty[4]
const char * av_default_item_name(void *ptr)
Return the context name.
static void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
void ff_mqc_init_contexts(MqcState *mqc)
MQ-coder context initialisations.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
uint16_t mant[JPEG2000_MAX_DECLEVELS *3]
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static int get_tlm(Jpeg2000DecoderContext *s, int n)
#define FF_ARRAY_ELEMS(a)
static av_cold int jpeg2000_decode_init(AVCodecContext *avctx)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static int get_qcd(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q, uint8_t *properties)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
static int init_tile(Jpeg2000DecoderContext *s, int tileno)
Jpeg2000CodingStyle codsty[4]
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
static void dequantization_int(int x, int y, Jpeg2000Cblk *cblk, Jpeg2000Component *comp, Jpeg2000T1Context *t1, Jpeg2000Band *band)
static int get_cod(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, uint8_t *properties)
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
Macro definitions for various function/variable attributes.
static int jpeg2000_read_bitstream_packets(Jpeg2000DecoderContext *s)
static enum AVPixelFormat rgb_pix_fmts[]
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static void dequantization_float(int x, int y, Jpeg2000Cblk *cblk, Jpeg2000Component *comp, Jpeg2000T1Context *t1, Jpeg2000Band *band)
static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static void tile_codeblocks(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
#define JPEG2000_CSTY_SOP
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
8 bits with AV_PIX_FMT_RGB32 palette
#define WRITE_FRAME(D, PIXEL)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Multithreading support functions.
Jpeg2000TgtNode * zerobits
#define FF_CODEC_PROPERTY_LOSSLESS
static int tag_tree_decode(Jpeg2000DecoderContext *s, Jpeg2000TgtNode *node, int threshold)
#define u(width, name, range_min, range_max)
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Jpeg2000POCEntry poc[MAX_POCS]
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
#define JPEG2000_T1_SIG_SE
#define JPEG2000_CBLK_SEGSYM
static av_always_inline int bytestream2_size(GetByteContext *g)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
uint8_t log2_prec_widths[JPEG2000_MAX_RESLEVELS]
static int get_poc(Jpeg2000DecoderContext *s, int size, Jpeg2000POC *p)
#define JPEG2000_CSTY_EPH
static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile, int *tp_index, Jpeg2000CodingStyle *codsty, Jpeg2000ResLevel *rlevel, int precno, int layno, uint8_t *expn, int numgbits)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int getnpasses(Jpeg2000DecoderContext *s)
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
static const uint16_t mask[17]
#define PTRDIFF_SPECIFIER
#define YUV_PIXEL_FORMATS
void ff_jpeg2000_set_significance(Jpeg2000T1Context *t1, int x, int y, int negative)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static enum AVPixelFormat gray_pix_fmts[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int read_crg(Jpeg2000DecoderContext *s, int n)
#define JPEG2000_PGOD_CPRL
static int get_coc(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c, uint8_t *properties)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
uint8_t log2_prec_heights[JPEG2000_MAX_RESLEVELS]
int flags
AV_CODEC_FLAG_*.
#define JPEG2000_MAX_PASSES
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
int64_t max_pixels
The number of pixels per image to maximally accept.
#define JPEG2000_CBLK_RESET
static int get_ppm(Jpeg2000DecoderContext *s, int n)
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define JPEG2000_SOP_FIXED_BYTES
static int ff_jpeg2000_ceildiv(int a, int64_t b)
static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
static const AVClass jpeg2000_class
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have so the codec calls ff_thread_report set FF_CODEC_CAP_ALLOCATE_PROGRESS in AVCodec caps_internal and use ff_thread_get_buffer() to allocate frames.The frames must then be freed with ff_thread_release_buffer().Otherwise decode directly into the user-supplied frames.Call ff_thread_report_progress() after some part of the current picture has decoded.A good place to put this is where draw_horiz_band() is called-add this if it isn't called anywhere
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
static int get_ppt(Jpeg2000DecoderContext *s, int n)
uint8_t nb_components
The number of components each pixel has, (1-4)
enum AVPictureType pict_type
Picture type of the frame.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define AV_PIX_FMT_GRAY16
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
struct Jpeg2000TgtNode * parent
#define JPEG2000_T1_SGN_S
JPEG 2000 structures and defines common to encoder and decoder.
#define JPEG2000_MAX_RESLEVELS
static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty, Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk, int width, int height, int bandpos, uint8_t roi_shift)
static int needs_termination(int style, int passno)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static int ff_jpeg2000_getsigctxno(int flag, int bandno)
#define FF_PROFILE_JPEG2000_DCINEMA_4K
#define JPEG2000_MAX_DECLEVELS
static int jpeg2000_decode_packets_po_iteration(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile, int RSpoc, int CSpoc, int LYEpoc, int REpoc, int CEpoc, int Ppoc, int *tp_index)
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
static int get_siz(Jpeg2000DecoderContext *s)
static int get_plt(Jpeg2000DecoderContext *s, int n)
#define JPEG2000_PGOD_RPCL
static void roi_scale_cblk(Jpeg2000Cblk *cblk, Jpeg2000Component *comp, Jpeg2000T1Context *t1)
static int ff_jpeg2000_ceildivpow2(int a, int b)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
static av_always_inline int bytestream2_tell(GetByteContext *g)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
int(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
Libavcodec external API header.
static enum AVPixelFormat yuv_pix_fmts[]
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_WB16 unsigned int_TMPL byte
int ff_mqc_decode(MqcState *mqc, uint8_t *cxstate)
MQ decoder.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
main external API structure.
AVCodec ff_jpeg2000_decoder
static int pix_fmt_match(enum AVPixelFormat pix_fmt, int components, int bpc, uint32_t log2_chroma_wh, int pal8)
void av_cold ff_mqc_init_context_tables(void)
MQ-coder Initialize context tables (QE, NLPS, NMPS)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
static int getlblockinc(Jpeg2000DecoderContext *s)
Describe the class of an AVClass context structure.
static const AVProfile profiles[]
Rational number (pair of numerator and denominator).
static av_cold void jpeg2000_init_static_data(void)
static int get_rgn(Jpeg2000DecoderContext *s, int n)
#define FF_COMPLIANCE_STRICT
Strictly conform to all the things in the spec no matter what consequences.
#define JPEG2000_SOP_BYTE_LENGTH
static const AVOption options[]
GetByteContext packed_headers_stream
#define JPEG2000_T1_SIG_S
Jpeg2000ResLevel * reslevel
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint8_t expn[JPEG2000_MAX_DECLEVELS *3]
static int jpeg2000_decode_packets(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
static int get_sot(Jpeg2000DecoderContext *s, int n)
static int jp2_find_codestream(Jpeg2000DecoderContext *s)
static void jpeg2000_dec_cleanup(Jpeg2000DecoderContext *s)
static void decode_sigpass(Jpeg2000T1Context *t1, int width, int height, int bpno, int bandno, int vert_causal_ctx_csty_symbol)
static void dequantization_int_97(int x, int y, Jpeg2000Cblk *cblk, Jpeg2000Component *comp, Jpeg2000T1Context *t1, Jpeg2000Band *band)
common internal api header.
common internal and external API header
static void select_stream(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile, int *tp_index, Jpeg2000CodingStyle *codsty)
GetByteContext header_tpg
Jpeg2000QuantStyle qntsty[4]
int ff_dwt_decode(DWTContext *s, void *t)
#define XYZ_PIXEL_FORMATS
#define GRAY_PIXEL_FORMATS
GetByteContext packed_headers_stream
unsigned properties
Properties of the stream that gets decoded.
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
#define MKBETAG(a, b, c, d)
#define JPEG2000_CBLK_BYPASS
int ff_jpeg2000_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, int cbps, int dx, int dy, AVCodecContext *avctx)
#define JPEG2000_T1_SIG_SW
#define JPEG2000_PGOD_LRCP
static int get_bits(Jpeg2000DecoderContext *s, int n)
static int ff_thread_once(char *control, void(*routine)(void))
#define FF_PROFILE_JPEG2000_DCINEMA_2K
int key_frame
1 -> keyframe, 0-> not
Jpeg2000TilePart tile_part[32]
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
static int ff_jpeg2000_getrefctxno(int flag)
#define JPEG2000_CSTY_PREC
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
int depth
Number of bits in the component.
AVPixelFormat
Pixel format.
static double val(void *priv, double ch)
This structure stores compressed data.
static int get_qcx(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Jpeg2000CodingStyle codsty[4]
const AVProfile ff_jpeg2000_profiles[]
void * av_mallocz_array(size_t nmemb, size_t size)
static int ff_jpeg2000_getsgnctxno(int flag, int *xorbit)
static int jpeg2000_decode_tile(AVCodecContext *avctx, void *td, int jobnr, int threadnr)