[FFmpeg-devel] [PATCH 3/5] avcodec/mjpegdec: Avoid copying data when flipping image
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Thu Apr 14 18:57:38 EEST 2022
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 at outlook.com>
---
libavcodec/mjpegdec.c | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
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;
}
}
}
--
2.32.0
More information about the ffmpeg-devel
mailing list