From patchwork Wed Jun 14 05:03:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Mark X-Patchwork-Id: 3974 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.22.4 with SMTP id 4csp141858vsw; Tue, 13 Jun 2017 22:07:03 -0700 (PDT) X-Received: by 10.28.12.2 with SMTP id 2mr13630990wmm.39.1497416823021; Tue, 13 Jun 2017 22:07:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497416822; cv=none; d=google.com; s=arc-20160816; b=IA4kjjq7S4nD/2EU4k1979xuPNjBG/e2f71/0f3pxZeltaedLFt3XWMiO5bM8P7GCd +Gbwqw7Bh/HCnO4Lf+QJ4TRIbRA0rcbQQx0Ec688/Q3Z/GtJoItnWQ1ZzuLEsq3mhLfI F0NO27mv7o6g5etbV/SZ5yPydjUc4TBf4ePuNglJzlR5MY82zfT3jVFsS4HxN4sn/JPL u5rVsQNluoSTnewinjUhgfdsmuHq4ZR2BzdR2CjXSCs88q4iBXMefExfdeP7G9LyVJN7 tqxSJT9HZYTsmNeAqUq1lcp/Vile2zXuj0gLH/YeJ2nXhdovUyImUczpIEoVuxsEcban ahYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=iHzMO/abYh7xzVXl2e/c3Yg0HSxcOrKDQ45zPx9uFxw=; b=aAJlavzRUNt2DqKJ5idblrKVh1sqSe2Ia7fLfkZcr3WFMyw3DPL16WJbC4EFc8bCJi 6ofAsjlA8g1yIZJAlTdU6O7/WHznV2Lv05KdWSTc7GabTXUjYVp0UlZU3gaGb33H5DMr d+Z1t8KJ7KsDsxxCPqLMI4OyDdeRqZugLqjR+FI8wFFOXY1E67EVWfY7E5mq0UCTM0cm KMFjHvBwbUoW97K3/R8G4F2Mmn/wlAvrS8JWWk0uHKqEwxZ+/RG7dOvdV5fPF907tFoz bYkeoQeaeNp594IZyUUz9kCKLWh5OjRB6ssSNtiehRkNXbJQ678/97SRQhzTaghBFwiM i21w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=FPAYVLx3; 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 193si13488018wmw.153.2017.06.13.22.07.02; Tue, 13 Jun 2017 22:07:02 -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 header.b=FPAYVLx3; 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 E3328689FBE; Wed, 14 Jun 2017 08:06:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f196.google.com (mail-qk0-f196.google.com [209.85.220.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1721D689E99 for ; Wed, 14 Jun 2017 08:06:51 +0300 (EEST) Received: by mail-qk0-f196.google.com with SMTP id u8so2258910qka.0 for ; Tue, 13 Jun 2017 22:06:53 -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:in-reply-to:references; bh=4GVSFFo8AV0jCZSizfkd6FqJFL+DL/2FkMf9ADQjF+A=; b=FPAYVLx3M1xst8RQ98pd2QokXeDfpSXMW5znfnNBLL++fH6Z/zuDhC7jqhKw2edIks iJhNTY3zgdv8gNngreAey+Xg5+2DV5C1i2w/UDkKYaXRFfbx5zBZWpJIZRyfUc7x7Imx eI1XWke4SnTCSJAzwHH86sXm0qVH2J3BL7gcxXvKfojcKzDOm2M+HQxTNgidL3ajX3wU Wk0EclvsJbCIl//28DnfKBtxdGjNJsvKKTRekbg8Q3Cmk7n26jFDMRlzi2CW4WC+OzIH 7e3z/YYBk7YPp2Wtg4xc/ZwSiYFA1UWqd5TnyOSn4Qxbao5Q7+wA017hQ9kZwRvu3ew9 UccQ== 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:in-reply-to :references; bh=4GVSFFo8AV0jCZSizfkd6FqJFL+DL/2FkMf9ADQjF+A=; b=k6GxZ/Ht2HAQfkmIaj//VHbXr1z1NCqLI+IyuYX6x1gmE43ItScnGNGiJwuDzIfxAU iwmhnxlyWu3f7M63dtVL0JnO8AmmFXFROmiO2hQmmZj1KpuVTE8UOovzMMs6h+X/Dg5Y 8YLDY29GyWpJvHleysHFBAN4Fpz3U1hkeFWniNaY3gCMVhNtwGSATvp9upVZ8lqWEnF/ dpAWOBAWl0wRQ78d02Q1HOQ+wXxYIjhsz2A1TLCw6BboHmyF00REqvJkSj/ikyTGSzUp aMnV+erzKzjI5LsZZQx4JxZBU8M96QhngweXJ62yteAl2nV06vjH1tl592ZcnzW0tM+n U9Ag== X-Gm-Message-State: AKS2vOyTwbCwKVWOimF2G/hwUR+Qrm5LXySVaqp1+CXL5beLU2tnZrt+ EF20+yD2goQf5aMtStg= X-Received: by 10.55.17.83 with SMTP id b80mr4431975qkh.5.1497416812349; Tue, 13 Jun 2017 22:06:52 -0700 (PDT) Received: from Klingon.fios-router.home (pool-173-69-140-247.bltmmd.fios.verizon.net. [173.69.140.247]) by smtp.gmail.com with ESMTPSA id j54sm4962674qtc.59.2017.06.13.22.06.51 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 13 Jun 2017 22:06:51 -0700 (PDT) From: Kevin Mark To: ffmpeg-devel@ffmpeg.org Date: Wed, 14 Jun 2017 01:03:18 -0400 Message-Id: <20170614050318.16835-1-kmark937@gmail.com> X-Mailer: git-send-email 2.13.1 In-Reply-To: References: Subject: [FFmpeg-devel] [PATCH] libavfilter/scale: Populate ow/oh when using 0 as w/h 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: Kevin Mark MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The input width and height is known at parse time so there's no reason ow/oh should not be usable when using 0 as the width or height expression. Previously in "scale=0:ow" ow would be set to "0" which works, conveniently, as "scale=0:0" is perfectly valid input but this breaks down when you do something like "scale=0:ow/4" which one could reasonably expect to work as well, but does not as ow is 0 not the real value. This change handles the 0 case for w/h immediately so the ow/oh variables work as expected. Consequently, the rest of the code does not need to handle 0 input. w/h will always be > 0 or < 0. The second explicit (int) cast ensures that ow/oh appear as integers as a user might expect when dealing with pixel dimensions. Signed-off-by: Kevin Mark --- libavfilter/scale.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/libavfilter/scale.c b/libavfilter/scale.c index 03745ddcb8..eaee95fac6 100644 --- a/libavfilter/scale.c +++ b/libavfilter/scale.c @@ -158,19 +158,19 @@ int ff_scale_eval_dimensions(void *log_ctx, av_expr_parse_and_eval(&res, (expr = w_expr), names, var_values, NULL, NULL, NULL, NULL, NULL, 0, log_ctx); - eval_w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res; + eval_w = var_values[VAR_OUT_W] = var_values[VAR_OW] = (int) res == 0 ? inlink->w : (int) res; if ((ret = av_expr_parse_and_eval(&res, (expr = h_expr), names, var_values, NULL, NULL, NULL, NULL, NULL, 0, log_ctx)) < 0) goto fail; - eval_h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res; + eval_h = var_values[VAR_OUT_H] = var_values[VAR_OH] = (int) res == 0 ? inlink->h : (int) res; /* evaluate again the width, as it may depend on the output height */ if ((ret = av_expr_parse_and_eval(&res, (expr = w_expr), names, var_values, NULL, NULL, NULL, NULL, NULL, 0, log_ctx)) < 0) goto fail; - eval_w = res; + eval_w = (int) res == 0 ? inlink->w : (int) res; w = eval_w; h = eval_h; @@ -186,13 +186,10 @@ int ff_scale_eval_dimensions(void *log_ctx, factor_h = -h; } - if (w < 0 && h < 0) - eval_w = eval_h = 0; - - if (!(w = eval_w)) + if (w < 0 && h < 0) { w = inlink->w; - if (!(h = eval_h)) h = inlink->h; + } /* Make sure that the result is divisible by the factor we determined * earlier. If no factor was set, it is nothing will happen as the default