Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/libavcodec/j2kdec.c b/libavcodec/j2kdec.c
- index 683062d..3e78b0b 100644
- --- a/libavcodec/j2kdec.c
- +++ b/libavcodec/j2kdec.c
- @@ -30,6 +30,7 @@
- #include "avcodec.h"
- #include "bytestream.h"
- #include "internal.h"
- +#include "thread.h"
- #include "j2k.h"
- #include "libavutil/common.h"
- @@ -205,6 +206,7 @@ static int tag_tree_decode(J2kDecoderContext *s, J2kTgtNode *node, int threshold
- static int get_siz(J2kDecoderContext *s)
- {
- int i, ret;
- + ThreadFrame frame = { .f = s->picture };
- if (bytestream2_get_bytes_left(&s->g) < 36)
- return AVERROR(EINVAL);
- @@ -282,7 +284,7 @@ static int get_siz(J2kDecoderContext *s)
- }
- - if ((ret = ff_get_buffer(s->avctx, s->picture, 0)) < 0)
- + if ((ret = ff_thread_get_buffer(s->avctx, &frame, 0)) < 0)
- return ret;
- s->picture->pict_type = AV_PICTURE_TYPE_I;
- @@ -1088,6 +1090,6 @@ AVCodec ff_j2k_decoder = {
- .priv_data_size = sizeof(J2kDecoderContext),
- .init = j2kdec_init,
- .decode = decode_frame,
- - .capabilities = CODEC_CAP_EXPERIMENTAL,
- + .capabilities = CODEC_CAP_EXPERIMENTAL | CODEC_CAP_FRAME_THREADS,
- .long_name = NULL_IF_CONFIG_SMALL("JPEG 2000"),
- };
- diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
- index 20e5c9c..7b902fa 100644
- --- a/libavcodec/jpeg2000dec.c
- +++ b/libavcodec/jpeg2000dec.c
- @@ -86,9 +86,6 @@ typedef struct Jpeg2000DecoderContext {
- int16_t curtileno;
- Jpeg2000Tile *tile;
- - /*options parameters*/
- - int16_t lowres;
- - int16_t reduction_factor;
- } Jpeg2000DecoderContext;
- /* get_bits functions for JPEG2000 packet bitstream
- @@ -205,9 +202,9 @@ static int get_siz(Jpeg2000DecoderContext *s)
- /* compute image size with reduction factor */
- s->avctx->width = ff_jpeg2000_ceildivpow2(s->width - s->image_offset_x,
- - s->reduction_factor);
- + s->avctx->lowres);
- s->avctx->height = ff_jpeg2000_ceildivpow2(s->height - s->image_offset_y,
- - s->reduction_factor);
- + s->avctx->lowres);
- switch (s->avctx->profile) {
- case FF_PROFILE_JPEG2000_DCINEMA_2K:
- @@ -254,10 +251,10 @@ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
- c->nreslevels = bytestream_get_byte(&s->buf) + 1; // num of resolution levels - 1
- /* compute number of resolution levels to decode */
- - if (c->nreslevels < s->reduction_factor)
- + if (c->nreslevels < s->avctx->lowres)
- c->nreslevels2decode = 1;
- else
- - c->nreslevels2decode = c->nreslevels - s->reduction_factor;
- + c->nreslevels2decode = c->nreslevels - s->avctx->lowres;
- c->log2_cblk_width = bytestream_get_byte(&s->buf) + 2; // cblk width
- c->log2_cblk_height = bytestream_get_byte(&s->buf) + 2; // cblk height
- @@ -635,7 +632,14 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s,
- Jpeg2000Cblk *cblk = prec->cblk + cblkno;
- if (s->buf_end - s->buf < cblk->lengthinc)
- return AVERROR(EINVAL);
- - bytestream_get_buffer(&s->buf, cblk->data, cblk->lengthinc);
- + /* A code-block data can be empty. In that case initialize data
- + * with 0xffff. */
- + if (cblk->lengthinc > 0)
- + bytestream_get_buffer(&s->buf, cblk->data, cblk->lengthinc);
- + else {
- + cblk->data[0] = 0xff;
- + cblk->data[1] = 0xff;
- + }
- cblk->length += cblk->lengthinc;
- cblk->lengthinc = 0;
- }
- @@ -853,12 +857,15 @@ static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,
- {
- int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y;
- - for (y = 0; y < height + 2; y++)
- - memset(t1->flags[y], 0, (width + 2) * sizeof(width));
- -
- for (y = 0; y < height; y++)
- memset(t1->data[y], 0, width * sizeof(width));
- + /* If code-block contains no compressed data: nothing to do. */
- + if (cblk->length == 0)
- + return 0;
- + for (y = 0; y < height + 2; y++)
- + memset(t1->flags[y], 0, (width + 2) * sizeof(width));
- +
- ff_mqc_initdec(&t1->mqc, cblk->data);
- cblk->data[cblk->length] = 0xff;
- cblk->data[cblk->length + 1] = 0xff;
- @@ -1252,8 +1259,6 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
- s->buf_end = s->buf_start + avpkt->size;
- s->curtileno = 0; // TODO: only one tile in DCI JP2K. to implement for more tiles
- - // reduction factor, i.e number of resolution levels to skip
- - s->reduction_factor = s->lowres;
- ff_jpeg2000_init_tier1_luts();
- @@ -1301,12 +1306,6 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
- #define OFFSET(x) offsetof(Jpeg2000DecoderContext, x)
- #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
- -static const AVOption options[] = {
- - { "lowres", "Lower the decoding resolution by a power of two",
- - OFFSET(lowres), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, JPEG2000_MAX_RESLEVELS - 1, VD },
- - { NULL },
- -};
- -
- static const AVProfile profiles[] = {
- { FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0, "JPEG 2000 codestream restriction 0" },
- { FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1, "JPEG 2000 codestream restriction 1" },
- @@ -1319,7 +1318,6 @@ static const AVProfile profiles[] = {
- static const AVClass class = {
- .class_name = "jpeg2000",
- .item_name = av_default_item_name,
- - .option = options,
- .version = LIBAVUTIL_VERSION_INT,
- };
- @@ -1330,6 +1328,7 @@ AVCodec ff_jpeg2000_decoder = {
- .id = AV_CODEC_ID_JPEG2000,
- .capabilities = CODEC_CAP_FRAME_THREADS,
- .priv_data_size = sizeof(Jpeg2000DecoderContext),
- + .max_lowres = 31,
- .decode = jpeg2000_decode_frame,
- .priv_class = &class,
- .pix_fmts = (enum PixelFormat[]) { AV_PIX_FMT_XYZ12,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement