From patchwork Mon Apr 3 18:34:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Constantino X-Patchwork-Id: 3272 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.44.195 with SMTP id s186csp204362vss; Mon, 3 Apr 2017 11:34:31 -0700 (PDT) X-Received: by 10.223.130.36 with SMTP id 33mr16859253wrb.150.1491244471508; Mon, 03 Apr 2017 11:34:31 -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 i42si21028395wra.68.2017.04.03.11.34.31; Mon, 03 Apr 2017 11:34:31 -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 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 DFA0E680AF7; Mon, 3 Apr 2017 21:34:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f171.google.com (mail-wr0-f171.google.com [209.85.128.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F0E17680949 for ; Mon, 3 Apr 2017 21:34:19 +0300 (EEST) Received: by mail-wr0-f171.google.com with SMTP id w11so180363642wrc.3 for ; Mon, 03 Apr 2017 11:34:21 -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; bh=S8PKnS7B7CVCsPEIsh6skEEXEzPgb5En2peC52jCNOA=; b=TB/6kBWxKqP4g5E8D+QlLhvasK5yWt5QdirHQXqOa4xvTK6c0Dmc8bmMZv7POVmNdY Pv9tecU+wbeh4MEMqC55iu6QI7/+66BbpneP1i/aMRcTP7ztJ8kfy94AYf/cqJD7+0/f ZDO3iYdT8wViw4lU6//cvaxTBqGp2nZeNqdtOI+fNn+1/g3zftRZZmjoC+rNleIc1oxo jRmun+AOtxHnmOoDToF+NRBszGbBhmOp/IKg7JOyKTZ4zwnl695RmWTYGDdzVrxuMlUv 0s8byeNBiJI52Ps32B2HR85LeU5gMjqVUxcCZakxfyGfoAE0bJKMmYKU3WiEq2O5bcxi 5ntw== 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; bh=S8PKnS7B7CVCsPEIsh6skEEXEzPgb5En2peC52jCNOA=; b=frAJbO0S4LZrpzhdo6zEC6xpJXbsxqGIftw0nwHlG4UdBovRPI11PbEeWIsvdAIMHG bnNveag6YU8jruo9gr7t1wvn0jxdCbJ1LxL67YvrhFAdvml/6dzigJsccrHXN3VsDHTM cbsRJyNKAFNyMLKcicPuKW9HW2rAmFm4J2uOcpxVEaLW/wxbCneRAK4mVvGqDyFYeqjq FBUeR2M0IKDkXuGChEaUX4Z4DwG9doOY5cq3m7aNgMRjIFBBkkaaB7pQmuldj0R01jyY WvUky8vxbcAfbY54meH6n7eBoFaF5hrDoqECm5MNJ/rnX/MiqoGKiuBYgg4F+W8UaxK0 fTLQ== X-Gm-Message-State: AFeK/H3x9Loyy2OHQj5A3ci+e1ll5s2Vfml1nSJmod0qfQ3zsnilp3vLGYTnkqtMvpCS5A== X-Received: by 10.28.128.209 with SMTP id b200mr11569568wmd.140.1491244461199; Mon, 03 Apr 2017 11:34:21 -0700 (PDT) Received: from localhost.localdomain (10.246.114.89.rev.vodafone.pt. [89.114.246.10]) by smtp.gmail.com with ESMTPSA id y43sm1217216wrd.62.2017.04.03.11.34.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Apr 2017 11:34:20 -0700 (PDT) From: Ricardo Constantino To: ffmpeg-devel@ffmpeg.org Date: Mon, 3 Apr 2017 19:34:09 +0100 Message-Id: <20170403183409.10892-1-wiiaboo@gmail.com> X-Mailer: git-send-email 2.12.1 Subject: [FFmpeg-devel] [PATCH] vf_pad: center image on padded area if negative x/y 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" or if x/y go beyond padded area. This is mostly useful when paired with the aspect option. Defaults aren't changed. Idea for this was taken from mpv's soon-to-be-removed expand vf. --- doc/filters.texi | 3 +++ libavfilter/vf_pad.c | 12 +++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index bc37e667e0..32720dba41 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -10430,6 +10430,9 @@ expression, and vice versa. The default value of @var{x} and @var{y} is 0. +If @var{x} or @var{y} evaluate to a negative number, they'll be changed +so the input image is centered on the padded area. + @item color Specify the color of the padded area. For the syntax of this option, check the "Color" section in the ffmpeg-utils manual. diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c index 5b81379691..757170e742 100644 --- a/libavfilter/vf_pad.c +++ b/libavfilter/vf_pad.c @@ -173,8 +173,13 @@ static int config_input(AVFilterLink *inlink) goto eval_fail; s->x = var_values[VAR_X] = res; + if (s->x < 0 || s->x + inlink->w > s->w) + s->x = var_values[VAR_X] = (s->w - inlink->w) / 2; + if (s->y < 0 || s->y + inlink->h > s->h) + s->y = var_values[VAR_Y] = (s->h - inlink->h) / 2; + /* sanity check params */ - if (s->w < 0 || s->h < 0 || s->x < 0 || s->y < 0) { + if (s->w < 0 || s->h < 0) { av_log(ctx, AV_LOG_ERROR, "Negative values are not acceptable.\n"); return AVERROR(EINVAL); } @@ -192,10 +197,7 @@ static int config_input(AVFilterLink *inlink) inlink->w, inlink->h, s->w, s->h, s->x, s->y, s->rgba_color[0], s->rgba_color[1], s->rgba_color[2], s->rgba_color[3]); - if (s->x < 0 || s->y < 0 || - s->w <= 0 || s->h <= 0 || - (unsigned)s->x + (unsigned)inlink->w > s->w || - (unsigned)s->y + (unsigned)inlink->h > s->h) { + if (s->w <= 0 || s->h <= 0) { av_log(ctx, AV_LOG_ERROR, "Input area %d:%d:%d:%d not within the padded area 0:0:%d:%d or zero-sized\n", s->x, s->y, s->x + inlink->w, s->y + inlink->h, s->w, s->h);