[FFmpeg-devel] [PATCH] life source

Clément Bœsch ubitux at gmail.com
Sun Dec 4 18:05:04 CET 2011


On Sun, Dec 04, 2011 at 01:16:21PM +0100, Stefano Sabatini wrote:
> On date Sunday 2011-11-20 20:11:05 +0100, Clément Bœsch encoded:
> > On Sat, Nov 19, 2011 at 11:14:46PM +0100, Stefano Sabatini wrote:
> > > On date Sunday 2011-06-26 20:11:52 +0200, Stefano Sabatini encoded:
> > > > From 680fc136c9f85e289b86195dc54e5b76bffe6b97 Mon Sep 17 00:00:00 2001
> > > > From: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> > > > Date: Sun, 26 Jun 2011 19:47:18 +0200
> > > > Subject: [PATCH] lavfi: add lifesrc source
> > > > 
> > > > ---
> > > >  libavfilter/Makefile       |    1 +
> > > >  libavfilter/allfilters.c   |    1 +
> > > >  libavfilter/vsrc_lifesrc.c |  305 ++++++++++++++++++++++++++++++++++++++++++++
> > > >  3 files changed, 307 insertions(+), 0 deletions(-)
> > > >  create mode 100644 libavfilter/vsrc_lifesrc.c
> > > 
> > > Well since I'm in an all-play-no-work mood I worked to an updated
> > > version.
> > > 
> > > I could also add support to "bricks" (cells which can't never be
> > > filled) and provide an option for specifying connected topology, but
> > > that can be done later.
> > > 
> > > Example:
> > > ffplay -f lavfi "lifesrc=f=CREDITS:s=300x300:rule=21219, boxblur=2:2, negate"
> > 
> > fun :)
> > 
> > [...]
> > > +
> > > +    if (!life->filename) {
> > > +        av_log(ctx, AV_LOG_ERROR, "No filename specified, aborting\n");
> > > +        return AVERROR(EINVAL);
> > > +    }
> > > +
> > > +    if ((ret = init_pattern_from_file(ctx) < 0))
> > > +        return ret;
> > 
> > if ((ret = ...) < 0), or else it will crash with for instance an empty
> > file.
> 
> Fixed.
>  
> > BTW, I agree with both Michael and Nicolas about having it upstream (I
> > want to do something on it :)) and the random init board in case of no
> > file.
> 
> Added random grid generation in case of no specified file (based on a
> simple probabilistic approach), border stitching (by default) and
> implemented a saner syntax for specifying rules based on the game of
> life Wikipedia article. Also changed the name lifesrc -> life.
> 

We will need to add FFmpeg in the "Notable Life programs" section now ;)

> I'll apply it in a few days if no one has more comments, documentation
> remarks are especially appreciated.
> -- 
> FFmpeg = Free Forgiving Mysterious Portable Efficient Guru

> From 807a3d6a306070a3d64cb367187a91fde2656e29 Mon Sep 17 00:00:00 2001
> From: Stefano Sabatini <stefasab at gmail.com>
> Date: Sun, 26 Jun 2011 19:47:18 +0200
> Subject: [PATCH] lavfi: add life source
> 
> ---
>  doc/filters.texi         |   80 +++++++++
>  libavfilter/Makefile     |    1 +
>  libavfilter/allfilters.c |    1 +
>  libavfilter/vsrc_life.c  |  410 ++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 492 insertions(+), 0 deletions(-)
>  create mode 100644 libavfilter/vsrc_life.c
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index fc34bf2..a83a2d3 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -2772,6 +2772,86 @@ Some examples follow:
>  frei0r_src=200x200:10:partik0l=1234 [overlay]; [in][overlay] overlay
>  @end example
>  
> + at section life
> +
> +Generate a life pattern.
> +
[...]
> +
> +Default value is "S23/B3", which is the original Conway's game of life
> +rule, and will keep a cell alive if it has 2 or 3 neighbor alive
> +cells, and will born a new cell if there are three alive cells around
> +a dead cell.
> +
> + at item random_fill_ratio, ratio
> +Set the random fill ratio for the initial random grid. It is a
> +floating point number value ranging from 0 to 1, defaults to 1/PHI.

Ignored when a file is specified I guess?

