From patchwork Sun May 26 00:07:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 13295 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 72E60448A21 for ; Sun, 26 May 2019 03:08:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5F519689A7D; Sun, 26 May 2019 03:08:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2B08D680800 for ; Sun, 26 May 2019 03:08:38 +0300 (EEST) Received: by mail-pl1-f195.google.com with SMTP id d14so66701pls.8 for ; Sat, 25 May 2019 17:08:38 -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=t411vB6catc225GHOEpyPtdnqgPyG/97uxT7jbCytbA=; b=AZApodtJw5wKB2Vrj9Urwa/kOWUeegZ4URlSGEA5KkpigEZpkXSiZbdmSuiCJIrFrb 7z+KTn6hfEJjh/6778gkZ27jPxCphOE5BUAm6/tMV+QTO5hcL83vPwhrnhInYOv7jQrc LEEZ0NzzD2ywpomepw3ATArXgYpdYY/OSlXbW9Xytn8RZIO8h43BSYVOwM/QSZXHdbUP mYI9gsHJGlKgjUQyCsp+1TaJoC7mPFZdOHGq4nhcQCT2SknGld+9Rjr8X7O2WsZ9GuhC 1puBMkZYskFFmdf8bw5EbAFhG1aEpH5wnwGW0IRgzhZ60tVWi0RKl1FY1q8GIJZ6GbyS qMWg== 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=t411vB6catc225GHOEpyPtdnqgPyG/97uxT7jbCytbA=; b=Q5GcCMrcyhxhzpL5Tz7oLERxDHSv/IxA8OORR8ApZxT5aCoUEoqJxXZdQdsnfmZVKj etUc1p7VYxpLMGQwv03HJ5ytmaW6ePJavChLnvIflrd5hFA17DoUjVhLVb7FiYnG9Als 9S9I4qgyVAoGaFgOGAjg8Bt+UABjIxc+/YnsbvwfvrZW8/OhpiOX8CqUhMFKk+VWlYAo gqa86ebX5aZ64Ov4MBPWjfvyragDQErsvn2jJGqwMwVWDrOT7zWSAxuDdBZ/vlpN2YAo 5NK8ubblpMjjZwEm6LomiAMVlRkEdXwoRCYV6nUSW/Oe6Zcbik5OLrt5ei5vhd1k0r+t ZD/g== X-Gm-Message-State: APjAAAU01bMTDxI9k87kZm72EupbS9fZdvk17rcGmXO+WdliuZz1IG/W dWwtxq/lA41uyv9u7RHeaJvr5kJG6ec= X-Google-Smtp-Source: APXvYqwlXmW5jMBFO0Sf54oyUeeEXRnT1ZYpor/eAimxYXbAga56oB1pGC1PUg/y2EiIKMXtmGckHg== X-Received: by 2002:a17:902:e00a:: with SMTP id ca10mr119383717plb.18.1558829316234; Sat, 25 May 2019 17:08:36 -0700 (PDT) Received: from localhost.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id a9sm6323945pgw.72.2019.05.25.17.08.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 May 2019 17:08:35 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 May 2019 08:07:47 +0800 Message-Id: <20190526000750.79563-2-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190526000750.79563-1-lance.lmwang@gmail.com> References: <20190526000750.79563-1-lance.lmwang@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] 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: michael@niedermayer.cc, Limin Wang , ceffmpeg@gmail.com, barsnick@gmx.net, james.darnley@gmail.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Merge the old patch 2/3/4 into one by Carl Eugen comments: https://patchwork.ffmpeg.org/patch/13270/ --- 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,