[FFmpeg-devel] [PATCH 3/5] lavfi/gradfun: fix dithering in MMX code.

Clément Bœsch ubitux at gmail.com
Fri Dec 7 00:46:07 CET 2012


Current dithering only use the first 4w instead of the whole 8 random values.
---
 libavfilter/x86/gradfun.c | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/libavfilter/x86/gradfun.c b/libavfilter/x86/gradfun.c
index 1ca5928..50e1c29 100644
--- a/libavfilter/x86/gradfun.c
+++ b/libavfilter/x86/gradfun.c
@@ -35,8 +35,8 @@ static void gradfun_filter_line_mmxext(uint8_t *dst, const uint8_t *src, const u
                                        const uint16_t *dithers)
 {
     intptr_t x;
-    if (width & 3) {
-        x = width & ~3;
+    if (width & 7) {
+        x = width & ~7;
         ff_gradfun_filter_line_c(dst + x, src + x, dc + x / 2, width - x, thresh, dithers);
         width = x;
     }
@@ -46,7 +46,9 @@ static void gradfun_filter_line_mmxext(uint8_t *dst, const uint8_t *src, const u
         "pxor       %%mm7, %%mm7 \n"
         "pshufw $0, %%mm5, %%mm5 \n"
         "movq          %6, %%mm6 \n"
-        "movq          %5, %%mm4 \n"
+        "movq          %5, %%mm3 \n"
+        "movq          %7, %%mm4 \n"
+
         "1: \n"
         "movd     (%2,%0), %%mm0 \n"
         "movd     (%3,%0), %%mm1 \n"
@@ -61,6 +63,28 @@ static void gradfun_filter_line_mmxext(uint8_t *dst, const uint8_t *src, const u
         "psubw      %%mm6, %%mm2 \n"
         "pminsw     %%mm7, %%mm2 \n" // m = -max(0, 127-m)
         "pmullw     %%mm2, %%mm2 \n"
+        "paddw      %%mm3, %%mm0 \n" // pix += dither
+        "psllw         $2, %%mm1 \n" // m = m*m*delta >> 14
+        "pmulhw     %%mm2, %%mm1 \n"
+        "paddw      %%mm1, %%mm0 \n" // pix += m
+        "psraw         $7, %%mm0 \n"
+        "packuswb   %%mm0, %%mm0 \n"
+        "movd       %%mm0, (%1,%0) \n" // dst = clip(pix>>7)
+        "add           $4, %0 \n"
+
+        "movd     (%2,%0), %%mm0 \n"
+        "movd     (%3,%0), %%mm1 \n"
+        "punpcklbw  %%mm7, %%mm0 \n"
+        "punpcklwd  %%mm1, %%mm1 \n"
+        "psllw         $7, %%mm0 \n"
+        "pxor       %%mm2, %%mm2 \n"
+        "psubw      %%mm0, %%mm1 \n" // delta = dc - pix
+        "psubw      %%mm1, %%mm2 \n"
+        "pmaxsw     %%mm1, %%mm2 \n"
+        "pmulhuw    %%mm5, %%mm2 \n" // m = abs(delta) * thresh >> 16
+        "psubw      %%mm6, %%mm2 \n"
+        "pminsw     %%mm7, %%mm2 \n" // m = -max(0, 127-m)
+        "pmullw     %%mm2, %%mm2 \n"
         "paddw      %%mm4, %%mm0 \n" // pix += dither
         "psllw         $2, %%mm1 \n" // m = m*m*delta >> 14
         "pmulhw     %%mm2, %%mm1 \n"
@@ -69,11 +93,12 @@ static void gradfun_filter_line_mmxext(uint8_t *dst, const uint8_t *src, const u
         "packuswb   %%mm0, %%mm0 \n"
         "movd       %%mm0, (%1,%0) \n" // dst = clip(pix>>7)
         "add           $4, %0 \n"
+
         "jl 1b \n"
         "emms \n"
         :"+r"(x)
         :"r"(dst+width), "r"(src+width), "r"(dc+width/2),
-         "rm"(thresh), "m"(*dithers), "m"(*pw_7f)
+         "rm"(thresh), "m"(*dithers), "m"(*pw_7f), "m"(*(dithers + 4))
         :"memory"
     );
 }
-- 
1.8.0.1



More information about the ffmpeg-devel mailing list