[FFmpeg-devel] [PATCH] lavu/eval: add clip function

Michael Niedermayer michaelni at gmx.at
Mon Jul 7 20:58:50 CEST 2014


On Fri, Jul 04, 2014 at 04:40:50PM +0200, Stefano Sabatini wrote:
> On date Friday 2014-07-04 14:26:45 +0200, Clément Bœsch encoded:
> > On Fri, Jul 04, 2014 at 02:13:58PM +0200, Stefano Sabatini wrote:
> > > TODO: bump micro
> > > ---
> > >  doc/utils.texi   | 4 ++++
> > >  libavutil/eval.c | 6 +++++-
> > >  2 files changed, 9 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/doc/utils.texi b/doc/utils.texi
> > > index 5abfb0c..83ff8b0 100644
> > > --- a/doc/utils.texi
> > > +++ b/doc/utils.texi
> > > @@ -782,6 +782,10 @@ large numbers (usually 2^53 and larger).
> > >  Round the value of expression @var{expr} upwards to the nearest
> > >  integer. For example, "ceil(1.5)" is "2.0".
> > >  
> > > + at item clip(x, min, max)
> > > +Return the value of @var{x} clipped between @var{min} and
> > > + at var{max}. Result is undefined if @var{min} is greater than @var{max}.
> > > +
> > 
> > You should add an extra check, because depending on the build
> > configuration it can be used to make ffmpeg abort.
> 
> Yeah. Also checking for NAN adds a lot of additional code. If we just
> want to avoid the abort() we can avoid the NAN checks. Another
> alternative would be to have a clip-safe slower function which
> performs checks on NAN.
> -- 
> FFmpeg = Forgiving and Furious Multimedia Patchable Exploitable Gymnast

>  doc/utils.texi      |    3 +++
>  libavutil/eval.c    |   14 +++++++++++++-
>  tests/ref/fate/eval |    9 +++++++++
>  3 files changed, 25 insertions(+), 1 deletion(-)
> c298677d930d4754b2ce78196d528d7f706aec9a  0003-lavu-eval-add-clip-function.patch
> From 819c751de01b542d22769b58f9b0e7f3be6bb810 Mon Sep 17 00:00:00 2001
> From: Stefano Sabatini <stefasab at gmail.com>
> Date: Fri, 4 Jul 2014 14:13:11 +0200
> Subject: [PATCH] lavu/eval: add clip function
> 
> TODO: bump micro
> ---
>  doc/utils.texi      |  3 +++
>  libavutil/eval.c    | 14 +++++++++++++-
>  tests/ref/fate/eval |  9 +++++++++
>  3 files changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/utils.texi b/doc/utils.texi
> index 5abfb0c..b92691f 100644
> --- a/doc/utils.texi
> +++ b/doc/utils.texi
> @@ -782,6 +782,9 @@ large numbers (usually 2^53 and larger).
>  Round the value of expression @var{expr} upwards to the nearest
>  integer. For example, "ceil(1.5)" is "2.0".
>  
> + at item clip(x, min, max)
> +Return the value of @var{x} clipped between @var{min} and @var{max}.
> +
>  @item cos(x)
>  Compute cosine of @var{x}.
>  
> diff --git a/libavutil/eval.c b/libavutil/eval.c
> index 4a313bf..1c53b79 100644
> --- a/libavutil/eval.c
> +++ b/libavutil/eval.c
> @@ -147,7 +147,7 @@ struct AVExpr {
>          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_sqrt, e_not, e_random, e_hypot, e_gcd,
> -        e_if, e_ifnot, e_print, e_bitand, e_bitor, e_between,
> +        e_if, e_ifnot, e_print, e_bitand, e_bitor, e_between, e_clip
>      } type;
>      double value; // is sign in other types
>      union {
> @@ -187,6 +187,13 @@ static double eval_expr(Parser *p, AVExpr *e)
>                                            e->param[2] ? eval_expr(p, e->param[2]) : 0);
>          case e_ifnot:  return e->value * (!eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) :
>                                            e->param[2] ? eval_expr(p, e->param[2]) : 0);
> +        case e_clip: {
> +            double x = eval_expr(p, e->param[0]);
> +            double min = eval_expr(p, e->param[1]), max = eval_expr(p, e->param[2]);
> +            if (isnan(min) || isnan(max) || isnan(x) || min > max)
> +                return NAN;

> +            return e->value * av_clip(eval_expr(p, e->param[0]), min, max);

this should be av_clipd()

should be ok otherwise

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If a bugfix only changes things apparently unrelated to the bug with no
further explanation, that is a good sign that the bugfix is wrong.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140707/0e8a3efc/attachment.asc>


More information about the ffmpeg-devel mailing list