28 #include "libavutil/file.h"
29 #include "libavutil/lfg.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/parseutils.h"
32 #include "libavutil/random_seed.h"
33 #include "libavutil/avstring.h"
59 #define OFFSET(x) offsetof(CellAutoContext, x)
60 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
74 {
"random_seed",
"set the seed for filling the initial grid randomly",
OFFSET(random_seed),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, UINT32_MAX,
FLAGS },
75 {
"seed",
"set the seed for filling the initial grid randomly",
OFFSET(random_seed),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, UINT32_MAX,
FLAGS },
95 for (i = 0; i < cellauto->
w; i++)
96 line[i] = row[i] ?
'@' :
' ';
113 if (w > cellauto->
w) {
115 "The specified width is %d which cannot contain the provided string width of %d\n",
122 cellauto->
h = (double)cellauto->
w *
M_PHI;
131 for (i = (cellauto->
w - w)/2;; i++) {
133 if (*p ==
'\n' || !*p)
171 av_log(ctx,
AV_LOG_ERROR,
"Only one of the filename or pattern options can be used\n");
178 }
else if (cellauto->
pattern) {
193 for (i = 0; i < cellauto->
w; i++) {
195 if (r <= cellauto->random_fill_ratio)
196 cellauto->
buf[i] = 1;
201 "s:%dx%d r:%d/%d rule:%d stitch:%d scroll:%d full:%d seed:%u\n",
221 outlink->
w = cellauto->
w;
222 outlink->
h = cellauto->
h;
239 for (i = 0; i < cellauto->
w; i++) {
241 pos[NW] = i-1 < 0 ? cellauto->
w-1 : i-1;
243 pos[NE] = i+1 == cellauto->
w ? 0 : i+1;
244 v = prev_row[pos[NW]]<<2 | prev_row[pos[
N]]<<1 | prev_row[pos[NE]];
247 v|= i-1 >= 0 ? prev_row[i-1]<<2 : 0;
248 v|= prev_row[i ]<<1 ;
249 v|= i+1 < cellauto->
w ? prev_row[i+1] : 0;
251 row[i] = !!(cellauto->
rule & (1<<
v));
252 av_dlog(ctx,
"i:%d context:%c%c%c -> cell:%d\n", i,
253 v&4?
'@':
' ', v&2?
'@':
' ', v&1?
'@':
' ', row[i]);
262 int i, j, k, row_idx = 0;
270 for (i = 0; i < cellauto->
h; i++) {
272 uint8_t *row = cellauto->
buf + row_idx*cellauto->
w;
274 for (k = 0, j = 0; j < cellauto->
w; j++) {
275 byte |= row[j]<<(7-k++);
276 if (k==8 || j == cellauto->
w-1) {
282 row_idx = (row_idx + 1) % cellauto->
h;
296 for (i = 0; i < cellauto->
h-1; i++)
302 picref->
pts = cellauto->
pts++;
305 show_cellauto_row(outlink->
src);
329 .description =
NULL_IF_CONFIG_SMALL(
"Create pattern generated by an elementary cellular automaton."),
331 .priv_class = &cellauto_class,
static int request_frame(AVFilterLink *outlink)
This structure describes decoded (raw) audio or video data.
const char * name
Filter name.
void * priv
private data for use by the filter
static const AVFilterPad outputs[]
int h
agreed upon image height
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static av_cold int init(AVFilterContext *ctx)
const char * name
Pad name.
static const AVFilterPad cellauto_outputs[]
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static int config_props(AVFilterLink *outlink)
#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_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#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...
AVFilterContext * src
source filter
static int init_pattern_from_file(AVFilterContext *ctx)
AVPixelFormat
Pixel format.
int w
agreed upon image width
static void fill_picture(AVFilterContext *ctx, AVFrame *picref)
static void evolve(AVFilterContext *ctx)
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
AVFilter avfilter_vsrc_cellauto
Main libavfilter public API header.
void av_lfg_init(AVLFG *c, unsigned int seed)
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
rational number numerator/denominator
static int query_formats(AVFilterContext *ctx)
offset must point to AVRational
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
offset must point to two consecutive integers
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int av_isgraph(int c)
Locale-independent conversion of ASCII isgraph.
static int init_pattern_from_string(AVFilterContext *ctx)
static const AVOption cellauto_options[]
int64_t generation
the generation number, starting from 0
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
static av_cold void uninit(AVFilterContext *ctx)
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
#define AVFILTER_DEFINE_CLASS(fname)
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...
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...