From patchwork Tue Dec 12 13:06:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan X-Patchwork-Id: 6701 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp4056559jah; Tue, 12 Dec 2017 05:13:25 -0800 (PST) X-Google-Smtp-Source: ACJfBovKE9pi7Dz8MCLrzx2EtvTJNPc5nxAxbbmqfMJVWOyz0Dhs16eCr7Bs+mgLL/uYVLG/PAnE X-Received: by 10.28.1.196 with SMTP id 187mr1719529wmb.151.1513084404993; Tue, 12 Dec 2017 05:13:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513084404; cv=none; d=google.com; s=arc-20160816; b=B//XMH9drxre23/9o74L3ozXDqBDwVdTOFBqc7dLOHheC4pihHoYU1SwPzC0Ub+otR 3Wo9dezy1g4/0t/a3v2IDS7kr2yybBomaUctCvfC5nJ8B+88BlbIVx6xN6fzTzGU3KS7 MX3FgMNUxE9pIjAMNnhOWC6SzWnTfVmtr0ArIX6lCnsk9q9ib5whv1cbiLQXNiJe/rcB SREEHEux8TDZrgWhD0ySd6VeUZnkqfLqG2WmxJBBLGhKzXc4Dk4pgsdTFSjztHIPXjb8 p1a4YuTBhrmZgVGVTkzj9SnueITnP1g8/LN+ZJESIGS5kIqFpEnHGFlVD2A8k2g8tBsv Tkyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:mime-version:user-agent:date:message-id:from:to :dkim-signature:delivered-to:arc-authentication-results; bh=Z2RHjwx1i6SphoGMaVfojNqBV/9z0xvOkBAMA6eEvZU=; b=c72Ow+J9ivU72TNhLGNNP6nJKR4huO8f/LnwrL8wXrGpmzcmwjpVZIAgjn4IbSJpjK yq6iYSXAELmLOueaMbxQNL7spv9o0l0aSWu1sPI1CAiPO2SEerN2yd0NYe4PPoJDtVtg rxslbKhJfJC59Y3WU0Pd532Ys18toMoZPTD6pV/mjsJtWHrtoWwLF8ckEfeHj9e2Vgi+ WbN9Pa7xe3f9SwHdX/xVzapiVWVmatNkHcYbJz8QQ3fBYqA1LWIqRjbw8HEYAzXbWdeD yuORDM73+CVn+z21TaUiG5ylcVag34D2lm0GtwPju/gjAbs+1ruUVkdabShYr6b+jo91 uFRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=AVMh8gWY; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 81si4942465wmb.59.2017.12.12.05.13.23; Tue, 12 Dec 2017 05:13:24 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=AVMh8gWY; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C2AF368A624; Tue, 12 Dec 2017 15:13:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f170.google.com (mail-pf0-f170.google.com [209.85.192.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E696368A60C for ; Tue, 12 Dec 2017 15:13:07 +0200 (EET) Received: by mail-pf0-f170.google.com with SMTP id e3so14154737pfi.10 for ; Tue, 12 Dec 2017 05:13:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=R04rYXaFeoWDHOhVnYkBaYL7olZQYOZyYDc7U6NPwQ0=; b=AVMh8gWY58SXZbrMqKuKCl2uQbOE5Lz8rWP3G7tQDHH2SoGVafFSg3O0+RCGbI4k3w CluC9/NIIbZkF8mW7ISp4keIFKm0sD9TU52odAQ4lRCuAReqVW3mL4RZOB8+MX0oRCEr NDBL/w6OHSzhj5EDFhppdjqlxr1JriCyE0/MjgdZAmtloKie0QRFX1uIPzLFnBz6bm76 J/CvGZMeca/W7XWQkUNR+MiCMPkseSWjcF0NL6QXE50X4tRmrjC9JBNMnp/Wa9oHnmpv lladRLaL2i1myHbOf6mDlt82mephqxsYp+8l/jUkn+53BA5w9EnPc7DsmNqGqMrTag/3 iOmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=R04rYXaFeoWDHOhVnYkBaYL7olZQYOZyYDc7U6NPwQ0=; b=QSEjji5q2EklfBRqudMYklwaw+SrJIVJTowNIPCgzHmtkT9mH2S7nQBvuYJW2lRRwH TWMq7OlTPiJ1wNWFUY8TR/xEBIVo3mJH/Ov0WRrZJkVKY5Nlz7SnZoRG5J82xAeIS+d4 j1VOLQN0zwuASSXE+FWJEim5ZJUZoYdaQVEtmvouvKCRTbcwQahGJa543DUhrvEtHqSy DXeuMCX4B7BfU3bVpXQBoe2O7KvSA9Vt4gPeDp4vMwC9jSF/FORlm7E3yTs28k1aUKYC VjF0R6pj2KJbnD5Jsufld66XkiJe7oQ9LvaFNedDCK83m5Zqr6JOhJNFPsIX9wYTc564 c2mw== X-Gm-Message-State: AKGB3mJdbddMq2TbeiEQ707R1aMeQ03Xt6RWp862mEvM1FMNziLpKtrF qqptivUDIMQdfUq7RoHqxcctAJ8w X-Received: by 10.84.204.136 with SMTP id b8mr2231309ple.319.1513083995561; Tue, 12 Dec 2017 05:06:35 -0800 (PST) Received: from [192.168.1.105] ([103.206.133.250]) by smtp.gmail.com with ESMTPSA id z23sm26732834pgc.2.2017.12.12.05.06.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 05:06:34 -0800 (PST) To: ffmpeg-devel@ffmpeg.org From: Gyan Doshi Message-ID: <74cceee0-b9aa-e60a-2089-9cd706833154@gmail.com> Date: Tue, 12 Dec 2017 18:36:29 +0530 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 Content-Language: en-US Subject: [FFmpeg-devel] [PATCH] avfilter/drawbox+drawgrid - add option to prevent overwriting, of source pixels 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" As noted in ticket #6911, drawbox and drawgrids implement anomalous behaviour if the source or user-color has alpha - source pixels are destroyed. Patch introduces new boolean option, whose default value, allows both expected result and current behaviour. Regards, Gyan From cc2979978a8c101588c237c0bc9b6c03731b10e9 Mon Sep 17 00:00:00 2001 From: Gyan Doshi Date: Mon, 11 Dec 2017 22:35:18 +0530 Subject: [PATCH] avfilter/drawbox+drawgrid - add option to prevent overwriting of source pixels If the user-supplied color in drawbox and drawgrid filters is non-opaque, the box & grid painting overwrites the input's pixels (including alpha). Users typically expect the alpha of the specified color to only act as a key for compositing on top of the main input. Added option allows users to select between replacement and composition. Tested and documented. --- doc/filters.texi | 10 ++++++++++ libavfilter/vf_drawbox.c | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 3346438231..70105b928a 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -7146,6 +7146,11 @@ The expression which sets the thickness of the box edge. A value of @code{fill} will create a filled box. Default value is @code{3}. See below for the list of accepted constants. + +@item replace +Applicable if the input has alpha. With value @code{1}, the pixels of the painted box +will overwrite the video's color and alpha pixels. +Default is @code{0}, which composites the box onto the input, leaving the video's alpha intact. @end table The parameters for @var{x}, @var{y}, @var{w} and @var{h} and @var{t} are expressions containing the @@ -7243,6 +7248,11 @@ video with inverted luma. The expression which sets the thickness of the grid line. Default value is @code{1}. See below for the list of accepted constants. + +@item replace +Applicable if the input has alpha. With @code{1} the pixels of the painted grid +will overwrite the video's color and alpha pixels. +Default is @code{0}, which composites the grid onto the input, leaving the video's alpha intact. @end table The parameters for @var{x}, @var{y}, @var{w} and @var{h} and @var{t} are expressions containing the diff --git a/libavfilter/vf_drawbox.c b/libavfilter/vf_drawbox.c index d351846594..c9cb63dbd1 100644 --- a/libavfilter/vf_drawbox.c +++ b/libavfilter/vf_drawbox.c @@ -80,6 +80,7 @@ typedef struct DrawBoxContext { char *w_expr, *h_expr; ///< expression for width and height char *t_expr; ///< expression for thickness int have_alpha; + int replace; } DrawBoxContext; static const int NUM_EXPR_EVALS = 5; @@ -213,7 +214,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) int plane, x, y, xb = s->x, yb = s->y; unsigned char *row[4]; - if (s->have_alpha) { + if (s->have_alpha && s->replace) { for (y = FFMAX(yb, 0); y < frame->height && y < (yb + s->h); y++) { row[0] = frame->data[0] + y * frame->linesize[0]; row[3] = frame->data[3] + y * frame->linesize[3]; @@ -286,6 +287,7 @@ static const AVOption drawbox_options[] = { { "c", "set color of the box", OFFSET(color_str), AV_OPT_TYPE_STRING, { .str = "black" }, CHAR_MIN, CHAR_MAX, FLAGS }, { "thickness", "set the box thickness", OFFSET(t_expr), AV_OPT_TYPE_STRING, { .str="3" }, CHAR_MIN, CHAR_MAX, FLAGS }, { "t", "set the box thickness", OFFSET(t_expr), AV_OPT_TYPE_STRING, { .str="3" }, CHAR_MIN, CHAR_MAX, FLAGS }, + { "replace", "replace color & alpha", OFFSET(replace), AV_OPT_TYPE_BOOL, { .i64=0 }, 0, 1, FLAGS }, { NULL } }; @@ -354,7 +356,7 @@ static int drawgrid_filter_frame(AVFilterLink *inlink, AVFrame *frame) int plane, x, y; uint8_t *row[4]; - if (drawgrid->have_alpha) { + if (drawgrid->have_alpha && drawgrid->replace) { for (y = 0; y < frame->height; y++) { row[0] = frame->data[0] + y * frame->linesize[0]; row[3] = frame->data[3] + y * frame->linesize[3]; @@ -418,6 +420,7 @@ static const AVOption drawgrid_options[] = { { "c", "set color of the grid", OFFSET(color_str), AV_OPT_TYPE_STRING, { .str = "black" }, CHAR_MIN, CHAR_MAX, FLAGS }, { "thickness", "set grid line thickness", OFFSET(t_expr), AV_OPT_TYPE_STRING, {.str="1"}, CHAR_MIN, CHAR_MAX, FLAGS }, { "t", "set grid line thickness", OFFSET(t_expr), AV_OPT_TYPE_STRING, {.str="1"}, CHAR_MIN, CHAR_MAX, FLAGS }, + { "replace", "replace color & alpha", OFFSET(replace), AV_OPT_TYPE_BOOL, { .i64=0 }, 0, 1, FLAGS }, { NULL } };