2 * JPEG 2000 image decoder
3 * Copyright (c) 2007 Kamil Nowosad
4 * Copyright (c) 2013 Nicolas Bertrand <nicoinattendu@gmail.com>
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 * JPEG 2000 image decoder
28 #include "libavutil/avassert.h"
29 #include "libavutil/common.h"
30 #include "libavutil/opt.h"
32 #include "bytestream.h"
37 #define JP2_SIG_TYPE 0x6A502020
38 #define JP2_SIG_VALUE 0x0D0A870A
39 #define JP2_CODESTREAM 0x6A703263
44 typedef struct Jpeg2000TilePart {
45 uint8_t tile_index; // Tile index who refers the tile-part
46 const uint8_t *tp_end;
47 GetByteContext tpg; // bit stream in tile-part
50 /* RMK: For JPEG2000 DCINEMA 3 tile-parts in a tile
51 * one per component, so tile_part elements have a size of 3 */
52 typedef struct Jpeg2000Tile {
53 Jpeg2000Component *comp;
54 uint8_t properties[4];
55 Jpeg2000CodingStyle codsty[4];
56 Jpeg2000QuantStyle qntsty[4];
57 Jpeg2000TilePart tile_part[4];
58 uint16_t tp_idx; // Tile-part index
61 typedef struct Jpeg2000DecoderContext {
63 AVCodecContext *avctx;
67 int image_offset_x, image_offset_y;
68 int tile_offset_x, tile_offset_y;
69 uint8_t cbps[4]; // bits per sample in particular components
70 uint8_t sgnd[4]; // if a component is signed
71 uint8_t properties[4];
75 int tile_width, tile_height;
76 int numXtiles, numYtiles;
79 Jpeg2000CodingStyle codsty[4];
80 Jpeg2000QuantStyle qntsty[4];
88 /*options parameters*/
91 } Jpeg2000DecoderContext;
93 /* get_bits functions for JPEG2000 packet bitstream
94 * It is a get_bit function with a bit-stuffing routine. If the value of the
95 * byte is 0xFF, the next byte includes an extra zero bit stuffed into the MSB.
96 * cf. ISO-15444-1:2002 / B.10.1 Bit-stuffing routine */
97 static int get_bits(Jpeg2000DecoderContext *s, int n)
103 if (s->bit_index == 0) {
104 s->bit_index = 7 + (bytestream2_get_byte(&s->g) != 0xFFu);
107 res |= (bytestream2_peek_byte(&s->g) >> s->bit_index) & 1;
112 static void jpeg2000_flush(Jpeg2000DecoderContext *s)
114 if (bytestream2_get_byte(&s->g) == 0xff)
115 bytestream2_skip(&s->g, 1);
119 /* decode the value stored in node */
120 static int tag_tree_decode(Jpeg2000DecoderContext *s, Jpeg2000TgtNode *node,
123 Jpeg2000TgtNode *stack[30];
124 int sp = -1, curval = 0;
127 return AVERROR(EINVAL);
129 while (node && !node->vis) {
137 curval = stack[sp]->val;
139 while (curval < threshold && sp >= 0) {
140 if (curval < stack[sp]->val)
141 curval = stack[sp]->val;
142 while (curval < threshold) {
144 if ((ret = get_bits(s, 1)) > 0) {
152 stack[sp]->val = curval;
158 /* marker segments */
159 /* get sizes and offsets of image, tiles; number of components */
160 static int get_siz(Jpeg2000DecoderContext *s)
164 if (bytestream2_get_bytes_left(&s->g) < 36)
165 return AVERROR(EINVAL);
167 s->avctx->profile = bytestream2_get_be16u(&s->g); // Rsiz
168 s->width = bytestream2_get_be32u(&s->g); // Width
169 s->height = bytestream2_get_be32u(&s->g); // Height
170 s->image_offset_x = bytestream2_get_be32u(&s->g); // X0Siz
171 s->image_offset_y = bytestream2_get_be32u(&s->g); // Y0Siz
172 s->tile_width = bytestream2_get_be32u(&s->g); // XTSiz
173 s->tile_height = bytestream2_get_be32u(&s->g); // YTSiz
174 s->tile_offset_x = bytestream2_get_be32u(&s->g); // XT0Siz
175 s->tile_offset_y = bytestream2_get_be32u(&s->g); // YT0Siz
176 s->ncomponents = bytestream2_get_be16u(&s->g); // CSiz
178 if (s->ncomponents <= 0 || s->ncomponents > 4) {
179 av_log(s->avctx, AV_LOG_ERROR, "unsupported/invalid ncomponents: %d\n", s->ncomponents);
180 return AVERROR(EINVAL);
182 if (s->tile_width<=0 || s->tile_height<=0)
183 return AVERROR(EINVAL);
185 if (bytestream2_get_bytes_left(&s->g) < 3 * s->ncomponents)
186 return AVERROR(EINVAL);
188 for (i = 0; i < s->ncomponents; i++) { // Ssiz_i XRsiz_i, YRsiz_i
189 uint8_t x = bytestream2_get_byteu(&s->g);
190 s->cbps[i] = (x & 0x7f) + 1;
191 s->precision = FFMAX(s->cbps[i], s->precision);
192 s->sgnd[i] = !!(x & 0x80);
193 s->cdx[i] = bytestream2_get_byteu(&s->g);
194 s->cdy[i] = bytestream2_get_byteu(&s->g);
195 if (s->cdx[i] != 1 || s->cdy[i] != 1) {
196 av_log(s->avctx, AV_LOG_ERROR, "unsupported/ CDxy values %d %d for component %d\n", s->cdx[i], s->cdy[i], i);
197 if (!s->cdx[i] || !s->cdy[i])
198 return AVERROR_INVALIDDATA;
202 s->numXtiles = ff_jpeg2000_ceildiv(s->width - s->tile_offset_x, s->tile_width);
203 s->numYtiles = ff_jpeg2000_ceildiv(s->height - s->tile_offset_y, s->tile_height);
205 if (s->numXtiles * (uint64_t)s->numYtiles > INT_MAX/sizeof(Jpeg2000Tile))
206 return AVERROR(EINVAL);
208 s->tile = av_mallocz(s->numXtiles * s->numYtiles * sizeof(*s->tile));
210 return AVERROR(ENOMEM);
212 for (i = 0; i < s->numXtiles * s->numYtiles; i++) {
213 Jpeg2000Tile *tile = s->tile + i;
215 tile->comp = av_mallocz(s->ncomponents * sizeof(*tile->comp));
217 return AVERROR(ENOMEM);
220 /* compute image size with reduction factor */
221 s->avctx->width = ff_jpeg2000_ceildivpow2(s->width - s->image_offset_x,
222 s->reduction_factor);
223 s->avctx->height = ff_jpeg2000_ceildivpow2(s->height - s->image_offset_y,
224 s->reduction_factor);
226 switch(s->ncomponents) {
228 if (s->precision > 8)
229 s->avctx->pix_fmt = AV_PIX_FMT_GRAY16;
231 s->avctx->pix_fmt = AV_PIX_FMT_GRAY8;
234 switch (s->avctx->profile) {
235 case FF_PROFILE_JPEG2000_DCINEMA_2K:
236 case FF_PROFILE_JPEG2000_DCINEMA_4K:
237 /* XYZ color-space for digital cinema profiles */
238 s->avctx->pix_fmt = AV_PIX_FMT_XYZ12;
241 if (s->precision > 8)
242 s->avctx->pix_fmt = AV_PIX_FMT_RGB48;
244 s->avctx->pix_fmt = AV_PIX_FMT_RGB24;
249 s->avctx->pix_fmt = AV_PIX_FMT_RGBA;
252 /* pixel format can not be identified */
253 s->avctx->pix_fmt = AV_PIX_FMT_NONE;
259 /* get common part for COD and COC segments */
260 static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
264 if (bytestream2_get_bytes_left(&s->g) < 5)
265 return AVERROR(EINVAL);
266 c->nreslevels = bytestream2_get_byteu(&s->g) + 1; // num of resolution levels - 1
267 if (c->nreslevels >= JPEG2000_MAX_RESLEVELS) {
268 av_log(s->avctx, AV_LOG_ERROR, "nreslevels %d is invalid\n", c->nreslevels);
269 return AVERROR_INVALIDDATA;
272 /* compute number of resolution levels to decode */
273 if (c->nreslevels < s->reduction_factor)
274 c->nreslevels2decode = 1;
276 c->nreslevels2decode = c->nreslevels - s->reduction_factor;
278 c->log2_cblk_width = (bytestream2_get_byteu(&s->g) & 15) + 2; // cblk width
279 c->log2_cblk_height = (bytestream2_get_byteu(&s->g) & 15) + 2; // cblk height
281 if (c->log2_cblk_width > 10 || c->log2_cblk_height > 10 ||
282 c->log2_cblk_width + c->log2_cblk_height > 14) {
283 av_log(s->avctx, AV_LOG_ERROR, "cblk size invalid\n");
284 return AVERROR_INVALIDDATA;
287 c->cblk_style = bytestream2_get_byteu(&s->g);
288 if (c->cblk_style != 0) { // cblk style
289 av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style);
291 c->transform = bytestream2_get_byteu(&s->g); // DWT transformation type
292 /* set integer 9/7 DWT in case of BITEXACT flag */
293 if ((s->avctx->flags & CODEC_FLAG_BITEXACT) && (c->transform == FF_DWT97))
294 c->transform = FF_DWT97_INT;
296 if (c->csty & JPEG2000_CSTY_PREC) {
298 for (i = 0; i < c->nreslevels; i++) {
299 byte = bytestream2_get_byte(&s->g);
300 c->log2_prec_widths[i] = byte & 0x0F; // precinct PPx
301 c->log2_prec_heights[i] = (byte >> 4) & 0x0F; // precinct PPy
304 memset(c->log2_prec_widths , 15, sizeof(c->log2_prec_widths ));
305 memset(c->log2_prec_heights, 15, sizeof(c->log2_prec_heights));
310 /* get coding parameters for a particular tile or whole image*/
311 static int get_cod(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c,
314 Jpeg2000CodingStyle tmp;
317 if (bytestream2_get_bytes_left(&s->g) < 5)
318 return AVERROR(EINVAL);
320 tmp.csty = bytestream2_get_byteu(&s->g);
322 // get progression order
323 tmp.prog_order = bytestream2_get_byteu(&s->g);
325 tmp.nlayers = bytestream2_get_be16u(&s->g);
326 tmp.mct = bytestream2_get_byteu(&s->g); // multiple component transformation
328 if ((ret = get_cox(s, &tmp)) < 0)
331 for (compno = 0; compno < s->ncomponents; compno++)
332 if (!(properties[compno] & HAD_COC))
333 memcpy(c + compno, &tmp, sizeof(tmp));
337 /* Get coding parameters for a component in the whole image or a
338 * particular tile. */
339 static int get_coc(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c,
344 if (bytestream2_get_bytes_left(&s->g) < 2)
345 return AVERROR(EINVAL);
347 compno = bytestream2_get_byteu(&s->g);
350 c->csty = bytestream2_get_byteu(&s->g);
352 if ((ret = get_cox(s, c)) < 0)
355 properties[compno] |= HAD_COC;
359 /* Get common part for QCD and QCC segments. */
360 static int get_qcx(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q)
364 if (bytestream2_get_bytes_left(&s->g) < 1)
365 return AVERROR(EINVAL);
367 x = bytestream2_get_byteu(&s->g); // Sqcd
369 q->nguardbits = x >> 5;
370 q->quantsty = x & 0x1f;
372 if (q->quantsty == JPEG2000_QSTY_NONE) {
374 if (bytestream2_get_bytes_left(&s->g) < n || 32*3 < n)
375 return AVERROR(EINVAL);
376 for (i = 0; i < n; i++)
377 q->expn[i] = bytestream2_get_byteu(&s->g) >> 3;
378 } else if (q->quantsty == JPEG2000_QSTY_SI) {
379 if (bytestream2_get_bytes_left(&s->g) < 2)
380 return AVERROR(EINVAL);
381 x = bytestream2_get_be16u(&s->g);
382 q->expn[0] = x >> 11;
383 q->mant[0] = x & 0x7ff;
384 for (i = 1; i < 32 * 3; i++) {
385 int curexpn = FFMAX(0, q->expn[0] - (i - 1) / 3);
386 q->expn[i] = curexpn;
387 q->mant[i] = q->mant[0];
391 if (bytestream2_get_bytes_left(&s->g) < 2 * n || 32*3 < n)
392 return AVERROR(EINVAL);
393 for (i = 0; i < n; i++) {
394 x = bytestream2_get_be16u(&s->g);
395 q->expn[i] = x >> 11;
396 q->mant[i] = x & 0x7ff;
402 /* Get quantization parameters for a particular tile or a whole image. */
403 static int get_qcd(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q,
406 Jpeg2000QuantStyle tmp;
409 if (get_qcx(s, n, &tmp))
411 for (compno = 0; compno < s->ncomponents; compno++)
412 if (!(properties[compno] & HAD_QCC))
413 memcpy(q + compno, &tmp, sizeof(tmp));
417 /* Get quantization parameters for a component in the whole image
418 * on in a particular tile. */
419 static int get_qcc(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q,
424 if (bytestream2_get_bytes_left(&s->g) < 1)
425 return AVERROR(EINVAL);
427 compno = bytestream2_get_byteu(&s->g);
428 if (compno >= s->ncomponents) {
429 av_log(s->avctx, AV_LOG_ERROR, "Invalid compno\n");
430 return AVERROR_INVALIDDATA;
433 properties[compno] |= HAD_QCC;
434 return get_qcx(s, n - 1, q + compno);
437 /* Get start of tile segment. */
438 static int get_sot(Jpeg2000DecoderContext *s, int n)
440 Jpeg2000TilePart *tp;
445 if (bytestream2_get_bytes_left(&s->g) < 8)
446 return AVERROR(EINVAL);
448 s->curtileno = Isot = bytestream2_get_be16u(&s->g); // Isot
449 if ((unsigned)s->curtileno >= s->numXtiles * s->numYtiles) {
451 return AVERROR(EINVAL);
453 Psot = bytestream2_get_be32u(&s->g); // Psot
454 TPsot = bytestream2_get_byteu(&s->g); // TPsot
456 /* Read TNSot but not used */
457 bytestream2_get_byteu(&s->g); // TNsot
459 if (TPsot >= FF_ARRAY_ELEMS(s->tile[s->curtileno].tile_part)) {
460 av_log(s->avctx, AV_LOG_ERROR, "TPsot %d too big\n", TPsot);
461 return AVERROR_PATCHWELCOME;
464 s->tile[s->curtileno].tp_idx = TPsot;
465 tp = s->tile[s->curtileno].tile_part + TPsot;
466 tp->tile_index = Isot;
467 tp->tp_end = s->g.buffer + Psot - n - 2;
470 Jpeg2000Tile *tile = s->tile + s->curtileno;
473 memcpy(tile->codsty, s->codsty, s->ncomponents * sizeof(Jpeg2000CodingStyle));
474 memcpy(tile->qntsty, s->qntsty, s->ncomponents * sizeof(Jpeg2000QuantStyle));
480 /* Tile-part lengths: see ISO 15444-1:2002, section A.7.1
481 * Used to know the number of tile parts and lengths.
482 * There may be multiple TLMs in the header.
483 * TODO: The function is not used for tile-parts management, nor anywhere else.
484 * It can be useful to allocate memory for tile parts, before managing the SOT
485 * markers. Parsing the TLM header is needed to increment the input header
487 * This marker is mandatory for DCI. */
488 static uint8_t get_tlm(Jpeg2000DecoderContext *s, int n)
490 uint8_t Stlm, ST, SP, tile_tlm, i;
491 bytestream2_get_byte(&s->g); /* Ztlm: skipped */
492 Stlm = bytestream2_get_byte(&s->g);
494 // too complex ? ST = ((Stlm >> 4) & 0x01) + ((Stlm >> 4) & 0x02);
495 ST = (Stlm >> 4) & 0x03;
496 // TODO: Manage case of ST = 0b11 --> raise error
497 SP = (Stlm >> 6) & 0x01;
498 tile_tlm = (n - 4) / ((SP + 1) * 2 + ST);
499 for (i = 0; i < tile_tlm; i++) {
504 bytestream2_get_byte(&s->g);
507 bytestream2_get_be16(&s->g);
510 bytestream2_get_be32(&s->g);
514 bytestream2_get_be16(&s->g);
516 bytestream2_get_be32(&s->g);
522 static int init_tile(Jpeg2000DecoderContext *s, int tileno)
525 int tilex = tileno % s->numXtiles;
526 int tiley = tileno / s->numXtiles;
527 Jpeg2000Tile *tile = s->tile + tileno;
530 return AVERROR(ENOMEM);
532 for (compno = 0; compno < s->ncomponents; compno++) {
533 Jpeg2000Component *comp = tile->comp + compno;
534 Jpeg2000CodingStyle *codsty = tile->codsty + compno;
535 Jpeg2000QuantStyle *qntsty = tile->qntsty + compno;
536 int ret; // global bandno
538 comp->coord_o[0][0] = FFMAX(tilex * s->tile_width + s->tile_offset_x, s->image_offset_x);
539 comp->coord_o[0][1] = FFMIN((tilex + 1) * s->tile_width + s->tile_offset_x, s->width);
540 comp->coord_o[1][0] = FFMAX(tiley * s->tile_height + s->tile_offset_y, s->image_offset_y);
541 comp->coord_o[1][1] = FFMIN((tiley + 1) * s->tile_height + s->tile_offset_y, s->height);
543 comp->coord[0][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][0], s->reduction_factor);
544 comp->coord[0][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[0][1], s->reduction_factor);
545 comp->coord[1][0] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][0], s->reduction_factor);
546 comp->coord[1][1] = ff_jpeg2000_ceildivpow2(comp->coord_o[1][1], s->reduction_factor);
548 if (ret = ff_jpeg2000_init_component(comp, codsty, qntsty,
549 s->cbps[compno], s->cdx[compno],
550 s->cdy[compno], s->avctx))
556 /* Read the number of coding passes. */
557 static int getnpasses(Jpeg2000DecoderContext *s)
564 if ((num = get_bits(s, 2)) != 3)
565 return num < 0 ? num : 3 + num;
566 if ((num = get_bits(s, 5)) != 31)
567 return num < 0 ? num : 6 + num;
568 num = get_bits(s, 7);
569 return num < 0 ? num : 37 + num;
572 static int getlblockinc(Jpeg2000DecoderContext *s)
575 while (ret = get_bits(s, 1)) {
583 static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s,
584 Jpeg2000CodingStyle *codsty,
585 Jpeg2000ResLevel *rlevel, int precno,
586 int layno, uint8_t *expn, int numgbits)
588 int bandno, cblkno, ret, nb_code_blocks;
590 if (!(ret = get_bits(s, 1))) {
596 for (bandno = 0; bandno < rlevel->nbands; bandno++) {
597 Jpeg2000Band *band = rlevel->band + bandno;
598 Jpeg2000Prec *prec = band->prec + precno;
600 if (band->coord[0][0] == band->coord[0][1] ||
601 band->coord[1][0] == band->coord[1][1])
604 nb_code_blocks = prec->nb_codeblocks_height *
605 prec->nb_codeblocks_width;
606 for (cblkno = 0; cblkno < nb_code_blocks; cblkno++) {
607 Jpeg2000Cblk *cblk = prec->cblk + cblkno;
608 int incl, newpasses, llen;
611 incl = get_bits(s, 1);
613 incl = tag_tree_decode(s, prec->cblkincl + cblkno, layno + 1) == layno;
620 cblk->nonzerobits = expn[bandno] + numgbits - 1 -
621 tag_tree_decode(s, prec->zerobits + cblkno,
623 if ((newpasses = getnpasses(s)) < 0)
625 if ((llen = getlblockinc(s)) < 0)
627 cblk->lblock += llen;
628 if ((ret = get_bits(s, av_log2(newpasses) + cblk->lblock)) < 0)
630 cblk->lengthinc = ret;
631 cblk->npasses += newpasses;
636 if (codsty->csty & JPEG2000_CSTY_EPH) {
637 if (bytestream2_peek_be16(&s->g) == JPEG2000_EPH)
638 bytestream2_skip(&s->g, 2);
640 av_log(s->avctx, AV_LOG_ERROR, "EPH marker not found.\n");
643 for (bandno = 0; bandno < rlevel->nbands; bandno++) {
644 Jpeg2000Band *band = rlevel->band + bandno;
645 Jpeg2000Prec *prec = band->prec + precno;
647 nb_code_blocks = prec->nb_codeblocks_height * prec->nb_codeblocks_width;
648 for (cblkno = 0; cblkno < nb_code_blocks; cblkno++) {
649 Jpeg2000Cblk *cblk = prec->cblk + cblkno;
650 if ( bytestream2_get_bytes_left(&s->g) < cblk->lengthinc
651 || sizeof(cblk->data) < cblk->lengthinc
653 return AVERROR(EINVAL);
654 /* Code-block data can be empty. In that case initialize data
656 if (cblk->lengthinc > 0) {
657 bytestream2_get_bufferu(&s->g, cblk->data, cblk->lengthinc);
659 cblk->data[0] = 0xFF;
660 cblk->data[1] = 0xFF;
662 cblk->length += cblk->lengthinc;
669 static int jpeg2000_decode_packets(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
671 int layno, reslevelno, compno, precno, ok_reslevel;
675 switch (tile->codsty[0].prog_order) {
676 case JPEG2000_PGOD_LRCP:
677 case JPEG2000_PGOD_RLCP:
678 for (layno = 0; layno < tile->codsty[0].nlayers; layno++) {
680 for (reslevelno = 0; ok_reslevel; reslevelno++) {
682 for (compno = 0; compno < s->ncomponents; compno++) {
683 Jpeg2000CodingStyle *codsty = tile->codsty + compno;
684 Jpeg2000QuantStyle *qntsty = tile->qntsty + compno;
685 if (reslevelno < codsty->nreslevels) {
686 Jpeg2000ResLevel *rlevel = tile->comp[compno].reslevel +
689 for (precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++)
690 if (jpeg2000_decode_packet(s,
693 qntsty->expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
702 case JPEG2000_PGOD_CPRL:
703 for (compno = 0; compno < s->ncomponents; compno++) {
704 Jpeg2000CodingStyle *codsty = tile->codsty + compno;
705 Jpeg2000QuantStyle *qntsty = tile->qntsty + compno;
707 /* Set bit stream buffer address according to tile-part.
708 * For DCinema one tile-part per component, so can be
709 * indexed by component. */
710 s->g = tile->tile_part[compno].tpg;
712 /* Position loop (y axis)
713 * TODO: Automate computing of step 256.
714 * Fixed here, but to be computed before entering here. */
715 for (y = 0; y < s->height; y += 256) {
716 /* Position loop (y axis)
717 * TODO: automate computing of step 256.
718 * Fixed here, but to be computed before entering here. */
719 for (x = 0; x < s->width; x += 256) {
720 for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
722 uint8_t reducedresno = codsty->nreslevels - 1 -reslevelno; // ==> N_L - r
723 Jpeg2000ResLevel *rlevel = tile->comp[compno].reslevel + reslevelno;
725 if (!((y % (1 << (rlevel->log2_prec_height + reducedresno)) == 0) ||
726 (y == 0))) // TODO: 2nd condition simplified as try0 always =0 for dcinema
729 if (!((x % (1 << (rlevel->log2_prec_width + reducedresno)) == 0) ||
730 (x == 0))) // TODO: 2nd condition simplified as try0 always =0 for dcinema
733 // check if a precinct exists
734 prcx = ff_jpeg2000_ceildivpow2(x, reducedresno) >> rlevel->log2_prec_width;
735 prcy = ff_jpeg2000_ceildivpow2(y, reducedresno) >> rlevel->log2_prec_height;
736 precno = prcx + rlevel->num_precincts_x * prcy;
737 for (layno = 0; layno < tile->codsty[0].nlayers; layno++) {
738 if (jpeg2000_decode_packet(s, codsty, rlevel,
740 qntsty->expn + (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
754 /* EOC marker reached */
755 bytestream2_skip(&s->g, 2);
760 /* TIER-1 routines */
761 static void decode_sigpass(Jpeg2000T1Context *t1, int width, int height,
762 int bpno, int bandno, int bpass_csty_symbol,
763 int vert_causal_ctx_csty_symbol)
765 int mask = 3 << (bpno - 1), y0, x, y;
767 for (y0 = 0; y0 < height; y0 += 4)
768 for (x = 0; x < width; x++)
769 for (y = y0; y < height && y < y0 + 4; y++) {
770 if ((t1->flags[y+1][x+1] & JPEG2000_T1_SIG_NB)
771 && !(t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))) {
773 if (vert_causal_ctx_csty_symbol && y == y0 + 3)
774 flags_mask &= ~(JPEG2000_T1_SIG_S | JPEG2000_T1_SIG_SW | JPEG2000_T1_SIG_SE);
775 if (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_jpeg2000_getsigctxno(t1->flags[y+1][x+1] & flags_mask, bandno))) {
776 int xorbit, ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y+1][x+1], &xorbit);
777 if (bpass_csty_symbol)
778 t1->data[y][x] = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ? -mask : mask;
780 t1->data[y][x] = (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ^ xorbit) ?
783 ff_jpeg2000_set_significance(t1, x, y,
786 t1->flags[y + 1][x + 1] |= JPEG2000_T1_VIS;
791 static void decode_refpass(Jpeg2000T1Context *t1, int width, int height,
797 phalf = 1 << (bpno - 1);
800 for (y0 = 0; y0 < height; y0 += 4)
801 for (x = 0; x < width; x++)
802 for (y = y0; y < height && y < y0 + 4; y++)
803 if ((t1->flags[y + 1][x + 1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS)) == JPEG2000_T1_SIG) {
804 int ctxno = ff_jpeg2000_getrefctxno(t1->flags[y + 1][x + 1]);
805 int r = ff_mqc_decode(&t1->mqc,
806 t1->mqc.cx_states + ctxno)
808 t1->data[y][x] += t1->data[y][x] < 0 ? -r : r;
809 t1->flags[y + 1][x + 1] |= JPEG2000_T1_REF;
813 static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1,
814 int width, int height, int bpno, int bandno,
815 int seg_symbols, int vert_causal_ctx_csty_symbol)
817 int mask = 3 << (bpno - 1), y0, x, y, runlen, dec;
819 for (y0 = 0; y0 < height; y0 += 4) {
820 for (x = 0; x < width; x++) {
821 if (y0 + 3 < height &&
822 !((t1->flags[y0 + 1][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
823 (t1->flags[y0 + 2][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
824 (t1->flags[y0 + 3][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
825 (t1->flags[y0 + 4][x + 1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)))) {
826 if (!ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_RL))
828 runlen = ff_mqc_decode(&t1->mqc,
829 t1->mqc.cx_states + MQC_CX_UNI);
830 runlen = (runlen << 1) | ff_mqc_decode(&t1->mqc,
839 for (y = y0 + runlen; y < y0 + 4 && y < height; y++) {
841 if (!(t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))) {
843 if (vert_causal_ctx_csty_symbol && y == y0 + 3)
844 flags_mask &= ~(JPEG2000_T1_SIG_S | JPEG2000_T1_SIG_SW | JPEG2000_T1_SIG_SE);
845 dec = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_jpeg2000_getsigctxno(t1->flags[y+1][x+1] & flags_mask,
851 int ctxno = ff_jpeg2000_getsgnctxno(t1->flags[y + 1][x + 1],
853 t1->data[y][x] = (ff_mqc_decode(&t1->mqc,
854 t1->mqc.cx_states + ctxno) ^
857 ff_jpeg2000_set_significance(t1, x, y, t1->data[y][x] < 0);
860 t1->flags[y + 1][x + 1] &= ~JPEG2000_T1_VIS;
866 val = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
867 val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
868 val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
869 val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
871 av_log(s->avctx, AV_LOG_ERROR,
872 "Segmentation symbol value incorrect\n");
876 static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,
877 Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk,
878 int width, int height, int bandpos)
880 int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y, clnpass_cnt = 0;
881 int bpass_csty_symbol = JPEG2000_CBLK_BYPASS & codsty->cblk_style;
882 int vert_causal_ctx_csty_symbol = JPEG2000_CBLK_VSC & codsty->cblk_style;
884 for (y = 0; y < height; y++)
885 memset(t1->data[y], 0, width * sizeof(**t1->data));
887 /* If code-block contains no compressed data: nothing to do. */
891 for (y = 0; y < height+2; y++)
892 memset(t1->flags[y], 0, (width + 2)*sizeof(**t1->flags));
894 cblk->data[cblk->length] = 0xff;
895 cblk->data[cblk->length+1] = 0xff;
896 ff_mqc_initdec(&t1->mqc, cblk->data);
901 decode_sigpass(t1, width, height, bpno + 1, bandpos,
902 bpass_csty_symbol && (clnpass_cnt >= 4), vert_causal_ctx_csty_symbol);
905 decode_refpass(t1, width, height, bpno + 1);
906 if (bpass_csty_symbol && clnpass_cnt >= 4)
907 ff_mqc_initdec(&t1->mqc, cblk->data);
910 decode_clnpass(s, t1, width, height, bpno + 1, bandpos,
911 codsty->cblk_style & JPEG2000_CBLK_SEGSYM, vert_causal_ctx_csty_symbol);
912 clnpass_cnt = clnpass_cnt + 1;
913 if (bpass_csty_symbol && clnpass_cnt >= 4)
914 ff_mqc_initdec(&t1->mqc, cblk->data);
927 /* TODO: Verify dequantization for lossless case
928 * comp->data can be float or int
929 * band->stepsize can be float or int
930 * depending on the type of DWT transformation.
931 * see ISO/IEC 15444-1:2002 A.6.1 */
933 /* Float dequantization of a codeblock.*/
934 static void dequantization_float(int x, int y, Jpeg2000Cblk *cblk,
935 Jpeg2000Component *comp,
936 Jpeg2000T1Context *t1, Jpeg2000Band *band)
939 int w = cblk->coord[0][1] - cblk->coord[0][0];
940 for (j = 0; j < (cblk->coord[1][1] - cblk->coord[1][0]); ++j) {
941 float *datap = &comp->f_data[(comp->coord[0][1] - comp->coord[0][0]) * (y + j) + x];
942 int *src = t1->data[j];
943 for (i = 0; i < w; ++i)
944 datap[i] = src[i] * band->f_stepsize;
948 /* Integer dequantization of a codeblock.*/
949 static void dequantization_int(int x, int y, Jpeg2000Cblk *cblk,
950 Jpeg2000Component *comp,
951 Jpeg2000T1Context *t1, Jpeg2000Band *band)
954 int w = cblk->coord[0][1] - cblk->coord[0][0];
955 for (j = 0; j < (cblk->coord[1][1] - cblk->coord[1][0]); ++j) {
956 int32_t *datap = &comp->i_data[(comp->coord[0][1] - comp->coord[0][0]) * (y + j) + x];
957 int *src = t1->data[j];
958 for (i = 0; i < w; ++i)
959 datap[i] = (src[i] * band->i_stepsize + (1 << 15)) >> 16;
963 /* Inverse ICT parameters in float and integer.
964 * int value = (float value) * (1<<16) */
965 static const float f_ict_params[4] = {
971 static const int i_ict_params[4] = {
978 static void mct_decode(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile)
981 int32_t *src[3], i0, i1, i2;
982 float *srcf[3], i0f, i1f, i2f;
984 for (i = 0; i < 3; i++)
985 if (tile->codsty[0].transform == FF_DWT97)
986 srcf[i] = tile->comp[i].f_data;
988 src [i] = tile->comp[i].i_data;
990 for (i = 0; i < 2; i++)
991 csize *= tile->comp[0].coord[i][1] - tile->comp[0].coord[i][0];
993 switch (tile->codsty[0].transform) {
995 for (i = 0; i < csize; i++) {
996 i0f = *srcf[0] + (f_ict_params[0] * *srcf[2]);
997 i1f = *srcf[0] - (f_ict_params[1] * *srcf[1])
998 - (f_ict_params[2] * *srcf[2]);
999 i2f = *srcf[0] + (f_ict_params[3] * *srcf[1]);
1006 for (i = 0; i < csize; i++) {
1007 i0 = *src[0] + (((i_ict_params[0] * *src[2]) + (1 << 15)) >> 16);
1008 i1 = *src[0] - (((i_ict_params[1] * *src[1]) + (1 << 15)) >> 16)
1009 - (((i_ict_params[2] * *src[2]) + (1 << 15)) >> 16);
1010 i2 = *src[0] + (((i_ict_params[3] * *src[1]) + (1 << 15)) >> 16);
1017 for (i = 0; i < csize; i++) {
1018 i1 = *src[0] - (*src[2] + *src[1] >> 2);
1029 static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
1032 int compno, reslevelno, bandno;
1036 Jpeg2000T1Context t1;
1038 /* Loop on tile components */
1039 for (compno = 0; compno < s->ncomponents; compno++) {
1040 Jpeg2000Component *comp = tile->comp + compno;
1041 Jpeg2000CodingStyle *codsty = tile->codsty + compno;
1043 /* Loop on resolution levels */
1044 for (reslevelno = 0; reslevelno < codsty->nreslevels2decode; reslevelno++) {
1045 Jpeg2000ResLevel *rlevel = comp->reslevel + reslevelno;
1047 for (bandno = 0; bandno < rlevel->nbands; bandno++) {
1048 int nb_precincts, precno;
1049 Jpeg2000Band *band = rlevel->band + bandno;
1050 int cblkno = 0, bandpos;
1052 bandpos = bandno + (reslevelno > 0);
1054 if (band->coord[0][0] == band->coord[0][1] || band->coord[1][0] == band->coord[1][1])
1057 nb_precincts = rlevel->num_precincts_x * rlevel->num_precincts_y;
1058 /* Loop on precincts */
1059 for (precno = 0; precno < nb_precincts; precno++) {
1060 Jpeg2000Prec *prec = band->prec + precno;
1062 /* Loop on codeblocks */
1063 for (cblkno = 0; cblkno < prec->nb_codeblocks_width * prec->nb_codeblocks_height; cblkno++) {
1065 Jpeg2000Cblk *cblk = prec->cblk + cblkno;
1066 decode_cblk(s, codsty, &t1, cblk,
1067 cblk->coord[0][1] - cblk->coord[0][0],
1068 cblk->coord[1][1] - cblk->coord[1][0],
1071 /* Manage band offsets */
1072 x = cblk->coord[0][0];
1073 y = cblk->coord[1][0];
1075 if (codsty->transform == FF_DWT97)
1076 dequantization_float(x, y, cblk, comp, &t1, band);
1078 dequantization_int(x, y, cblk, comp, &t1, band);
1082 } /* end reslevel */
1085 ff_dwt_decode(&comp->dwt, codsty->transform == FF_DWT97 ? (void*)comp->f_data : (void*)comp->i_data);
1088 /* inverse MCT transformation */
1089 if (tile->codsty[0].mct)
1090 mct_decode(s, tile);
1092 if (s->precision <= 8) {
1093 for (compno = 0; compno < s->ncomponents; compno++) {
1094 Jpeg2000Component *comp = tile->comp + compno;
1095 float *datap = comp->f_data;
1096 int32_t *i_datap = comp->i_data;
1097 int cbps = s->cbps[compno];
1098 int w = tile->comp[compno].coord[0][1] - s->image_offset_x;
1100 y = tile->comp[compno].coord[1][0] - s->image_offset_y;
1101 line = picture->data[0] + y * picture->linesize[0];
1102 for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y += s->cdy[compno]) {
1105 x = tile->comp[compno].coord[0][0] - s->image_offset_x;
1106 dst = line + x * s->ncomponents + compno;
1108 if (tile->codsty->transform == FF_DWT97) {
1109 for (; x < w; x += s->cdx[compno]) {
1110 int val = lrintf(*datap) + (1 << (cbps - 1));
1111 /* DC level shift and clip see ISO 15444-1:2002 G.1.2 */
1112 val = av_clip(val, 0, (1 << cbps) - 1);
1113 *dst = val << (8 - cbps);
1115 dst += s->ncomponents;
1118 for (; x < w; x += s->cdx[compno]) {
1119 int val = *i_datap + (1 << (cbps - 1));
1120 /* DC level shift and clip see ISO 15444-1:2002 G.1.2 */
1121 val = av_clip(val, 0, (1 << cbps) - 1);
1122 *dst = val << (8 - cbps);
1124 dst += s->ncomponents;
1127 line += picture->linesize[0];
1131 for (compno = 0; compno < s->ncomponents; compno++) {
1132 Jpeg2000Component *comp = tile->comp + compno;
1133 float *datap = comp->f_data;
1134 int32_t *i_datap = comp->i_data;
1136 int cbps = s->cbps[compno];
1137 int w = tile->comp[compno].coord[0][1] - s->image_offset_x;
1139 y = tile->comp[compno].coord[1][0] - s->image_offset_y;
1140 linel = (uint16_t *)picture->data[0] + y * (picture->linesize[0] >> 1);
1141 for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y += s->cdy[compno]) {
1144 x = tile->comp[compno].coord[0][0] - s->image_offset_x;
1145 dst = linel + (x * s->ncomponents + compno);
1146 if (tile->codsty->transform == FF_DWT97) {
1147 for (; x < w; x += s-> cdx[compno]) {
1148 int val = lrintf(*datap) + (1 << (cbps - 1));
1149 /* DC level shift and clip see ISO 15444-1:2002 G.1.2 */
1150 val = av_clip(val, 0, (1 << cbps) - 1);
1151 /* align 12 bit values in little-endian mode */
1152 *dst = val << (16 - cbps);
1154 dst += s->ncomponents;
1157 for (; x < w; x += s-> cdx[compno]) {
1158 int val = *i_datap + (1 << (cbps - 1));
1159 /* DC level shift and clip see ISO 15444-1:2002 G.1.2 */
1160 val = av_clip(val, 0, (1 << cbps) - 1);
1161 /* align 12 bit values in little-endian mode */
1162 *dst = val << (16 - cbps);
1164 dst += s->ncomponents;
1167 linel += picture->linesize[0] >> 1;
1175 static void jpeg2000_dec_cleanup(Jpeg2000DecoderContext *s)
1178 for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++) {
1179 for (compno = 0; compno < s->ncomponents; compno++) {
1180 Jpeg2000Component *comp = s->tile[tileno].comp + compno;
1181 Jpeg2000CodingStyle *codsty = s->tile[tileno].codsty + compno;
1183 ff_jpeg2000_cleanup(comp, codsty);
1185 av_freep(&s->tile[tileno].comp);
1188 s->numXtiles = s->numYtiles = 0;
1191 static int jpeg2000_read_main_headers(Jpeg2000DecoderContext *s)
1193 Jpeg2000CodingStyle *codsty = s->codsty;
1194 Jpeg2000QuantStyle *qntsty = s->qntsty;
1195 uint8_t *properties = s->properties;
1202 if (bytestream2_get_bytes_left(&s->g) < 2) {
1203 av_log(s->avctx, AV_LOG_ERROR, "Missing EOC\n");
1207 marker = bytestream2_get_be16u(&s->g);
1208 oldpos = bytestream2_tell(&s->g);
1210 if (marker == JPEG2000_SOD) {
1211 Jpeg2000Tile *tile = s->tile + s->curtileno;
1212 Jpeg2000TilePart *tp = tile->tile_part + tile->tp_idx;
1214 bytestream2_init(&tp->tpg, s->g.buffer, tp->tp_end - s->g.buffer);
1215 bytestream2_skip(&s->g, tp->tp_end - s->g.buffer);
1219 if (marker == JPEG2000_EOC)
1222 if (bytestream2_get_bytes_left(&s->g) < 2)
1223 return AVERROR(EINVAL);
1224 len = bytestream2_get_be16u(&s->g);
1229 s->numXtiles = s->numYtiles = 0;
1232 ret = get_coc(s, codsty, properties);
1235 ret = get_cod(s, codsty, properties);
1238 ret = get_qcc(s, len, qntsty, properties);
1241 ret = get_qcd(s, len, qntsty, properties);
1244 if (!(ret = get_sot(s, len))) {
1245 av_assert1(s->curtileno >= 0);
1246 codsty = s->tile[s->curtileno].codsty;
1247 qntsty = s->tile[s->curtileno].qntsty;
1248 properties = s->tile[s->curtileno].properties;
1252 // the comment is ignored
1253 bytestream2_skip(&s->g, len - 2);
1256 // Tile-part lengths
1257 ret = get_tlm(s, len);
1260 av_log(s->avctx, AV_LOG_ERROR,
1261 "unsupported marker 0x%.4X at pos 0x%X\n",
1262 marker, bytestream2_tell(&s->g) - 4);
1263 bytestream2_skip(&s->g, len - 2);
1266 if (bytestream2_tell(&s->g) - oldpos != len || ret) {
1267 av_log(s->avctx, AV_LOG_ERROR,
1268 "error during processing marker segment %.4x\n", marker);
1269 return ret ? ret : -1;
1275 /* Read bit stream packets --> T2 operation. */
1276 static int jpeg2000_read_bitstream_packets(Jpeg2000DecoderContext *s)
1281 for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++) {
1282 Jpeg2000Tile *tile = s->tile + tileno;
1284 if (ret = init_tile(s, tileno))
1287 s->g = tile->tile_part[0].tpg;
1288 if (ret = jpeg2000_decode_packets(s, tile))
1295 static int jp2_find_codestream(Jpeg2000DecoderContext *s)
1297 uint32_t atom_size, atom;
1298 int found_codestream = 0, search_range = 10;
1300 while (!found_codestream && search_range && bytestream2_get_bytes_left(&s->g) >= 8) {
1301 atom_size = bytestream2_get_be32u(&s->g);
1302 atom = bytestream2_get_be32u(&s->g);
1303 if (atom == JP2_CODESTREAM) {
1304 found_codestream = 1;
1306 if (bytestream2_get_bytes_left(&s->g) < atom_size - 8)
1308 bytestream2_skipu(&s->g, atom_size - 8);
1313 if (found_codestream)
1318 static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
1319 int *got_frame, AVPacket *avpkt)
1321 Jpeg2000DecoderContext *s = avctx->priv_data;
1322 ThreadFrame frame = { .f = data };
1323 AVFrame *picture = data;
1327 bytestream2_init(&s->g, avpkt->data, avpkt->size);
1330 // reduction factor, i.e number of resolution levels to skip
1331 s->reduction_factor = s->lowres;
1333 if (bytestream2_get_bytes_left(&s->g) < 2) {
1334 ret = AVERROR(EINVAL);
1338 // check if the image is in jp2 format
1339 if (bytestream2_get_bytes_left(&s->g) >= 12 &&
1340 (bytestream2_get_be32u(&s->g) == 12) &&
1341 (bytestream2_get_be32u(&s->g) == JP2_SIG_TYPE) &&
1342 (bytestream2_get_be32u(&s->g) == JP2_SIG_VALUE)) {
1343 if (!jp2_find_codestream(s)) {
1344 av_log(avctx, AV_LOG_ERROR,
1345 "couldn't find jpeg2k codestream atom\n");
1350 bytestream2_seek(&s->g, 0, SEEK_SET);
1353 if (bytestream2_get_be16u(&s->g) != JPEG2000_SOC) {
1354 av_log(avctx, AV_LOG_ERROR, "SOC marker not present\n");
1358 if (ret = jpeg2000_read_main_headers(s))
1361 /* get picture buffer */
1362 if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
1364 picture->pict_type = AV_PICTURE_TYPE_I;
1365 picture->key_frame = 1;
1367 if (ret = jpeg2000_read_bitstream_packets(s))
1370 for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++)
1371 if (ret = jpeg2000_decode_tile(s, s->tile + tileno, picture))
1374 jpeg2000_dec_cleanup(s);
1378 return bytestream2_tell(&s->g);
1380 jpeg2000_dec_cleanup(s);
1384 static void jpeg2000_init_static_data(AVCodec *codec)
1386 ff_jpeg2000_init_tier1_luts();
1389 #define OFFSET(x) offsetof(Jpeg2000DecoderContext, x)
1390 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1392 static const AVOption options[] = {
1393 { "lowres", "Lower the decoding resolution by a power of two",
1394 OFFSET(lowres), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, JPEG2000_MAX_RESLEVELS - 1, VD },
1398 static const AVProfile profiles[] = {
1399 { FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0, "JPEG 2000 codestream restriction 0" },
1400 { FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1, "JPEG 2000 codestream restriction 1" },
1401 { FF_PROFILE_JPEG2000_CSTREAM_NO_RESTRICTION, "JPEG 2000 no codestream restrictions" },
1402 { FF_PROFILE_JPEG2000_DCINEMA_2K, "JPEG 2000 digital cinema 2K" },
1403 { FF_PROFILE_JPEG2000_DCINEMA_4K, "JPEG 2000 digital cinema 4K" },
1404 { FF_PROFILE_UNKNOWN },
1407 static const AVClass class = {
1408 .class_name = "jpeg2000",
1409 .item_name = av_default_item_name,
1411 .version = LIBAVUTIL_VERSION_INT,
1414 AVCodec ff_jpeg2000_decoder = {
1416 .long_name = NULL_IF_CONFIG_SMALL("JPEG 2000"),
1417 .type = AVMEDIA_TYPE_VIDEO,
1418 .id = AV_CODEC_ID_JPEG2000,
1419 .capabilities = CODEC_CAP_FRAME_THREADS,
1420 .priv_data_size = sizeof(Jpeg2000DecoderContext),
1421 .init_static_data = jpeg2000_init_static_data,
1422 .decode = jpeg2000_decode_frame,
1423 .priv_class = &class,
1425 .profiles = NULL_IF_CONFIG_SMALL(profiles)