From patchwork Fri Jul 21 09:50:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 4411 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp692297vsb; Fri, 21 Jul 2017 02:50:16 -0700 (PDT) X-Received: by 10.28.103.138 with SMTP id b132mr4103495wmc.35.1500630616204; Fri, 21 Jul 2017 02:50:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500630616; cv=none; d=google.com; s=arc-20160816; b=xxbfrs1OENItnEb+U085AcDWa/19ulAr60OE/G7uO1L0tdNz4X4rg7uSEXsucHuq+n 61vgnldrMPKtPoN9wB0d20+tMgCcZCR8Ph/X8ssvyS2sUaj0klpLQzdBfEyq6PItV94l oG2LlIRa0f7z9QLHkTxJRDoVVr+o2WxXMR4a+3Lums6iyWZLlqpyRV6VuJFce81eHClI g8h27od2nImO1Jn8nK876q2fQggKk1mYabBzHbAoYuESnQvUspJitd6jgswsrwgg/Uqo k2KHI+PYB70P5WvjzCWJCQHj+GCoWwvk74fXthVA7mJxdhSOkhhm5Kb16V8l6r/pXcx8 9scA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to:arc-authentication-results; bh=w/B8TNa/26ul2b/RKw4LlnvLA1BingOX36WSO+/DHQ4=; b=AjvBxinHwmLCtYZ2bRYoPOGMfwQHZ6QBZtecrAhObx02PTrU9WBfYgAEyLNSaBC3AI UJqlM2Yz5usgAm0dla7xrDVxHVLaGNWs2fvnKTZt53uHbucy2vDVtpqCy/jVOL/b0QTw yNGi0ckJKi08Dds6L17YQaGt44Tk42oz8Npg1hIkcpg1sFlYwqla8qVwAWj3mck9REJy phtiMc6Whhn4FjFtWo2tM5YgUP+vteb705ePqn6l0TMFcOVfsE7JxtjMDbqm4LW+KB7o wedtGIKh+CayaiMVWVXWdbwuM1xdmVDk9R7rSBgkD9gKs7qO9rZ0oC7Uv4J6UwzEgCB8 dK7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 74si7902645wrc.395.2017.07.21.02.50.15; Fri, 21 Jul 2017 02:50:16 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DD94C689C81; Fri, 21 Jul 2017 12:50:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef2.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 88F2B689C6C for ; Fri, 21 Jul 2017 12:49:58 +0300 (EEST) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef2.ens.fr (8.13.6/1.01.28121999) with ESMTP id v6L9o6iE099206 for ; Fri, 21 Jul 2017 11:50:06 +0200 (CEST) Received: by phare.normalesup.org (Postfix, from userid 1001) id 68CC0E00BD; Fri, 21 Jul 2017 11:50:06 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Fri, 21 Jul 2017 11:50:03 +0200 Message-Id: <20170721095003.20505-1-george@nsup.org> X-Mailer: git-send-email 2.13.2 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef2.ens.fr [129.199.96.32]); Fri, 21 Jul 2017 11:50:06 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH] lavfi/testsrc2: fix completely transparent alpha. 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Nicolas George --- doc/filters.texi | 5 +++++ libavfilter/vsrc_testsrc.c | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) Fixed the undefined shift, thanks Clément for noticing. Added documentation. Note: until now, the "default" was 0, not 255. But it produces an ugly image, so I considered nobody really uses it like that and decided it was ok to change it to a saner default, but it can be discussed. It does not break our existing FATE tests. Note to whoever will push "fate: add vf_overlay test for main source with alpha channel": if this patch is required and I have not applied it, feel free to do it yourself. diff --git a/doc/filters.texi b/doc/filters.texi index 2708fdb1df..e265c4ef59 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -16390,6 +16390,11 @@ The sources accept the following parameters: @table @option +@item alpha +Specify the alpha (opacity) of the background, only available in the +@code{testsrc2} source. The value must be between 0 (fully transparent) and +255 (fully opaque, the default). + @item color, c Specify the color of the source, only available in the @code{color} source. For the syntax of this option, check the "Color" section in the diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c index c4a5ae3742..fe0d50aa41 100644 --- a/libavfilter/vsrc_testsrc.c +++ b/libavfilter/vsrc_testsrc.c @@ -66,6 +66,9 @@ typedef struct TestSourceContext { /* only used by testsrc */ int nb_decimals; + /* only used by testsrc2 */ + int alpha; + /* only used by color */ FFDrawContext draw; FFDrawColor color; @@ -685,6 +688,7 @@ AVFilter ff_vsrc_testsrc = { static const AVOption testsrc2_options[] = { COMMON_OPTIONS + { "alpha", "set global alpha (opacity)", OFFSET(alpha), AV_OPT_TYPE_INT, {.i64 = 255}, 0, 255, FLAGS }, { NULL } }; @@ -735,6 +739,7 @@ static void test2_fill_picture(AVFilterContext *ctx, AVFrame *frame) { TestSourceContext *s = ctx->priv; FFDrawColor color; + unsigned alpha = (uint32_t)s->alpha << 24; /* colored background */ { @@ -746,7 +751,8 @@ static void test2_fill_picture(AVFilterContext *ctx, AVFrame *frame) x2 = ff_draw_round_to_sub(&s->draw, 0, 0, x2); set_color(s, &color, ((i & 1) ? 0xFF0000 : 0) | ((i & 2) ? 0x00FF00 : 0) | - ((i & 4) ? 0x0000FF : 0)); + ((i & 4) ? 0x0000FF : 0) | + alpha); ff_fill_rectangle(&s->draw, &color, frame->data, frame->linesize, x, 0, x2 - x, frame->height); x = x2; @@ -763,7 +769,7 @@ static void test2_fill_picture(AVFilterContext *ctx, AVFrame *frame) g0 = av_rescale_q(s->pts, s->time_base, av_make_q(1, 128)); for (x = 0; x < s->w; x += dx) { g = (av_rescale(x, 6 * 256, s->w) + g0) % (6 * 256); - set_color(s, &color, color_gradient(g)); + set_color(s, &color, color_gradient(g) | alpha); y = y0 + av_rescale(x, s->h / 2, s->w); y %= 2 * (s->h - 16); if (y > s->h - 16) @@ -785,7 +791,7 @@ static void test2_fill_picture(AVFilterContext *ctx, AVFrame *frame) int c, i; for (c = 0; c < 3; c++) { - set_color(s, &color, 0xBBBBBB ^ (0xFF << (c << 3))); + set_color(s, &color, (0xBBBBBB ^ (0xFF << (c << 3))) | alpha); pos = av_rescale_q(s->pts, s->time_base, av_make_q(64 >> (c << 1), cycle)) % cycle; xh = pos < 1 * l ? pos : pos < 2 * l ? l :