avfilter/vsrc_cellauto: use the name 's' for the pointer to the private context
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
This commit is contained in:
parent
a62d4a01e8
commit
0f711126b8
@ -86,55 +86,55 @@ AVFILTER_DEFINE_CLASS(cellauto);
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
static void show_cellauto_row(AVFilterContext *ctx)
|
static void show_cellauto_row(AVFilterContext *ctx)
|
||||||
{
|
{
|
||||||
CellAutoContext *cellauto = ctx->priv;
|
CellAutoContext *s = ctx->priv;
|
||||||
int i;
|
int i;
|
||||||
uint8_t *row = cellauto->buf + cellauto->w * cellauto->buf_row_idx;
|
uint8_t *row = s->buf + s->w * s->buf_row_idx;
|
||||||
char *line = av_malloc(cellauto->w + 1);
|
char *line = av_malloc(s->w + 1);
|
||||||
if (!line)
|
if (!line)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < cellauto->w; i++)
|
for (i = 0; i < s->w; i++)
|
||||||
line[i] = row[i] ? '@' : ' ';
|
line[i] = row[i] ? '@' : ' ';
|
||||||
line[i] = 0;
|
line[i] = 0;
|
||||||
av_log(ctx, AV_LOG_DEBUG, "generation:%"PRId64" row:%s|\n", cellauto->generation, line);
|
av_log(ctx, AV_LOG_DEBUG, "generation:%"PRId64" row:%s|\n", s->generation, line);
|
||||||
av_free(line);
|
av_free(line);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int init_pattern_from_string(AVFilterContext *ctx)
|
static int init_pattern_from_string(AVFilterContext *ctx)
|
||||||
{
|
{
|
||||||
CellAutoContext *cellauto = ctx->priv;
|
CellAutoContext *s = ctx->priv;
|
||||||
char *p;
|
char *p;
|
||||||
int i, w = 0;
|
int i, w = 0;
|
||||||
|
|
||||||
w = strlen(cellauto->pattern);
|
w = strlen(s->pattern);
|
||||||
av_log(ctx, AV_LOG_DEBUG, "w:%d\n", w);
|
av_log(ctx, AV_LOG_DEBUG, "w:%d\n", w);
|
||||||
|
|
||||||
if (cellauto->w) {
|
if (s->w) {
|
||||||
if (w > cellauto->w) {
|
if (w > s->w) {
|
||||||
av_log(ctx, AV_LOG_ERROR,
|
av_log(ctx, AV_LOG_ERROR,
|
||||||
"The specified width is %d which cannot contain the provided string width of %d\n",
|
"The specified width is %d which cannot contain the provided string width of %d\n",
|
||||||
cellauto->w, w);
|
s->w, w);
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* width was not specified, set it to width of the provided row */
|
/* width was not specified, set it to width of the provided row */
|
||||||
cellauto->w = w;
|
s->w = w;
|
||||||
cellauto->h = (double)cellauto->w * M_PHI;
|
s->h = (double)s->w * M_PHI;
|
||||||
}
|
}
|
||||||
|
|
||||||
cellauto->buf = av_mallocz_array(sizeof(uint8_t) * cellauto->w, cellauto->h);
|
s->buf = av_mallocz_array(sizeof(uint8_t) * s->w, s->h);
|
||||||
if (!cellauto->buf)
|
if (!s->buf)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
/* fill buf */
|
/* fill buf */
|
||||||
p = cellauto->pattern;
|
p = s->pattern;
|
||||||
for (i = (cellauto->w - w)/2;; i++) {
|
for (i = (s->w - w)/2;; i++) {
|
||||||
av_log(ctx, AV_LOG_DEBUG, "%d %c\n", i, *p == '\n' ? 'N' : *p);
|
av_log(ctx, AV_LOG_DEBUG, "%d %c\n", i, *p == '\n' ? 'N' : *p);
|
||||||
if (*p == '\n' || !*p)
|
if (*p == '\n' || !*p)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
cellauto->buf[i] = !!av_isgraph(*(p++));
|
s->buf[i] = !!av_isgraph(*(p++));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -142,165 +142,165 @@ static int init_pattern_from_string(AVFilterContext *ctx)
|
|||||||
|
|
||||||
static int init_pattern_from_file(AVFilterContext *ctx)
|
static int init_pattern_from_file(AVFilterContext *ctx)
|
||||||
{
|
{
|
||||||
CellAutoContext *cellauto = ctx->priv;
|
CellAutoContext *s = ctx->priv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = av_file_map(cellauto->filename,
|
ret = av_file_map(s->filename,
|
||||||
&cellauto->file_buf, &cellauto->file_bufsize, 0, ctx);
|
&s->file_buf, &s->file_bufsize, 0, ctx);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* create a string based on the read file */
|
/* create a string based on the read file */
|
||||||
cellauto->pattern = av_malloc(cellauto->file_bufsize + 1);
|
s->pattern = av_malloc(s->file_bufsize + 1);
|
||||||
if (!cellauto->pattern)
|
if (!s->pattern)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
memcpy(cellauto->pattern, cellauto->file_buf, cellauto->file_bufsize);
|
memcpy(s->pattern, s->file_buf, s->file_bufsize);
|
||||||
cellauto->pattern[cellauto->file_bufsize] = 0;
|
s->pattern[s->file_bufsize] = 0;
|
||||||
|
|
||||||
return init_pattern_from_string(ctx);
|
return init_pattern_from_string(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int init(AVFilterContext *ctx)
|
static av_cold int init(AVFilterContext *ctx)
|
||||||
{
|
{
|
||||||
CellAutoContext *cellauto = ctx->priv;
|
CellAutoContext *s = ctx->priv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!cellauto->w && !cellauto->filename && !cellauto->pattern)
|
if (!s->w && !s->filename && !s->pattern)
|
||||||
av_opt_set(cellauto, "size", "320x518", 0);
|
av_opt_set(s, "size", "320x518", 0);
|
||||||
|
|
||||||
if (cellauto->filename && cellauto->pattern) {
|
if (s->filename && s->pattern) {
|
||||||
av_log(ctx, AV_LOG_ERROR, "Only one of the filename or pattern options can be used\n");
|
av_log(ctx, AV_LOG_ERROR, "Only one of the filename or pattern options can be used\n");
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cellauto->filename) {
|
if (s->filename) {
|
||||||
if ((ret = init_pattern_from_file(ctx)) < 0)
|
if ((ret = init_pattern_from_file(ctx)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
} else if (cellauto->pattern) {
|
} else if (s->pattern) {
|
||||||
if ((ret = init_pattern_from_string(ctx)) < 0)
|
if ((ret = init_pattern_from_string(ctx)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
/* fill the first row randomly */
|
/* fill the first row randomly */
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
cellauto->buf = av_mallocz_array(sizeof(uint8_t) * cellauto->w, cellauto->h);
|
s->buf = av_mallocz_array(sizeof(uint8_t) * s->w, s->h);
|
||||||
if (!cellauto->buf)
|
if (!s->buf)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
if (cellauto->random_seed == -1)
|
if (s->random_seed == -1)
|
||||||
cellauto->random_seed = av_get_random_seed();
|
s->random_seed = av_get_random_seed();
|
||||||
|
|
||||||
av_lfg_init(&cellauto->lfg, cellauto->random_seed);
|
av_lfg_init(&s->lfg, s->random_seed);
|
||||||
|
|
||||||
for (i = 0; i < cellauto->w; i++) {
|
for (i = 0; i < s->w; i++) {
|
||||||
double r = (double)av_lfg_get(&cellauto->lfg) / UINT32_MAX;
|
double r = (double)av_lfg_get(&s->lfg) / UINT32_MAX;
|
||||||
if (r <= cellauto->random_fill_ratio)
|
if (r <= s->random_fill_ratio)
|
||||||
cellauto->buf[i] = 1;
|
s->buf[i] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
av_log(ctx, AV_LOG_VERBOSE,
|
av_log(ctx, AV_LOG_VERBOSE,
|
||||||
"s:%dx%d r:%d/%d rule:%d stitch:%d scroll:%d full:%d seed:%u\n",
|
"s:%dx%d r:%d/%d rule:%d stitch:%d scroll:%d full:%d seed:%u\n",
|
||||||
cellauto->w, cellauto->h, cellauto->frame_rate.num, cellauto->frame_rate.den,
|
s->w, s->h, s->frame_rate.num, s->frame_rate.den,
|
||||||
cellauto->rule, cellauto->stitch, cellauto->scroll, cellauto->start_full,
|
s->rule, s->stitch, s->scroll, s->start_full,
|
||||||
cellauto->random_seed);
|
s->random_seed);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold void uninit(AVFilterContext *ctx)
|
static av_cold void uninit(AVFilterContext *ctx)
|
||||||
{
|
{
|
||||||
CellAutoContext *cellauto = ctx->priv;
|
CellAutoContext *s = ctx->priv;
|
||||||
|
|
||||||
av_file_unmap(cellauto->file_buf, cellauto->file_bufsize);
|
av_file_unmap(s->file_buf, s->file_bufsize);
|
||||||
av_freep(&cellauto->buf);
|
av_freep(&s->buf);
|
||||||
av_freep(&cellauto->pattern);
|
av_freep(&s->pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int config_props(AVFilterLink *outlink)
|
static int config_props(AVFilterLink *outlink)
|
||||||
{
|
{
|
||||||
CellAutoContext *cellauto = outlink->src->priv;
|
CellAutoContext *s = outlink->src->priv;
|
||||||
|
|
||||||
outlink->w = cellauto->w;
|
outlink->w = s->w;
|
||||||
outlink->h = cellauto->h;
|
outlink->h = s->h;
|
||||||
outlink->time_base = av_inv_q(cellauto->frame_rate);
|
outlink->time_base = av_inv_q(s->frame_rate);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void evolve(AVFilterContext *ctx)
|
static void evolve(AVFilterContext *ctx)
|
||||||
{
|
{
|
||||||
CellAutoContext *cellauto = ctx->priv;
|
CellAutoContext *s = ctx->priv;
|
||||||
int i, v, pos[3];
|
int i, v, pos[3];
|
||||||
uint8_t *row, *prev_row = cellauto->buf + cellauto->buf_row_idx * cellauto->w;
|
uint8_t *row, *prev_row = s->buf + s->buf_row_idx * s->w;
|
||||||
enum { NW, N, NE };
|
enum { NW, N, NE };
|
||||||
|
|
||||||
cellauto->buf_prev_row_idx = cellauto->buf_row_idx;
|
s->buf_prev_row_idx = s->buf_row_idx;
|
||||||
cellauto->buf_row_idx = cellauto->buf_row_idx == cellauto->h-1 ? 0 : cellauto->buf_row_idx+1;
|
s->buf_row_idx = s->buf_row_idx == s->h-1 ? 0 : s->buf_row_idx+1;
|
||||||
row = cellauto->buf + cellauto->w * cellauto->buf_row_idx;
|
row = s->buf + s->w * s->buf_row_idx;
|
||||||
|
|
||||||
for (i = 0; i < cellauto->w; i++) {
|
for (i = 0; i < s->w; i++) {
|
||||||
if (cellauto->stitch) {
|
if (s->stitch) {
|
||||||
pos[NW] = i-1 < 0 ? cellauto->w-1 : i-1;
|
pos[NW] = i-1 < 0 ? s->w-1 : i-1;
|
||||||
pos[N] = i;
|
pos[N] = i;
|
||||||
pos[NE] = i+1 == cellauto->w ? 0 : i+1;
|
pos[NE] = i+1 == s->w ? 0 : i+1;
|
||||||
v = prev_row[pos[NW]]<<2 | prev_row[pos[N]]<<1 | prev_row[pos[NE]];
|
v = prev_row[pos[NW]]<<2 | prev_row[pos[N]]<<1 | prev_row[pos[NE]];
|
||||||
} else {
|
} else {
|
||||||
v = 0;
|
v = 0;
|
||||||
v|= i-1 >= 0 ? prev_row[i-1]<<2 : 0;
|
v|= i-1 >= 0 ? prev_row[i-1]<<2 : 0;
|
||||||
v|= prev_row[i ]<<1 ;
|
v|= prev_row[i ]<<1 ;
|
||||||
v|= i+1 < cellauto->w ? prev_row[i+1] : 0;
|
v|= i+1 < s->w ? prev_row[i+1] : 0;
|
||||||
}
|
}
|
||||||
row[i] = !!(cellauto->rule & (1<<v));
|
row[i] = !!(s->rule & (1<<v));
|
||||||
ff_dlog(ctx, "i:%d context:%c%c%c -> cell:%d\n", i,
|
ff_dlog(ctx, "i:%d context:%c%c%c -> cell:%d\n", i,
|
||||||
v&4?'@':' ', v&2?'@':' ', v&1?'@':' ', row[i]);
|
v&4?'@':' ', v&2?'@':' ', v&1?'@':' ', row[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
cellauto->generation++;
|
s->generation++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fill_picture(AVFilterContext *ctx, AVFrame *picref)
|
static void fill_picture(AVFilterContext *ctx, AVFrame *picref)
|
||||||
{
|
{
|
||||||
CellAutoContext *cellauto = ctx->priv;
|
CellAutoContext *s = ctx->priv;
|
||||||
int i, j, k, row_idx = 0;
|
int i, j, k, row_idx = 0;
|
||||||
uint8_t *p0 = picref->data[0];
|
uint8_t *p0 = picref->data[0];
|
||||||
|
|
||||||
if (cellauto->scroll && cellauto->generation >= cellauto->h)
|
if (s->scroll && s->generation >= s->h)
|
||||||
/* show on top the oldest row */
|
/* show on top the oldest row */
|
||||||
row_idx = (cellauto->buf_row_idx + 1) % cellauto->h;
|
row_idx = (s->buf_row_idx + 1) % s->h;
|
||||||
|
|
||||||
/* fill the output picture with the whole buffer */
|
/* fill the output picture with the whole buffer */
|
||||||
for (i = 0; i < cellauto->h; i++) {
|
for (i = 0; i < s->h; i++) {
|
||||||
uint8_t byte = 0;
|
uint8_t byte = 0;
|
||||||
uint8_t *row = cellauto->buf + row_idx*cellauto->w;
|
uint8_t *row = s->buf + row_idx*s->w;
|
||||||
uint8_t *p = p0;
|
uint8_t *p = p0;
|
||||||
for (k = 0, j = 0; j < cellauto->w; j++) {
|
for (k = 0, j = 0; j < s->w; j++) {
|
||||||
byte |= row[j]<<(7-k++);
|
byte |= row[j]<<(7-k++);
|
||||||
if (k==8 || j == cellauto->w-1) {
|
if (k==8 || j == s->w-1) {
|
||||||
k = 0;
|
k = 0;
|
||||||
*p++ = byte;
|
*p++ = byte;
|
||||||
byte = 0;
|
byte = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
row_idx = (row_idx + 1) % cellauto->h;
|
row_idx = (row_idx + 1) % s->h;
|
||||||
p0 += picref->linesize[0];
|
p0 += picref->linesize[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int request_frame(AVFilterLink *outlink)
|
static int request_frame(AVFilterLink *outlink)
|
||||||
{
|
{
|
||||||
CellAutoContext *cellauto = outlink->src->priv;
|
CellAutoContext *s = outlink->src->priv;
|
||||||
AVFrame *picref = ff_get_video_buffer(outlink, cellauto->w, cellauto->h);
|
AVFrame *picref = ff_get_video_buffer(outlink, s->w, s->h);
|
||||||
if (!picref)
|
if (!picref)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
picref->sample_aspect_ratio = (AVRational) {1, 1};
|
picref->sample_aspect_ratio = (AVRational) {1, 1};
|
||||||
if (cellauto->generation == 0 && cellauto->start_full) {
|
if (s->generation == 0 && s->start_full) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < cellauto->h-1; i++)
|
for (i = 0; i < s->h-1; i++)
|
||||||
evolve(outlink->src);
|
evolve(outlink->src);
|
||||||
}
|
}
|
||||||
fill_picture(outlink->src, picref);
|
fill_picture(outlink->src, picref);
|
||||||
evolve(outlink->src);
|
evolve(outlink->src);
|
||||||
|
|
||||||
picref->pts = cellauto->pts++;
|
picref->pts = s->pts++;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
show_cellauto_row(outlink->src);
|
show_cellauto_row(outlink->src);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user