From patchwork Tue Jun 6 04:43:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Mark X-Patchwork-Id: 3854 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.10.2 with SMTP id 2csp1671527vsk; Mon, 5 Jun 2017 21:43:44 -0700 (PDT) X-Received: by 10.223.145.195 with SMTP id 61mr17467525wri.43.1496724224445; Mon, 05 Jun 2017 21:43:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496724224; cv=none; d=google.com; s=arc-20160816; b=rJrR0IaGxFLjr4lkLsLLxLvenV07Wi0sm43mTezzN/JH720lDZYmsOj5crz5M7NN4+ ROtiZ4PEcahDgQ+ShcWM0O6WKwmYgl7TMqlzvzkKt96t9S1Hy/DfDIJbdxILZUOtLaMm eFDNk4TCPwyFf0mWS/hlo2Ja8Ql9iYuEjandZaY1NIDoPSCPvIawEJUM3gyZse6RhknP 0/3F4EqCD7waEjWXvZ0B2iqMtAJk+kqmgSWCLWowZIbgvWo9AxfPwJknMa1b35hig0B3 h1IDRpKna6WJ51sn18lyCUj3Vn9URt+9bw+oO5kfR2Bat0OvFbrCWD2a9bcb9077eBl4 UUpg== 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:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=HVVYZGqJt+Z4sDTBgyT40jlBD8ldQxIItqEPQc/Look=; b=iTcDvYLGSOGvS+QE3TEwFb9k1zWGjI1lx3wn4CbYQsIhLCzm59LwnMimrHELzyzp+R SZpukmPwE8Top4OaPoPKzPHaB6nOM3raMaP9HH+kUCkJF04GatRrJCQAVaQgsA14IEu5 nvbbxEsR7VXAoT8fWr0ggB8kWDheQK98OiAo2planRvY1r9OM1rBLyVpvSaj5j96Hely ge4S3G7cxzqI5hELZDen1vvIJTDU4kgVhVb5/IIjU8yEBsd3hsrllLMNXuG/gctbnjQt fGUuB0m8OP3RePcTyewNH8bco4fKbejg9EjD5rwLKzgxGhXpUEjNbKOSJ0gI/0xXK8Pn ZbHQ== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e133si15356100wma.1.2017.06.05.21.43.43; Mon, 05 Jun 2017 21:43: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 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 D647A689DCB; Tue, 6 Jun 2017 07:43:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 520FE689834 for ; Tue, 6 Jun 2017 07:43:26 +0300 (EEST) Received: by mail-qt0-f195.google.com with SMTP id x58so13708697qtc.2 for ; Mon, 05 Jun 2017 21:43:33 -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=sbEFtxIfya1z8MXuUGCtkeV4ZkfC1UHsv37OPJ3fBkw=; b=ZfbN25yBT8hPW6y8XIfQFXcQcU9/g55rm0S9y/iStOiEEuz49HefWoEPBXnvVEQ3tJ gq5BeAFNA0vm59gfLQ5Nul+MfBq9Sob8quyqSKPYhYBK6D4srkSnhy0JQDTN6Puu9zJB 93SsAvCUsCC8uIADbyMZb9WCrx5LM5G8kvYXki6EgKMk3m65B6vFK/scMJkOixjxtdrK TtoijwqmR5rVgkwJTdFr068kQdJB0N/STMhJGL7oWfwG5m0jsv9nGOqNndD4XAAdVssh votfjUr6EcJSA1NGxGlsGLLq01vZ971BMuWT//a0qBo0+lIhYJwQb3OyzuRc4uW6sNlY xsxQ== 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=sbEFtxIfya1z8MXuUGCtkeV4ZkfC1UHsv37OPJ3fBkw=; b=rVlwdcAvcZsopeq3D6i6mKJljOIDVuzXsB6Yr3Ys7tI3qmmO9wbfxHkxBLVyQMEocF i9oSjp2Tt+VJNmCjrbU8e0ACNegyACgpnAiTcFxfBNBh8IsGEgQOFx0gOiaKmpmx8C/f nv0yYqbKv03nYIwLet8YDlkPKkcoNxfrwEtRFXFz4YPn7d7ILOpu1+3egLLAywWOXBdF 75/NDOpuALP7sjhkD9ecJxWopT7jIFmjem2htr0Fc9f2hQF1gPR3EO1M2RWjhrdvC8aW kSirLRJA/+N5GyP6rnS6ODUBJdbv1MndAOPyG1egeiJKhV2P5u0rMOHieTC5y6Y0wlUx 24GQ== X-Gm-Message-State: AODbwcAt0KAYU09MQW87yUGSWku2tT4u7PCrjjUfdZiaGPpdUEE9yEVR bNCzg0i4CcGcREqBIgA= X-Received: by 10.200.42.171 with SMTP id b40mr28644981qta.122.1496724212081; Mon, 05 Jun 2017 21:43:32 -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 26sm666166qkw.4.2017.06.05.21.43.31 (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 05 Jun 2017 21:43:31 -0700 (PDT) From: Kevin Mark To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Jun 2017 00:43:13 -0400 Message-Id: <20170606044313.77983-1-kmark937@gmail.com> X-Mailer: git-send-email 2.13.0 Subject: [FFmpeg-devel] [PATCH] libavutil/eval: Add round function to expression parser 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" We have floor, ceil, and trunc. Let's add round. Signed-off-by: Kevin Mark --- doc/utils.texi | 3 +++ libavutil/eval.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/utils.texi b/doc/utils.texi index 1734439459..d65bdf0b0e 100644 --- a/doc/utils.texi +++ b/doc/utils.texi @@ -914,6 +914,9 @@ various input values that the expression can access through @code{ld(0)}. When the expression evaluates to 0 then the corresponding input value will be returned. +@item round(expr) +Round the value of expression @var{expr} to the nearest integer. For example, "round(1.5)" is "2.0". + @item sin(x) Compute sine of @var{x}. diff --git a/libavutil/eval.c b/libavutil/eval.c index 7e866155db..638259adef 100644 --- a/libavutil/eval.c +++ b/libavutil/eval.c @@ -153,7 +153,7 @@ struct AVExpr { e_squish, e_gauss, e_ld, e_isnan, e_isinf, e_mod, e_max, e_min, e_eq, e_gt, e_gte, e_lte, e_lt, e_pow, e_mul, e_div, e_add, - e_last, e_st, e_while, e_taylor, e_root, e_floor, e_ceil, e_trunc, + e_last, e_st, e_while, e_taylor, e_root, e_floor, e_ceil, e_trunc, e_round, e_sqrt, e_not, e_random, e_hypot, e_gcd, e_if, e_ifnot, e_print, e_bitand, e_bitor, e_between, e_clip, e_atan2 } type; @@ -189,6 +189,7 @@ static double eval_expr(Parser *p, AVExpr *e) case e_floor: return e->value * floor(eval_expr(p, e->param[0])); case e_ceil : return e->value * ceil (eval_expr(p, e->param[0])); case e_trunc: return e->value * trunc(eval_expr(p, e->param[0])); + case e_round: return e->value * round(eval_expr(p, e->param[0])); case e_sqrt: return e->value * sqrt (eval_expr(p, e->param[0])); case e_not: return e->value * (eval_expr(p, e->param[0]) == 0); case e_if: return e->value * (eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) : @@ -440,6 +441,7 @@ static int parse_primary(AVExpr **e, Parser *p) else if (strmatch(next, "floor" )) d->type = e_floor; else if (strmatch(next, "ceil" )) d->type = e_ceil; else if (strmatch(next, "trunc" )) d->type = e_trunc; + else if (strmatch(next, "round" )) d->type = e_round; else if (strmatch(next, "sqrt" )) d->type = e_sqrt; else if (strmatch(next, "not" )) d->type = e_not; else if (strmatch(next, "pow" )) d->type = e_pow; @@ -637,6 +639,7 @@ static int verify_expr(AVExpr *e) case e_floor: case e_ceil: case e_trunc: + case e_round: case e_sqrt: case e_not: case e_random: