diff options
Diffstat (limited to 'ffmpeg/libavcodec/libopenjpegdec.c')
| -rw-r--r-- | ffmpeg/libavcodec/libopenjpegdec.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/ffmpeg/libavcodec/libopenjpegdec.c b/ffmpeg/libavcodec/libopenjpegdec.c index f8b6165..0543e3a 100644 --- a/ffmpeg/libavcodec/libopenjpegdec.c +++ b/ffmpeg/libavcodec/libopenjpegdec.c @@ -32,6 +32,7 @@ #include "libavutil/pixfmt.h" #include "libavutil/opt.h" #include "avcodec.h" +#include "internal.h" #include "thread.h" #if HAVE_OPENJPEG_1_5_OPENJPEG_H @@ -59,10 +60,15 @@ AV_PIX_FMT_YUV420P16,AV_PIX_FMT_YUV422P16,AV_PIX_FMT_YUV444P16, \ AV_PIX_FMT_YUVA420P16,AV_PIX_FMT_YUVA422P16,AV_PIX_FMT_YUVA444P16 +#define XYZ_PIXEL_FORMATS AV_PIX_FMT_XYZ12 + static const enum AVPixelFormat libopenjpeg_rgb_pix_fmts[] = {RGB_PIXEL_FORMATS}; static const enum AVPixelFormat libopenjpeg_gray_pix_fmts[] = {GRAY_PIXEL_FORMATS}; static const enum AVPixelFormat libopenjpeg_yuv_pix_fmts[] = {YUV_PIXEL_FORMATS}; -static const enum AVPixelFormat libopenjpeg_all_pix_fmts[] = {RGB_PIXEL_FORMATS,GRAY_PIXEL_FORMATS,YUV_PIXEL_FORMATS}; +static const enum AVPixelFormat libopenjpeg_all_pix_fmts[] = {RGB_PIXEL_FORMATS, + GRAY_PIXEL_FORMATS, + YUV_PIXEL_FORMATS, + XYZ_PIXEL_FORMATS}; typedef struct { AVClass *class; @@ -202,12 +208,16 @@ static inline void libopenjpeg_copyto16(AVFrame *picture, opj_image_t *image) { int *comp_data; uint16_t *img_ptr; int index, x, y; + int adjust[4]; + for (x = 0; x < image->numcomps; x++) + adjust[x] = FFMAX(FFMIN(16 - image->comps[x].prec, 8), 0); + for (index = 0; index < image->numcomps; index++) { comp_data = image->comps[index].data; for (y = 0; y < image->comps[index].h; y++) { img_ptr = (uint16_t*) (picture->data[index] + y * picture->linesize[index]); for (x = 0; x < image->comps[index].w; x++) { - *img_ptr = *comp_data; + *img_ptr = *comp_data << adjust[index]; img_ptr++; comp_data++; } @@ -236,7 +246,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, opj_dinfo_t *dec; opj_cio_t *stream; opj_image_t *image; - int width, height, ret = -1; + int width, height, ret; int pixel_size = 0; int ispacked = 0; int i; @@ -258,7 +268,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, if (!dec) { av_log(avctx, AV_LOG_ERROR, "Error initializing decoder.\n"); - return -1; + return AVERROR_UNKNOWN; } opj_set_event_mgr((opj_common_ptr)dec, NULL, NULL); ctx->dec_params.cp_limit_decoding = LIMIT_TO_MAIN_HEADER; @@ -271,7 +281,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, av_log(avctx, AV_LOG_ERROR, "Codestream could not be opened for reading.\n"); opj_destroy_decompress(dec); - return -1; + return AVERROR_UNKNOWN; } // Decode the header only. @@ -281,19 +291,15 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, if (!image) { av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n"); opj_destroy_decompress(dec); - return -1; + return AVERROR_UNKNOWN; } width = image->x1 - image->x0; height = image->y1 - image->y0; - if (av_image_check_size(width, height, 0, avctx) < 0) { - av_log(avctx, AV_LOG_ERROR, - "%dx%d dimension invalid.\n", width, height); + ret = ff_set_dimensions(avctx, width, height); + if (ret < 0) goto done; - } - - avcodec_set_dimensions(avctx, width, height); if (avctx->pix_fmt != AV_PIX_FMT_NONE) if (!libopenjpeg_matches_pix_fmt(image, avctx->pix_fmt)) @@ -310,7 +316,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, if (image->comps[i].prec > avctx->bits_per_raw_sample) avctx->bits_per_raw_sample = image->comps[i].prec; - if (ff_thread_get_buffer(avctx, &frame, 0) < 0) + if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0) goto done; ctx->dec_params.cp_limit_decoding = NO_LIMITATION; @@ -321,6 +327,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, if (!stream) { av_log(avctx, AV_LOG_ERROR, "Codestream could not be opened for reading.\n"); + ret = AVERROR_UNKNOWN; goto done; } @@ -331,6 +338,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, if (!image) { av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n"); + ret = AVERROR_UNKNOWN; goto done; } @@ -367,6 +375,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, break; default: av_log(avctx, AV_LOG_ERROR, "unsupported pixel size %d\n", pixel_size); + ret = AVERROR_PATCHWELCOME; goto done; } @@ -387,7 +396,7 @@ static const AVOption options[] = { { NULL }, }; -static const AVClass class = { +static const AVClass openjpeg_class = { .class_name = "libopenjpeg", .item_name = av_default_item_name, .option = options, @@ -396,6 +405,7 @@ static const AVClass class = { AVCodec ff_libopenjpeg_decoder = { .name = "libopenjpeg", + .long_name = NULL_IF_CONFIG_SMALL("OpenJPEG JPEG 2000"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_JPEG2000, .priv_data_size = sizeof(LibOpenJPEGContext), @@ -403,6 +413,5 @@ AVCodec ff_libopenjpeg_decoder = { .decode = libopenjpeg_decode_frame, .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS, .max_lowres = 31, - .long_name = NULL_IF_CONFIG_SMALL("OpenJPEG JPEG 2000"), - .priv_class = &class, + .priv_class = &openjpeg_class, }; |
