From patchwork Thu Jun 6 07:09:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 13434 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9DD13447FE9 for ; Thu, 6 Jun 2019 10:16:02 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 87A6F68A758; Thu, 6 Jun 2019 10:16:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8EDBA689D68 for ; Thu, 6 Jun 2019 10:15:55 +0300 (EEST) Received: by mail-pl1-f193.google.com with SMTP id f97so556773plb.5 for ; Thu, 06 Jun 2019 00:15:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ELXmYb6+iAueMoA4ttAMVbQNh3zi01pyzJ8GitAO0yA=; b=K1dx3ExaFnLVeNaw+K6VlqJGDSPW6vaWuQSGt5fb3c4A9t8GvMNcqF0Wo6L1gMEVIV xktC2V44dhFaxvsFX7H86uEW9KqTHT5CKR3+O2p4LPFleBe0Un2LqPdHLoP1nXRNg188 WsfslTSrl/9URFJqRtkskEMkGd/8NJhR7IohplsJu5FjbouxLL2x2bPArFdbykZZHaDe zI5lEUrx0Qq3NTYvsy+Uyw1g8Z/+M34E3M61KXdefjkIAw+GztxB4y2D7y33lAuzKJJW mS67d+UGYha0cLGWfX2MKctr2WRo40NsrrL029zAe4y+q7cdvqYJ9PA1yOgGtGq2tQ+I ZOsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ELXmYb6+iAueMoA4ttAMVbQNh3zi01pyzJ8GitAO0yA=; b=SWK6y/y7OnRUI7bncmKXRU34dQYPFrKtDd1hxNi7fEG3CDl301MGHDiLd+hWxcmqyV XH9g5+9gQ1jxHT1n2815FkSEfj0kQkyJQg3JdM9pCZ1ek0p+jhgO6tWOX7NMitHY1wI4 qSxYYFrjPjAooSA4xUKNmaHhmFrSW3tY1DHIhRXCPWDxd0oglNYvLtzpUC5FScoS3cYo ZnwpB/yvk+idQP4prCSRywci08Dv7thQI6W82WzirlIcQLEpCNSCEpseRY6cGR9Kzqbx o6/h30LqVpR10o8jcxwLfbxE+Lwfxr3YUdJIQI8bcO6xUrkZQJ40CKOE6u9eXjQn3q/m hnpg== X-Gm-Message-State: APjAAAUpWeofbNGxrCpf2LmDSMO0pJz5SXUJa39YcTvhGdGiOJ+7Zl/X hvm4dP1vqJMQjrID1Or5hgO21AKsPhk= X-Google-Smtp-Source: APXvYqya7Z1gMGd792Wr41nPEkLGKWYyZYSIQSbErlRD6vPhFs+f4ZKG9CCTa8jEIu2X1Ac7mxCMQA== X-Received: by 2002:a17:902:bb95:: with SMTP id m21mr49506065pls.154.1559805034519; Thu, 06 Jun 2019 00:10:34 -0700 (PDT) Received: from localhost.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id e6sm1009863pfi.42.2019.06.06.00.10.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 06 Jun 2019 00:10:33 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 6 Jun 2019 15:09:55 +0800 Message-Id: <20190606070959.9608-2-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190606070959.9608-1-lance.lmwang@gmail.com> References: <20190526000750.79563-5-lance.lmwang@gmail.com> <20190606070959.9608-1-lance.lmwang@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 2/6] libavfilter/vf_overlay.c: Add "\" for the following macro style function X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: lq@chinaffmpeg.org, Limin Wang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Signed-off-by: Limin Wang --- libavfilter/vf_overlay.c | 358 +++++++++++++++++++-------------------- 1 file changed, 179 insertions(+), 179 deletions(-) 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<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<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,