From: Gautam Ramakrishnan <gautamr...@gmail.com> This patch makes selection of pix_fmt similar to that in the native decoder. This makes samples such as p0_05.j2k and p1_03.j2k decodable by libopenjpeg. --- libavcodec/libopenjpegdec.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c index 344c5ba5a3..f5f208784e 100644 --- a/libavcodec/libopenjpegdec.c +++ b/libavcodec/libopenjpegdec.c @@ -272,11 +272,11 @@ static inline void libopenjpeg_copyto8(AVFrame *picture, opj_image_t *image) { int *comp_data; uint8_t *img_ptr; int index, x, y; - for (index = 0; index < image->numcomps; index++) { + int plane = index?index-1:image->numcomps-1; comp_data = image->comps[index].data; for (y = 0; y < image->comps[index].h; y++) { - img_ptr = picture->data[index] + y * picture->linesize[index]; + img_ptr = picture->data[plane] + y * picture->linesize[plane]; for (x = 0; x < image->comps[index].w; x++) { *img_ptr = 0x80 * image->comps[index].sgnd + *comp_data; img_ptr++; @@ -408,6 +408,23 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, if (avctx->pix_fmt == AV_PIX_FMT_NONE) avctx->pix_fmt = libopenjpeg_guess_pix_fmt(image); + if (avctx->pix_fmt == AV_PIX_FMT_NONE) { + if (image->numcomps == 4 && + image->comps[0].dx == 1 && image->comps[0].dy == 1 && + image->comps[1].dx == 1 && image->comps[1].dy == 1 && + image->comps[2].dx == image->comps[3].dx && + image->comps[2].dy == image->comps[3].dy) { + int maxprec = 0; + for (int i = 0; i < 4; i++) + maxprec = FFMAX(maxprec, image->comps[i].prec); + if (maxprec == 8 && + image->comps[2].dx == 2 && + image->comps[2].dy == 2) { + avctx->pix_fmt = AV_PIX_FMT_YUVA420P; + } + } + } + if (avctx->pix_fmt == AV_PIX_FMT_NONE) { av_log(avctx, AV_LOG_ERROR, "Unable to determine pixel format.\n"); ret = AVERROR_UNKNOWN; -- 2.17.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".