FFmpeg: libavfilter/vsrc_cellauto.c Source File
Go to the documentation of this file. 1 /*
2 * Copyright (c) Stefano Sabatini 2011
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 * cellular automaton video source, based on Stephen Wolfram "experimentus crucis"
24 */
25
26 /* #define DEBUG */
27
37
57
58 #define OFFSET(x) offsetof(CellAutoContext, x)
59 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
60
73 {
"random_seed",
"set the seed for filling the initial grid randomly",
OFFSET(random_seed),
AV_OPT_TYPE_INT64, {.i64 = -1}, -1, UINT32_MAX,
FLAGS },
74 {
"seed",
"set the seed for filling the initial grid randomly",
OFFSET(random_seed),
AV_OPT_TYPE_INT64, {.i64 = -1}, -1, UINT32_MAX,
FLAGS },
80 };
81
83
84 #ifdef DEBUG
86 {
89 uint8_t *row =
s->buf +
s->w *
s->buf_row_idx;
92 return;
93
94 for (
i = 0;
i <
s->w;
i++)
95 line[
i] = row[
i] ?
'@' :
' ';
99 }
100 #endif
101
103 {
105 char *p;
107
108 w = strlen(
s->pattern);
110
114 "The specified width is %d which cannot contain the provided string width of %d\n",
117 }
118 } else {
119 /* width was not specified, set it to width of the provided row */
122 }
123
127
128 /* fill buf */
130 for (
i = (
s->w -
w)/2;;
i++) {
132 if (*p == '\n' || !*p)
133 break;
134 else
136 }
137
138 return 0;
139 }
140
142 {
145
147 &
s->file_buf, &
s->file_bufsize, 0,
ctx);
150
151 /* create a string based on the read file */
155 memcpy(
s->pattern,
s->file_buf,
s->file_bufsize);
156 s->pattern[
s->file_bufsize] = 0;
157
159 }
160
162 {
165
166 if (!
s->w && !
s->filename && !
s->pattern)
168
169 if (
s->filename &&
s->pattern) {
172 }
173
177 }
else if (
s->pattern) {
180 } else {
181 /* fill the first row randomly */
183
187 if (
s->random_seed == -1)
189
191
192 for (
i = 0;
i <
s->w;
i++) {
194 if (r <= s->random_fill_ratio)
196 }
197 }
198
200 "s:%dx%d r:%d/%d rule:%d stitch:%d scroll:%d full:%d seed:%"PRId64"\n",
201 s->w,
s->h,
s->frame_rate.num,
s->frame_rate.den,
202 s->rule,
s->stitch,
s->scroll,
s->start_full,
204 return 0;
205 }
206
208 {
210
214 }
215
217 {
219
224
225 return 0;
226 }
227
229 {
232 uint8_t *row, *prev_row =
s->buf +
s->buf_row_idx *
s->w;
234
235 s->buf_prev_row_idx =
s->buf_row_idx;
236 s->buf_row_idx =
s->buf_row_idx ==
s->h-1 ? 0 :
s->buf_row_idx+1;
237 row =
s->buf +
s->w *
s->buf_row_idx;
238
239 for (
i = 0;
i <
s->w;
i++) {
241 pos[NW] =
i-1 < 0 ?
s->w-1 :
i-1;
243 pos[NE] =
i+1 ==
s->w ? 0 :
i+1;
244 v = prev_row[
pos[NW]]<<2 | prev_row[
pos[
N]]<<1 | prev_row[
pos[NE]];
245 } else {
246 v = 0;
247 v|=
i-1 >= 0 ? prev_row[
i-1]<<2 : 0;
248 v|= prev_row[
i ]<<1 ;
249 v|=
i+1 <
s->w ? prev_row[
i+1] : 0;
250 }
251 row[
i] = !!(
s->rule & (1<<v));
252 ff_dlog(
ctx,
"i:%d context:%c%c%c -> cell:%d\n",
i,
253 v&4?
'@':
' ', v&2?
'@':
' ', v&1?
'@':
' ', row[
i]);
254 }
255
257 }
258
260 {
262 int i, j, k, row_idx = 0;
263 uint8_t *p0 = picref->
data[0];
264
265 if (
s->scroll &&
s->generation >=
s->h)
266 /* show on top the oldest row */
267 row_idx = (
s->buf_row_idx + 1) %
s->h;
268
269 /* fill the output picture with the whole buffer */
271 uint8_t byte = 0;
272 uint8_t *row =
s->buf + row_idx*
s->w;
273 uint8_t *p = p0;
274 for (k = 0, j = 0; j <
s->w; j++) {
275 byte |= row[j]<<(7-k++);
276 if (k==8 || j ==
s->w-1) {
277 k = 0;
279 byte = 0;
280 }
281 }
282 row_idx = (row_idx + 1) %
s->h;
284 }
285 }
286
288 {
291 if (!picref)
294 if (
s->generation == 0 &&
s->start_full) {
296 for (
i = 0;
i <
s->h-1;
i++)
298 }
301
302 picref->
pts =
s->pts++;
304
305 #ifdef DEBUG
306 show_cellauto_row(outlink->
src);
307 #endif
309 }
310
312 {
317 },
318 };
319
322 .description =
NULL_IF_CONFIG_SMALL(
"Create pattern generated by an elementary cellular automaton."),
324 .priv_class = &cellauto_class,
330 };
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
int64_t generation
the generation number, starting from 0
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int64_t duration
Duration of the frame, in the same units as pts.
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
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).
#define AV_LOG_VERBOSE
Detailed information.
const char * name
Filter name.
static int init_pattern_from_file(AVFilterContext *ctx)
A link between two filters.
static av_cold int init(AVFilterContext *ctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
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...
void * priv
private data for use by the filter
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
A filter pad used for either input or output.
static int config_props(AVFilterLink *outlink)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int request_frame(AVFilterLink *outlink)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void av_file_unmap(uint8_t *bufptr, size_t size)
Unmap or free the buffer bufptr created by av_file_map().
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
static void evolve(AVFilterContext *ctx)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
static const AVFilterPad cellauto_outputs[]
Context structure for the Lagged Fibonacci PRNG.
AVFILTER_DEFINE_CLASS(cellauto)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
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
AVFilterContext * src
source filter
static av_const int av_isgraph(int c)
Locale-independent conversion of ASCII isgraph.
static void fill_picture(AVFilterContext *ctx, AVFrame *picref)
const AVFilter ff_vsrc_cellauto
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
static av_cold void uninit(AVFilterContext *ctx)
int h
agreed upon image height
static int init_pattern_from_string(AVFilterContext *ctx)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
#define FILTER_OUTPUTS(array)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
static const AVOption cellauto_options[]
Generated on Thu Sep 26 2024 23:15:42 for FFmpeg by
doxygen
1.8.17