[FFmpeg-devel] [PATCH] sanm: make use of dsputil

Paul B Mahol onemda at gmail.com
Sat Jul 7 20:08:20 CEST 2012


About 27% faster decoding.

Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 libavcodec/sanm.c |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 2b548f2..2a0fb77 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -25,6 +25,7 @@
 #include "avcodec.h"
 #include "bytestream.h"
 #include "libavutil/bswap.h"
+#include "libavcodec/dsputil.h"
 #include "sanm_data.h"
 
 #define NGLYPHS 256
@@ -449,8 +450,7 @@ static int old_codec37(SANMVideoContext *ctx, int top,
                     int code;
                     if (skip_run) {
                         skip_run--;
-                        for (k = 0; k < 4; k++)
-                            memcpy(dst + i + k * stride, prev + i + k * stride, 4);
+                        copy_block4(dst + i, prev + i, stride, stride, 4);
                         continue;
                     }
                     if (bytestream2_get_bytes_left(&ctx->gb) < 1)
@@ -501,8 +501,7 @@ static int old_codec37(SANMVideoContext *ctx, int top,
                     int code;
                     if (skip_run) {
                         skip_run--;
-                        for (k = 0; k < 4; k++)
-                            memcpy(dst + i + k * stride, prev + i + k * stride, 4);
+                        copy_block4(dst + i, prev + i, stride, stride, 4);
                         continue;
                     }
                     code = bytestream2_get_byte(&ctx->gb);
@@ -769,10 +768,21 @@ static int decode_nop(SANMVideoContext *ctx)
 
 static void copy_block(uint16_t *pdest, uint16_t *psrc, int block_size, int pitch)
 {
-    int y;
+    uint8_t *dst = (uint8_t *)pdest;
+    uint8_t *src = (uint8_t *)psrc;
+    int stride = pitch * 2;
 
-    for (y = 0; y < block_size; y++, pdest += pitch, psrc += pitch)
-        memcpy(pdest, psrc, block_size * sizeof(pdest[0]));
+    switch (block_size) {
+    case 2:
+        copy_block4(dst, src, stride, stride, 2);
+        break;
+    case 4:
+        copy_block8(dst, src, stride, stride, 4);
+        break;
+    case 8:
+        copy_block16(dst, src, stride, stride, 8);
+        break;
+    }
 }
 
 static void fill_block(uint16_t *pdest, uint16_t color, int block_size, int pitch)
-- 
1.7.7



More information about the ffmpeg-devel mailing list