From patchwork Wed Sep 16 05:09:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 22425 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 3648844B648 for ; Wed, 16 Sep 2020 08:10:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0A98F68B995; Wed, 16 Sep 2020 08:10:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from qq.com (out203-205-221-155.mail.qq.com [203.205.221.155]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 140976881FE for ; Wed, 16 Sep 2020 08:10:30 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1600233023; bh=GOt9ud4BHymHkD0q64OATGEQlqJrUf20W2WK+n5MIdo=; h=From:To:Cc:Subject:Date; b=UvphSnAr8CoJxKtBoIx+dfZIkOHtteTeGyIsh9QYWu241xqi3JmTqfrNIf3K0Rbm+ E+s4YAD9tKhkHPyHyfWcSse2EpATfSve/anHm0Jt7JtSHdZD/hxDLcC3b4sRHGmpYv wRGC2fIseyic+ROx+sf23WyxHCe4K8O+aQCKIFno= Received: from localhost.localdomain ([14.17.22.37]) by newxmesmtplogicsvrszc7.qq.com (NewEsmtp) with SMTP id 25C81C96; Wed, 16 Sep 2020 13:09:28 +0800 X-QQ-mid: xmsmtpt1600232968t50v5z75s Message-ID: X-QQ-XMAILINFO: OcBT4SkMQhJmux9SS5rTfYl75s0w8LF857W8n2Hk1rYXG6RUP6hsdxzTyhajsP 7NO3fGyKsPnn5u9QQfk2u7I2J1uTlN3wNJDrdPhMC9FWAONzlTQpn+6DsG9olH3QmjUK2UdO+ukX Mq23z351DbNU/nE9SzJ4YEuWUZ8OnKg2YQTfgRulJQREUKSlfFtt7jCsgD9aAmLxc+MDZrpmpA+L LOjnRwpsb3rat86W2VWmDMVoyb9ZVtXo2W07Tu9/BZP3RbJcfPh6NZWx0KM0+4NVDq2jsXQGHWBg lZPJH9sNfIxiDDsOJIrQm8qkYmmq3wqpXK5OauHTloew6wT44daHYdwtGgv9hgdxJZN34GcTXZae uqLH7l7Ti5sTbizgUHEZrKxQ2eExPnRr+iNT0SkxTUooakClKH3DW1bjrN8NZip2j+I5Ucth7sQO v5Z1f5k+5X/r8oyVUcY4A62WQB1uJPjtMInf3uFjseWczBNr9+Wyw7Hk4TrcobMTcOFVBDxjFxx+ 5Jqoe8pA1HCWttae9lNSEKF2xniVo/De6SVmsum7AiBxqntja/3AxE1JqLLCvY4aPP+7UlpUETyK /ZkGvYb+wqvK0iejgi2wXOq7hPWZC1FV6tJ1qKy4PoA9cw8NBMpzm4740BHxHV38MBXjWmtfzCHw 2YMuXYI1l7rlSaDowFJxrnYvhEukgg+nmrFcYx5FfQg+RCnPb0e3N1nkPvK6ejMWZz7rzbuPR+VE LVux8rWQbDubFsnn2FrwM64FTGLxcAzbg/ From: quinkblack@foxmail.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 16 Sep 2020 13:09:22 +0800 X-OQ-MSGID: <20200916050922.8920-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_delogo: remove duplicated code 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: Zhao Zhili MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Zhao Zhili 1. Remove the modification of x, y, w and h parameters since they are reset by filter_frame. 2. config_input leads to error out when logo area is outside of the frame, while filter_frame fix the parameters automatically. Make config_input don't return error to keep the logic consistent. --- libavfilter/vf_delogo.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index 6069c30163..39f06512fa 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -271,11 +271,6 @@ static av_cold int init(AVFilterContext *ctx) av_log(ctx, AV_LOG_VERBOSE, "x:%d y:%d, w:%d h:%d band:%d show:%d\n", s->x, s->y, s->w, s->h, s->band, s->show); - s->w += s->band*2; - s->h += s->band*2; - s->x -= s->band; - s->y -= s->band; - return 0; } @@ -284,10 +279,21 @@ static int config_input(AVFilterLink *inlink) DelogoContext *s = inlink->dst->priv; /* Check whether the logo area fits in the frame */ - if (s->x + (s->band - 1) < 0 || s->x + s->w - (s->band*2 - 2) > inlink->w || - s->y + (s->band - 1) < 0 || s->y + s->h - (s->band*2 - 2) > inlink->h) { - av_log(s, AV_LOG_ERROR, "Logo area is outside of the frame.\n"); - return AVERROR(EINVAL); + if (s->x + (s->band - 1) <= 0 || s->x + s->w - (s->band*2 - 2) > inlink->w || + s->y + (s->band - 1) <= 0 || s->y + s->h - (s->band*2 - 2) > inlink->h) { + av_log(s, AV_LOG_WARNING, "Logo area is outside of the frame," + " logo(x:%d y:%d w:%d h:%d), frame(%dx%d)," + " auto set the area inside of the frame." + " Note: x and y must be 1 at least.\n", + s->x, s->y, s->w, s->h, inlink->w, inlink->h); + if (s->x + (s->band - 1) <= 0) + s->x = 1 + s->band; + if (s->y + (s->band - 1) <= 0) + s->y = 1 + s->band; + if (s->x + s->w - (s->band*2 - 2) > inlink->w) + s->w = inlink->w - s->x - (s->band*2 - 2); + if (s->y + s->h - (s->band*2 - 2) > inlink->h) + s->h = inlink->h - s->y - (s->band*2 - 2); } return 0; @@ -313,21 +319,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) s->w = av_expr_eval(s->w_pexpr, s->var_values, s); s->h = av_expr_eval(s->h_pexpr, s->var_values, s); - if (s->x + (s->band - 1) <= 0 || s->x + s->w - (s->band*2 - 2) > inlink->w || - s->y + (s->band - 1) <= 0 || s->y + s->h - (s->band*2 - 2) > inlink->h) { - av_log(s, AV_LOG_WARNING, "Logo area is outside of the frame," - " auto set the area inside of the frame\n"); - } - - if (s->x + (s->band - 1) <= 0) - s->x = 1 + s->band; - if (s->y + (s->band - 1) <= 0) - s->y = 1 + s->band; - if (s->x + s->w - (s->band*2 - 2) > inlink->w) - s->w = inlink->w - s->x - (s->band*2 - 2); - if (s->y + s->h - (s->band*2 - 2) > inlink->h) - s->h = inlink->h - s->y - (s->band*2 - 2); - ret = config_input(inlink); if (ret < 0) { av_frame_free(&in);