FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vsrc_life.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) Stefano Sabatini 2010
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * life video source, based on John Conways' Life Game
24  */
25 
26 /* #define DEBUG */
27 
28 #include "libavutil/file.h"
29 #include "libavutil/intreadwrite.h"
30 #include "libavutil/lfg.h"
31 #include "libavutil/opt.h"
32 #include "libavutil/parseutils.h"
33 #include "libavutil/random_seed.h"
34 #include "libavutil/avstring.h"
35 #include "avfilter.h"
36 #include "internal.h"
37 #include "formats.h"
38 #include "video.h"
39 
40 typedef struct {
41  const AVClass *class;
42  int w, h;
43  char *filename;
44  char *rule_str;
46  size_t file_bufsize;
47 
48  /**
49  * The two grid state buffers.
50  *
51  * A 0xFF (ALIVE_CELL) value means the cell is alive (or new born), while
52  * the decreasing values from 0xFE to 0 means the cell is dead; the range
53  * of values is used for the slow death effect, or mold (0xFE means dead,
54  * 0xFD means very dead, 0xFC means very very dead... and 0x00 means
55  * definitely dead/mold).
56  */
57  uint8_t *buf[2];
58 
60  uint16_t stay_rule; ///< encode the behavior for filled cells
61  uint16_t born_rule; ///< encode the behavior for empty cells
62  uint64_t pts;
65  uint32_t random_seed;
66  int stitch;
67  int mold;
68  uint8_t life_color[4];
69  uint8_t death_color[4];
70  uint8_t mold_color[4];
73 } LifeContext;
74 
75 #define ALIVE_CELL 0xFF
76 #define OFFSET(x) offsetof(LifeContext, x)
77 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
78 
79 static const AVOption life_options[] = {
80  { "filename", "set source file", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
81  { "f", "set source file", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
82  { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, FLAGS },
83  { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, FLAGS },
84  { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, FLAGS },
85  { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, FLAGS },
86  { "rule", "set rule", OFFSET(rule_str), AV_OPT_TYPE_STRING, {.str = "B3/S23"}, CHAR_MIN, CHAR_MAX, FLAGS },
87  { "random_fill_ratio", "set fill ratio for filling initial grid randomly", OFFSET(random_fill_ratio), AV_OPT_TYPE_DOUBLE, {.dbl=1/M_PHI}, 0, 1, FLAGS },
88  { "ratio", "set fill ratio for filling initial grid randomly", OFFSET(random_fill_ratio), AV_OPT_TYPE_DOUBLE, {.dbl=1/M_PHI}, 0, 1, FLAGS },
89  { "random_seed", "set the seed for filling the initial grid randomly", OFFSET(random_seed), AV_OPT_TYPE_INT, {.i64=-1}, -1, UINT32_MAX, FLAGS },
90  { "seed", "set the seed for filling the initial grid randomly", OFFSET(random_seed), AV_OPT_TYPE_INT, {.i64=-1}, -1, UINT32_MAX, FLAGS },
91  { "stitch", "stitch boundaries", OFFSET(stitch), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS },
92  { "mold", "set mold speed for dead cells", OFFSET(mold), AV_OPT_TYPE_INT, {.i64=0}, 0, 0xFF, FLAGS },
93  { "life_color", "set life color", OFFSET( life_color), AV_OPT_TYPE_COLOR, {.str="white"}, CHAR_MIN, CHAR_MAX, FLAGS },
94  { "death_color", "set death color", OFFSET(death_color), AV_OPT_TYPE_COLOR, {.str="black"}, CHAR_MIN, CHAR_MAX, FLAGS },
95  { "mold_color", "set mold color", OFFSET( mold_color), AV_OPT_TYPE_COLOR, {.str="black"}, CHAR_MIN, CHAR_MAX, FLAGS },
96  { NULL }
97 };
98 
100 
101 static int parse_rule(uint16_t *born_rule, uint16_t *stay_rule,
102  const char *rule_str, void *log_ctx)
103 {
104  char *tail;
105  const char *p = rule_str;
106  *born_rule = 0;
107  *stay_rule = 0;
108 
109  if (strchr("bBsS", *p)) {
110  /* parse rule as a Born / Stay Alive code, see
111  * http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life */
112  do {
113  uint16_t *rule = (*p == 'b' || *p == 'B') ? born_rule : stay_rule;
114  p++;
115  while (*p >= '0' && *p <= '8') {
116  *rule += 1<<(*p - '0');
117  p++;
118  }
119  if (*p != '/')
120  break;
121  p++;
122  } while (strchr("bBsS", *p));
123 
124  if (*p)
125  goto error;
126  } else {
127  /* parse rule as a number, expressed in the form STAY|(BORN<<9),
128  * where STAY and BORN encode the corresponding 9-bits rule */
129  long int rule = strtol(rule_str, &tail, 10);
130  if (*tail)
131  goto error;
132  *born_rule = ((1<<9)-1) & rule;
133  *stay_rule = rule >> 9;
134  }
135 
136  return 0;
137 
138 error:
139  av_log(log_ctx, AV_LOG_ERROR, "Invalid rule code '%s' provided\n", rule_str);
140  return AVERROR(EINVAL);
141 }
142 
143 #ifdef DEBUG
144 static void show_life_grid(AVFilterContext *ctx)
145 {
146  LifeContext *life = ctx->priv;
147  int i, j;
148 
149  char *line = av_malloc(life->w + 1);
150  if (!line)
151  return;
152  for (i = 0; i < life->h; i++) {
153  for (j = 0; j < life->w; j++)
154  line[j] = life->buf[life->buf_idx][i*life->w + j] == ALIVE_CELL ? '@' : ' ';
155  line[j] = 0;
156  av_log(ctx, AV_LOG_DEBUG, "%3d: %s\n", i, line);
157  }
158  av_free(line);
159 }
160 #endif
161 
163 {
164  LifeContext *life = ctx->priv;
165  char *p;
166  int ret, i, i0, j, h = 0, w, max_w = 0;
167 
168  if ((ret = av_file_map(life->filename, &life->file_buf, &life->file_bufsize,
169  0, ctx)) < 0)
170  return ret;
171  av_freep(&life->filename);
172 
173  /* prescan file to get the number of lines and the maximum width */
174  w = 0;
175  for (i = 0; i < life->file_bufsize; i++) {
176  if (life->file_buf[i] == '\n') {
177  h++; max_w = FFMAX(w, max_w); w = 0;
178  } else {
179  w++;
180  }
181  }
182  av_log(ctx, AV_LOG_DEBUG, "h:%d max_w:%d\n", h, max_w);
183 
184  if (life->w) {
185  if (max_w > life->w || h > life->h) {
186  av_log(ctx, AV_LOG_ERROR,
187  "The specified size is %dx%d which cannot contain the provided file size of %dx%d\n",
188  life->w, life->h, max_w, h);
189  return AVERROR(EINVAL);
190  }
191  } else {
192  /* size was not specified, set it to size of the grid */
193  life->w = max_w;
194  life->h = h;
195  }
196 
197  if (!(life->buf[0] = av_calloc(life->h * life->w, sizeof(*life->buf[0]))) ||
198  !(life->buf[1] = av_calloc(life->h * life->w, sizeof(*life->buf[1])))) {
199  av_freep(&life->buf[0]);
200  av_freep(&life->buf[1]);
201  return AVERROR(ENOMEM);
202  }
203 
204  /* fill buf[0] */
205  p = life->file_buf;
206  for (i0 = 0, i = (life->h - h)/2; i0 < h; i0++, i++) {
207  for (j = (life->w - max_w)/2;; j++) {
208  av_log(ctx, AV_LOG_DEBUG, "%d:%d %c\n", i, j, *p == '\n' ? 'N' : *p);
209  if (*p == '\n') {
210  p++; break;
211  } else
212  life->buf[0][i*life->w + j] = av_isgraph(*(p++)) ? ALIVE_CELL : 0;
213  }
214  }
215  life->buf_idx = 0;
216 
217  return 0;
218 }
219 
220 static av_cold int init(AVFilterContext *ctx)
221 {
222  LifeContext *life = ctx->priv;
223  int ret;
224 
225  if (!life->w && !life->filename)
226  av_opt_set(life, "size", "320x240", 0);
227 
228  if ((ret = parse_rule(&life->born_rule, &life->stay_rule, life->rule_str, ctx)) < 0)
229  return ret;
230 
231  if (!life->mold && memcmp(life->mold_color, "\x00\x00\x00", 3))
232  av_log(ctx, AV_LOG_WARNING,
233  "Mold color is set while mold isn't, ignoring the color.\n");
234 
235  if (!life->filename) {
236  /* fill the grid randomly */
237  int i;
238 
239  if (!(life->buf[0] = av_calloc(life->h * life->w, sizeof(*life->buf[0]))) ||
240  !(life->buf[1] = av_calloc(life->h * life->w, sizeof(*life->buf[1])))) {
241  av_freep(&life->buf[0]);
242  av_freep(&life->buf[1]);
243  return AVERROR(ENOMEM);
244  }
245  if (life->random_seed == -1)
247 
248  av_lfg_init(&life->lfg, life->random_seed);
249 
250  for (i = 0; i < life->w * life->h; i++) {
251  double r = (double)av_lfg_get(&life->lfg) / UINT32_MAX;
252  if (r <= life->random_fill_ratio)
253  life->buf[0][i] = ALIVE_CELL;
254  }
255  life->buf_idx = 0;
256  } else {
257  if ((ret = init_pattern_from_file(ctx)) < 0)
258  return ret;
259  }
260 
261  av_log(ctx, AV_LOG_VERBOSE,
262  "s:%dx%d r:%d/%d rule:%s stay_rule:%d born_rule:%d stitch:%d seed:%u\n",
263  life->w, life->h, life->frame_rate.num, life->frame_rate.den,
264  life->rule_str, life->stay_rule, life->born_rule, life->stitch,
265  life->random_seed);
266  return 0;
267 }
268 
269 static av_cold void uninit(AVFilterContext *ctx)
270 {
271  LifeContext *life = ctx->priv;
272 
273  av_file_unmap(life->file_buf, life->file_bufsize);
274  av_freep(&life->rule_str);
275  av_freep(&life->buf[0]);
276  av_freep(&life->buf[1]);
277 }
278 
279 static int config_props(AVFilterLink *outlink)
280 {
281  LifeContext *life = outlink->src->priv;
282 
283  outlink->w = life->w;
284  outlink->h = life->h;
285  outlink->time_base = av_inv_q(life->frame_rate);
286 
287  return 0;
288 }
289 
290 static void evolve(AVFilterContext *ctx)
291 {
292  LifeContext *life = ctx->priv;
293  int i, j;
294  uint8_t *oldbuf = life->buf[ life->buf_idx];
295  uint8_t *newbuf = life->buf[!life->buf_idx];
296 
297  enum { NW, N, NE, W, E, SW, S, SE };
298 
299  /* evolve the grid */
300  for (i = 0; i < life->h; i++) {
301  for (j = 0; j < life->w; j++) {
302  int pos[8][2], n, alive, cell;
303  if (life->stitch) {
304  pos[NW][0] = (i-1) < 0 ? life->h-1 : i-1; pos[NW][1] = (j-1) < 0 ? life->w-1 : j-1;
305  pos[N ][0] = (i-1) < 0 ? life->h-1 : i-1; pos[N ][1] = j ;
306  pos[NE][0] = (i-1) < 0 ? life->h-1 : i-1; pos[NE][1] = (j+1) == life->w ? 0 : j+1;
307  pos[W ][0] = i ; pos[W ][1] = (j-1) < 0 ? life->w-1 : j-1;
308  pos[E ][0] = i ; pos[E ][1] = (j+1) == life->w ? 0 : j+1;
309  pos[SW][0] = (i+1) == life->h ? 0 : i+1; pos[SW][1] = (j-1) < 0 ? life->w-1 : j-1;
310  pos[S ][0] = (i+1) == life->h ? 0 : i+1; pos[S ][1] = j ;
311  pos[SE][0] = (i+1) == life->h ? 0 : i+1; pos[SE][1] = (j+1) == life->w ? 0 : j+1;
312  } else {
313  pos[NW][0] = (i-1) < 0 ? -1 : i-1; pos[NW][1] = (j-1) < 0 ? -1 : j-1;
314  pos[N ][0] = (i-1) < 0 ? -1 : i-1; pos[N ][1] = j ;
315  pos[NE][0] = (i-1) < 0 ? -1 : i-1; pos[NE][1] = (j+1) == life->w ? -1 : j+1;
316  pos[W ][0] = i ; pos[W ][1] = (j-1) < 0 ? -1 : j-1;
317  pos[E ][0] = i ; pos[E ][1] = (j+1) == life->w ? -1 : j+1;
318  pos[SW][0] = (i+1) == life->h ? -1 : i+1; pos[SW][1] = (j-1) < 0 ? -1 : j-1;
319  pos[S ][0] = (i+1) == life->h ? -1 : i+1; pos[S ][1] = j ;
320  pos[SE][0] = (i+1) == life->h ? -1 : i+1; pos[SE][1] = (j+1) == life->w ? -1 : j+1;
321  }
322 
323  /* compute the number of live neighbor cells */
324  n = (pos[NW][0] == -1 || pos[NW][1] == -1 ? 0 : oldbuf[pos[NW][0]*life->w + pos[NW][1]] == ALIVE_CELL) +
325  (pos[N ][0] == -1 || pos[N ][1] == -1 ? 0 : oldbuf[pos[N ][0]*life->w + pos[N ][1]] == ALIVE_CELL) +
326  (pos[NE][0] == -1 || pos[NE][1] == -1 ? 0 : oldbuf[pos[NE][0]*life->w + pos[NE][1]] == ALIVE_CELL) +
327  (pos[W ][0] == -1 || pos[W ][1] == -1 ? 0 : oldbuf[pos[W ][0]*life->w + pos[W ][1]] == ALIVE_CELL) +
328  (pos[E ][0] == -1 || pos[E ][1] == -1 ? 0 : oldbuf[pos[E ][0]*life->w + pos[E ][1]] == ALIVE_CELL) +
329  (pos[SW][0] == -1 || pos[SW][1] == -1 ? 0 : oldbuf[pos[SW][0]*life->w + pos[SW][1]] == ALIVE_CELL) +
330  (pos[S ][0] == -1 || pos[S ][1] == -1 ? 0 : oldbuf[pos[S ][0]*life->w + pos[S ][1]] == ALIVE_CELL) +
331  (pos[SE][0] == -1 || pos[SE][1] == -1 ? 0 : oldbuf[pos[SE][0]*life->w + pos[SE][1]] == ALIVE_CELL);
332  cell = oldbuf[i*life->w + j];
333  alive = 1<<n & (cell == ALIVE_CELL ? life->stay_rule : life->born_rule);
334  if (alive) *newbuf = ALIVE_CELL; // new cell is alive
335  else if (cell) *newbuf = cell - 1; // new cell is dead and in the process of mold
336  else *newbuf = 0; // new cell is definitely dead
337  av_dlog(ctx, "i:%d j:%d live_neighbors:%d cell:%d -> cell:%d\n", i, j, n, cell, *newbuf);
338  newbuf++;
339  }
340  }
341 
342  life->buf_idx = !life->buf_idx;
343 }
344 
346 {
347  LifeContext *life = ctx->priv;
348  uint8_t *buf = life->buf[life->buf_idx];
349  int i, j, k;
350 
351  /* fill the output picture with the old grid buffer */
352  for (i = 0; i < life->h; i++) {
353  uint8_t byte = 0;
354  uint8_t *p = picref->data[0] + i * picref->linesize[0];
355  for (k = 0, j = 0; j < life->w; j++) {
356  byte |= (buf[i*life->w+j] == ALIVE_CELL)<<(7-k++);
357  if (k==8 || j == life->w-1) {
358  k = 0;
359  *p++ = byte;
360  byte = 0;
361  }
362  }
363  }
364 }
365 
366 // divide by 255 and round to nearest
367 // apply a fast variant: (X+127)/255 = ((X+127)*257+257)>>16 = ((X+128)*257)>>16
368 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
369 
370 static void fill_picture_rgb(AVFilterContext *ctx, AVFrame *picref)
371 {
372  LifeContext *life = ctx->priv;
373  uint8_t *buf = life->buf[life->buf_idx];
374  int i, j;
375 
376  /* fill the output picture with the old grid buffer */
377  for (i = 0; i < life->h; i++) {
378  uint8_t *p = picref->data[0] + i * picref->linesize[0];
379  for (j = 0; j < life->w; j++) {
380  uint8_t v = buf[i*life->w + j];
381  if (life->mold && v != ALIVE_CELL) {
382  const uint8_t *c1 = life-> mold_color;
383  const uint8_t *c2 = life->death_color;
384  int death_age = FFMIN((0xff - v) * life->mold, 0xff);
385  *p++ = FAST_DIV255((c2[0] << 8) + ((int)c1[0] - (int)c2[0]) * death_age);
386  *p++ = FAST_DIV255((c2[1] << 8) + ((int)c1[1] - (int)c2[1]) * death_age);
387  *p++ = FAST_DIV255((c2[2] << 8) + ((int)c1[2] - (int)c2[2]) * death_age);
388  } else {
389  const uint8_t *c = v == ALIVE_CELL ? life->life_color : life->death_color;
390  AV_WB24(p, c[0]<<16 | c[1]<<8 | c[2]);
391  p += 3;
392  }
393  }
394  }
395 }
396 
397 static int request_frame(AVFilterLink *outlink)
398 {
399  LifeContext *life = outlink->src->priv;
400  AVFrame *picref = ff_get_video_buffer(outlink, life->w, life->h);
401  if (!picref)
402  return AVERROR(ENOMEM);
403  picref->sample_aspect_ratio = (AVRational) {1, 1};
404  picref->pts = life->pts++;
405 
406  life->draw(outlink->src, picref);
407  evolve(outlink->src);
408 #ifdef DEBUG
409  show_life_grid(outlink->src);
410 #endif
411  return ff_filter_frame(outlink, picref);
412 }
413 
415 {
416  LifeContext *life = ctx->priv;
417  enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_NONE, AV_PIX_FMT_NONE };
418  AVFilterFormats *fmts_list;
419 
420  if (life->mold || memcmp(life-> life_color, "\xff\xff\xff", 3)
421  || memcmp(life->death_color, "\x00\x00\x00", 3)) {
422  pix_fmts[0] = AV_PIX_FMT_RGB24;
423  life->draw = fill_picture_rgb;
424  } else {
425  pix_fmts[0] = AV_PIX_FMT_MONOBLACK;
427  }
428 
429  fmts_list = ff_make_format_list(pix_fmts);
430  if (!fmts_list)
431  return AVERROR(ENOMEM);
432  ff_set_common_formats(ctx, fmts_list);
433  return 0;
434 }
435 
436 static const AVFilterPad life_outputs[] = {
437  {
438  .name = "default",
439  .type = AVMEDIA_TYPE_VIDEO,
440  .request_frame = request_frame,
441  .config_props = config_props,
442  },
443  { NULL}
444 };
445 
447  .name = "life",
448  .description = NULL_IF_CONFIG_SMALL("Create life."),
449  .priv_size = sizeof(LifeContext),
450  .priv_class = &life_class,
451  .init = init,
452  .uninit = uninit,
454  .inputs = NULL,
455  .outputs = life_outputs,
456 };
Definition: lfg.h:25
#define NULL
Definition: coverity.c:32
float v
uint32_t random_seed
Definition: vsrc_life.c:65
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
uint16_t stay_rule
encode the behavior for filled cells
Definition: vsrc_life.c:60
AVOption.
Definition: opt.h:255
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:65
static const AVFilterPad life_outputs[]
Definition: vsrc_life.c:436
int num
numerator
Definition: rational.h:44
static void fill_picture_monoblack(AVFilterContext *ctx, AVFrame *picref)
Definition: vsrc_life.c:345
static av_cold int init(AVFilterContext *ctx)
Definition: vsrc_life.c:220
static int request_frame(AVFilterLink *outlink)
Definition: vsrc_life.c:397
static void fill_picture_rgb(AVFilterContext *ctx, AVFrame *picref)
Definition: vsrc_life.c:370
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:109
int av_isgraph(int c)
Locale-independent conversion of ASCII isgraph.
Definition: avstring.c:325
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
AVLFG lfg
Definition: vsrc_life.c:71
const char * name
Pad name.
Definition: internal.h:67
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1145
uint8_t
#define av_cold
Definition: attributes.h:74
#define av_malloc(s)
AVOptions.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:257
static int query_formats(AVFilterContext *ctx)
Definition: vsrc_life.c:414
#define N
Definition: vf_pp7.c:73
uint8_t death_color[4]
Definition: vsrc_life.c:69
Misc file utilities.
static const uint64_t c1
Definition: murmur3.c:49
char * rule_str
Definition: vsrc_life.c:44
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:61
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Definition: file.c:129
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:542
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...
Definition: file.c:49
static int config_props(AVFilterLink *outlink)
Definition: vsrc_life.c:279
#define S(s, c, i)
#define AVERROR(e)
Definition: error.h:43
static av_cold void uninit(AVFilterContext *ctx)
Definition: vsrc_life.c:269
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
AVFilter ff_vsrc_life
Definition: vsrc_life.c:446
const char * r
Definition: vf_curves.c:107
void * priv
private data for use by the filter
Definition: avfilter.h:654
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
Definition: graph2dot.c:48
#define FAST_DIV255(x)
Definition: vsrc_life.c:368
static void evolve(AVFilterContext *ctx)
Definition: vsrc_life.c:290
int stitch
Definition: vsrc_life.c:66
#define FFMAX(a, b)
Definition: common.h:64
uint8_t buf_idx
Definition: vsrc_life.c:59
#define OFFSET(x)
Definition: vsrc_life.c:76
#define E
Definition: avdct.c:32
#define FFMIN(a, b)
Definition: common.h:66
uint8_t * file_buf
Definition: vsrc_life.c:45
In the ELBG jargon, a cell is the set of points that are closest to a codebook entry.
Definition: elbg.c:39
ret
Definition: avfilter.c:974
AVFILTER_DEFINE_CLASS(life)
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
uint8_t life_color[4]
Definition: vsrc_life.c:68
#define FLAGS
Definition: vsrc_life.c:77
#define AV_WB24(p, d)
Definition: intreadwrite.h:450
int n
Definition: avisynth_c.h:547
static int init_pattern_from_file(AVFilterContext *ctx)
Definition: vsrc_life.c:162
#define ALIVE_CELL
Definition: vsrc_life.c:75
#define av_dlog(pctx,...)
av_dlog macros
Definition: log.h:330
double random_fill_ratio
Definition: vsrc_life.c:64
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
Definition: bytestream.h:85
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
void(* draw)(AVFilterContext *, AVFrame *)
Definition: vsrc_life.c:72
uint16_t born_rule
encode the behavior for empty cells
Definition: vsrc_life.c:61
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:252
#define SE
Definition: dvdsubenc.c:453
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:38
void * buf
Definition: avisynth_c.h:553
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:470
#define W(a, i, v)
Definition: jpegls.h:122
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
rational number numerator/denominator
Definition: rational.h:43
#define M_PHI
Definition: mathematics.h:43
offset must point to AVRational
Definition: opt.h:235
const char * name
Filter name.
Definition: avfilter.h:474
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition: lfg.c:30
offset must point to two consecutive integers
Definition: opt.h:232
misc parsing utilities
#define SW(val, pdst)
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
Definition: mem.c:258
uint64_t pts
Definition: vsrc_life.c:62
static int parse_rule(uint16_t *born_rule, uint16_t *stay_rule, const char *rule_str, void *log_ctx)
Definition: vsrc_life.c:101
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:133
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:73
static double c[64]
static const uint64_t c2
Definition: murmur3.c:50
int den
denominator
Definition: rational.h:45
AVRational frame_rate
Definition: vsrc_life.c:63
static const AVOption life_options[]
Definition: vsrc_life.c:79
#define av_free(p)
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:633
#define av_freep(p)
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
Definition: random_seed.c:109
size_t file_bufsize
Definition: vsrc_life.c:46
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:369
uint8_t mold_color[4]
Definition: vsrc_life.c:70
uint8_t * buf[2]
The two grid state buffers.
Definition: vsrc_life.c:57
char * filename
Definition: vsrc_life.c:43