[FFmpeg-devel,v3,2/6] libavfilter/vf_overlay.c: Add "\" for the following macro style function

Submitted by lance.lmwang@gmail.com on June 6, 2019, 7:09 a.m.

Details

Message ID 20190606070959.9608-2-lance.lmwang@gmail.com
State New
Headers show

Commit Message

lance.lmwang@gmail.com June 6, 2019, 7:09 a.m.
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavfilter/vf_overlay.c | 358 +++++++++++++++++++--------------------
 1 file changed, 179 insertions(+), 179 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index b468cedf2e..ba8147f579 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -441,189 +441,189 @@  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,
-                                   int src_w, int src_h,
-                                   int dst_w, int dst_h,
-                                   int x, int y,
-                                   int jobnr, int nb_jobs)
-{
-    uint8_t alpha;          /* the amount of overlay to blend on to main */
-    uint8_t *s, *sa, *d, *da;
-    int i, imax, j, jmax;
-    int slice_start, slice_end;
-
-    imax = FFMIN(-y + dst_h, src_h);
-    slice_start = (imax * jobnr) / nb_jobs;
-    slice_end = ((imax * (jobnr+1)) / nb_jobs);
-
-    i = FFMAX(-y, 0);
-    sa = src->data[3] + (i + slice_start) * src->linesize[3];
-    da = dst->data[3] + (y + i + slice_start) * dst->linesize[3];
-
-    for (i = i + slice_start; i < slice_end; i++) {
-        j = FFMAX(-x, 0);
-        s = sa + j;
-        d = da + x+j;
-
-        for (jmax = FFMIN(-x + dst_w, src_w); j < jmax; j++) {
-            alpha = *s;
-            if (alpha != 0 && alpha != 255) {
-                uint8_t alpha_d = *d;
-                alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d);
-            }
-            switch (alpha) {
-            case 0:
-                break;
-            case 255:
-                *d = *s;
-                break;
-            default:
-                /* apply alpha compositing: main_alpha += (1-main_alpha) * overlay_alpha */
-                *d += FAST_DIV255((255 - *d) * *s);
-            }
-            d += 1;
-            s += 1;
-        }
-        da += dst->linesize[3];
-        sa += src->linesize[3];
-    }
+static inline void alpha_composite(const AVFrame *src, const AVFrame *dst,                                             \
+                                   int src_w, int src_h,                                                               \
+                                   int dst_w, int dst_h,                                                               \
+                                   int x, int y,                                                                       \
+                                   int jobnr, int nb_jobs)                                                             \
+{                                                                                                                      \
+    uint8_t alpha;          /* the amount of overlay to blend on to main */                                            \
+    uint8_t *s, *sa, *d, *da;                                                                                          \
+    int i, imax, j, jmax;                                                                                              \
+    int slice_start, slice_end;                                                                                        \
+                                                                                                                       \
+    imax = FFMIN(-y + dst_h, src_h);                                                                                   \
+    slice_start = (imax * jobnr) / nb_jobs;                                                                            \
+    slice_end = ((imax * (jobnr+1)) / nb_jobs);                                                                        \
+                                                                                                                       \
+    i = FFMAX(-y, 0);                                                                                                  \
+    sa = src->data[3] + (i + slice_start) * src->linesize[3];                                                          \
+    da = dst->data[3] + (y + i + slice_start) * dst->linesize[3];                                                      \
+                                                                                                                       \
+    for (i = i + slice_start; i < slice_end; i++) {                                                                    \
+        j = FFMAX(-x, 0);                                                                                              \
+        s = sa + j;                                                                                                    \
+        d = da + x+j;                                                                                                  \
+                                                                                                                       \
+        for (jmax = FFMIN(-x + dst_w, src_w); j < jmax; j++) {                                                         \
+            alpha = *s;                                                                                                \
+            if (alpha != 0 && alpha != 255) {                                                                          \
+                uint8_t alpha_d = *d;                                                                                  \
+                alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d);                                                           \
+            }                                                                                                          \
+            switch (alpha) {                                                                                           \
+            case 0:                                                                                                    \
+                break;                                                                                                 \
+            case 255:                                                                                                  \
+                *d = *s;                                                                                               \
+                break;                                                                                                 \
+            default:                                                                                                   \
+                /* apply alpha compositing: main_alpha += (1-main_alpha) * overlay_alpha */                            \
+                *d += FAST_DIV255((255 - *d) * *s);                                                                    \
+            }                                                                                                          \
+            d += 1;                                                                                                    \
+            s += 1;                                                                                                    \
+        }                                                                                                              \
+        da += dst->linesize[3];                                                                                        \
+        sa += src->linesize[3];                                                                                        \
+    }                                                                                                                  \
 }
 
