49 #define JP2_SIG_TYPE 0x6A502020
50 #define JP2_SIG_VALUE 0x0D0A870A
51 #define JP2_CODESTREAM 0x6A703263
52 #define JP2_HEADER 0x6A703268
63 #define HT_MIXED 0x80 // bit 7 of SPcod/SPcoc
76 if (
s->bit_index == 0) {
77 s->bit_index = 7 + (bytestream2_get_byte(&
s->g) != 0xFF
u);
80 res |= (bytestream2_peek_byte(&
s->g) >>
s->bit_index) & 1;
87 if (bytestream2_get_byte(&
s->g) == 0xff)
97 int sp = -1, curval = 0;
104 while (node && !node->
vis) {
112 curval = stack[sp]->
val;
114 while (curval < threshold && sp >= 0) {
115 if (curval < stack[sp]->
val)
116 curval = stack[sp]->
val;
117 while (curval < threshold) {
127 stack[sp]->
val = curval;
134 int bpc, uint32_t log2_chroma_wh,
int pal8)
141 if (
desc->nb_components != components) {
145 switch (components) {
147 match = match &&
desc->comp[3].depth >= bpc &&
148 (log2_chroma_wh >> 14 & 3) == 0 &&
149 (log2_chroma_wh >> 12 & 3) == 0;
152 match = match &&
desc->comp[2].depth >= bpc &&
153 (log2_chroma_wh >> 10 & 3) ==
desc->log2_chroma_w &&
154 (log2_chroma_wh >> 8 & 3) ==
desc->log2_chroma_h;
157 match = match &&
desc->comp[1].depth >= bpc &&
158 (log2_chroma_wh >> 6 & 3) ==
desc->log2_chroma_w &&
159 (log2_chroma_wh >> 4 & 3) ==
desc->log2_chroma_h;
163 match = match &&
desc->comp[0].depth >= bpc &&
164 (log2_chroma_wh >> 2 & 3) == 0 &&
165 (log2_chroma_wh & 3) == 0 &&
173 #define RGB_PIXEL_FORMATS AV_PIX_FMT_PAL8,AV_PIX_FMT_RGB24,AV_PIX_FMT_RGBA,AV_PIX_FMT_RGB48,AV_PIX_FMT_RGBA64
174 #define GRAY_PIXEL_FORMATS AV_PIX_FMT_GRAY8,AV_PIX_FMT_GRAY8A,AV_PIX_FMT_GRAY16,AV_PIX_FMT_YA16
175 #define YUV_PIXEL_FORMATS AV_PIX_FMT_YUV410P,AV_PIX_FMT_YUV411P,AV_PIX_FMT_YUVA420P, \
176 AV_PIX_FMT_YUV420P,AV_PIX_FMT_YUV422P,AV_PIX_FMT_YUVA422P, \
177 AV_PIX_FMT_YUV440P,AV_PIX_FMT_YUV444P,AV_PIX_FMT_YUVA444P, \
178 AV_PIX_FMT_YUV420P9,AV_PIX_FMT_YUV422P9,AV_PIX_FMT_YUV444P9, \
179 AV_PIX_FMT_YUVA420P9,AV_PIX_FMT_YUVA422P9,AV_PIX_FMT_YUVA444P9, \
180 AV_PIX_FMT_YUV420P10,AV_PIX_FMT_YUV422P10,AV_PIX_FMT_YUV444P10, \
181 AV_PIX_FMT_YUVA420P10,AV_PIX_FMT_YUVA422P10,AV_PIX_FMT_YUVA444P10, \
182 AV_PIX_FMT_YUV420P12,AV_PIX_FMT_YUV422P12,AV_PIX_FMT_YUV444P12, \
183 AV_PIX_FMT_YUV420P14,AV_PIX_FMT_YUV422P14,AV_PIX_FMT_YUV444P14, \
184 AV_PIX_FMT_YUV420P16,AV_PIX_FMT_YUV422P16,AV_PIX_FMT_YUV444P16, \
185 AV_PIX_FMT_YUVA420P16,AV_PIX_FMT_YUVA422P16,AV_PIX_FMT_YUVA444P16
186 #define XYZ_PIXEL_FORMATS AV_PIX_FMT_XYZ12
204 uint32_t log2_chroma_wh = 0;
206 int possible_fmts_nb = 0;
216 s->avctx->profile = bytestream2_get_be16u(&
s->g);
217 s->width = bytestream2_get_be32u(&
s->g);
218 s->height = bytestream2_get_be32u(&
s->g);
219 s->image_offset_x = bytestream2_get_be32u(&
s->g);
220 s->image_offset_y = bytestream2_get_be32u(&
s->g);
221 s->tile_width = bytestream2_get_be32u(&
s->g);
222 s->tile_height = bytestream2_get_be32u(&
s->g);
223 s->tile_offset_x = bytestream2_get_be32u(&
s->g);
224 s->tile_offset_y = bytestream2_get_be32u(&
s->g);
225 ncomponents = bytestream2_get_be16u(&
s->g);
232 if (ncomponents <= 0) {
238 if (ncomponents > 4) {
244 if (
s->tile_offset_x < 0 ||
s->tile_offset_y < 0 ||
245 s->image_offset_x <
s->tile_offset_x ||
246 s->image_offset_y <
s->tile_offset_y ||
247 s->tile_width + (
int64_t)
s->tile_offset_x <=
s->image_offset_x ||
248 s->tile_height + (
int64_t)
s->tile_offset_y <=
s->image_offset_y
254 if (
s->image_offset_x >=
s->width ||
s->image_offset_y >=
s->height) {
259 if (
s->reduction_factor && (
s->image_offset_x ||
s->image_offset_y) ){
260 av_log(
s->avctx,
AV_LOG_ERROR,
"reduction factor with image offsets is not fully implemented");
264 s->ncomponents = ncomponents;
266 if (
s->tile_width <= 0 ||
s->tile_height <= 0) {
268 s->tile_width,
s->tile_height);
273 av_log(
s->avctx,
AV_LOG_ERROR,
"Insufficient space for %d components in SIZ\n",
s->ncomponents);
277 for (
i = 0;
i <
s->ncomponents;
i++) {
278 if (
s->cdef[
i] < 0) {
279 for (
i = 0;
i <
s->ncomponents;
i++) {
282 if ((
s->ncomponents & 1) == 0)
283 s->cdef[
s->ncomponents-1] = 0;
289 for (
i = 0;
i <
s->ncomponents;
i++)
290 cdef_used |= 1<<
s->cdef[
i];
293 if (cdef_used != ((
int[]){0,2,3,14,15})[
s->ncomponents])
296 for (
i = 0;
i <
s->ncomponents;
i++) {
297 uint8_t x = bytestream2_get_byteu(&
s->g);
298 s->cbps[
i] = (x & 0x7f) + 1;
299 s->precision =
FFMAX(
s->cbps[
i],
s->precision);
300 s->sgnd[
i] = !!(x & 0x80);
301 s->cdx[
i] = bytestream2_get_byteu(&
s->g);
302 s->cdy[
i] = bytestream2_get_byteu(&
s->g);
303 if ( !
s->cdx[
i] ||
s->cdx[
i] == 3 ||
s->cdx[
i] > 4
304 || !
s->cdy[
i] ||
s->cdy[
i] == 3 ||
s->cdy[
i] > 4) {
308 int i_remapped =
s->cdef[
i] ?
s->cdef[
i]-1 : (
s->ncomponents-1);
310 log2_chroma_wh |=
s->cdy[
i] >> 1 << i_remapped * 4 |
s->cdx[
i] >> 1 << i_remapped * 4 + 2;
317 if (
s->numXtiles * (uint64_t)
s->numYtiles > INT_MAX/
sizeof(*
s->tile) ||
320 s->numXtiles =
s->numYtiles = 0;
324 s->tile =
av_calloc(
s->numXtiles *
s->numYtiles,
sizeof(*
s->tile));
326 s->numXtiles =
s->numYtiles = 0;
330 for (
i = 0;
i <
s->numXtiles *
s->numYtiles;
i++) {
340 s->reduction_factor);
342 s->reduction_factor);
345 for (
i = 1;
i <
s->ncomponents;
i++) {
359 switch (
s->colour_space) {
379 && !
pix_fmt_match(
s->avctx->pix_fmt, ncomponents,
s->precision, log2_chroma_wh,
s->pal8))
382 for (
i = 0;
i < possible_fmts_nb; ++
i) {
383 if (
pix_fmt_match(possible_fmts[
i], ncomponents,
s->precision, log2_chroma_wh,
s->pal8)) {
384 s->avctx->pix_fmt = possible_fmts[
i];
389 if (
i == possible_fmts_nb) {
390 if (ncomponents == 4 &&
391 s->cdy[0] == 1 &&
s->cdx[0] == 1 &&
392 s->cdy[1] == 1 &&
s->cdx[1] == 1 &&
393 s->cdy[2] ==
s->cdy[3] &&
s->cdx[2] ==
s->cdx[3]) {
394 if (
s->precision == 8 &&
s->cdy[2] == 2 &&
s->cdx[2] == 2 && !
s->pal8) {
402 }
else if (ncomponents == 3 &&
s->precision == 8 &&
403 s->cdx[0] ==
s->cdx[1] &&
s->cdx[0] ==
s->cdx[2] &&
404 s->cdy[0] ==
s->cdy[1] &&
s->cdy[0] ==
s->cdy[2]) {
407 }
else if (ncomponents == 2 &&
s->precision == 8 &&
408 s->cdx[0] ==
s->cdx[1] &&
s->cdy[0] ==
s->cdy[1]) {
411 }
else if (ncomponents == 2 &&
s->precision == 16 &&
412 s->cdx[0] ==
s->cdx[1] &&
s->cdy[0] ==
s->cdy[1]) {
415 }
else if (ncomponents == 1 &&
s->precision == 8) {
418 }
else if (ncomponents == 1 &&
s->precision == 12) {
425 if (
i == possible_fmts_nb) {
427 "Unknown pix_fmt, profile: %d, colour_space: %d, "
428 "components: %d, precision: %d\n"
429 "cdx[0]: %d, cdy[0]: %d\n"
430 "cdx[1]: %d, cdy[1]: %d\n"
431 "cdx[2]: %d, cdy[2]: %d\n"
432 "cdx[3]: %d, cdy[3]: %d\n",
433 s->avctx->profile,
s->colour_space, ncomponents,
s->precision,
436 ncomponents > 1 ?
s->cdx[1] : 0,
437 ncomponents > 1 ?
s->cdy[1] : 0,
438 ncomponents > 2 ?
s->cdx[2] : 0,
439 ncomponents > 2 ?
s->cdy[2] : 0,
440 ncomponents > 3 ?
s->cdx[3] : 0,
441 ncomponents > 3 ?
s->cdy[3] : 0);
444 s->avctx->bits_per_raw_sample =
s->precision;
451 uint16_t Ccap_i[32] = { 0 };
460 Pcap = bytestream2_get_be32u(&
s->g);
461 s->isHT = (Pcap >> (31 - (15 - 1))) & 1;
462 for (
int i = 0;
i < 32;
i++) {
463 if ((Pcap >> (31 -
i)) & 1)
464 Ccap_i[
i] = bytestream2_get_be16u(&
s->g);
466 Ccap_15 = Ccap_i[14];
470 switch ((Ccap_15 >> 14) & 0x3) {
486 if ((Ccap_15 >> 13) & 1) {
491 s->Ccap15_b12 = (Ccap_15 >> 12) & 1;
493 s->Ccap15_b11 = (Ccap_15 >> 11) & 1;
495 s->Ccap15_b05 = (Ccap_15 >> 5) & 1;
503 s->HT_B = 4 * (
P - 19) + 27;
527 c->nreslevels = bytestream2_get_byteu(&
s->g) + 1;
533 if (
c->nreslevels <=
s->reduction_factor) {
538 av_log(
s->avctx,
AV_LOG_ERROR,
"reduction_factor too large for this bitstream, max is %d\n",
c->nreslevels - 1);
539 s->reduction_factor =
c->nreslevels - 1;
544 c->nreslevels2decode =
c->nreslevels -
s->reduction_factor;
546 c->log2_cblk_width = (bytestream2_get_byteu(&
s->g) & 15) + 2;
547 c->log2_cblk_height = (bytestream2_get_byteu(&
s->g) & 15) + 2;
549 if (
c->log2_cblk_width > 10 ||
c->log2_cblk_height > 10 ||
550 c->log2_cblk_width +
c->log2_cblk_height > 12) {
555 c->cblk_style = bytestream2_get_byteu(&
s->g);
556 if (
c->cblk_style != 0) {
565 c->transform = bytestream2_get_byteu(&
s->g);
569 #if FF_API_CODEC_PROPS
579 for (
i = 0;
i <
c->nreslevels;
i++) {
580 byte = bytestream2_get_byte(&
s->g);
581 c->log2_prec_widths[
i] =
byte & 0x0F;
582 c->log2_prec_heights[
i] = (
byte >> 4) & 0x0F;
584 if (
c->log2_prec_widths[
i] == 0 ||
c->log2_prec_heights[
i] == 0) {
586 c->log2_prec_widths[
i],
c->log2_prec_heights[
i]);
587 c->log2_prec_widths[
i] =
c->log2_prec_heights[
i] = 1;
592 memset(
c->log2_prec_widths , 15,
sizeof(
c->log2_prec_widths ));
593 memset(
c->log2_prec_heights, 15,
sizeof(
c->log2_prec_heights));
600 const uint8_t *properties)
610 tmp.csty = bytestream2_get_byteu(&
s->g);
613 tmp.prog_order = bytestream2_get_byteu(&
s->g);
615 tmp.nlayers = bytestream2_get_be16u(&
s->g);
616 tmp.mct = bytestream2_get_byteu(&
s->g);
618 if (
tmp.mct &&
s->ncomponents < 3) {
620 "MCT %"PRIu8
" with too few components (%d)\n",
621 tmp.mct,
s->ncomponents);
628 for (compno = 0; compno <
s->ncomponents; compno++)
629 if (!(properties[compno] &
HAD_COC))
630 memcpy(
c + compno, &
tmp,
sizeof(
tmp));
640 uint8_t has_eph, has_sop;
647 compno = bytestream2_get_byteu(&
s->g);
649 if (compno >=
s->ncomponents) {
651 "Invalid compno %d. There are %d components in the image.\n",
652 compno,
s->ncomponents);
659 c->csty = bytestream2_get_byteu(&
s->g);
674 compno = (
s->ncomponents < 257)? bytestream2_get_byte(&
s->g):
675 bytestream2_get_be16u(&
s->g);
676 if (bytestream2_get_byte(&
s->g)) {
683 if (compno < s->ncomponents) {
685 if (
s->curtileno == -1) {
686 v = bytestream2_get_byte(&
s->g);
689 s->roi_shift[compno] = v;
691 if (
s->tile[
s->curtileno].tp_idx != 0)
693 v = bytestream2_get_byte(&
s->g);
696 s->tile[
s->curtileno].comp[compno].roi_shift = v;
711 x = bytestream2_get_byteu(&
s->g);
721 for (
i = 0;
i < n;
i++)
722 q->
expn[
i] = bytestream2_get_byteu(&
s->g) >> 3;
726 x = bytestream2_get_be16u(&
s->g);
727 q->
expn[0] = x >> 11;
728 q->
mant[0] = x & 0x7ff;
730 int curexpn =
FFMAX(0, q->
expn[0] - (
i - 1) / 3);
731 q->
expn[
i] = curexpn;
739 for (
i = 0;
i < n;
i++) {
740 x = bytestream2_get_be16u(&
s->g);
741 q->
expn[
i] = x >> 11;
742 q->
mant[
i] = x & 0x7ff;
750 const uint8_t *properties)
755 memset(&
tmp, 0,
sizeof(
tmp));
759 for (compno = 0; compno <
s->ncomponents; compno++)
760 if (!(properties[compno] &
HAD_QCC))
761 memcpy(q + compno, &
tmp,
sizeof(
tmp));
775 compno = bytestream2_get_byteu(&
s->g);
777 if (compno >=
s->ncomponents) {
779 "Invalid compno %d. There are %d components in the image.\n",
780 compno,
s->ncomponents);
785 return get_qcx(
s, n - 1, q + compno);
791 int elem_size =
s->ncomponents <= 257 ? 7 : 9;
804 tmp.nb_poc = (
size - 2) / elem_size;
810 for (
i = 0;
i<
tmp.nb_poc;
i++) {
812 e->
RSpoc = bytestream2_get_byteu(&
s->g);
813 e->
CSpoc = bytestream2_get_byteu(&
s->g);
814 e->
LYEpoc = bytestream2_get_be16u(&
s->g);
815 e->
REpoc = bytestream2_get_byteu(&
s->g);
816 e->
CEpoc = bytestream2_get_byteu(&
s->g);
817 e->
Ppoc = bytestream2_get_byteu(&
s->g);
820 if (e->
CEpoc >
s->ncomponents)
821 e->
CEpoc =
s->ncomponents;
832 if (!
p->nb_poc ||
p->is_default) {
839 memcpy(
p->poc +
p->nb_poc,
tmp.poc,
tmp.nb_poc *
sizeof(
tmp.poc[0]));
840 p->nb_poc +=
tmp.nb_poc;
861 Isot = bytestream2_get_be16u(&
s->g);
862 if (Isot >=
s->numXtiles *
s->numYtiles)
866 Psot = bytestream2_get_be32u(&
s->g);
867 TPsot = bytestream2_get_byteu(&
s->g);
870 bytestream2_get_byteu(&
s->g);
885 s->tile[Isot].tp_idx = TPsot;
886 tp =
s->tile[Isot].tile_part + TPsot;
888 tp->
tp_end =
s->g.buffer + Psot - n - 2;
896 memcpy(&
tile->poc , &
s->poc ,
sizeof(
tile->poc));
897 tile->poc.is_default = 1;
905 if (
s->ncomponents*4 != n - 2) {
931 uint8_t Stlm, ST,
SP, tile_tlm,
i;
932 bytestream2_get_byte(&
s->g);
933 Stlm = bytestream2_get_byte(&
s->g);
936 ST = (Stlm >> 4) & 0x03;
942 SP = (Stlm >> 6) & 0x01;
943 tile_tlm = (n - 4) / ((
SP + 1) * 2 + ST);
944 for (
i = 0;
i < tile_tlm;
i++) {
949 bytestream2_get_byte(&
s->g);
952 bytestream2_get_be16(&
s->g);
956 bytestream2_get_be16(&
s->g);
958 bytestream2_get_be32(&
s->g);
975 bytestream2_get_byte(&
s->g);
977 for (
i = 0;
i < n - 3;
i++) {
978 v = bytestream2_get_byte(&
s->g);
994 bytestream2_get_byte(&
s->g);
996 s->packed_headers_size + n - 3);
998 s->packed_headers =
new;
1002 memset(&
s->packed_headers_stream, 0,
sizeof(
s->packed_headers_stream));
1005 s->packed_headers_size += n - 3;
1019 if (
s->curtileno < 0)
1022 tile = &
s->tile[
s->curtileno];
1023 if (
tile->tp_idx != 0) {
1025 "PPT marker can occur only on first tile part of a tile.\n");
1030 bytestream2_get_byte(&
s->g);
1032 tile->packed_headers_size + n - 3);
1034 tile->packed_headers =
new;
1037 memset(&
tile->packed_headers_stream, 0,
sizeof(
tile->packed_headers_stream));
1039 tile->packed_headers_size += n - 3;
1047 int tilex = tileno %
s->numXtiles;
1048 int tiley = tileno /
s->numXtiles;
1054 tile->coord[0][0] =
av_clip(tilex * (
int64_t)
s->tile_width +
s->tile_offset_x,
s->image_offset_x,
s->width);
1055 tile->coord[0][1] =
av_clip((tilex + 1) * (
int64_t)
s->tile_width +
s->tile_offset_x,
s->image_offset_x,
s->width);
1056 tile->coord[1][0] =
av_clip(tiley * (
int64_t)
s->tile_height +
s->tile_offset_y,
s->image_offset_y,
s->height);
1057 tile->coord[1][1] =
av_clip((tiley + 1) * (
int64_t)
s->tile_height +
s->tile_offset_y,
s->image_offset_y,
s->height);
1059 for (compno = 0; compno <
s->ncomponents; compno++) {
1065 comp->coord_o[0][0] =
tile->coord[0][0];
1066 comp->coord_o[0][1] =
tile->coord[0][1];
1067 comp->coord_o[1][0] =
tile->coord[1][0];
1068 comp->coord_o[1][1] =
tile->coord[1][1];
1080 if (!
comp->roi_shift)
1081 comp->roi_shift =
s->roi_shift[compno];
1084 if (
s->isHT && (!
s->Ccap15_b05) && (!codsty->
transform)) {
1085 av_log(
s->avctx,
AV_LOG_ERROR,
"Transformation = 0 (lossy DWT) is found in HTREV HT set\n");
1089 av_log(
s->avctx,
AV_LOG_ERROR,
"SPcod/SPcoc value does not match bit 14-15 values of Ccap15\n");
1093 s->cbps[compno],
s->cdx[compno],
1094 s->cdy[compno],
s->avctx))
1109 return num < 0 ? num : 3 + num;
1111 return num < 0 ? num : 6 + num;
1113 return num < 0 ? num : 37 + num;
1130 s->g =
tile->tile_part[*tp_index].header_tpg;
1134 s->g =
tile->tile_part[++(*tp_index)].tpg;
1144 s->g =
tile->tile_part[*tp_index].tpg;
1148 while (is_endof_tp) {
1150 s->g =
tile->tile_part[++(*tp_index)].tpg;
1160 av_log(
s->avctx,
AV_LOG_ERROR,
"SOP marker not found. instead %X\n", bytestream2_peek_be32(&
s->g));
1167 int layno,
const uint8_t *expn,
int numgbits)
1169 int bandno, cblkno,
ret, nb_code_blocks;
1172 if (layno < rlevel->band[0].prec[precno].decoded_layers)
1178 else if (
tile->has_ppt)
1179 s->g =
tile->packed_headers_stream;
1189 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
1193 if (band->
coord[0][0] == band->
coord[0][1] ||
1198 for (cblkno = 0; cblkno < nb_code_blocks; cblkno++) {
1200 int incl, newpasses, llen;
1214 int v = expn[bandno] + numgbits - 1 - (zbp -
tile->comp->roi_shift);
1215 if (v < 0 || v > 30) {
1217 "nonzerobits %d invalid or unsupported\n", v);
1230 uint8_t bypass_term_threshold = 0;
1231 uint8_t bits_to_read = 0;
1232 uint32_t segment_bytes = 0;
1234 uint8_t next_segment_passes = 0;
1235 int32_t href_passes, pass_bound;
1236 uint32_t tmp_length = 0;
1237 int32_t newpasses_copy, npasses_copy;
1249 "Block with length beyond 16 bits");
1266 newpasses_copy = newpasses;
1272 while (newpasses1 < newpasses_copy) {
1279 npasses_copy += newpasses1;
1280 newpasses_copy -= newpasses1;
1281 }
while (newpasses_copy);
1285 href_passes = (cblk->
npasses + newpasses - 1) % 3;
1286 segment_passes = newpasses - href_passes;
1288 bits_to_read = cblk->
lblock;
1289 if (segment_passes < 1) {
1292 segment_passes = newpasses;
1293 while (pass_bound <= segment_passes) {
1295 pass_bound += pass_bound;
1297 segment_bytes =
get_bits(
s, bits_to_read);
1298 if (segment_bytes) {
1308 while (pass_bound <= segment_passes) {
1310 pass_bound += pass_bound;
1312 segment_bytes =
get_bits(
s, bits_to_read);
1313 if (segment_bytes) {
1317 if (segment_bytes < 2)
1319 next_segment_passes = 2;
1323 }
else if (cblk->
lblock > 3 && segment_bytes > 1
1324 && (segment_bytes >> (bits_to_read - 1)) == 0) {
1326 next_segment_passes = 2;
1334 segment_passes = newpasses;
1335 while (pass_bound <= segment_passes) {
1337 pass_bound += pass_bound;
1338 segment_bytes <<= 1;
1348 segment_passes = newpasses;
1349 if (pass_bound <= segment_passes) {
1352 pass_bound += pass_bound;
1353 segment_bytes <<= 1;
1355 if (pass_bound > segment_passes)
1358 if (segment_bytes) {
1371 if(bits_to_read != 0)
1373 segment_passes = cblk->
npasses % 3;
1374 if (segment_passes == 0) {
1377 next_segment_passes = 2;
1378 if (segment_bytes == 1)
1383 segment_passes = newpasses > 1 ? 3 - segment_passes : 1;
1384 next_segment_passes = 1;
1385 bits_to_read =
av_log2(segment_passes);
1387 bits_to_read = (uint8_t) (bits_to_read + cblk->
lblock);
1388 segment_bytes =
get_bits(
s, bits_to_read);
1393 bits_to_read = (uint8_t) cblk->
lblock +
av_log2((uint8_t) newpasses);
1394 segment_bytes =
get_bits(
s, bits_to_read);
1395 segment_passes = newpasses;
1398 bits_to_read = cblk->
lblock;
1399 segment_bytes =
get_bits(
s, bits_to_read);
1401 next_segment_passes = 1;
1404 bypass_term_threshold = 10;
1405 if(bits_to_read != 0)
1407 if (cblk->
npasses < bypass_term_threshold) {
1409 segment_passes = bypass_term_threshold - cblk->
npasses;
1410 if (segment_passes > newpasses)
1411 segment_passes = newpasses;
1412 while ((2 << bits_to_read) <= segment_passes)
1414 next_segment_passes = 2;
1415 }
else if ((cblk->
npasses - bypass_term_threshold) % 3 < 2) {
1417 segment_passes = newpasses > 1 ? 2 - (cblk->
npasses - bypass_term_threshold) % 3 : 1;
1418 bits_to_read =
av_log2(segment_passes);
1419 next_segment_passes = 1;
1423 next_segment_passes = 2;
1425 bits_to_read = (uint8_t) (bits_to_read + cblk->
lblock);
1426 segment_bytes =
get_bits(
s, bits_to_read);
1433 newpasses -= (uint8_t) segment_passes;
1434 while (newpasses > 0) {
1435 segment_passes = newpasses > 1 ? next_segment_passes : 1;
1436 next_segment_passes = (uint8_t) (3 - next_segment_passes);
1437 bits_to_read = (uint8_t) (cblk->
lblock +
av_log2(segment_passes));
1438 segment_bytes =
get_bits(
s, bits_to_read);
1439 newpasses -= (uint8_t) (segment_passes);
1448 newpasses -= (uint8_t) (segment_passes);
1449 while (newpasses > 0) {
1450 if (bypass_term_threshold != 0) {
1451 segment_passes = newpasses > 1 ? next_segment_passes : 1;
1452 next_segment_passes = (uint8_t) (3 - next_segment_passes);
1453 bits_to_read = (uint8_t) (cblk->
lblock +
av_log2(segment_passes));
1458 bits_to_read = cblk->
lblock;
1460 segment_bytes =
get_bits(
s, bits_to_read);
1461 newpasses -= (uint8_t) (segment_passes);
1470 tmp_length = (tmp_length < cblk->lengthinc[
i]) ? cblk->
lengthinc[
i] : tmp_length;
1482 "Block with lengthinc greater than %zu",
1498 av_log(
s->avctx,
AV_LOG_ERROR,
"EPH marker not found. instead %X\n", bytestream2_peek_be32(&
s->g));
1503 tile->tile_part[*tp_index].header_tpg =
s->g;
1505 }
else if (
tile->has_ppt) {
1506 tile->packed_headers_stream =
s->g;
1509 for (bandno = 0; bandno < rlevel->
nbands; bandno++) {
1514 for (cblkno = 0; cblkno < nb_code_blocks; cblkno++) {
1518 for (cwsno = 0; cwsno < cblk->
nb_lengthinc; cwsno ++) {
1531 "Block length %"PRIu16
" or lengthinc %d is too large, left %d\n",
1553 tile->tile_part[*tp_index].tpg =
s->g;
1561 av_log(
s->avctx,
AV_LOG_ERROR,
"EPH marker not found. instead %X\n", bytestream2_peek_be32(&
s->g));
1564 tile->tile_part[*tp_index].header_tpg =
s->g;
1566 }
else if (
tile->has_ppt) {
1567 tile->packed_headers_stream =
s->g;
1570 tile->tile_part[*tp_index].tpg =
s->g;
1575 int RSpoc,
int CSpoc,
1576 int LYEpoc,
int REpoc,
int CEpoc,
1577 int Ppoc,
int *tp_index)
1580 int layno, reslevelno, compno, precno, ok_reslevel;
1588 for (reslevelno = RSpoc; ok_reslevel && reslevelno < REpoc; reslevelno++) {
1590 for (layno = 0; layno < LYEpoc; layno++) {
1591 for (compno = CSpoc; compno < CEpoc; compno++) {
1594 if (reslevelno < codsty->nreslevels) {
1602 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
1613 for (layno = 0; layno < LYEpoc; layno++) {
1615 for (reslevelno = RSpoc; ok_reslevel && reslevelno < REpoc; reslevelno++) {
1617 for (compno = CSpoc; compno < CEpoc; compno++) {
1620 if (reslevelno < codsty->nreslevels) {
1628 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
1639 for (compno = CSpoc; compno < CEpoc; compno++) {
1649 for (reslevelno = RSpoc; reslevelno <
FFMIN(codsty->
nreslevels, REpoc); reslevelno++) {
1650 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1655 if (step_x >= 31 || step_y >= 31){
1662 for (y =
tile->coord[1][0]; y < tile->coord[1][1]; y = (y/step_y + 1)*step_y) {
1663 for (x =
tile->coord[0][0]; x < tile->coord[0][1]; x = (x/step_x + 1)*step_x) {
1664 for (reslevelno = RSpoc; reslevelno <
FFMIN(codsty->
nreslevels, REpoc); reslevelno++) {
1665 unsigned prcx, prcy;
1666 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1668 int xc = x /
s->cdx[compno];
1669 int yc = y /
s->cdy[compno];
1691 for (layno = 0; layno < LYEpoc; layno++) {
1694 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
1707 for (reslevelno = RSpoc; ok_reslevel && reslevelno < REpoc; reslevelno++) {
1711 for (compno = CSpoc; compno < CEpoc; compno++) {
1715 if (reslevelno < codsty->nreslevels) {
1716 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1725 for (y =
tile->coord[1][0]; y < tile->coord[1][1]; y = (y/step_y + 1)*step_y) {
1726 for (x =
tile->coord[0][0]; x < tile->coord[0][1]; x = (x/step_x + 1)*step_x) {
1727 for (compno = CSpoc; compno < CEpoc; compno++) {
1731 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1733 unsigned prcx, prcy;
1736 if (!
s->cdx[compno] || !
s->cdy[compno])
1745 if (!(y % ((uint64_t)
s->cdy[compno] << (rlevel->
log2_prec_height + reducedresno)) == 0 ||
1749 if (!(x % ((uint64_t)
s->cdx[compno] << (rlevel->
log2_prec_width + reducedresno)) == 0 ||
1768 for (layno = 0; layno < LYEpoc; layno++) {
1772 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
1786 for (compno = CSpoc; compno < CEpoc; compno++) {
1790 for (reslevelno = RSpoc; reslevelno <
FFMIN(codsty->
nreslevels, REpoc); reslevelno++) {
1791 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1797 if (step_x >= 31 || step_y >= 31){
1804 for (y =
tile->coord[1][0]; y < tile->coord[1][1]; y = (y/step_y + 1)*step_y) {
1805 for (x =
tile->coord[0][0]; x < tile->coord[0][1]; x = (x/step_x + 1)*step_x) {
1806 for (compno = CSpoc; compno < CEpoc; compno++) {
1811 if (!
s->cdx[compno] || !
s->cdy[compno])
1814 for (reslevelno = RSpoc; reslevelno <
FFMIN(codsty->
nreslevels, REpoc); reslevelno++) {
1815 unsigned prcx, prcy;
1816 uint8_t reducedresno = codsty->
nreslevels - 1 -reslevelno;
1823 if (!(y % ((uint64_t)
s->cdy[compno] << (rlevel->
log2_prec_height + reducedresno)) == 0 ||
1827 if (!(x % ((uint64_t)
s->cdx[compno] << (rlevel->
log2_prec_width + reducedresno)) == 0 ||
1845 for (layno = 0; layno < LYEpoc; layno++) {
1848 qntsty->
expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
1872 if (
tile->poc.nb_poc) {
1873 for (
i=0;
i<
tile->poc.nb_poc;
i++) {
1888 tile->codsty[0].nlayers,
1891 tile->codsty[0].prog_order,
1903 int bpno,
int bandno,
1904 int vert_causal_ctx_csty_symbol)
1906 int mask = (3u << bpno)>>1, y0, x, y;
1908 for (y0 = 0; y0 <
height; y0 += 4)
1909 for (x = 0; x <
width; x++)
1910 for (y = y0; y <
height && y < y0 + 4; y++) {
1911 int flags_mask = -1;
1912 if (vert_causal_ctx_csty_symbol && y == y0 + 3)
1934 int bpno,
int vert_causal_ctx_csty_symbol)
1941 for (y0 = 0; y0 <
height; y0 += 4)
1942 for (x = 0; x <
width; x++)
1943 for (y = y0; y <
height && y < y0 + 4; y++)
1945 int flags_mask = (vert_causal_ctx_csty_symbol && y == y0 + 3) ?
1948 t1->
data[(y) * t1->
stride + x] |= phalf >> 1;
1961 int seg_symbols,
int vert_causal_ctx_csty_symbol)
1963 int mask = 3 << (bpno - 1), y0, x, y, runlen, dec;
1965 for (y0 = 0; y0 <
height; y0 += 4) {
1966 for (x = 0; x <
width; x++) {
1967 int flags_mask = -1;
1968 if (vert_causal_ctx_csty_symbol)
1988 for (y = y0 + runlen; y < y0 + 4 && y <
height; y++) {
1989 int flags_mask = -1;
1990 if (vert_causal_ctx_csty_symbol && y == y0 + 3)
2019 "Segmentation symbol value incorrect\n");
2025 int width,
int height,
int bandpos, uint8_t roi_shift,
const int M_b)
2027 int passno = cblk->
npasses, pass_t = 2, bpno = cblk->
nonzerobits - 1 + 31 - M_b - 1 - roi_shift;
2049 if (bpno < -1 || bpno > 29) {
2056 vert_causal_ctx_csty_symbol);
2065 vert_causal_ctx_csty_symbol);
2103 for (
int y = 0; y <
height; y++) {
2104 for (
int x = 0; x <
width; x++) {
2106 const uint32_t
mask = (
int64_t)UINT32_MAX >> (M_b + 1);
2108 n = x + (y * t1->
stride);
2110 sign =
val & INT32_MIN;
2113 if (roi_shift && (((uint32_t)
val & ~
mask) == 0))
2134 const int downshift = 31 - M_b;
2136 fscale /= (
float)(1LL << downshift);
2137 for (j = 0; j < (cblk->
coord[1][1] - cblk->
coord[1][0]); ++j) {
2138 float *datap = &
comp->f_data[(
comp->coord[0][1] -
comp->coord[0][0]) * (y + j) + x];
2140 for (
i = 0;
i <
w; ++
i) {
2143 val = -(
val & INT32_MAX);
2155 const int downshift =
FFMIN(31 - M_b, 31);
2157 for (j = 0; j < (cblk->
coord[1][1] - cblk->
coord[1][0]); ++j) {
2161 for (
i = 0;
i <
w; ++
i) {
2164 val = -((
val & INT32_MAX) >> downshift);
2171 for (
i = 0;
i <
w; ++
i) {
2174 val = -((
val & INT32_MAX) >> downshift);
2190 const int downshift = 31 - M_b;
2191 const int PRESCALE = 6;
2194 fscale /= (
float)(1LL << downshift);
2195 fscale *= (
float)(1 << PRESCALE);
2197 scale = (int)(fscale + 0.5);
2199 for (j = 0; j < (cblk->
coord[1][1] - cblk->
coord[1][0]); ++j) {
2202 for (
i = 0;
i <
w; ++
i) {
2205 val = -(
val & INT32_MAX);
2207 val = (
val + (1LL << (PRESCALE - 1))) >> PRESCALE;
2218 for (
i = 1;
i < 3;
i++) {
2219 if (
tile->codsty[0].transform !=
tile->codsty[
i].transform) {
2223 if (memcmp(
tile->comp[0].coord,
tile->comp[
i].coord,
sizeof(
tile->comp[0].coord))) {
2229 for (
i = 0;
i < 3;
i++)
2235 for (
i = 0;
i < 2;
i++)
2236 csize *=
tile->comp[0].coord[
i][1] -
tile->comp[0].coord[
i][0];
2238 s->dsp.mct_decode[
tile->codsty[0].transform](
src[0],
src[1],
src[2], csize);
2246 int compno, reslevelno, bandno;
2249 for (compno = 0; compno <
s->ncomponents; compno++) {
2263 for (bandno = 0; bandno < rlevel->
nbands; bandno++, subbandno++) {
2264 int nb_precincts, precno;
2266 int cblkno = 0, bandpos;
2270 bandpos = bandno + (reslevelno > 0);
2272 if (band->
coord[0][0] == band->
coord[0][1] ||
2283 for (precno = 0; precno < nb_precincts; precno++) {
2298 M_b,
comp->roi_shift);
2303 bandpos,
comp->roi_shift, M_b);
2331 #define WRITE_FRAME(D, PIXEL) \
2332 static inline void write_frame_ ## D(const Jpeg2000DecoderContext * s, Jpeg2000Tile * tile, \
2333 AVFrame * picture, int precision) \
2335 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(s->avctx->pix_fmt); \
2336 int planar = !!(pixdesc->flags & AV_PIX_FMT_FLAG_PLANAR); \
2337 int pixelsize = planar ? 1 : pixdesc->nb_components; \
2342 for (compno = 0; compno < s->ncomponents; compno++) { \
2343 Jpeg2000Component *comp = tile->comp + compno; \
2344 Jpeg2000CodingStyle *codsty = tile->codsty + compno; \
2346 float *datap = comp->f_data; \
2347 int32_t *i_datap = comp->i_data; \
2348 int cbps = s->cbps[compno]; \
2349 int w = tile->comp[compno].coord[0][1] - \
2350 ff_jpeg2000_ceildiv(s->image_offset_x, s->cdx[compno]); \
2351 int h = tile->comp[compno].coord[1][1] - \
2352 ff_jpeg2000_ceildiv(s->image_offset_y, s->cdy[compno]); \
2354 ptrdiff_t dstoffset = 0; \
2357 plane = s->cdef[compno] ? s->cdef[compno]-1 : (s->ncomponents-1); \
2359 dstoffset = s->cdef[compno] ? s->cdef[compno] - 1 : compno; \
2361 y = tile->comp[compno].coord[1][0] - \
2362 ff_jpeg2000_ceildiv(s->image_offset_y, s->cdy[compno]); \
2363 line = (PIXEL *)picture->data[plane] + y * (picture->linesize[plane] / sizeof(PIXEL));\
2364 for (; y < h; y++) { \
2367 x = tile->comp[compno].coord[0][0] - \
2368 ff_jpeg2000_ceildiv(s->image_offset_x, s->cdx[compno]); \
2369 dst = line + x * pixelsize + dstoffset; \
2371 if (codsty->transform == FF_DWT97) { \
2372 for (; x < w; x++) { \
2373 int val = lrintf(*datap) + (1 << (cbps - 1)); \
2375 val = av_clip(val, 0, (1 << cbps) - 1); \
2376 *dst = val << (precision - cbps); \
2381 for (; x < w; x++) { \
2382 int val = *i_datap + (1 << (cbps - 1)); \
2384 val = av_clip(val, 0, (1 << cbps) - 1); \
2385 *dst = val << (precision - cbps); \
2390 line += picture->linesize[plane] / sizeof(PIXEL); \
2402 int jobnr,
int threadnr)
2413 if (
tile->codsty[0].mct)
2416 if (
s->precision <= 8) {
2417 write_frame_8(
s,
tile, picture, 8);
2424 write_frame_16(
s,
tile, picture, precision);
2433 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++) {
2434 if (
s->tile[tileno].comp) {
2435 for (compno = 0; compno <
s->ncomponents; compno++) {
2442 av_freep(&
s->tile[tileno].packed_headers);
2443 s->tile[tileno].packed_headers_size = 0;
2447 s->packed_headers_size = 0;
2448 memset(&
s->packed_headers_stream, 0,
sizeof(
s->packed_headers_stream));
2450 memset(
s->codsty, 0,
sizeof(
s->codsty));
2451 memset(
s->qntsty, 0,
sizeof(
s->qntsty));
2452 memset(
s->properties, 0,
sizeof(
s->properties));
2453 memset(&
s->poc , 0,
sizeof(
s->poc));
2454 s->numXtiles =
s->numYtiles = 0;
2463 uint8_t *properties =
s->properties;
2464 uint8_t in_tile_headers = 0;
2476 marker = bytestream2_get_be16u(&
s->g);
2478 if (marker >= 0xFF30 && marker <= 0xFF3F)
2488 if (
s->curtileno < 0) {
2493 tile =
s->tile +
s->curtileno;
2494 tp =
tile->tile_part +
tile->tp_idx;
2495 if (tp->
tp_end <
s->g.buffer) {
2501 uint32_t tp_header_size = bytestream2_get_be32(&
s->packed_headers_stream);
2507 if (
tile->has_ppt &&
tile->tp_idx == 0) {
2519 len = bytestream2_get_be16(&
s->g);
2531 if (
s->ncomponents) {
2537 s->numXtiles =
s->numYtiles = 0;
2540 if (!
s->ncomponents) {
2547 if (in_tile_headers == 1 &&
s->isHT && (!
s->Ccap15_b11)) {
2549 "COC marker found in a tile header but the codestream belongs to the HOMOGENEOUS set\n");
2555 if (in_tile_headers == 1 &&
s->isHT && (!
s->Ccap15_b11)) {
2557 "COD marker found in a tile header but the codestream belongs to the HOMOGENEOUS set\n");
2563 if (in_tile_headers == 1 &&
s->isHT && (!
s->Ccap15_b11)) {
2565 "RGN marker found in a tile header but the codestream belongs to the HOMOGENEOUS set\n");
2569 if ((!
s->Ccap15_b12) &&
s->isHT) {
2570 av_log(
s->avctx,
AV_LOG_ERROR,
"RGN marker found but the codestream belongs to the RGNFREE set\n");
2575 if (in_tile_headers == 1 &&
s->isHT && (!
s->Ccap15_b11)) {
2577 "QCC marker found in a tile header but the codestream belongs to the HOMOGENEOUS set\n");
2583 if (in_tile_headers == 1 &&
s->isHT && (!
s->Ccap15_b11)) {
2585 "QCD marker found in a tile header but the codestream belongs to the HOMOGENEOUS set\n");
2591 if (in_tile_headers == 1 &&
s->isHT && (!
s->Ccap15_b11)) {
2593 "POC marker found in a tile header but the codestream belongs to the HOMOGENEOUS set\n");
2599 if (!in_tile_headers) {
2600 in_tile_headers = 1;
2607 codsty =
s->tile[
s->curtileno].codsty;
2608 qntsty =
s->tile[
s->curtileno].qntsty;
2609 poc = &
s->tile[
s->curtileno].poc;
2610 properties =
s->tile[
s->curtileno].properties;
2632 if (in_tile_headers) {
2642 "Cannot have both PPT and PPM marker.\n");
2645 if ((!
s->Ccap15_b11) &&
s->isHT) {
2646 av_log(
s->avctx,
AV_LOG_ERROR,
"PPT marker found but the codestream belongs to the HOMOGENEOUS set\n");
2657 "unsupported marker 0x%.4"PRIX16
" at pos 0x%X\n",
2664 "error during processing marker segment %.4"PRIx16
"\n",
2678 for (tileno = 0; tileno <
s->numXtiles *
s->numYtiles; tileno++) {
2693 uint32_t atom_size, atom, atom_end;
2694 int search_range = 10;
2699 atom_size = bytestream2_get_be32u(&
s->g);
2700 atom = bytestream2_get_be32u(&
s->g);
2701 if (atom_size == 1) {
2702 if (bytestream2_get_be32u(&
s->g)) {
2706 atom_size = bytestream2_get_be32u(&
s->g);
2724 uint32_t atom2_size, atom2, atom2_end;
2728 atom2_size = bytestream2_get_be32u(&
s->g);
2729 atom2 = bytestream2_get_be32u(&
s->g);
2731 if (atom2_size < 8 || atom2_end > atom_end || atom2_end < atom2_size)
2736 }
else if (atom2 ==
MKBETAG(
'c',
'o',
'l',
'r') && atom2_size >= 7) {
2737 int method = bytestream2_get_byteu(&
s->g);
2740 s->colour_space = bytestream2_get_be32u(&
s->g);
2742 }
else if (atom2 ==
MKBETAG(
'p',
'c',
'l',
'r') && atom2_size >= 6) {
2743 int i,
size, colour_count, colour_channels, colour_depth[3];
2744 colour_count = bytestream2_get_be16u(&
s->g);
2745 colour_channels = bytestream2_get_byteu(&
s->g);
2747 colour_depth[0] = (bytestream2_get_byteu(&
s->g) & 0x7f) + 1;
2748 colour_depth[1] = (bytestream2_get_byteu(&
s->g) & 0x7f) + 1;
2749 colour_depth[2] = (bytestream2_get_byteu(&
s->g) & 0x7f) + 1;
2750 size = (colour_depth[0] + 7 >> 3) * colour_count +
2751 (colour_depth[1] + 7 >> 3) * colour_count +
2752 (colour_depth[2] + 7 >> 3) * colour_count;
2754 colour_channels != 3 ||
2755 colour_depth[0] > 16 ||
2756 colour_depth[1] > 16 ||
2757 colour_depth[2] > 16 ||
2758 atom2_size <
size) {
2764 for (
i = 0;
i < colour_count;
i++) {
2766 if (colour_depth[0] <= 8) {
2767 r = bytestream2_get_byteu(&
s->g) << 8 - colour_depth[0];
2768 r |=
r >> colour_depth[0];
2770 r = bytestream2_get_be16u(&
s->g) >> colour_depth[0] - 8;
2772 if (colour_depth[1] <= 8) {
2773 g = bytestream2_get_byteu(&
s->g) << 8 - colour_depth[1];
2774 g |=
g >> colour_depth[1];
2776 g = bytestream2_get_be16u(&
s->g) >> colour_depth[1] - 8;
2778 if (colour_depth[2] <= 8) {
2779 b = bytestream2_get_byteu(&
s->g) << 8 - colour_depth[2];
2780 b |=
b >> colour_depth[2];
2782 b = bytestream2_get_be16u(&
s->g) >> colour_depth[2] - 8;
2784 s->palette[
i] = 0xff
u << 24 |
r << 16 |
g << 8 |
b;
2786 }
else if (atom2 ==
MKBETAG(
'c',
'd',
'e',
'f') && atom2_size >= 2) {
2787 int n = bytestream2_get_be16u(&
s->g);
2789 int cn = bytestream2_get_be16(&
s->g);
2790 av_unused int typ = bytestream2_get_be16(&
s->g);
2791 int asoc = bytestream2_get_be16(&
s->g);
2792 if (cn < 4 && asoc < 4)
2795 }
else if (atom2 ==
MKBETAG(
'r',
'e',
's',
' ') && atom2_size >= 18) {
2796 int64_t vnum, vden, hnum, hden, vexp, hexp;
2799 resx = bytestream2_get_be32u(&
s->g);
2800 if (resx !=
MKBETAG(
'r',
'e',
's',
'c') && resx !=
MKBETAG(
'r',
'e',
's',
'd')) {
2804 vnum = bytestream2_get_be16u(&
s->g);
2805 vden = bytestream2_get_be16u(&
s->g);
2806 hnum = bytestream2_get_be16u(&
s->g);
2807 hden = bytestream2_get_be16u(&
s->g);
2808 vexp = bytestream2_get_byteu(&
s->g);
2809 hexp = bytestream2_get_byteu(&
s->g);
2810 if (!vnum || !vden || !hnum || !hden) {
2822 if ( INT64_MAX / (hnum * vden) > pow(10, hexp)
2823 && INT64_MAX / (vnum * hden) > pow(10, vexp))
2825 hnum * vden * pow(10, hexp),
2826 vnum * hden * pow(10, vexp),
2830 }
while (atom_end - atom2_end >= 8);
2847 s->reduction_factor = avctx->
lowres;
2867 memset(
s->cdef, -1,
sizeof(
s->cdef));
2876 (bytestream2_get_be32u(&
s->g) == 12) &&
2881 "Could not find Jpeg2000 codestream atom.\n");
2900 if (
s->sar.num &&
s->sar.den)
2902 s->sar.num =
s->sar.den = 0;
2916 for (
int x = 0; x <
s->ncomponents &&
s->codsty[x].transform ==
FF_DWT53;)
2917 if (++x ==
s->ncomponents)
2927 memcpy(picture->
data[1],
s->palette, 256 *
sizeof(uint32_t));
2936 #define OFFSET(x) offsetof(Jpeg2000DecoderContext, x)
2937 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
2940 {
"lowres",
"Lower the decoding resolution by a power of two",
2953 .
p.
name =
"jpeg2000",