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
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 },
101 static int parse_rule(uint16_t *born_rule, uint16_t *stay_rule,
102 const char *rule_str,
void *log_ctx)
105 const char *p = rule_str;
109 if (strchr(
"bBsS", *p)) {
113 uint16_t *rule = (*p ==
'b' || *p ==
'B') ? born_rule : stay_rule;
115 while (*p >=
'0' && *p <=
'8') {
116 *rule += 1<<(*p -
'0');
122 }
while (strchr(
"bBsS", *p));
129 long int rule = strtol(rule_str, &tail, 10);
132 *born_rule = ((1<<9)-1) & rule;
133 *stay_rule = rule >> 9;
152 for (i = 0; i < life->
h; i++) {
153 for (j = 0; j < life->
w; j++)
166 int ret, i, i0, j, h = 0, w, max_w = 0;
177 h++; max_w =
FFMAX(w, max_w); w = 0;
185 if (max_w > life->
w || h > life->
h) {
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);
206 for (i0 = 0, i = (life->
h - h)/2; i0 < h; i0++, i++) {
207 for (j = (life->
w - max_w)/2;; j++) {
233 "Mold color is set while mold isn't, ignoring the color.\n");
250 for (i = 0; i < life->
w * life->
h; i++) {
252 if (r <= life->random_fill_ratio)
262 "s:%dx%d r:%d/%d rule:%s stay_rule:%d born_rule:%d stitch:%d seed:%u\n",
283 outlink->
w = life->
w;
284 outlink->
h = life->
h;
297 enum { NW,
N, NE,
W,
E, SW,
S,
SE };
300 for (i = 0; i < life->
h; i++) {
301 for (j = 0; j < life->
w; j++) {
302 int pos[8][2],
n, alive,
cell;
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;
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;
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];
335 else if (cell) *newbuf = cell - 1;
337 av_dlog(ctx,
"i:%d j:%d live_neighbors:%d cell:%d -> cell:%d\n", i, j, n, cell, *newbuf);
352 for (i = 0; i < life->
h; i++) {
355 for (k = 0, j = 0; j < life->
w; j++) {
357 if (k==8 || j == life->
w-1) {
368 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
377 for (i = 0; i < life->
h; i++) {
379 for (j = 0; j < life->
w; j++) {
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);
390 AV_WB24(p, c[0]<<16 | c[1]<<8 | c[2]);
404 picref->
pts = life->
pts++;
406 life->
draw(outlink->
src, picref);
409 show_life_grid(outlink->
src);
418 if (life->
mold || memcmp(life-> life_color,
"\xff\xff\xff", 3)
444 .priv_class = &life_class,