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++)
167 int ret,
i, i0, j,
h = 0,
w, max_w = 0;
178 h++; max_w =
FFMAX(
w, max_w);
w = 0;
186 if (max_w > life->
w ||
h > life->
h) {
188 "The specified size is %dx%d which cannot contain the provided file size of %dx%d\n",
189 life->
w, life->
h, max_w,
h);
207 for (i0 = 0,
i = (life->
h -
h)/2; i0 <
h; i0++,
i++) {
208 for (j = (life->
w - max_w)/2;; j++) {
234 "Mold color is set while mold isn't, ignoring the color.\n");
251 for (
i = 0;
i < life->
w * life->
h;
i++) {
253 if (r <= life->random_fill_ratio)
263 "s:%dx%d r:%d/%d rule:%s stay_rule:%d born_rule:%d stitch:%d seed:%"PRId64
"\n",
284 outlink->
w = life->
w;
285 outlink->
h = life->
h;
298 enum { NW,
N, NE,
W,
E,
SW,
S,
SE };
301 for (
i = 0;
i < life->
h;
i++) {
302 for (j = 0; j < life->
w; j++) {
303 int pos[8][2], n, alive, cell;
305 pos[NW][0] = (
i-1) < 0 ? life->
h-1 :
i-1;
pos[NW][1] = (j-1) < 0 ? life->
w-1 : j-1;
306 pos[
N ][0] = (
i-1) < 0 ? life->
h-1 :
i-1;
pos[
N ][1] = j ;
307 pos[NE][0] = (
i-1) < 0 ? life->
h-1 :
i-1;
pos[NE][1] = (j+1) == life->
w ? 0 : j+1;
308 pos[
W ][0] =
i ;
pos[
W ][1] = (j-1) < 0 ? life->
w-1 : j-1;
309 pos[
E ][0] =
i ;
pos[
E ][1] = (j+1) == life->
w ? 0 : j+1;
310 pos[
SW][0] = (
i+1) == life->
h ? 0 :
i+1;
pos[
SW][1] = (j-1) < 0 ? life->
w-1 : j-1;
311 pos[
S ][0] = (
i+1) == life->
h ? 0 :
i+1;
pos[
S ][1] = j ;
312 pos[
SE][0] = (
i+1) == life->
h ? 0 :
i+1;
pos[
SE][1] = (j+1) == life->
w ? 0 : j+1;
314 pos[NW][0] = (
i-1) < 0 ? -1 :
i-1;
pos[NW][1] = (j-1) < 0 ? -1 : j-1;
315 pos[
N ][0] = (
i-1) < 0 ? -1 :
i-1;
pos[
N ][1] = j ;
316 pos[NE][0] = (
i-1) < 0 ? -1 :
i-1;
pos[NE][1] = (j+1) == life->
w ? -1 : j+1;
317 pos[
W ][0] =
i ;
pos[
W ][1] = (j-1) < 0 ? -1 : j-1;
318 pos[
E ][0] =
i ;
pos[
E ][1] = (j+1) == life->
w ? -1 : j+1;
319 pos[
SW][0] = (
i+1) == life->
h ? -1 :
i+1;
pos[
SW][1] = (j-1) < 0 ? -1 : j-1;
320 pos[
S ][0] = (
i+1) == life->
h ? -1 :
i+1;
pos[
S ][1] = j ;
321 pos[
SE][0] = (
i+1) == life->
h ? -1 :
i+1;
pos[
SE][1] = (j+1) == life->
w ? -1 : j+1;
333 cell = oldbuf[
i*life->
w + j];
336 else if (cell) *newbuf = cell - 1;
338 ff_dlog(
ctx,
"i:%d j:%d live_neighbors:%d cell:%d -> cell:%d\n",
i, j, n, cell, *newbuf);
353 for (
i = 0;
i < life->
h;
i++) {
356 for (k = 0, j = 0; j < life->
w; j++) {
358 if (k==8 || j == life->
w-1) {
369 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
378 for (
i = 0;
i < life->
h;
i++) {
380 for (j = 0; j < life->
w; j++) {
385 int death_age =
FFMIN((0xff - v) * life->
mold, 0xff);
405 picref->
pts = life->
pts++;
407 life->
draw(outlink->
src, picref);
410 show_life_grid(outlink->
src);
421 if (life->
mold || memcmp(life-> life_color,
"\xff\xff\xff", 3)
448 .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.
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to 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).
static int query_formats(AVFilterContext *ctx)
#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.
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.
static const AVFilterPad outputs[]
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 const AVFilterPad life_outputs[]
static av_cold int init(AVFilterContext *ctx)
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_IMAGE_SIZE
offset must point to 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
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)
int w
agreed upon image width
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
const char * name
Pad name.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
int h
agreed upon image height
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)
static void fill_picture_rgb(AVFilterContext *ctx, AVFrame *picref)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.