Go to the documentation of this file.
76 #define ALIVE_CELL 0xFF
77 #define OFFSET(x) offsetof(LifeContext, x)
78 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
90 {
"random_seed",
"set the seed for filling the initial grid randomly",
OFFSET(random_seed),
AV_OPT_TYPE_INT64, {.i64=-1}, -1, UINT32_MAX,
FLAGS },
91 {
"seed",
"set the seed for filling the initial grid randomly",
OFFSET(random_seed),
AV_OPT_TYPE_INT64, {.i64=-1}, -1, UINT32_MAX,
FLAGS },
102 static int parse_rule(uint16_t *born_rule, uint16_t *stay_rule,
103 const char *rule_str,
void *log_ctx)
106 const char *p = rule_str;
110 if (strchr(
"bBsS", *p)) {
114 uint16_t *rule = (*p ==
'b' || *p ==
'B') ? born_rule : stay_rule;
116 while (*p >=
'0' && *p <=
'8') {
117 *rule += 1<<(*p -
'0');
123 }
while (strchr(
"bBsS", *p));
130 long int rule = strtol(rule_str, &tail, 10);
133 *born_rule = ((1<<9)-1) & rule;
134 *stay_rule = rule >> 9;
153 for (
i = 0;
i < life->
h;
i++) {
154 for (j = 0; j < life->
w; j++)
170 for (
i = 0;
i < life->
h;
i++) {
173 for (k = 0, j = 0; j < life->
w; j++) {
175 if (k==8 || j == life->
w-1) {
186 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
195 for (
i = 0;
i < life->
h;
i++) {
197 for (j = 0; j < life->
w; j++) {
198 uint8_t v = buf[
i*life->
w + j];
200 const uint8_t *
c1 = life-> mold_color;
202 int death_age =
FFMIN((0xff - v) * life->
mold, 0xff);
219 int ret,
i, i0, j,
h = 0,
w, max_w = 0;
230 h++; max_w =
FFMAX(
w, max_w);
w = 0;
238 if (max_w > life->
w ||
h > life->
h) {
240 "The specified size is %dx%d which cannot contain the provided file size of %dx%d\n",
241 life->
w, life->
h, max_w,
h);
259 for (i0 = 0,
i = (life->
h -
h)/2; i0 <
h; i0++,
i++) {
260 for (j = (life->
w - max_w)/2;; j++) {
286 "Mold color is set while mold isn't, ignoring the color.\n");
303 for (
i = 0;
i < life->
w * life->
h;
i++) {
305 if (r <= life->random_fill_ratio)
314 if (life->
mold || memcmp(life-> life_color,
"\xff\xff\xff", 3)
322 "s:%dx%d r:%d/%d rule:%s stay_rule:%d born_rule:%d stitch:%d seed:%"PRId64
"\n",
344 outlink->
w = life->
w;
345 outlink->
h = life->
h;
359 enum { NW,
N, NE,
W,
E,
SW,
S,
SE };
362 for (
i = 0;
i < life->
h;
i++) {
363 for (j = 0; j < life->
w; j++) {
364 int pos[8][2], n, alive, cell;
366 pos[NW][0] = (
i-1) < 0 ? life->
h-1 :
i-1;
pos[NW][1] = (j-1) < 0 ? life->
w-1 : j-1;
367 pos[
N ][0] = (
i-1) < 0 ? life->
h-1 :
i-1;
pos[
N ][1] = j ;
368 pos[NE][0] = (
i-1) < 0 ? life->
h-1 :
i-1;
pos[NE][1] = (j+1) == life->
w ? 0 : j+1;
369 pos[
W ][0] =
i ;
pos[
W ][1] = (j-1) < 0 ? life->
w-1 : j-1;
370 pos[
E ][0] =
i ;
pos[
E ][1] = (j+1) == life->
w ? 0 : j+1;
371 pos[
SW][0] = (
i+1) == life->
h ? 0 :
i+1;
pos[
SW][1] = (j-1) < 0 ? life->
w-1 : j-1;
372 pos[
S ][0] = (
i+1) == life->
h ? 0 :
i+1;
pos[
S ][1] = j ;
373 pos[
SE][0] = (
i+1) == life->
h ? 0 :
i+1;
pos[
SE][1] = (j+1) == life->
w ? 0 : j+1;
375 pos[NW][0] = (
i-1) < 0 ? -1 :
i-1;
pos[NW][1] = (j-1) < 0 ? -1 : j-1;
376 pos[
N ][0] = (
i-1) < 0 ? -1 :
i-1;
pos[
N ][1] = j ;
377 pos[NE][0] = (
i-1) < 0 ? -1 :
i-1;
pos[NE][1] = (j+1) == life->
w ? -1 : j+1;
378 pos[
W ][0] =
i ;
pos[
W ][1] = (j-1) < 0 ? -1 : j-1;
379 pos[
E ][0] =
i ;
pos[
E ][1] = (j+1) == life->
w ? -1 : j+1;
380 pos[
SW][0] = (
i+1) == life->
h ? -1 :
i+1;
pos[
SW][1] = (j-1) < 0 ? -1 : j-1;
381 pos[
S ][0] = (
i+1) == life->
h ? -1 :
i+1;
pos[
S ][1] = j ;
382 pos[
SE][0] = (
i+1) == life->
h ? -1 :
i+1;
pos[
SE][1] = (j+1) == life->
w ? -1 : j+1;
394 cell = oldbuf[
i*life->
w + j];
397 else if (cell) *newbuf = cell - 1;
399 ff_dlog(
ctx,
"i:%d j:%d live_neighbors:%d cell:%d -> cell:%d\n",
i, j, n, cell, *newbuf);
414 picref->
pts = life->
pts++;
417 life->
draw(outlink->
src, picref);
420 show_life_grid(outlink->
src);
451 .priv_class = &life_class,
static void error(const char *err)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int config_props(AVFilterLink *outlink)
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static void evolve(AVFilterContext *ctx)
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int64_t duration
Duration of the frame, in the same units as pts.
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
static av_cold void uninit(AVFilterContext *ctx)
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define AV_LOG_VERBOSE
Detailed information.
const char * name
Filter name.
static const AVOption life_options[]
A link between two filters.
uint16_t born_rule
encode the behavior for empty cells
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Link properties exposed to filter code, but not external callers.
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, int log_offset, void *log_ctx)
Read the file with name filename, and put its content in a newly allocated buffer or map it with mmap...
void * priv
private data for use by the filter
uint8_t * buf[2]
The two grid state buffers.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void(* draw)(AVFilterContext *, AVFrame *)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
static enum AVPixelFormat pix_fmts[]
uint16_t stay_rule
encode the behavior for filled cells
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static const AVFilterPad life_outputs[]
static av_cold int init(AVFilterContext *ctx)
#define FILTER_OUTPUTS(array)
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
static int parse_rule(uint16_t *born_rule, uint16_t *stay_rule, const char *rule_str, void *log_ctx)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static FilterLink * ff_filter_link(AVFilterLink *link)
Context structure for the Lagged Fibonacci PRNG.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_WB16 unsigned int_TMPL byte
AVFILTER_DEFINE_CLASS(life)
AVFilterContext * src
source filter
static av_const int av_isgraph(int c)
Locale-independent conversion of ASCII isgraph.
static int init_pattern_from_file(AVFilterContext *ctx)
const AVFilter ff_vsrc_life
#define i(width, name, range_min, range_max)
int w
agreed upon image width
#define FILTER_QUERY_FUNC2(func)
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
int h
agreed upon image height
@ AV_OPT_TYPE_INT
Underlying C type is int.
static int request_frame(AVFilterLink *outlink)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
static void fill_picture_monoblack(AVFilterContext *ctx, AVFrame *picref)
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
static void fill_picture_rgb(AVFilterContext *ctx, AVFrame *picref)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...