[FFmpeg-devel] [PATCH 4/7] libavfilter/vf_overlay.c: Add '\' for every line of the blend_plane function

lance.lmwang at gmail.com lance.lmwang at gmail.com
Fri May 24 12:36:13 EEST 2019


From: Limin Wang <lance.lmwang at gmail.com>

---
 libavfilter/vf_overlay.c | 214 +++++++++++++++++++--------------------
 1 file changed, 107 insertions(+), 107 deletions(-)

diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index f36be1601b..ba8147f579 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -441,113 +441,113 @@ static av_always_inline void blend_slice_packed_rgb(AVFilterContext *ctx,
     }
 }
 
-static av_always_inline void blend_plane(AVFilterContext *ctx,
-                                         AVFrame *dst, const AVFrame *src,
-                                         int src_w, int src_h,
-                                         int dst_w, int dst_h,
-                                         int i, int hsub, int vsub,
-                                         int x, int y,
-                                         int main_has_alpha,
-                                         int dst_plane,
-                                         int dst_offset,
-                                         int dst_step,
-                                         int straight,
-                                         int yuv,
-                                         int jobnr,
-                                         int nb_jobs)
-{
-    OverlayContext *octx = ctx->priv;
-    int src_wp = AV_CEIL_RSHIFT(src_w, hsub);
-    int src_hp = AV_CEIL_RSHIFT(src_h, vsub);
-    int dst_wp = AV_CEIL_RSHIFT(dst_w, hsub);
-    int dst_hp = AV_CEIL_RSHIFT(dst_h, vsub);
-    int yp = y>>vsub;
-    int xp = x>>hsub;
-    uint8_t *s, *sp, *d, *dp, *dap, *a, *da, *ap;
-    int jmax, j, k, kmax;
-    int slice_start, slice_end;
-
-    j = FFMAX(-yp, 0);
-    jmax = FFMIN3(-yp + dst_hp, FFMIN(src_hp, dst_hp), yp + src_hp);
-
-    slice_start = j + (jmax * jobnr) / nb_jobs;
-    slice_end = j + (jmax * (jobnr+1)) / nb_jobs;
-
-    sp = src->data[i] + (slice_start) * src->linesize[i];
-    dp = dst->data[dst_plane]
-                      + (yp + slice_start) * dst->linesize[dst_plane]
-                      + dst_offset;
-    ap = src->data[3] + (slice_start << vsub) * src->linesize[3];
-    dap = dst->data[3] + ((yp + slice_start) << vsub) * dst->linesize[3];
-
-    for (j = slice_start; j < slice_end; j++) {
-        k = FFMAX(-xp, 0);
-        d = dp + (xp+k) * dst_step;
-        s = sp + k;
-        a = ap + (k<<hsub);
-        da = dap + ((xp+k) << hsub);
-        kmax = FFMIN(-xp + dst_wp, src_wp);
-
-        if (((vsub && j+1 < src_hp) || !vsub) && octx->blend_row[i]) {
-            int c = octx->blend_row[i](d, da, s, a, kmax - k, src->linesize[3]);
-
-            s += c;
-            d += dst_step * c;
-            da += (1 << hsub) * c;
-            a += (1 << hsub) * c;
-            k += c;
-        }
-        for (; k < kmax; k++) {
-            int alpha_v, alpha_h, alpha;
-
-            /* average alpha for color components, improve quality */
-            if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
-                alpha = (a[0] + a[src->linesize[3]] +
-                         a[1] + a[src->linesize[3]+1]) >> 2;
-            } else if (hsub || vsub) {
-                alpha_h = hsub && k+1 < src_wp ?
-                    (a[0] + a[1]) >> 1 : a[0];
-                alpha_v = vsub && j+1 < src_hp ?
-                    (a[0] + a[src->linesize[3]]) >> 1 : a[0];
-                alpha = (alpha_v + alpha_h) >> 1;
-            } else
-                alpha = a[0];
-            /* if the main channel has an alpha channel, alpha has to be calculated */
-            /* to create an un-premultiplied (straight) alpha value */
-            if (main_has_alpha && alpha != 0 && alpha != 255) {
-                /* average alpha for color components, improve quality */
-                uint8_t alpha_d;
-                if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
-                    alpha_d = (da[0] + da[dst->linesize[3]] +
-                               da[1] + da[dst->linesize[3]+1]) >> 2;
-                } else if (hsub || vsub) {
-                    alpha_h = hsub && k+1 < src_wp ?
-                        (da[0] + da[1]) >> 1 : da[0];
-                    alpha_v = vsub && j+1 < src_hp ?
-                        (da[0] + da[dst->linesize[3]]) >> 1 : da[0];
-                    alpha_d = (alpha_v + alpha_h) >> 1;
-                } else
-                    alpha_d = da[0];
-                alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d);
-            }
-            if (straight) {
-                *d = FAST_DIV255(*d * (255 - alpha) + *s * alpha);
-            } else {
-                if (i && yuv)
-                    *d = av_clip(FAST_DIV255((*d - 128) * (255 - alpha)) + *s - 128, -128, 128) + 128;
-                else
-                    *d = FFMIN(FAST_DIV255(*d * (255 - alpha)) + *s, 255);
-            }
-            s++;
-            d += dst_step;
-            da += 1 << hsub;
-            a += 1 << hsub;
-        }
-        dp += dst->linesize[dst_plane];
-        sp += src->linesize[i];
-        ap += (1 << vsub) * src->linesize[3];
-        dap += (1 << vsub) * dst->linesize[3];
-    }
+static av_always_inline void blend_plane(AVFilterContext *ctx,                                                         \
+                                         AVFrame *dst, const AVFrame *src,                                             \
+                                         int src_w, int src_h,                                                         \
+                                         int dst_w, int dst_h,                                                         \
+                                         int i, int hsub, int vsub,                                                    \
+                                         int x, int y,                                                                 \
+                                         int main_has_alpha,                                                           \
+                                         int dst_plane,                                                                \
+                                         int dst_offset,                                                               \
+                                         int dst_step,                                                                 \
+                                         int straight,                                                                 \
+                                         int yuv,                                                                      \
+                                         int jobnr,                                                                    \
+                                         int nb_jobs)                                                                  \
+{                                                                                                                      \
+    OverlayContext *octx = ctx->priv;                                                                                  \
+    int src_wp = AV_CEIL_RSHIFT(src_w, hsub);                                                                          \
+    int src_hp = AV_CEIL_RSHIFT(src_h, vsub);                                                                          \
+    int dst_wp = AV_CEIL_RSHIFT(dst_w, hsub);                                                                          \
+    int dst_hp = AV_CEIL_RSHIFT(dst_h, vsub);                                                                          \
+    int yp = y>>vsub;                                                                                                  \
+    int xp = x>>hsub;                                                                                                  \
+    uint8_t *s, *sp, *d, *dp, *dap, *a, *da, *ap;                                                                      \
+    int jmax, j, k, kmax;                                                                                              \
+    int slice_start, slice_end;                                                                                        \
+                                                                                                                       \
+    j = FFMAX(-yp, 0);                                                                                                 \
+    jmax = FFMIN3(-yp + dst_hp, FFMIN(src_hp, dst_hp), yp + src_hp);                                                   \
+                                                                                                                       \
+    slice_start = j + (jmax * jobnr) / nb_jobs;                                                                        \
+    slice_end = j + (jmax * (jobnr+1)) / nb_jobs;                                                                      \
+                                                                                                                       \
+    sp = src->data[i] + (slice_start) * src->linesize[i];                                                              \
+    dp = dst->data[dst_plane]                                                                                          \
+                      + (yp + slice_start) * dst->linesize[dst_plane]                                                  \
+                      + dst_offset;                                                                                    \
+    ap = src->data[3] + (slice_start << vsub) * src->linesize[3];                                                      \
+    dap = dst->data[3] + ((yp + slice_start) << vsub) * dst->linesize[3];                                              \
+                                                                                                                       \
+    for (j = slice_start; j < slice_end; j++) {                                                                        \
+        k = FFMAX(-xp, 0);                                                                                             \
+        d = dp + (xp+k) * dst_step;                                                                                    \
+        s = sp + k;                                                                                                    \
+        a = ap + (k<<hsub);                                                                                            \
+        da = dap + ((xp+k) << hsub);                                                                                   \
+        kmax = FFMIN(-xp + dst_wp, src_wp);                                                                            \
+                                                                                                                       \
+        if (((vsub && j+1 < src_hp) || !vsub) && octx->blend_row[i]) {                                                 \
+            int c = octx->blend_row[i](d, da, s, a, kmax - k, src->linesize[3]);                                       \
+                                                                                                                       \
+            s += c;                                                                                                    \
+            d += dst_step * c;                                                                                         \
+            da += (1 << hsub) * c;                                                                                     \
+            a += (1 << hsub) * c;                                                                                      \
+            k += c;                                                                                                    \
+        }                                                                                                              \
+        for (; k < kmax; k++) {                                                                                        \
+            int alpha_v, alpha_h, alpha;                                                                               \
+                                                                                                                       \
+            /* average alpha for color components, improve quality */                                                  \
+            if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {                                                        \
+                alpha = (a[0] + a[src->linesize[3]] +                                                                  \
+                         a[1] + a[src->linesize[3]+1]) >> 2;                                                           \
+            } else if (hsub || vsub) {                                                                                 \
+                alpha_h = hsub && k+1 < src_wp ?                                                                       \
+                    (a[0] + a[1]) >> 1 : a[0];                                                                         \
+                alpha_v = vsub && j+1 < src_hp ?                                                                       \
+                    (a[0] + a[src->linesize[3]]) >> 1 : a[0];                                                          \
+                alpha = (alpha_v + alpha_h) >> 1;                                                                      \
+            } else                                                                                                     \
+                alpha = a[0];                                                                                          \
+            /* if the main channel has an alpha channel, alpha has to be calculated */                                 \
+            /* to create an un-premultiplied (straight) alpha value */                                                 \
+            if (main_has_alpha && alpha != 0 && alpha != 255) {                                                        \
+                /* average alpha for color components, improve quality */                                              \
+                uint8_t alpha_d;                                                                                       \
+                if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {                                                    \
+                    alpha_d = (da[0] + da[dst->linesize[3]] +                                                          \
+                               da[1] + da[dst->linesize[3]+1]) >> 2;                                                   \
+                } else if (hsub || vsub) {                                                                             \
+                    alpha_h = hsub && k+1 < src_wp ?                                                                   \
+                        (da[0] + da[1]) >> 1 : da[0];                                                                  \
+                    alpha_v = vsub && j+1 < src_hp ?                                                                   \
+                        (da[0] + da[dst->linesize[3]]) >> 1 : da[0];                                                   \
+                    alpha_d = (alpha_v + alpha_h) >> 1;                                                                \
+                } else                                                                                                 \
+                    alpha_d = da[0];                                                                                   \
+                alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d);                                                           \
+            }                                                                                                          \
+            if (straight) {                                                                                            \
+                *d = FAST_DIV255(*d * (255 - alpha) + *s * alpha);                                                     \
+            } else {                                                                                                   \
+                if (i && yuv)                                                                                          \
+                    *d = av_clip(FAST_DIV255((*d - 128) * (255 - alpha)) + *s - 128, -128, 128) + 128;                 \
+                else                                                                                                   \
+                    *d = FFMIN(FAST_DIV255(*d * (255 - alpha)) + *s, 255);                                             \
+            }                                                                                                          \
+            s++;                                                                                                       \
+            d += dst_step;                                                                                             \
+            da += 1 << hsub;                                                                                           \
+            a += 1 << hsub;                                                                                            \
+        }                                                                                                              \
+        dp += dst->linesize[dst_plane];                                                                                \
+        sp += src->linesize[i];                                                                                        \
+        ap += (1 << vsub) * src->linesize[3];                                                                          \
+        dap += (1 << vsub) * dst->linesize[3];                                                                         \
+    }                                                                                                                  \
 }
 
 static inline void alpha_composite(const AVFrame *src, const AVFrame *dst,                                             \
-- 
2.21.0



More information about the ffmpeg-devel mailing list