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_INT, {.i64=-1}, -1, UINT32_MAX,
FLAGS },
91 {
"seed",
"set the seed for filling the initial grid randomly",
OFFSET(random_seed),
AV_OPT_TYPE_INT, {.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:%u\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;
325 n = (pos[NW][0] == -1 || pos[NW][1] == -1 ? 0 : oldbuf[pos[NW][0]*life->
w + pos[NW][1]] ==
ALIVE_CELL) +
326 (pos[
N ][0] == -1 || pos[
N ][1] == -1 ? 0 : oldbuf[pos[
N ][0]*life->
w + pos[
N ][1]] ==
ALIVE_CELL) +
327 (pos[NE][0] == -1 || pos[NE][1] == -1 ? 0 : oldbuf[pos[NE][0]*life->
w + pos[NE][1]] ==
ALIVE_CELL) +
328 (pos[
W ][0] == -1 || pos[
W ][1] == -1 ? 0 : oldbuf[pos[
W ][0]*life->
w + pos[
W ][1]] ==
ALIVE_CELL) +
329 (pos[
E ][0] == -1 || pos[
E ][1] == -1 ? 0 : oldbuf[pos[
E ][0]*life->
w + pos[
E ][1]] ==
ALIVE_CELL) +
330 (pos[
SW][0] == -1 || pos[
SW][1] == -1 ? 0 : oldbuf[pos[
SW][0]*life->
w + pos[
SW][1]] ==
ALIVE_CELL) +
331 (pos[
S ][0] == -1 || pos[
S ][1] == -1 ? 0 : oldbuf[pos[
S ][0]*life->
w + pos[
S ][1]] ==
ALIVE_CELL) +
332 (pos[
SE][0] == -1 || pos[
SE][1] == -1 ? 0 : oldbuf[pos[
SE][0]*life->
w + pos[
SE][1]] ==
ALIVE_CELL);
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);
386 *p++ =
FAST_DIV255((c2[0] << 8) + ((
int)c1[0] - (
int)c2[0]) * death_age);
387 *p++ =
FAST_DIV255((c2[1] << 8) + ((
int)c1[1] - (
int)c2[1]) * death_age);
388 *p++ =
FAST_DIV255((c2[2] << 8) + ((
int)c1[2] - (
int)c2[2]) * death_age);
391 AV_WB24(p, c[0]<<16 | c[1]<<8 | c[2]);
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,
This structure describes decoded (raw) audio or video data.
uint16_t stay_rule
encode the behavior for filled cells
#define AV_LOG_WARNING
Something somehow does not look correct.
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
static const AVFilterPad life_outputs[]
int h
agreed upon image height
static void fill_picture_monoblack(AVFilterContext *ctx, AVFrame *picref)
static av_cold int init(AVFilterContext *ctx)
static int request_frame(AVFilterLink *outlink)
static void fill_picture_rgb(AVFilterContext *ctx, AVFrame *picref)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
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.
A filter pad used for either input or output.
A link between two filters.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
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...
static int config_props(AVFilterLink *outlink)
static av_cold void uninit(AVFilterContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
static void evolve(AVFilterContext *ctx)
int w
agreed upon image width
common internal API header
In the ELBG jargon, a cell is the set of points that are closest to a codebook entry.
AVFILTER_DEFINE_CLASS(life)
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
AVFilterContext * src
source filter
static int init_pattern_from_file(AVFilterContext *ctx)
static const AVFilterPad outputs[]
static const AVFilterPad inputs[]
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
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
void(* draw)(AVFilterContext *, AVFrame *)
uint16_t born_rule
encode the behavior for empty cells
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Describe the class of an AVClass context structure.
rational number numerator/denominator
offset must point to AVRational
const char * name
Filter name.
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
offset must point to two consecutive integers
static enum AVPixelFormat pix_fmts[]
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...
static int parse_rule(uint16_t *born_rule, uint16_t *stay_rule, const char *rule_str, void *log_ctx)
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static av_const int av_isgraph(int c)
Locale-independent conversion of ASCII isgraph.
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
static const AVOption life_options[]
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
AVPixelFormat
Pixel format.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
uint8_t * buf[2]
The two grid state buffers.