> +
> + at item random_seed, seed
> +Set the seed for filling the initial grid, must be an integer included
> +between 0 and UINT32_MAX. If not specified, or if explicitely set to

explicitly

> +-1, the filter will try to use a good random seed at a best effort bases.
> +
> + at item size, s
> +Set the size of the output video.
> +
> +If the @option{filename} option is specified it is set by default to
> +the same value of the input file, and the specified size must contain
> +the size specified in the initial grid file.
> +Otherwise it is set by default to "320x240" for a randomly generated
> +initial grid.
> +

We can't have a larger area in which the grid from the file would be set
in the center, right? IIRC the first initial patch had that kind of
behaviour. I don't mind if this isn't possible anymore, but it might be
nice to explicit it.

> + at item stitch
> +If set to 1, stitch the left and right grid edges together, and the
> +top and bottom edges also. Defaults to 1.
> + at end table
> +

Great :)

[...]
> diff --git a/libavfilter/vsrc_life.c b/libavfilter/vsrc_life.c
> new file mode 100644
> index 0000000..8e91a72
> --- /dev/null
> +++ b/libavfilter/vsrc_life.c
[...]
> +static void evolve(AVFilterContext *ctx)
> +{
> +    LifeContext *life = ctx->priv;
> +    int i, j, v;
> +    uint8_t *oldbuf = life->buf[ life->buf_idx];
> +    uint8_t *newbuf = life->buf[!life->buf_idx];
> +
> +    enum { NW, N, NE, W, E, SW, S, SE };
> +
> +    /* evolve the grid */
> +    for (i = 0; i < life->h; i++) {
> +        for (j = 0; j < life->w; j++) {
> +            int pos[8][2], n;
> +            if (life->stitch) {
> +                pos[NW][0] = (i-1) < 0 ? life->h-1 : i-1; pos[NW][1] = (j-1) < 0 ? life->w-1 : j-1;
> +                pos[N ][0] = (i-1) < 0 ? life->h-1 : i-1; pos[N ][1] =                         j  ;
> +                pos[NE][0] = (i-1) < 0 ? life->h-1 : i-1; pos[NE][1] = (j+1) == life->w ?  0 : j+1;
> +                pos[W ][0] =                         i  ; pos[W ][1] = (j-1) < 0 ? life->w-1 : j-1;
> +                pos[E ][0] =                         i  ; pos[E ][1] = (j+1) == life->w ? 0  : j+1;
> +                pos[SW][0] = (i+1) == life->h ?  0 : i+1; pos[SW][1] = (j-1) < 0 ? life->w-1 : j-1;
> +                pos[S ][0] = (i+1) == life->h ?  0 : i+1; pos[S ][1] =                         j  ;
> +                pos[SE][0] = (i+1) == life->h ?  0 : i+1; pos[SE][1] = (j+1) == life->w ?  0 : j+1;
> +            } else {
> +                pos[NW][0] = (i-1) < 0 ? -1        : i-1; pos[NW][1] = (j-1) < 0 ? -1        : j-1;
> +                pos[N ][0] = (i-1) < 0 ? -1        : i-1; pos[N ][1] =                       j  ;
                                                                                               ^^^^
                                                                                     just a lack of spaces

> +                pos[NE][0] = (i-1) < 0 ? -1        : i-1; pos[NE][1] = (j+1) == life->w ? -1 : j+1;
> +                pos[W ][0] =                         i  ; pos[W ][1] = (j-1) < 0        ? -1 : j-1;
> +                pos[E ][0] =                         i  ; pos[E ][1] = (j+1) == life->w ? -1 : j+1;
> +                pos[SW][0] = (i+1) == life->h ? -1 : i+1; pos[SW][1] = (j-1) < 0        ? -1 : j-1;
> +                pos[S ][0] = (i+1) == life->h ? -1 : i+1; pos[S ][1] =                         j  ;
> +                pos[SE][0] = (i+1) == life->h ? -1 : i+1; pos[SE][1] = (j+1) == life->w ? -1 : j+1;
> +            }
> +

Anyway, looks good to me. I'll rebased my patch and submit it when this is
upstream. Thanks!

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20111204/4718767e/attachment.asc>


More information about the ffmpeg-devel mailing list