[FFmpeg-cvslog] avfilter/vf_blend: refactor similar code

Paul B Mahol git at videolan.org
Mon Sep 27 20:13:28 EEST 2021


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Sep 27 19:10:17 2021 +0200| [d7408a786f350d4cd9a338821a4c63a0642eb000] | committer: Paul B Mahol

avfilter/vf_blend: refactor similar code

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

 libavfilter/vf_blend.c | 93 +++++++++++++++-----------------------------------
 1 file changed, 27 insertions(+), 66 deletions(-)

diff --git a/libavfilter/vf_blend.c b/libavfilter/vf_blend.c
index ff06940a66..db315fa86f 100644
--- a/libavfilter/vf_blend.c
+++ b/libavfilter/vf_blend.c
@@ -142,74 +142,35 @@ COPY(bottom, 32)
 
 #undef COPY
 
-static void blend_normal_8bit(const uint8_t *top, ptrdiff_t top_linesize,
-                              const uint8_t *bottom, ptrdiff_t bottom_linesize,
-                              uint8_t *dst, ptrdiff_t dst_linesize,
-                              ptrdiff_t width, ptrdiff_t height,
-                              FilterParams *param, double *values, int starty)
-{
-    const float opacity = param->opacity;
-    int i, j;
-
-    for (i = 0; i < height; i++) {
-        for (j = 0; j < width; j++) {
-            dst[j] = top[j] * opacity + bottom[j] * (1.f - opacity);
-        }
-        dst    += dst_linesize;
-        top    += top_linesize;
-        bottom += bottom_linesize;
-    }
+#define BLEND_NORMAL(name, type)                                                  \
+static void blend_normal_##name(const uint8_t *_top, ptrdiff_t top_linesize,      \
+                                const uint8_t *_bottom, ptrdiff_t bottom_linesize,\
+                                uint8_t *_dst, ptrdiff_t dst_linesize,            \
+                                ptrdiff_t width, ptrdiff_t height,                \
+                                FilterParams *param, double *values, int starty)  \
+{                                                                                 \
+    const type *top = (type*)_top;                                                \
+    const type *bottom = (type*)_bottom;                                          \
+    type *dst = (type*)_dst;                                                      \
+    const float opacity = param->opacity;                                         \
+                                                                                  \
+    dst_linesize /= sizeof(type);                                                 \
+    top_linesize /= sizeof(type);                                                 \
+    bottom_linesize /= sizeof(type);                                              \
+                                                                                  \
+    for (int i = 0; i < height; i++) {                                            \
+        for (int j = 0; j < width; j++) {                                         \
+            dst[j] = top[j] * opacity + bottom[j] * (1.f - opacity);              \
+        }                                                                         \
+        dst    += dst_linesize;                                                   \
+        top    += top_linesize;                                                   \
+        bottom += bottom_linesize;                                                \
+    }                                                                             \
 }
 
-static void blend_normal_16bit(const uint8_t *_top, ptrdiff_t top_linesize,
-                                  const uint8_t *_bottom, ptrdiff_t bottom_linesize,
-                                  uint8_t *_dst, ptrdiff_t dst_linesize,
-                                  ptrdiff_t width, ptrdiff_t height,
-                                  FilterParams *param, double *values, int starty)
-{
-    const uint16_t *top = (uint16_t*)_top;
-    const uint16_t *bottom = (uint16_t*)_bottom;
-    uint16_t *dst = (uint16_t*)_dst;
-    const float opacity = param->opacity;
-    int i, j;
-    dst_linesize /= 2;
-    top_linesize /= 2;
-    bottom_linesize /= 2;
-
-    for (i = 0; i < height; i++) {
-        for (j = 0; j < width; j++) {
-            dst[j] = top[j] * opacity + bottom[j] * (1.f - opacity);
-        }
-        dst    += dst_linesize;
-        top    += top_linesize;
-        bottom += bottom_linesize;
-    }
-}
-
-static void blend_normal_32bit(const uint8_t *_top, ptrdiff_t top_linesize,
-                               const uint8_t *_bottom, ptrdiff_t bottom_linesize,
-                               uint8_t *_dst, ptrdiff_t dst_linesize,
-                               ptrdiff_t width, ptrdiff_t height,
-                               FilterParams *param, double *values, int starty)
-{
-    const float *top = (float*)_top;
-    const float *bottom = (float*)_bottom;
-    float *dst = (float*)_dst;
-    const float opacity = param->opacity;
-    int i, j;
-    dst_linesize /= 4;
-    top_linesize /= 4;
-    bottom_linesize /= 4;
-
-    for (i = 0; i < height; i++) {
-        for (j = 0; j < width; j++) {
-            dst[j] = top[j] * opacity + bottom[j] * (1.f - opacity);
-        }
-        dst    += dst_linesize;
-        top    += top_linesize;
-        bottom += bottom_linesize;
-    }
-}
+BLEND_NORMAL(8bit,  uint8_t)
+BLEND_NORMAL(16bit, uint16_t)
+BLEND_NORMAL(32bit, float)
 
 #define DEFINE_BLEND8(name, expr)                                              \
 static void blend_## name##_8bit(const uint8_t *top, ptrdiff_t top_linesize,         \



More information about the ffmpeg-cvslog mailing list