From patchwork Tue Sep 13 23:38:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 567 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp2388554vsd; Tue, 13 Sep 2016 16:38:45 -0700 (PDT) X-Received: by 10.194.140.77 with SMTP id re13mr10382980wjb.79.1473809925005; Tue, 13 Sep 2016 16:38:45 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e23si1185757wmc.77.2016.09.13.16.38.39; Tue, 13 Sep 2016 16:38:44 -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; dkim=neutral (body hash did not verify) header.i=@gmail.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; dmarc=fail (p=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 35E3C68A050; Wed, 14 Sep 2016 02:38:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4A59868A049 for ; Wed, 14 Sep 2016 02:38:19 +0300 (EEST) Received: by mail-wm0-f65.google.com with SMTP id g141so499wmd.1 for ; Tue, 13 Sep 2016 16:38:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=WK0rmhjuAZql79bK93eu1ooyd8gujgUonOaqqEvftXE=; b=VTbrYQevqyMoUYvD7YvDh5TH/wZpPxhy+mAKxs06i3jkGEB36IymE9zUmKzqhrsubr BxA43QCsneSI+2SrQe2B8A4cNE0KrL4kxmp3Ff096hjbw0MzXBAtWLYm1kkso0w2jJIj L7Gwgy1xlg4Kt0olDUe/BxPEZxeUNEbgtqNxKN4XO/LjZzQVs/N/r8Sw3trQ58enBXWq H5z8iwTqs0LAIY3CPNUL/dFh5xQbvSEZUwBkM9xDcypM4GltBuRmctuvurJbkUsxMr3V IQv0gpFZxFBGxQ0Z7e/0JT3f2USLjsTEDUpXcOnAU/ZFgPAlt4UJsSF9l4Aa0qRfn4hk u5gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=WK0rmhjuAZql79bK93eu1ooyd8gujgUonOaqqEvftXE=; b=CcOHxpFQQCrsvcV1pwvlyNM/hxx8vgZ71jSkMPXX4luob1gynq6vd7oZe3W1+/J8ED c7kLP/7mHIYZOQqmaxDVx/8zH+/LHJT2GYaG3F1lOfw27SNlgZs5sLOx0bmjlcR4ygHv iIpNW/LflXRg6SX3NMfR2YYTb1oP/hQ+OqhiqV8IlPhLjuotCa0tR5Up5hvj6ww8YMlA 0MpmTFNbv2/kIyQfUWDoGqFtXu/5UY+JG/72TDHBeaZmubmaO6iip7yAuAhVlqmUWf+C jIVwEQQfSWQVthwudmYUUBPeNGdvREB1WRu1iaVSsMIcshGd5iyoG234SjiDfVBjlQdF 1qoA== X-Gm-Message-State: AE9vXwMYpvahXmcH3++cTKpo8hMJLHQeP2ADAgHTxzWwCb1zJ1iwk+kx0CZYNfBOTi6oRg== X-Received: by 10.28.129.145 with SMTP id c139mr59178wmd.102.1473809911192; Tue, 13 Sep 2016 16:38:31 -0700 (PDT) Received: from computer.gigaset.lan (141-136-220-60.dsl.iskon.hr. [141.136.220.60]) by smtp.gmail.com with ESMTPSA id f123sm1124943wmf.11.2016.09.13.16.38.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Sep 2016 16:38:30 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Wed, 14 Sep 2016 01:38:20 +0200 Message-Id: <1473809900-18068-1-git-send-email-onemda@gmail.com> X-Mailer: git-send-email 2.5.0 Subject: [FFmpeg-devel] [PATCH] avfilter/drawutils: allow drawing opaque text on transparent background 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- Fixes #3302. --- libavfilter/drawutils.c | 7 ++++--- libavfilter/drawutils.h | 1 + libavfilter/vf_drawtext.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libavfilter/drawutils.c b/libavfilter/drawutils.c index f6760be..905eaa3 100644 --- a/libavfilter/drawutils.c +++ b/libavfilter/drawutils.c @@ -211,10 +211,11 @@ int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags) draw->desc = desc; draw->format = format; draw->nb_planes = nb_planes; + draw->flags = flags; memcpy(draw->pixelstep, pixelstep, sizeof(draw->pixelstep)); draw->hsub[1] = draw->hsub[2] = draw->hsub_max = desc->log2_chroma_w; draw->vsub[1] = draw->vsub[2] = draw->vsub_max = desc->log2_chroma_h; - for (i = 0; i < (desc->nb_components - !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)); i++) + for (i = 0; i < (desc->nb_components - !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA && !(flags & 1))); i++) draw->comp_mask[desc->comp[i].plane] |= 1 << desc->comp[i].offset; return 0; @@ -452,7 +453,7 @@ void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color, /* 0x101 * alpha is in the [ 2 ; 0x1001] range */ alpha = 0x101 * color->rgba[3] + 0x2; } - nb_planes = draw->nb_planes - !!(draw->desc->flags & AV_PIX_FMT_FLAG_ALPHA); + nb_planes = draw->nb_planes - !!(draw->desc->flags & AV_PIX_FMT_FLAG_ALPHA && !(draw->flags & 1)); nb_planes += !nb_planes; for (plane = 0; plane < nb_planes; plane++) { nb_comp = draw->pixelstep[plane]; @@ -630,7 +631,7 @@ void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, } else { alpha = (0x101 * color->rgba[3] + 0x2) >> 8; } - nb_planes = draw->nb_planes - !!(draw->desc->flags & AV_PIX_FMT_FLAG_ALPHA); + nb_planes = draw->nb_planes - !!(draw->desc->flags & AV_PIX_FMT_FLAG_ALPHA && !(draw->flags & 1)); nb_planes += !nb_planes; for (plane = 0; plane < nb_planes; plane++) { nb_comp = draw->pixelstep[plane]; diff --git a/libavfilter/drawutils.h b/libavfilter/drawutils.h index 1fb3e4f..11ec97a 100644 --- a/libavfilter/drawutils.h +++ b/libavfilter/drawutils.h @@ -55,6 +55,7 @@ typedef struct FFDrawContext { uint8_t vsub[MAX_PLANES]; /*< vertical subsampling */ uint8_t hsub_max; uint8_t vsub_max; + unsigned flags; } FFDrawContext; typedef struct FFDrawColor { diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 214aef0..996c26d 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -730,7 +730,7 @@ static int config_input(AVFilterLink *inlink) DrawTextContext *s = ctx->priv; int ret; - ff_draw_init(&s->dc, inlink->format, 0); + ff_draw_init(&s->dc, inlink->format, 1); ff_draw_color(&s->dc, &s->fontcolor, s->fontcolor.rgba); ff_draw_color(&s->dc, &s->shadowcolor, s->shadowcolor.rgba); ff_draw_color(&s->dc, &s->bordercolor, s->bordercolor.rgba);