From 118b36f418fb050aebecd0c868b04bdc45293012 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Thu, 14 Apr 2022 16:43:53 +0200 Subject: [PATCH] avcodec/mjpegdec: Avoid copying data when flipping image Basically reverts af15c17daa5d8d2940c0263ba4d3ecec761c11ee. Flipping a picture by modifying the pointers is so common that even users of direct rendering should take it into account. Reviewed-by: Michael Niedermayer Signed-off-by: Andreas Rheinhardt --- libavcodec/mjpegdec.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 65337360b0..ca7e752f16 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -2770,28 +2770,18 @@ the_end: } } if (s->flipped && !s->rgb) { - int j; ret = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, &hshift, &vshift); if (ret) return ret; - av_assert0(s->nb_components == av_pix_fmt_count_planes(s->picture_ptr->format)); + av_assert0(s->nb_components == av_pix_fmt_count_planes(frame->format)); for (index=0; indexnb_components; index++) { - uint8_t *dst = s->picture_ptr->data[index]; - int w = s->picture_ptr->width; - int h = s->picture_ptr->height; - if(index && index<3){ - w = AV_CEIL_RSHIFT(w, hshift); + int h = frame->height; + if (index && index < 3) h = AV_CEIL_RSHIFT(h, vshift); - } - if(dst){ - uint8_t *dst2 = dst + s->picture_ptr->linesize[index]*(h-1); - for (i=0; ipicture_ptr->linesize[index]; - dst2 -= s->picture_ptr->linesize[index]; - } + if (frame->data[index]) { + frame->data[index] += (h - 1) * frame->linesize[index]; + frame->linesize[index] *= -1; } } }