38 #define JP2_SIG_TYPE 0x6A502020
39 #define JP2_SIG_VALUE 0x0D0A870A
40 #define JP2_CODESTREAM 0x6A703263
96 s->
bit_index = 7 + (bytestream2_get_byte(&s->
g) != 0xFF
u);
99 res |= (bytestream2_peek_byte(&s->
g) >> s->
bit_index) & 1;
106 if (bytestream2_get_byte(&s->
g) == 0xff)
116 int sp = -1, curval = 0;
121 while (node && !node->
vis) {
129 curval = stack[
sp]->
val;
131 while (curval < threshold && sp >= 0) {
132 if (curval < stack[sp]->
val)
133 curval = stack[
sp]->
val;
134 while (curval < threshold) {
144 stack[
sp]->
val = curval;
161 s->
width = bytestream2_get_be32u(&s->
g);
162 s->
height = bytestream2_get_be32u(&s->
g);
182 uint8_t x = bytestream2_get_byteu(&s->
g);
183 s->
cbps[i] = (x & 0x7f) + 1;
185 s->
sgnd[i] = !!(x & 0x80);
186 s->
cdx[i] = bytestream2_get_byteu(&s->
g);
187 s->
cdy[i] = bytestream2_get_byteu(&s->
g);
188 if (s->
cdx[i] != 1 || s->
cdy[i] != 1) {
298 byte = bytestream2_get_byte(&s->
g);
319 tmp.
csty = bytestream2_get_byteu(&s->
g);
327 tmp.
nlayers = bytestream2_get_be16u(&s->
g);
328 tmp.
mct = bytestream2_get_byteu(&s->
g);
331 for (compno = 0; compno < s->
ncomponents; compno++)
332 if (!(properties[compno] &
HAD_COC))
333 memcpy(c + compno, &tmp,
sizeof(tmp));
347 compno = bytestream2_get_byteu(&s->
g);
350 c->
csty = bytestream2_get_byteu(&s->
g);
365 x = bytestream2_get_byteu(&s->
g);
374 for (i = 0; i <
n; i++)
375 q->
expn[i] = bytestream2_get_byteu(&s->
g) >> 3;
379 x = bytestream2_get_be16u(&s->
g);
380 q->
expn[0] = x >> 11;
381 q->
mant[0] = x & 0x7ff;
382 for (i = 1; i < 32 * 3; i++) {
383 int curexpn =
FFMAX(0, q->
expn[0] - (i - 1) / 3);
384 q->
expn[i] = curexpn;
391 for (i = 0; i <
n; i++) {
392 x = bytestream2_get_be16u(&s->
g);
393 q->
expn[i] = x >> 11;
394 q->
mant[i] = x & 0x7ff;
409 for (compno = 0; compno < s->
ncomponents; compno++)
410 if (!(properties[compno] &
HAD_QCC))
411 memcpy(q + compno, &tmp,
sizeof(tmp));
425 compno = bytestream2_get_byteu(&s->
g);
427 return get_qcx(s, n - 1, q + compno);
444 if (!bytestream2_get_byteu(&s->
g)) {
451 bytestream2_get_byteu(&s->
g);
466 uint8_t Stlm, ST, SP, tile_tlm, i;
467 bytestream2_get_byte(&s->
g);
468 Stlm = bytestream2_get_byte(&s->
g);
471 ST = (Stlm >> 4) & 0x03;
473 SP = (Stlm >> 6) & 0x01;
474 tile_tlm = (n - 4) / ((SP + 1) * 2 + ST);
475 for (i = 0; i < tile_tlm; i++) {
480 bytestream2_get_byte(&s->
g);
483 bytestream2_get_be16(&s->
g);
486 bytestream2_get_be32(&s->
g);
490 bytestream2_get_be16(&s->
g);
492 bytestream2_get_be32(&s->
g);
507 for (compno = 0; compno < s->
ncomponents; compno++) {
538 return num < 0 ? num : 3 + num;
540 return num < 0 ? num : 6 + num;
542 return num < 0 ? num : 37 + num;
559 int layno,
uint8_t *expn,
int numgbits)
561 int bandno, cblkno,
ret, nb_code_blocks;
569 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
579 for (cblkno = 0; cblkno < nb_code_blocks; cblkno++) {
581 int incl, newpasses, llen;
616 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
621 for (cblkno = 0; cblkno < nb_code_blocks; cblkno++) {
632 cblk->
data[0] = 0xFF;
633 cblk->
data[1] = 0xFF;
644 int layno, reslevelno, compno, precno, ok_reslevel;
648 for (reslevelno = 0; ok_reslevel; reslevelno++) {
650 for (compno = 0; compno < s->
ncomponents; compno++) {
653 if (reslevelno < codsty->nreslevels) {
661 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
673 int bpno,
int bandno,
int bpass_csty_symbol,
674 int vert_causal_ctx_csty_symbol)
676 int mask = 3 << (bpno - 1), y0, x,
y;
678 for (y0 = 0; y0 <
height; y0 += 4)
679 for (x = 0; x <
width; x++)
680 for (
y = y0;
y < height &&
y < y0 + 4;
y++) {
684 if (vert_causal_ctx_csty_symbol &&
y == y0 + 3)
688 if (bpass_csty_symbol)
708 phalf = 1 << (bpno - 1);
711 for (y0 = 0; y0 <
height; y0 += 4)
712 for (x = 0; x <
width; x++)
713 for (y = y0; y < height && y < y0 + 4; y++)
726 int seg_symbols,
int vert_causal_ctx_csty_symbol)
728 int mask = 3 << (bpno - 1), y0, x,
y, runlen, dec;
730 for (y0 = 0; y0 <
height; y0 += 4) {
731 for (x = 0; x <
width; x++) {
732 if (y0 + 3 < height &&
750 for (
y = y0 + runlen;
y < y0 + 4 &&
y <
height;
y++) {
754 if (vert_causal_ctx_csty_symbol &&
y == y0 + 3)
783 "Segmentation symbol value incorrect\n");
795 for (
y = 0;
y < height+2;
y++)
796 memset(t1->
flags[
y], 0, (width + 2)*
sizeof(
int));
799 memset(t1->
data[
y], 0, width*
sizeof(
int));
809 bpass_csty_symbol && (clnpass_cnt >= 4), vert_causal_ctx_csty_symbol);
813 if (bpass_csty_symbol && clnpass_cnt >= 4)
819 clnpass_cnt = clnpass_cnt + 1;
820 if (bpass_csty_symbol && clnpass_cnt >= 4)
840 float *datap = &comp->
f_data[(comp->
coord[0][1] - comp->
coord[0][0]) * y + x];
841 for (j = 0; j < (cblk->
coord[1][1] - cblk->
coord[1][0]); ++j)
842 for (i = 0; i < (cblk->
coord[0][1] - cblk->
coord[0][0]); ++i) {
843 idx = (comp->
coord[0][1] - comp->
coord[0][0]) * j + i;
855 for (j = 0; j < (cblk->
coord[1][1] - cblk->
coord[1][0]); ++j)
856 for (i = 0; i < (cblk->
coord[0][1] - cblk->
coord[0][0]); ++i) {
857 idx = (comp->
coord[0][1] - comp->
coord[0][0]) * j + i;
882 float *srcf[3], i0f, i1f,
i2f;
884 for (i = 0; i < 3; i++)
890 for (i = 0; i < 2; i++)
895 for (i = 0; i < csize; i++) {
906 for (i = 0; i < csize; i++) {
907 i0 = *src[0] + (((
i_ict_params[0] * *src[2]) + (1 << 15)) >> 16);
908 i1 = *src[0] - (((
i_ict_params[1] * *src[1]) + (1 << 15)) >> 16)
910 i2 = *src[0] + (((
i_ict_params[3] * *src[1]) + (1 << 15)) >> 16);
917 for (i = 0; i < csize; i++) {
918 i1 = *src[0] - (*src[2] + *src[1] >> 2);
932 int compno, reslevelno, bandno;
939 for (compno = 0; compno < s->
ncomponents; compno++) {
947 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
948 int nb_precincts, precno;
950 int cblkno=0, bandpos;
952 bandpos = bandno + (reslevelno > 0);
959 for (precno = 0; precno < nb_precincts; precno++) {
972 x = cblk->
coord[0][0];
973 y = cblk->
coord[1][0];
992 for (compno = 0; compno < s->
ncomponents; compno++) {
994 float *datap = comp->
f_data;
1009 val =
lrintf(*datap) + (1 << (s->
cbps[compno] - 1));
1011 val = *i_datap + (1 << (s->
cbps[compno] - 1));
1012 val = av_clip(val, 0, (1 << s->
cbps[compno]) - 1);
1013 *dst = val << (8 - s->
cbps[compno]);
1022 for (compno = 0; compno < s->
ncomponents; compno++) {
1024 float *datap = comp->
f_data;
1029 linel = (uint16_t*)picture->
data[0] + y * (picture->
linesize[0] >> 1);
1039 val =
lrintf(*datap) + (1 << (s->
cbps[compno] - 1));
1041 val = *i_datap + (1 << (s->
cbps[compno] - 1));
1042 val = av_clip(val, 0, (1 << s->
cbps[compno]) - 1);
1044 *dst = val << (16 - s->
cbps[compno]);
1060 for (compno = 0; compno < s->
ncomponents; compno++) {
1087 marker = bytestream2_get_be16u(&s->
g);
1107 len = bytestream2_get_be16u(&s->
g);
1115 ret =
get_coc(s, codsty, properties);
1118 ret =
get_cod(s, codsty, properties);
1121 ret =
get_qcc(s, len, qntsty, properties);
1124 ret =
get_qcd(s, len, qntsty, properties);
1143 "unsupported marker 0x%.4X at pos 0x%X\n",
1150 "error during processing marker segment %.4x\n", marker);
1151 return ret ? ret : -1;
1159 uint32_t atom_size, atom;
1160 int found_codestream = 0, search_range = 10;
1163 atom_size = bytestream2_get_be32u(&s->
g);
1164 atom = bytestream2_get_be32u(&s->
g);
1166 found_codestream = 1;
1175 if (found_codestream)
1203 (bytestream2_get_be32u(&s->
g) == 12) &&
1243 #define OFFSET(x) offsetof(Jpeg2000DecoderContext, x)
1244 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1247 {
"lowres",
"Lower the decoding resolution by a power of two",
1261 static const AVClass class = {
1277 .priv_class = &
class,