diff mbox series

[FFmpeg-devel] avutil/imgutils: optimize image copying

Message ID tencent_9CC187B353F352961985D8B31162C2189309@qq.com
State New
Headers show
Series [FFmpeg-devel] avutil/imgutils: optimize image copying | expand

Checks

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

Commit Message

徐福隆 May 5, 2023, 8:31 a.m. UTC
It makes sense when copying 4K/8K video frame, got 2.7% speed up.
When the condition is no padding and src_linesize equals to dst,
we could copy plane instead of line by line.
before    after   rate
4K video:
9145      8998    1.6%
9804      9465    3.4%
9645      9394    2.6%
8K video:
28411     27718   2.4%
31288     30056   3.9%
32336     31571   2.4%

Signed-off-by: xufuji456 <839789740@qq.com>
---
 libavutil/imgutils.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Tomas Härdin May 9, 2023, 9:59 a.m. UTC | #1
fre 2023-05-05 klockan 16:31 +0800 skrev xufuji456:
> It makes sense when copying 4K/8K video frame, got 2.7% speed up.
> When the condition is no padding and src_linesize equals to dst,
> we could copy plane instead of line by line.
> before    after   rate
> 4K video:
> 9145      8998    1.6%
> 9804      9465    3.4%
> 9645      9394    2.6%
> 8K video:
> 28411     27718   2.4%
> 31288     30056   3.9%
> 32336     31571   2.4%
> 
> Signed-off-by: xufuji456 <839789740@qq.com>
> ---
>  libavutil/imgutils.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)

Nice, looks OK to me

/Tomas
diff mbox series

Patch

diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
index 9ab5757cf6..f5898756ba 100644
--- a/libavutil/imgutils.c
+++ b/libavutil/imgutils.c
@@ -525,10 +525,18 @@  int av_image_copy_to_buffer(uint8_t *dst, int dst_size,
         const uint8_t *src = src_data[i];
         h = (height + (1 << shift) - 1) >> shift;
 
-        for (j = 0; j < h; j++) {
-            memcpy(dst, src, linesize[i]);
-            dst += FFALIGN(linesize[i], align);
-            src += src_linesize[i];
+        // When src's linesize equals to dst, we could copy plane directly
+        if (src_linesize[i] == linesize[i] && FFALIGN(linesize[i], align) == linesize[i]) {
+            int len = linesize[i] * h;
+            memcpy(dst, src, len);
+            dst += len;
+            src += len;
+        } else {
+            for (j = 0; j < h; j++) {
+                memcpy(dst, src, linesize[i]);
+                dst += FFALIGN(linesize[i], align);
+                src += src_linesize[i];
+            }
         }
     }