46 #define JP2_SIG_TYPE 0x6A502020 47 #define JP2_SIG_VALUE 0x0D0A870A 48 #define JP2_CODESTREAM 0x6A703263 49 #define JP2_HEADER 0x6A703268 109 uint32_t palette[256];
144 s->
bit_index = 7 + (bytestream2_get_byte(&s->
g) != 0xFF
u);
147 res |= (bytestream2_peek_byte(&s->
g) >> s->
bit_index) & 1;
154 if (bytestream2_get_byte(&s->
g) == 0xff)
164 int sp = -1, curval = 0;
171 while (node && !node->
vis) {
179 curval = stack[
sp]->
val;
181 while (curval < threshold && sp >= 0) {
182 if (curval < stack[sp]->
val)
183 curval = stack[
sp]->
val;
184 while (curval < threshold) {
194 stack[
sp]->
val = curval;
201 int bpc, uint32_t log2_chroma_wh,
int pal8)
212 switch (components) {
214 match = match && desc->
comp[3].
depth >= bpc &&
215 (log2_chroma_wh >> 14 & 3) == 0 &&
216 (log2_chroma_wh >> 12 & 3) == 0;
218 match = match && desc->
comp[2].
depth >= bpc &&
222 match = match && desc->
comp[1].
depth >= bpc &&
227 match = match && desc->
comp[0].
depth >= bpc &&
228 (log2_chroma_wh >> 2 & 3) == 0 &&
229 (log2_chroma_wh & 3) == 0 &&
237 #define RGB_PIXEL_FORMATS AV_PIX_FMT_PAL8,AV_PIX_FMT_RGB24,AV_PIX_FMT_RGBA,AV_PIX_FMT_RGB48,AV_PIX_FMT_RGBA64 238 #define GRAY_PIXEL_FORMATS AV_PIX_FMT_GRAY8,AV_PIX_FMT_GRAY8A,AV_PIX_FMT_GRAY16,AV_PIX_FMT_YA16 239 #define YUV_PIXEL_FORMATS AV_PIX_FMT_YUV410P,AV_PIX_FMT_YUV411P,AV_PIX_FMT_YUVA420P, \ 240 AV_PIX_FMT_YUV420P,AV_PIX_FMT_YUV422P,AV_PIX_FMT_YUVA422P, \ 241 AV_PIX_FMT_YUV440P,AV_PIX_FMT_YUV444P,AV_PIX_FMT_YUVA444P, \ 242 AV_PIX_FMT_YUV420P9,AV_PIX_FMT_YUV422P9,AV_PIX_FMT_YUV444P9, \ 243 AV_PIX_FMT_YUVA420P9,AV_PIX_FMT_YUVA422P9,AV_PIX_FMT_YUVA444P9, \ 244 AV_PIX_FMT_YUV420P10,AV_PIX_FMT_YUV422P10,AV_PIX_FMT_YUV444P10, \ 245 AV_PIX_FMT_YUVA420P10,AV_PIX_FMT_YUVA422P10,AV_PIX_FMT_YUVA444P10, \ 246 AV_PIX_FMT_YUV420P12,AV_PIX_FMT_YUV422P12,AV_PIX_FMT_YUV444P12, \ 247 AV_PIX_FMT_YUV420P14,AV_PIX_FMT_YUV422P14,AV_PIX_FMT_YUV444P14, \ 248 AV_PIX_FMT_YUV420P16,AV_PIX_FMT_YUV422P16,AV_PIX_FMT_YUV444P16, \ 249 AV_PIX_FMT_YUVA420P16,AV_PIX_FMT_YUVA422P16,AV_PIX_FMT_YUVA444P16 250 #define XYZ_PIXEL_FORMATS AV_PIX_FMT_XYZ12 268 uint32_t log2_chroma_wh = 0;
270 int possible_fmts_nb = 0;
279 s->
width = bytestream2_get_be32u(&s->
g);
280 s->
height = bytestream2_get_be32u(&s->
g);
287 ncomponents = bytestream2_get_be16u(&s->
g);
298 if (ncomponents <= 0) {
304 if (ncomponents > 4) {
344 uint8_t x = bytestream2_get_byteu(&s->
g);
345 s->
cbps[
i] = (x & 0x7f) + 1;
347 s->
sgnd[
i] = !!(x & 0x80);
348 s->
cdx[
i] = bytestream2_get_byteu(&s->
g);
349 s->
cdy[
i] = bytestream2_get_byteu(&s->
g);
350 if ( !s->
cdx[i] || s->
cdx[i] == 3 || s->
cdx[i] > 4
351 || !s->
cdy[i] || s->
cdy[i] == 3 || s->
cdy[i] > 4) {
355 log2_chroma_wh |= s->
cdy[
i] >> 1 << i * 4 | s->
cdx[
i] >> 1 << i * 4 + 2;
420 for (i = 0; i < possible_fmts_nb; ++
i) {
427 if (i == possible_fmts_nb) {
428 if (ncomponents == 4 &&
429 s->
cdy[0] == 1 && s->
cdx[0] == 1 &&
430 s->
cdy[1] == 1 && s->
cdx[1] == 1 &&
444 if (i == possible_fmts_nb) {
446 "Unknown pix_fmt, profile: %d, colour_space: %d, " 447 "components: %d, precision: %d\n" 448 "cdx[0]: %d, cdy[0]: %d\n" 449 "cdx[1]: %d, cdy[1]: %d\n" 450 "cdx[2]: %d, cdy[2]: %d\n" 451 "cdx[3]: %d, cdy[3]: %d\n",
455 ncomponents > 1 ? s->
cdx[1] : 0,
456 ncomponents > 1 ? s->
cdy[1] : 0,
457 ncomponents > 2 ? s->
cdx[2] : 0,
458 ncomponents > 2 ? s->
cdy[2] : 0,
459 ncomponents > 3 ? s->
cdx[3] : 0,
460 ncomponents > 3 ? s->
cdy[3] : 0);
524 byte = bytestream2_get_byte(&s->
g);
554 tmp.
csty = bytestream2_get_byteu(&s->
g);
559 tmp.
nlayers = bytestream2_get_be16u(&s->
g);
560 tmp.
mct = bytestream2_get_byteu(&s->
g);
564 "MCT %"PRIu8
" with too few components (%d)\n",
569 if ((ret =
get_cox(s, &tmp)) < 0)
572 for (compno = 0; compno < s->
ncomponents; compno++)
573 if (!(properties[compno] &
HAD_COC))
574 memcpy(c + compno, &tmp,
sizeof(tmp));
591 compno = bytestream2_get_byteu(&s->
g);
595 "Invalid compno %d. There are %d components in the image.\n",
602 c->
csty = bytestream2_get_byteu(&s->
g);
615 compno = (s->
ncomponents < 257)? bytestream2_get_byte(&s->
g):
616 bytestream2_get_be16u(&s->
g);
617 if (bytestream2_get_byte(&s->
g)) {
624 if (compno < s->ncomponents) {
627 v = bytestream2_get_byte(&s->
g);
634 v = bytestream2_get_byte(&s->
g);
652 x = bytestream2_get_byteu(&s->
g);
662 for (i = 0; i < n; i++)
663 q->
expn[i] = bytestream2_get_byteu(&s->
g) >> 3;
667 x = bytestream2_get_be16u(&s->
g);
668 q->
expn[0] = x >> 11;
669 q->
mant[0] = x & 0x7ff;
671 int curexpn =
FFMAX(0, q->
expn[0] - (i - 1) / 3);
672 q->
expn[
i] = curexpn;
680 for (i = 0; i < n; i++) {
681 x = bytestream2_get_be16u(&s->
g);
682 q->
expn[
i] = x >> 11;
683 q->
mant[
i] = x & 0x7ff;
696 memset(&tmp, 0,
sizeof(tmp));
698 if ((ret =
get_qcx(s, n, &tmp)) < 0)
700 for (compno = 0; compno < s->
ncomponents; compno++)
701 if (!(properties[compno] &
HAD_QCC))
702 memcpy(q + compno, &tmp,
sizeof(tmp));
716 compno = bytestream2_get_byteu(&s->
g);
720 "Invalid compno %d. There are %d components in the image.\n",
726 return get_qcx(s, n - 1, q + compno);
745 tmp.
nb_poc = (size - 2) / elem_size;
751 for (i = 0; i<tmp.
nb_poc; i++) {
753 e->
RSpoc = bytestream2_get_byteu(&s->
g);
754 e->
CSpoc = bytestream2_get_byteu(&s->
g);
755 e->
LYEpoc = bytestream2_get_be16u(&s->
g);
756 e->
REpoc = bytestream2_get_byteu(&s->
g);
757 e->
CEpoc = bytestream2_get_byteu(&s->
g);
758 e->
Ppoc = bytestream2_get_byteu(&s->
g);
802 Isot = bytestream2_get_be16u(&s->
g);
807 Psot = bytestream2_get_be32u(&s->
g);
808 TPsot = bytestream2_get_byteu(&s->
g);
811 bytestream2_get_byteu(&s->
g);
837 memcpy(&tile->
poc , &s->
poc ,
sizeof(tile->
poc));
864 bytestream2_get_byte(&s->
g);
865 Stlm = bytestream2_get_byte(&s->
g);
868 ST = (Stlm >> 4) & 0x03;
874 SP = (Stlm >> 6) & 0x01;
875 tile_tlm = (n - 4) / ((SP + 1) * 2 + ST);
876 for (i = 0; i < tile_tlm; i++) {
881 bytestream2_get_byte(&s->
g);
884 bytestream2_get_be16(&s->
g);
888 bytestream2_get_be16(&s->
g);
890 bytestream2_get_be32(&s->
g);
907 bytestream2_get_byte(&s->
g);
909 for (i = 0; i < n - 3; i++) {
910 v = bytestream2_get_byte(&s->
g);
933 "PPT marker can occur only on first tile part of a tile.\n");
938 bytestream2_get_byte(&s->
g);
969 for (compno = 0; compno < s->
ncomponents; compno++) {
995 s->
cbps[compno], s->
cdx[compno],
1011 return num < 0 ? num : 3 + num;
1013 return num < 0 ? num : 6 + num;
1015 return num < 0 ? num : 37 + num;
1045 int layno,
uint8_t *expn,
int numgbits)
1047 int bandno, cblkno, ret, nb_code_blocks;
1050 if (layno < rlevel->band[0].prec[precno].decoded_layers)
1065 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
1069 if (band->
coord[0][0] == band->
coord[0][1] ||
1074 for (cblkno = 0; cblkno < nb_code_blocks; cblkno++) {
1076 int incl, newpasses, llen;
1089 int v = expn[bandno] + numgbits - 1 -
1091 if (v < 0 || v > 30) {
1093 "nonzerobits %d invalid or unsupported\n", v);
1109 "Block with length beyond 16 bits");
1128 while (newpasses1 < newpasses) {
1154 newpasses -= newpasses1;
1172 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
1177 for (cblkno = 0; cblkno < nb_code_blocks; cblkno++) {
1181 for (cwsno = 0; cwsno < cblk->
nb_lengthinc; cwsno ++) {
1194 "Block length %"PRIu16
" or lengthinc %d is too large, left %d\n",
1228 int Ppoc,
int *tp_index)
1231 int layno, reslevelno, compno, precno, ok_reslevel;
1239 for (reslevelno = RSpoc; ok_reslevel && reslevelno <
REpoc; reslevelno++) {
1241 for (layno = 0; layno <
LYEpoc; layno++) {
1242 for (compno = CSpoc; compno <
CEpoc; compno++) {
1245 if (reslevelno < codsty->nreslevels) {
1253 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
1264 for (layno = 0; layno <
LYEpoc; layno++) {
1266 for (reslevelno = RSpoc; ok_reslevel && reslevelno <
REpoc; reslevelno++) {
1268 for (compno = CSpoc; compno <
CEpoc; compno++) {
1271 if (reslevelno < codsty->nreslevels) {
1279 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
1290 for (compno = CSpoc; compno <
CEpoc; compno++) {
1300 for (reslevelno = RSpoc; reslevelno <
FFMIN(codsty->
nreslevels, REpoc); reslevelno++) {
1306 if (step_x >= 31 || step_y >= 31){
1313 for (y = tile->
coord[1][0]; y < tile->coord[1][1]; y = (y/step_y + 1)*step_y) {
1314 for (x = tile->
coord[0][0]; x < tile->coord[0][1]; x = (x/step_x + 1)*step_x) {
1315 for (reslevelno = RSpoc; reslevelno <
FFMIN(codsty->
nreslevels, REpoc); reslevelno++) {
1316 unsigned prcx, prcy;
1319 int xc = x / s->
cdx[compno];
1320 int yc = y / s->
cdy[compno];
1342 for (layno = 0; layno <
LYEpoc; layno++) {
1345 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
1358 for (reslevelno = RSpoc; ok_reslevel && reslevelno <
REpoc; reslevelno++) {
1362 for (compno = CSpoc; compno <
CEpoc; compno++) {
1366 if (reslevelno < codsty->nreslevels) {
1376 for (y = tile->
coord[1][0]; y < tile->coord[1][1]; y = (y/step_y + 1)*step_y) {
1377 for (x = tile->
coord[0][0]; x < tile->coord[0][1]; x = (x/step_x + 1)*step_x) {
1378 for (compno = CSpoc; compno <
CEpoc; compno++) {
1384 unsigned prcx, prcy;
1386 int xc = x / s->
cdx[compno];
1387 int yc = y / s->
cdy[compno];
1413 for (layno = 0; layno <
LYEpoc; layno++) {
1417 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
1431 for (compno = CSpoc; compno <
CEpoc; compno++) {
1435 for (reslevelno = RSpoc; reslevelno <
FFMIN(codsty->
nreslevels, REpoc); reslevelno++) {
1442 if (step_x >= 31 || step_y >= 31){
1449 for (y = tile->
coord[1][0]; y < tile->coord[1][1]; y = (y/step_y + 1)*step_y) {
1450 for (x = tile->
coord[0][0]; x < tile->coord[0][1]; x = (x/step_x + 1)*step_x) {
1451 for (compno = CSpoc; compno <
CEpoc; compno++) {
1455 int xc = x / s->
cdx[compno];
1456 int yc = y / s->
cdy[compno];
1458 for (reslevelno = RSpoc; reslevelno <
FFMIN(codsty->
nreslevels, REpoc); reslevelno++) {
1459 unsigned prcx, prcy;
1483 for (layno = 0; layno <
LYEpoc; layno++) {
1486 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
1541 int bpno,
int bandno,
1542 int vert_causal_ctx_csty_symbol)
1544 int mask = 3 << (bpno - 1), y0, x, y;
1546 for (y0 = 0; y0 <
height; y0 += 4)
1547 for (x = 0; x <
width; x++)
1548 for (y = y0; y < height && y < y0 + 4; y++) {
1549 int flags_mask = -1;
1550 if (vert_causal_ctx_csty_symbol && y == y0 + 3)
1571 int bpno,
int vert_causal_ctx_csty_symbol)
1576 phalf = 1 << (bpno - 1);
1579 for (y0 = 0; y0 <
height; y0 += 4)
1580 for (x = 0; x <
width; x++)
1581 for (y = y0; y < height && y < y0 + 4; y++)
1583 int flags_mask = (vert_causal_ctx_csty_symbol && y == y0 + 3) ?
1596 int seg_symbols,
int vert_causal_ctx_csty_symbol)
1598 int mask = 3 << (bpno - 1), y0, x, y, runlen, dec;
1600 for (y0 = 0; y0 <
height; y0 += 4) {
1601 for (x = 0; x <
width; x++) {
1602 int flags_mask = -1;
1603 if (vert_causal_ctx_csty_symbol)
1605 if (y0 + 3 < height &&
1623 for (y = y0 + runlen; y < y0 + 4 && y <
height; y++) {
1624 int flags_mask = -1;
1625 if (vert_causal_ctx_csty_symbol && y == y0 + 3)
1656 "Segmentation symbol value incorrect\n");
1686 if (bpno < 0 || bpno > 29) {
1693 vert_causal_ctx_csty_symbol);
1696 decode_refpass(t1, width, height, bpno + 1, vert_causal_ctx_csty_symbol);
1702 vert_causal_ctx_csty_symbol);
1730 if (cblk->
data + cblk->
length - 2*(term_cnt < cblk->nb_terminations) != t1->
mqc.
bp) {
1732 cblk->
data + cblk->
length - 2*(term_cnt < cblk->nb_terminations) - t1->
mqc.
bp);
1744 val = (quan_parameter < 0)?-quan_parameter:quan_parameter;
1746 if (val > (1 << roi_shift))
1747 return (quan_parameter < 0)?-(val >> roi_shift):(val >> roi_shift);
1748 return quan_parameter;
1764 for (j = 0; j < (cblk->
coord[1][1] - cblk->
coord[1][0]); ++j) {
1765 float *datap = &comp->
f_data[(comp->
coord[0][1] - comp->
coord[0][0]) * (y + j) + x];
1767 for (i = 0; i <
w; ++
i)
1779 for (j = 0; j < (cblk->
coord[1][1] - cblk->
coord[1][0]); ++j) {
1783 for (i = 0; i <
w; ++
i)
1784 datap[i] = src[i] / 2;
1787 for (i = 0; i <
w; ++
i)
1799 for (j = 0; j < (cblk->
coord[1][1] - cblk->
coord[1][0]); ++j) {
1802 for (i = 0; i <
w; ++
i)
1812 for (i = 1; i < 3; i++) {
1823 for (i = 0; i < 3; i++)
1829 for (i = 0; i < 2; i++)
1841 for (j = 0; j < (cblk->
coord[1][1] - cblk->
coord[1][0]); ++j) {
1843 for (i = 0; i <
w; ++
i)
1852 int compno, reslevelno, bandno;
1855 for (compno = 0; compno < s->
ncomponents; compno++) {
1866 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
1867 int nb_precincts, precno;
1869 int cblkno = 0, bandpos;
1871 bandpos = bandno + (reslevelno > 0);
1873 if (band->
coord[0][0] == band->
coord[0][1] ||
1879 for (precno = 0; precno < nb_precincts; precno++) {
1919 #define WRITE_FRAME(D, PIXEL) \ 1920 static inline void write_frame_ ## D(Jpeg2000DecoderContext * s, Jpeg2000Tile * tile, \ 1921 AVFrame * picture, int precision) \ 1923 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(s->avctx->pix_fmt); \ 1924 int planar = !!(pixdesc->flags & AV_PIX_FMT_FLAG_PLANAR); \ 1925 int pixelsize = planar ? 1 : pixdesc->nb_components; \ 1930 for (compno = 0; compno < s->ncomponents; compno++) { \ 1931 Jpeg2000Component *comp = tile->comp + compno; \ 1932 Jpeg2000CodingStyle *codsty = tile->codsty + compno; \ 1934 float *datap = comp->f_data; \ 1935 int32_t *i_datap = comp->i_data; \ 1936 int cbps = s->cbps[compno]; \ 1937 int w = tile->comp[compno].coord[0][1] - s->image_offset_x; \ 1941 plane = s->cdef[compno] ? s->cdef[compno]-1 : (s->ncomponents-1); \ 1943 y = tile->comp[compno].coord[1][0] - s->image_offset_y / s->cdy[compno]; \ 1944 line = (PIXEL *)picture->data[plane] + y * (picture->linesize[plane] / sizeof(PIXEL));\ 1945 for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y++) { \ 1948 x = tile->comp[compno].coord[0][0] - s->image_offset_x / s->cdx[compno]; \ 1949 dst = line + x * pixelsize + compno*!planar; \ 1951 if (codsty->transform == FF_DWT97) { \ 1952 for (; x < w; x++) { \ 1953 int val = lrintf(*datap) + (1 << (cbps - 1)); \ 1955 val = av_clip(val, 0, (1 << cbps) - 1); \ 1956 *dst = val << (precision - cbps); \ 1961 for (; x < w; x++) { \ 1962 int val = *i_datap + (1 << (cbps - 1)); \ 1964 val = av_clip(val, 0, (1 << cbps) - 1); \ 1965 *dst = val << (precision - cbps); \ 1970 line += picture->linesize[plane] / sizeof(PIXEL); \ 1982 int jobnr,
int threadnr)
1996 if (s->
cdef[x] < 0) {
2007 write_frame_8(s, tile, picture, 8);
2014 write_frame_16(s, tile, picture, precision);
2025 for (compno = 0; compno < s->
ncomponents; compno++) {
2040 memset(&s->
poc , 0,
sizeof(s->
poc));
2062 marker = bytestream2_get_be16u(&s->
g);
2097 len = bytestream2_get_be16(&s->
g);
2118 ret =
get_coc(s, codsty, properties);
2121 ret =
get_cod(s, codsty, properties);
2127 ret =
get_qcc(s, len, qntsty, properties);
2130 ret =
get_qcd(s, len, qntsty, properties);
2136 if (!(ret =
get_sot(s, len))) {
2167 "unsupported marker 0x%.4"PRIX16
" at pos 0x%X\n",
2174 "error during processing marker segment %.4"PRIx16
"\n",
2176 return ret ? ret : -1;
2203 uint32_t atom_size, atom, atom_end;
2204 int search_range = 10;
2209 atom_size = bytestream2_get_be32u(&s->
g);
2210 atom = bytestream2_get_be32u(&s->
g);
2211 if (atom_size == 1) {
2212 if (bytestream2_get_be32u(&s->
g)) {
2216 atom_size = bytestream2_get_be32u(&s->
g);
2234 uint32_t atom2_size, atom2, atom2_end;
2238 atom2_size = bytestream2_get_be32u(&s->
g);
2239 atom2 = bytestream2_get_be32u(&s->
g);
2241 if (atom2_size < 8 || atom2_end > atom_end || atom2_end < atom2_size)
2246 }
else if (atom2 ==
MKBETAG(
'c',
'o',
'l',
'r') && atom2_size >= 7) {
2247 int method = bytestream2_get_byteu(&s->
g);
2252 }
else if (atom2 ==
MKBETAG(
'p',
'c',
'l',
'r') && atom2_size >= 6) {
2253 int i,
size, colour_count, colour_channels, colour_depth[3];
2254 colour_count = bytestream2_get_be16u(&s->
g);
2255 colour_channels = bytestream2_get_byteu(&s->
g);
2257 colour_depth[0] = (bytestream2_get_byteu(&s->
g) & 0x7f) + 1;
2258 colour_depth[1] = (bytestream2_get_byteu(&s->
g) & 0x7f) + 1;
2259 colour_depth[2] = (bytestream2_get_byteu(&s->
g) & 0x7f) + 1;
2260 size = (colour_depth[0] + 7 >> 3) * colour_count +
2261 (colour_depth[1] + 7 >> 3) * colour_count +
2262 (colour_depth[2] + 7 >> 3) * colour_count;
2264 colour_channels != 3 ||
2265 colour_depth[0] > 16 ||
2266 colour_depth[1] > 16 ||
2267 colour_depth[2] > 16 ||
2268 atom2_size < size) {
2274 for (i = 0; i < colour_count; i++) {
2276 if (colour_depth[0] <= 8) {
2277 r = bytestream2_get_byteu(&s->
g) << 8 - colour_depth[0];
2278 r |= r >> colour_depth[0];
2280 r = bytestream2_get_be16u(&s->
g) >> colour_depth[0] - 8;
2282 if (colour_depth[1] <= 8) {
2283 g = bytestream2_get_byteu(&s->
g) << 8 - colour_depth[1];
2284 g |= g >> colour_depth[1];
2286 g = bytestream2_get_be16u(&s->
g) >> colour_depth[1] - 8;
2288 if (colour_depth[2] <= 8) {
2289 b = bytestream2_get_byteu(&s->
g) << 8 - colour_depth[2];
2290 b |= b >> colour_depth[2];
2292 b = bytestream2_get_be16u(&s->
g) >> colour_depth[2] - 8;
2294 s->
palette[
i] = 0xff
u << 24 | r << 16 | g << 8 |
b;
2296 }
else if (atom2 ==
MKBETAG(
'c',
'd',
'e',
'f') && atom2_size >= 2) {
2297 int n = bytestream2_get_be16u(&s->
g);
2299 int cn = bytestream2_get_be16(&s->
g);
2300 int av_unused typ = bytestream2_get_be16(&s->
g);
2301 int asoc = bytestream2_get_be16(&s->
g);
2302 if (cn < 4 && asoc < 4)
2305 }
else if (atom2 ==
MKBETAG(
'r',
'e',
's',
' ') && atom2_size >= 18) {
2306 int64_t vnum, vden, hnum, hden, vexp, hexp;
2309 resx = bytestream2_get_be32u(&s->
g);
2310 if (resx !=
MKBETAG(
'r',
'e',
's',
'c') && resx !=
MKBETAG(
'r',
'e',
's',
'd')) {
2314 vnum = bytestream2_get_be16u(&s->
g);
2315 vden = bytestream2_get_be16u(&s->
g);
2316 hnum = bytestream2_get_be16u(&s->
g);
2317 hden = bytestream2_get_be16u(&s->
g);
2318 vexp = bytestream2_get_byteu(&s->
g);
2319 hexp = bytestream2_get_byteu(&s->
g);
2320 if (!vnum || !vden || !hnum || !hden) {
2332 if ( INT64_MAX / (hnum * vden) > pow(10, hexp)
2333 && INT64_MAX / (vnum * hden) > pow(10, vexp))
2335 hnum * vden * pow(10, hexp),
2336 vnum * hden * pow(10, vexp),
2340 }
while (atom_end - atom2_end >= 8);
2378 memset(s->
cdef, -1,
sizeof(s->
cdef));
2387 (bytestream2_get_be32u(&s->
g) == 12) &&
2392 "Could not find Jpeg2000 codestream atom.\n");
2427 memcpy(picture->
data[1], s->
palette, 256 *
sizeof(uint32_t));
2439 #define OFFSET(x) offsetof(Jpeg2000DecoderContext, x) 2440 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM 2443 {
"lowres",
"Lower the decoding resolution by a power of two",
2464 .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
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
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)
Jpeg2000TgtNode * cblkincl
static enum AVPixelFormat xyz_pix_fmts[]
av_cold void ff_jpeg2000dsp_init(Jpeg2000DSPContext *c)
#define JPEG2000_T1_SIG_NB
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
#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)
static av_cold int jpeg2000_decode_init(AVCodecContext *avctx)
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)
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)
static av_cold int end(AVCodecContext *avctx)
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)
Allocate, reallocate, or free an array.
#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
#define i(width, name, range_min, range_max)
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().
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
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
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define JPEG2000_SOP_FIXED_BYTES
static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
static const AVClass jpeg2000_class
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)
#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 int get_siz(Jpeg2000DecoderContext *s)
static int get_plt(Jpeg2000DecoderContext *s, int n)
#define FF_ARRAY_ELEMS(a)
#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[]
int ff_mqc_decode(MqcState *mqc, uint8_t *cxstate)
MQ decoder.
static void select_stream(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile, int *tp_index)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
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[]
#define JPEG2000_T1_SIG_S
Jpeg2000ResLevel * reslevel
static int ff_jpeg2000_ceildiv(int a, int b)
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
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
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)
Allocate a memory block for an array with av_mallocz().
static int ff_jpeg2000_getsgnctxno(int flag, int *xorbit)
static int jpeg2000_decode_tile(AVCodecContext *avctx, void *td, int jobnr, int threadnr)