diff mbox series

[FFmpeg-devel,3/5] avcodec/mjpegdec: Avoid copying data when flipping image

Message ID AS8PR01MB7944BDFADBE541D77C9A518A8FEF9@AS8PR01MB7944.eurprd01.prod.exchangelabs.com
State Accepted
Headers show
Series [FFmpeg-devel,1/5] avcodec/mjpegdec: Always reset got_picture at the beginnig of decoding | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt April 14, 2022, 3:57 p.m. UTC
Basically reverts af15c17daa5d8d2940c0263ba4d3ecec761c11ee.
Flipping a picture by modifying the pointers is so common
that even users of direct rendering should take it into account.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mjpegdec.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

Comments

Michael Niedermayer April 17, 2022, 12:57 p.m. UTC | #1
On Thu, Apr 14, 2022 at 05:57:38PM +0200, Andreas Rheinhardt wrote:
> Basically reverts af15c17daa5d8d2940c0263ba4d3ecec761c11ee.
> Flipping a picture by modifying the pointers is so common
> that even users of direct rendering should take it into account.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/mjpegdec.c | 18 ++++--------------
>  1 file changed, 4 insertions(+), 14 deletions(-)

LGTM

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 939dedce33..33beda12ea 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -2762,28 +2762,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(frame->format));
         for (index=0; index<s->nb_components; index++) {
-            uint8_t *dst = frame->data[index];
-            int w = frame->width;
             int h = frame->height;
-            if(index && index<3){
-                w = AV_CEIL_RSHIFT(w, hshift);
+            if (index && index < 3)
                 h = AV_CEIL_RSHIFT(h, vshift);
-            }
-            if(dst){
-                uint8_t *dst2 = dst + frame->linesize[index]*(h-1);
-                for (i=0; i<h/2; i++) {
-                    for (j=0; j<w; j++)
-                        FFSWAP(int, dst[j], dst2[j]);
-                    dst  += frame->linesize[index];
-                    dst2 -= frame->linesize[index];
-                }
+            if (frame->data[index]) {
+                frame->data[index]     += (h - 1) * frame->linesize[index];
+                frame->linesize[index] *= -1;
             }
         }
     }