From 798490812a05471862629b7250674a24575d1291 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 31 Mar 2014 15:52:15 +0200 Subject: [PATCH] avcodec/mjpegdec: upgrade upscale_v to support multiple planes Signed-off-by: Michael Niedermayer --- libavcodec/mjpegdec.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 931c28ab68..43bec98e13 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -414,7 +414,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) else goto unk_pixfmt; s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; - s->upscale_v = 2; + s->upscale_v = 4; s->upscale_h = 2*(pix_fmt_id == 0x22122100); s->chroma_height = s->height; break; @@ -424,7 +424,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) else goto unk_pixfmt; s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; - s->upscale_v = (pix_fmt_id == 0x22211200); + s->upscale_v = 2*(pix_fmt_id == 0x22211200); s->upscale_h = 4; s->chroma_height = s->height; break; @@ -433,7 +433,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) else goto unk_pixfmt; s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; - s->upscale_v = 2; + s->upscale_v = 4; s->upscale_h = 4; s->chroma_height = s->height / 2; break; @@ -472,7 +472,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) else goto unk_pixfmt; s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; - s->upscale_v = (pix_fmt_id == 0x22121100) + 1; + s->upscale_v = 2 << (pix_fmt_id == 0x22121100); break; case 0x22111100: if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV420P : AV_PIX_FMT_YUVJ420P; @@ -2052,24 +2052,29 @@ the_end: } } if (s->upscale_v) { - uint8_t *dst = &((uint8_t *)s->picture_ptr->data[s->upscale_v])[(s->height - 1) * s->linesize[s->upscale_v]]; - int w; - avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &hshift, &vshift); - w = s->width >> hshift; + int p; av_assert0(avctx->pix_fmt == AV_PIX_FMT_YUVJ444P || avctx->pix_fmt == AV_PIX_FMT_YUV444P || avctx->pix_fmt == AV_PIX_FMT_YUVJ422P || avctx->pix_fmt == AV_PIX_FMT_YUV422P); - for (i = s->height - 1; i; i--) { - uint8_t *src1 = &((uint8_t *)s->picture_ptr->data[s->upscale_v])[i / 2 * s->linesize[s->upscale_v]]; - uint8_t *src2 = &((uint8_t *)s->picture_ptr->data[s->upscale_v])[(i + 1) / 2 * s->linesize[s->upscale_v]]; - if (src1 == src2) { - memcpy(dst, src1, w); - } else { - for (index = 0; index < w; index++) - dst[index] = (src1[index] + src2[index]) >> 1; + avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &hshift, &vshift); + for (p = 1; p < 4; p++) { + uint8_t *dst = &((uint8_t *)s->picture_ptr->data[p])[(s->height - 1) * s->linesize[p]]; + int w; + if (!(s->upscale_v & (1<width >> hshift; + for (i = s->height - 1; i; i--) { + uint8_t *src1 = &((uint8_t *)s->picture_ptr->data[p])[i / 2 * s->linesize[p]]; + uint8_t *src2 = &((uint8_t *)s->picture_ptr->data[p])[(i + 1) / 2 * s->linesize[p]]; + if (src1 == src2) { + memcpy(dst, src1, w); + } else { + for (index = 0; index < w; index++) + dst[index] = (src1[index] + src2[index]) >> 1; + } + dst -= s->linesize[p]; } - dst -= s->linesize[s->upscale_v]; } } if (s->flipped) {