Commit 2f8b6e90 authored by Stefano Sabatini's avatar Stefano Sabatini

lavfi: add life source

parent 6c26fe8b
......@@ -128,6 +128,7 @@ easier to use. The changes are:
- CRI ADX audio format demuxer
- Playstation Portable PMP format demuxer
- Microsoft Windows ICO demuxer
- life source
version 0.8:
......
......@@ -2782,6 +2782,113 @@ Some examples follow:
frei0r_src=200x200:10:partik0l=1234 [overlay]; [in][overlay] overlay
@end example
@section life
Generate a life pattern.
This source is based on a generalization of John Conway's life game.
The sourced input represents a life grid, each pixel represents a cell
which can be in one of two possible states, alive or dead. Every cell
interacts with its eight neighbours, which are the cells that are
horizontally, vertically, or diagonally adjacent.
At each interaction the grid evolves according to the adopted rule,
which specifies the number of neighbor alive cells which will make a
cell stay alive or born. The @option{rule} option allows to specify
the rule to adopt.
This source accepts a list of options in the form of
@var{key}=@var{value} pairs separated by ":". A description of the
accepted options follows.
@table @option
@item filename, f
Set the file from which to read the initial grid state. In the file,
each non-whitespace character is considered an alive cell, and newline
is used to delimit the end of each row.
If this option is not specified, the initial grid is generated
randomly.
@item rate, r
Set the video rate, that is the number of frames generated per second.
Default is 25.
@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.
It is ignored when a file is specified.
@item random_seed, seed
Set the seed for filling the initial random grid, must be an integer
included between 0 and UINT32_MAX. If not specified, or if explicitly
set to -1, the filter will try to use a good random seed on a best
effort basis.
@item rule
Set the life rule.
A rule can be specified with a code of the kind "S@var{NS}/B@var{NB}",
where @var{NS} and @var{NB} are sequences of numbers in the range 0-8,
@var{NS} specifies the number of alive neighbor cells which make a
live cell stay alive, and @var{NB} the number of alive neighbor cells
which make a dead cell to become alive (i.e. to "born").
"s" and "b" can be used in place of "S" and "B", respectively.
Alternatively a rule can be specified by an 18-bits integer. The 9
high order bits are used to encode the next cell state if it is alive
for each number of neighbor alive cells, the low order bits specify
the rule for "borning" new cells. Higher order bits encode for an
higher number of neighbor cells.
For example the number 6153 = @code{(12<<9)+9} specifies a stay alive
rule of 12 and a born rule of 9, which corresponds to "S23/B03".
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.
@item size, s
Set the size of the output video.
If @option{filename} is specified, the size is set by default to the
same size of the input file. If @option{size} is set, it must contain
the size specified in the input file, and the initial grid defined in
that file is centered in the larger resulting area.
If a filename is not specified, the size value defaults to "320x240"
(used for a randomly generated initial grid).
@item stitch
If set to 1, stitch the left and right grid edges together, and the
top and bottom edges also. Defaults to 1.
@end table
@subsection Examples
@itemize
@item
Read a grid from @file{pattern}, and center it on a grid of size
300x300 pixels:
@example
life=f=pattern:s=300x300
@end example
@item
Generate a random grid of size 200x200, with a fill ratio of 2/3:
@example
life=ratio=2/3:s=200x200
@end example
@item
Specify a custom rule for evolving a randomly generated grid:
@example
life=rule=S14/B34
@end example
@end itemize
@section nullsrc, rgbtestsrc, testsrc
The @code{nullsrc} source returns unprocessed video frames. It is
......
......@@ -86,6 +86,7 @@ OBJS-$(CONFIG_YADIF_FILTER) += vf_yadif.o
OBJS-$(CONFIG_BUFFER_FILTER) += vsrc_buffer.o
OBJS-$(CONFIG_COLOR_FILTER) += vsrc_color.o
OBJS-$(CONFIG_FREI0R_SRC_FILTER) += vf_frei0r.o
OBJS-$(CONFIG_LIFE_FILTER) += vsrc_life.o
OBJS-$(CONFIG_MANDELBROT_FILTER) += vsrc_mandelbrot.o
OBJS-$(CONFIG_MOVIE_FILTER) += src_movie.o
OBJS-$(CONFIG_MPTESTSRC_FILTER) += vsrc_mptestsrc.o
......
......@@ -97,6 +97,7 @@ void avfilter_register_all(void)
REGISTER_FILTER (BUFFER, buffer, vsrc);
REGISTER_FILTER (COLOR, color, vsrc);
REGISTER_FILTER (FREI0R, frei0r_src, vsrc);
REGISTER_FILTER (LIFE, life, vsrc);
REGISTER_FILTER (MANDELBROT, mandelbrot, vsrc);
REGISTER_FILTER (MOVIE, movie, vsrc);
REGISTER_FILTER (MPTESTSRC, mptestsrc, vsrc);
......
......@@ -29,8 +29,8 @@
#include "libavutil/rational.h"
#define LIBAVFILTER_VERSION_MAJOR 2
#define LIBAVFILTER_VERSION_MINOR 50
#define LIBAVFILTER_VERSION_MICRO 1
#define LIBAVFILTER_VERSION_MINOR 51
#define LIBAVFILTER_VERSION_MICRO 0
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment