[FFmpeg-cvslog] avfilter/xbr: refactor alpha blending macros

Clément Bœsch git at videolan.org
Thu Dec 25 23:50:59 CET 2014


ffmpeg | branch: master | Clément Bœsch <u at pkh.me> | Sun Nov 16 11:55:08 2014 +0100| [2188df96cf49f414ea041aa4d7996b7d85b936fc] | committer: Clément Bœsch

avfilter/xbr: refactor alpha blending macros

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2188df96cf49f414ea041aa4d7996b7d85b936fc
---

 libavfilter/vf_xbr.c |   26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git a/libavfilter/vf_xbr.c b/libavfilter/vf_xbr.c
index 47e4b76..2b1e6ff 100644
--- a/libavfilter/vf_xbr.c
+++ b/libavfilter/vf_xbr.c
@@ -76,26 +76,12 @@ static uint32_t pixel_diff(uint32_t x, uint32_t y, const uint32_t *r2y)
 }
 
 #define ALPHA_BLEND_128_W(dst, src) dst = ((src & LB_MASK) >> 1) + ((dst & LB_MASK) >> 1)
-
-#define ALPHA_BLEND_32_W(dst, src) \
-    dst = ((RED_BLUE_MASK & ((dst & RED_BLUE_MASK) + ((((src & RED_BLUE_MASK) - \
-          (dst & RED_BLUE_MASK))) >> 3))) | (GREEN_MASK & ((dst & GREEN_MASK) + \
-          ((((src & GREEN_MASK) - (dst & GREEN_MASK))) >> 3))))
-
-#define ALPHA_BLEND_64_W(dst, src) \
-    dst = ((RED_BLUE_MASK & ((dst & RED_BLUE_MASK) + ((((src & RED_BLUE_MASK) - \
-          (dst & RED_BLUE_MASK))) >> 2))) | (GREEN_MASK & ((dst & GREEN_MASK) + \
-          ((((src & GREEN_MASK) - (dst & GREEN_MASK))) >> 2))))
-
-#define ALPHA_BLEND_192_W(dst, src) \
-    dst = ((RED_BLUE_MASK & ((dst & RED_BLUE_MASK) + ((((src & RED_BLUE_MASK) - \
-          (dst & RED_BLUE_MASK)) * 3) >> 2))) | (GREEN_MASK & ((dst & GREEN_MASK) + \
-          ((((src & GREEN_MASK) - (dst & GREEN_MASK)) * 3) >> 2))))
-
-#define ALPHA_BLEND_224_W(dst, src) \
-    dst = ((RED_BLUE_MASK & ((dst & RED_BLUE_MASK) + ((((src & RED_BLUE_MASK) - \
-          (dst & RED_BLUE_MASK)) * 7) >> 3))) | (GREEN_MASK & ((dst & GREEN_MASK) + \
-          ((((src & GREEN_MASK) - (dst & GREEN_MASK)) * 7) >> 3))))
+#define ALPHA_BLEND_BASE(a, b, m, s) (  (RED_BLUE_MASK & (((a) & RED_BLUE_MASK) + (((((b) & RED_BLUE_MASK) - ((a) & RED_BLUE_MASK)) * (m)) >> (s)))) \
+                                      | (GREEN_MASK    & (((a) & GREEN_MASK)    + (((((b) & GREEN_MASK)    - ((a) & GREEN_MASK))    * (m)) >> (s)))))
+#define ALPHA_BLEND_32_W(dst, src)  dst = ALPHA_BLEND_BASE(dst, src, 1, 3)
+#define ALPHA_BLEND_64_W(dst, src)  dst = ALPHA_BLEND_BASE(dst, src, 1, 2)
+#define ALPHA_BLEND_192_W(dst, src) dst = ALPHA_BLEND_BASE(dst, src, 3, 2)
+#define ALPHA_BLEND_224_W(dst, src) dst = ALPHA_BLEND_BASE(dst, src, 7, 3)
 
 #define df(A, B) pixel_diff(A, B, r2y)
 #define eq(A, B) (df(A, B) < 155)



More information about the ffmpeg-cvslog mailing list