-static av_always_inline void blend_slice_yuv(AVFilterContext *ctx,
-                                             AVFrame *dst, const AVFrame *src,
-                                             int hsub, int vsub,
-                                             int main_has_alpha,
-                                             int x, int y,
-                                             int is_straight,
-                                             int jobnr, int nb_jobs)
-{
-    OverlayContext *s = ctx->priv;
-    const int src_w = src->width;
-    const int src_h = src->height;
-    const int dst_w = dst->width;
-    const int dst_h = dst->height;
-
-    blend_plane(ctx, dst, src, src_w, src_h, dst_w, dst_h, 0, 0,       0, x, y, main_has_alpha,
-                s->main_desc->comp[0].plane, s->main_desc->comp[0].offset, s->main_desc->comp[0].step, is_straight, 1,
-                jobnr, nb_jobs);
-    blend_plane(ctx, dst, src, src_w, src_h, dst_w, dst_h, 1, hsub, vsub, x, y, main_has_alpha,
-                s->main_desc->comp[1].plane, s->main_desc->comp[1].offset, s->main_desc->comp[1].step, is_straight, 1,
-                jobnr, nb_jobs);
-    blend_plane(ctx, dst, src, src_w, src_h, dst_w, dst_h, 2, hsub, vsub, x, y, main_has_alpha,
-                s->main_desc->comp[2].plane, s->main_desc->comp[2].offset, s->main_desc->comp[2].step, is_straight, 1,
-                jobnr, nb_jobs);
-
-    if (main_has_alpha)
-        alpha_composite(src, dst, src_w, src_h, dst_w, dst_h, x, y, jobnr, nb_jobs);
+static av_always_inline void blend_slice_yuv(AVFilterContext *ctx,                                                     \
+                                             AVFrame *dst, const AVFrame *src,                                         \
+                                             int hsub, int vsub,                                                       \
+                                             int main_has_alpha,                                                       \
+                                             int x, int y,                                                             \
+                                             int is_straight,                                                          \
+                                             int jobnr, int nb_jobs)                                                   \
+{                                                                                                                      \
+    OverlayContext *s = ctx->priv;                                                                                     \
+    const int src_w = src->width;                                                                                      \
+    const int src_h = src->height;                                                                                     \
+    const int dst_w = dst->width;                                                                                      \
+    const int dst_h = dst->height;                                                                                     \
+                                                                                                                       \
+    blend_plane(ctx, dst, src, src_w, src_h, dst_w, dst_h, 0, 0,       0, x, y, main_has_alpha,                        \
+                s->main_desc->comp[0].plane, s->main_desc->comp[0].offset, s->main_desc->comp[0].step, is_straight, 1, \
+                jobnr, nb_jobs);                                                                                       \
+    blend_plane(ctx, dst, src, src_w, src_h, dst_w, dst_h, 1, hsub, vsub, x, y, main_has_alpha,                        \
+                s->main_desc->comp[1].plane, s->main_desc->comp[1].offset, s->main_desc->comp[1].step, is_straight, 1, \
+                jobnr, nb_jobs);                                                                                       \
+    blend_plane(ctx, dst, src, src_w, src_h, dst_w, dst_h, 2, hsub, vsub, x, y, main_has_alpha,                        \
+                s->main_desc->comp[2].plane, s->main_desc->comp[2].offset, s->main_desc->comp[2].step, is_straight, 1, \
+                jobnr, nb_jobs);                                                                                       \
+                                                                                                                       \
+    if (main_has_alpha)                                                                                                \
+        alpha_composite(src, dst, src_w, src_h, dst_w, dst_h, x, y, jobnr, nb_jobs);                                   \
 }
 
 static av_always_inline void blend_slice_planar_rgb(AVFilterContext *ctx,