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 },
102static 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++) {
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++) {
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];
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);
450 .p.priv_class = &life_class,
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int request_frame(AVFilterLink *outlink)
const FFFilter ff_vsrc_life
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
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
#define i(width, name, range_min, range_max)
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ 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...
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
static av_const int av_isgraph(int c)
Locale-independent conversion of ASCII isgraph.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
#define FILTER_OUTPUTS(array)
static FilterLink * ff_filter_link(AVFilterLink *link)
#define AVFILTER_DEFINE_CLASS(fname)
#define FILTER_QUERY_FUNC2(func)
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...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
static int config_props(AVBitStreamFilterLink *link)
Describe the class of an AVClass context structure.
void * priv
private data for use by the filter
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
A filter pad used for either input or output.
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).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
int64_t duration
Duration of the frame, in the same units as pts.
Context structure for the Lagged Fibonacci PRNG.
Rational number (pair of numerator and denominator).
Link properties exposed to filter code, but not external callers.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
uint16_t born_rule
encode the behavior for empty cells
uint8_t * buf[2]
The two grid state buffers.
void(* draw)(AVFilterContext *, AVFrame *)
uint16_t stay_rule
encode the behavior for filled cells
In the ELBG jargon, a cell is the set of points that are closest to a codebook entry.
static void error(const char *err)
static AVFormatContext * ctx
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int init_pattern_from_file(AVFilterContext *ctx)
static int config_props(AVFilterLink *outlink)
static const AVOption life_options[]
static void evolve(AVFilterContext *ctx)
static void fill_picture_rgb(AVFilterContext *ctx, AVFrame *picref)
static int request_frame(AVFilterLink *outlink)
static int parse_rule(uint16_t *born_rule, uint16_t *stay_rule, const char *rule_str, void *log_ctx)
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static av_cold void uninit(AVFilterContext *ctx)
static void fill_picture_monoblack(AVFilterContext *ctx, AVFrame *picref)
static const AVFilterPad life_outputs[]