LCOV - code coverage report
Current view: top level - libavfilter - vsrc_life.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 113 188 60.1 %
Date: 2017-12-17 16:07:53 Functions: 8 10 80.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) Stefano Sabatini 2010
       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             :  * life video source, based on John Conways' Life Game
      24             :  */
      25             : 
      26             : /* #define DEBUG */
      27             : 
      28             : #include "libavutil/file.h"
      29             : #include "libavutil/internal.h"
      30             : #include "libavutil/intreadwrite.h"
      31             : #include "libavutil/lfg.h"
      32             : #include "libavutil/opt.h"
      33             : #include "libavutil/parseutils.h"
      34             : #include "libavutil/random_seed.h"
      35             : #include "libavutil/avstring.h"
      36             : #include "avfilter.h"
      37             : #include "internal.h"
      38             : #include "formats.h"
      39             : #include "video.h"
      40             : 
      41             : typedef struct LifeContext {
      42             :     const AVClass *class;
      43             :     int w, h;
      44             :     char *filename;
      45             :     char *rule_str;
      46             :     uint8_t *file_buf;
      47             :     size_t file_bufsize;
      48             : 
      49             :     /**
      50             :      * The two grid state buffers.
      51             :      *
      52             :      * A 0xFF (ALIVE_CELL) value means the cell is alive (or new born), while
      53             :      * the decreasing values from 0xFE to 0 means the cell is dead; the range
      54             :      * of values is used for the slow death effect, or mold (0xFE means dead,
      55             :      * 0xFD means very dead, 0xFC means very very dead... and 0x00 means
      56             :      * definitely dead/mold).
      57             :      */
      58             :     uint8_t *buf[2];
      59             : 
      60             :     uint8_t  buf_idx;
      61             :     uint16_t stay_rule;         ///< encode the behavior for filled cells
      62             :     uint16_t born_rule;         ///< encode the behavior for empty cells
      63             :     uint64_t pts;
      64             :     AVRational frame_rate;
      65             :     double   random_fill_ratio;
      66             :     uint32_t random_seed;
      67             :     int stitch;
      68             :     int mold;
      69             :     uint8_t  life_color[4];
      70             :     uint8_t death_color[4];
      71             :     uint8_t  mold_color[4];
      72             :     AVLFG lfg;
      73             :     void (*draw)(AVFilterContext*, AVFrame*);
      74             : } LifeContext;
      75             : 
      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
      79             : 
      80             : static const AVOption life_options[] = {
      81             :     { "filename", "set source file",  OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
      82             :     { "f",        "set source file",  OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
      83             :     { "size",     "set video size",   OFFSET(w),        AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, FLAGS },
      84             :     { "s",        "set video size",   OFFSET(w),        AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, FLAGS },
      85             :     { "rate",     "set video rate",   OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },
      86             :     { "r",        "set video rate",   OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },
      87             :     { "rule",     "set rule",         OFFSET(rule_str), AV_OPT_TYPE_STRING, {.str = "B3/S23"}, CHAR_MIN, CHAR_MAX, FLAGS },
      88             :     { "random_fill_ratio", "set fill ratio for filling initial grid randomly", OFFSET(random_fill_ratio), AV_OPT_TYPE_DOUBLE, {.dbl=1/M_PHI}, 0, 1, FLAGS },
      89             :     { "ratio",             "set fill ratio for filling initial grid randomly", OFFSET(random_fill_ratio), AV_OPT_TYPE_DOUBLE, {.dbl=1/M_PHI}, 0, 1, FLAGS },
      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 },
      92             :     { "stitch",      "stitch boundaries", OFFSET(stitch), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
      93             :     { "mold",        "set mold speed for dead cells", OFFSET(mold), AV_OPT_TYPE_INT, {.i64=0}, 0, 0xFF, FLAGS },
      94             :     { "life_color",  "set life color",  OFFSET( life_color), AV_OPT_TYPE_COLOR, {.str="white"}, CHAR_MIN, CHAR_MAX, FLAGS },
      95             :     { "death_color", "set death color", OFFSET(death_color), AV_OPT_TYPE_COLOR, {.str="black"}, CHAR_MIN, CHAR_MAX, FLAGS },
      96             :     { "mold_color",  "set mold color",  OFFSET( mold_color), AV_OPT_TYPE_COLOR, {.str="black"}, CHAR_MIN, CHAR_MAX, FLAGS },
      97             :     { NULL }
      98             : };
      99             : 
     100             : AVFILTER_DEFINE_CLASS(life);
     101             : 
     102           1 : static int parse_rule(uint16_t *born_rule, uint16_t *stay_rule,
     103             :                       const char *rule_str, void *log_ctx)
     104             : {
     105             :     char *tail;
     106           1 :     const char *p = rule_str;
     107           1 :     *born_rule = 0;
     108           1 :     *stay_rule = 0;
     109             : 
     110           1 :     if (strchr("bBsS", *p)) {
     111             :         /* parse rule as a Born / Stay Alive code, see
     112             :          * http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life */
     113             :         do {
     114           2 :             uint16_t *rule = (*p == 'b' || *p == 'B') ? born_rule : stay_rule;
     115           2 :             p++;
     116           7 :             while (*p >= '0' && *p <= '8') {
     117           3 :                 *rule += 1<<(*p - '0');
     118           3 :                 p++;
     119             :             }
     120           2 :             if (*p != '/')
     121           1 :                 break;
     122           1 :             p++;
     123           1 :         } while (strchr("bBsS", *p));
     124             : 
     125           1 :         if (*p)
     126           0 :             goto error;
     127             :     } else {
     128             :         /* parse rule as a number, expressed in the form STAY|(BORN<<9),
     129             :          * where STAY and BORN encode the corresponding 9-bits rule */
     130           0 :         long int rule = strtol(rule_str, &tail, 10);
     131           0 :         if (*tail)
     132           0 :             goto error;
     133           0 :         *born_rule  = ((1<<9)-1) & rule;
     134           0 :         *stay_rule = rule >> 9;
     135             :     }
     136             : 
     137           1 :     return 0;
     138             : 
     139           0 : error:
     140           0 :     av_log(log_ctx, AV_LOG_ERROR, "Invalid rule code '%s' provided\n", rule_str);
     141           0 :     return AVERROR(EINVAL);
     142             : }
     143             : 
     144             : #ifdef DEBUG
     145             : static void show_life_grid(AVFilterContext *ctx)
     146             : {
     147             :     LifeContext *life = ctx->priv;
     148             :     int i, j;
     149             : 
     150             :     char *line = av_malloc(life->w + 1);
     151             :     if (!line)
     152             :         return;
     153             :     for (i = 0; i < life->h; i++) {
     154             :         for (j = 0; j < life->w; j++)
     155             :             line[j] = life->buf[life->buf_idx][i*life->w + j] == ALIVE_CELL ? '@' : ' ';
     156             :         line[j] = 0;
     157             :         av_log(ctx, AV_LOG_DEBUG, "%3d: %s\n", i, line);
     158             :     }
     159             :     av_free(line);
     160             : }
     161             : #endif
     162             : 
     163           0 : static int init_pattern_from_file(AVFilterContext *ctx)
     164             : {
     165           0 :     LifeContext *life = ctx->priv;
     166             :     char *p;
     167           0 :     int ret, i, i0, j, h = 0, w, max_w = 0;
     168             : 
     169           0 :     if ((ret = av_file_map(life->filename, &life->file_buf, &life->file_bufsize,
     170             :                            0, ctx)) < 0)
     171           0 :         return ret;
     172           0 :     av_freep(&life->filename);
     173             : 
     174             :     /* prescan file to get the number of lines and the maximum width */
     175           0 :     w = 0;
     176           0 :     for (i = 0; i < life->file_bufsize; i++) {
     177           0 :         if (life->file_buf[i] == '\n') {
     178           0 :             h++; max_w = FFMAX(w, max_w); w = 0;
     179             :         } else {
     180           0 :             w++;
     181             :         }
     182             :     }
     183           0 :     av_log(ctx, AV_LOG_DEBUG, "h:%d max_w:%d\n", h, max_w);
     184             : 
     185           0 :     if (life->w) {
     186           0 :         if (max_w > life->w || h > life->h) {
     187           0 :             av_log(ctx, AV_LOG_ERROR,
     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);
     190           0 :             return AVERROR(EINVAL);
     191             :         }
     192             :     } else {
     193             :         /* size was not specified, set it to size of the grid */
     194           0 :         life->w = max_w;
     195           0 :         life->h = h;
     196             :     }
     197             : 
     198           0 :     if (!(life->buf[0] = av_calloc(life->h * life->w, sizeof(*life->buf[0]))) ||
     199           0 :         !(life->buf[1] = av_calloc(life->h * life->w, sizeof(*life->buf[1])))) {
     200           0 :         av_freep(&life->buf[0]);
     201           0 :         av_freep(&life->buf[1]);
     202           0 :         return AVERROR(ENOMEM);
     203             :     }
     204             : 
     205             :     /* fill buf[0] */
     206           0 :     p = life->file_buf;
     207           0 :     for (i0 = 0, i = (life->h - h)/2; i0 < h; i0++, i++) {
     208           0 :         for (j = (life->w - max_w)/2;; j++) {
     209           0 :             av_log(ctx, AV_LOG_DEBUG, "%d:%d %c\n", i, j, *p == '\n' ? 'N' : *p);
     210           0 :             if (*p == '\n') {
     211           0 :                 p++; break;
     212             :             } else
     213           0 :                 life->buf[0][i*life->w + j] = av_isgraph(*(p++)) ? ALIVE_CELL : 0;
     214             :         }
     215             :     }
     216           0 :     life->buf_idx = 0;
     217             : 
     218           0 :     return 0;
     219             : }
     220             : 
     221           1 : static av_cold int init(AVFilterContext *ctx)
     222             : {
     223           1 :     LifeContext *life = ctx->priv;
     224             :     int ret;
     225             : 
     226           1 :     if (!life->w && !life->filename)
     227           0 :         av_opt_set(life, "size", "320x240", 0);
     228             : 
     229           1 :     if ((ret = parse_rule(&life->born_rule, &life->stay_rule, life->rule_str, ctx)) < 0)
     230           0 :         return ret;
     231             : 
     232           1 :     if (!life->mold && memcmp(life->mold_color, "\x00\x00\x00", 3))
     233           0 :         av_log(ctx, AV_LOG_WARNING,
     234             :                "Mold color is set while mold isn't, ignoring the color.\n");
     235             : 
     236           1 :     if (!life->filename) {
     237             :         /* fill the grid randomly */
     238             :         int i;
     239             : 
     240           2 :         if (!(life->buf[0] = av_calloc(life->h * life->w, sizeof(*life->buf[0]))) ||
     241           1 :             !(life->buf[1] = av_calloc(life->h * life->w, sizeof(*life->buf[1])))) {
     242           0 :             av_freep(&life->buf[0]);
     243           0 :             av_freep(&life->buf[1]);
     244           0 :             return AVERROR(ENOMEM);
     245             :         }
     246           1 :         if (life->random_seed == -1)
     247           0 :             life->random_seed = av_get_random_seed();
     248             : 
     249           1 :         av_lfg_init(&life->lfg, life->random_seed);
     250             : 
     251        1601 :         for (i = 0; i < life->w * life->h; i++) {
     252        1600 :             double r = (double)av_lfg_get(&life->lfg) / UINT32_MAX;
     253        1600 :             if (r <= life->random_fill_ratio)
     254         171 :                 life->buf[0][i] = ALIVE_CELL;
     255             :         }
     256           1 :         life->buf_idx = 0;
     257             :     } else {
     258           0 :         if ((ret = init_pattern_from_file(ctx)) < 0)
     259           0 :             return ret;
     260             :     }
     261             : 
     262           3 :     av_log(ctx, AV_LOG_VERBOSE,
     263             :            "s:%dx%d r:%d/%d rule:%s stay_rule:%d born_rule:%d stitch:%d seed:%"PRIu32"\n",
     264             :            life->w, life->h, life->frame_rate.num, life->frame_rate.den,
     265           2 :            life->rule_str, life->stay_rule, life->born_rule, life->stitch,
     266             :            life->random_seed);
     267           1 :     return 0;
     268             : }
     269             : 
     270           1 : static av_cold void uninit(AVFilterContext *ctx)
     271             : {
     272           1 :     LifeContext *life = ctx->priv;
     273             : 
     274           1 :     av_file_unmap(life->file_buf, life->file_bufsize);
     275           1 :     av_freep(&life->rule_str);
     276           1 :     av_freep(&life->buf[0]);
     277           1 :     av_freep(&life->buf[1]);
     278           1 : }
     279             : 
     280           1 : static int config_props(AVFilterLink *outlink)
     281             : {
     282           1 :     LifeContext *life = outlink->src->priv;
     283             : 
     284           1 :     outlink->w = life->w;
     285           1 :     outlink->h = life->h;
     286           1 :     outlink->time_base = av_inv_q(life->frame_rate);
     287             : 
     288           1 :     return 0;
     289             : }
     290             : 
     291          11 : static void evolve(AVFilterContext *ctx)
     292             : {
     293          11 :     LifeContext *life = ctx->priv;
     294             :     int i, j;
     295          11 :     uint8_t *oldbuf = life->buf[ life->buf_idx];
     296          11 :     uint8_t *newbuf = life->buf[!life->buf_idx];
     297             : 
     298             :     enum { NW, N, NE, W, E, SW, S, SE };
     299             : 
     300             :     /* evolve the grid */
     301         451 :     for (i = 0; i < life->h; i++) {
     302       18040 :         for (j = 0; j < life->w; j++) {
     303             :             int pos[8][2], n, alive, cell;
     304       17600 :             if (life->stitch) {
     305       17600 :                 pos[NW][0] = (i-1) < 0 ? life->h-1 : i-1; pos[NW][1] = (j-1) < 0 ? life->w-1 : j-1;
     306       17600 :                 pos[N ][0] = (i-1) < 0 ? life->h-1 : i-1; pos[N ][1] =                         j  ;
     307       17600 :                 pos[NE][0] = (i-1) < 0 ? life->h-1 : i-1; pos[NE][1] = (j+1) == life->w ?  0 : j+1;
     308       17600 :                 pos[W ][0] =                         i  ; pos[W ][1] = (j-1) < 0 ? life->w-1 : j-1;
     309       17600 :                 pos[E ][0] =                         i  ; pos[E ][1] = (j+1) == life->w ? 0  : j+1;
     310       17600 :                 pos[SW][0] = (i+1) == life->h ?  0 : i+1; pos[SW][1] = (j-1) < 0 ? life->w-1 : j-1;
     311       17600 :                 pos[S ][0] = (i+1) == life->h ?  0 : i+1; pos[S ][1] =                         j  ;
     312       17600 :                 pos[SE][0] = (i+1) == life->h ?  0 : i+1; pos[SE][1] = (j+1) == life->w ?  0 : j+1;
     313             :             } else {
     314           0 :                 pos[NW][0] = (i-1) < 0 ? -1        : i-1; pos[NW][1] = (j-1) < 0 ? -1        : j-1;
     315           0 :                 pos[N ][0] = (i-1) < 0 ? -1        : i-1; pos[N ][1] =                         j  ;
     316           0 :                 pos[NE][0] = (i-1) < 0 ? -1        : i-1; pos[NE][1] = (j+1) == life->w ? -1 : j+1;
     317           0 :                 pos[W ][0] =                         i  ; pos[W ][1] = (j-1) < 0 ? -1        : j-1;
     318           0 :                 pos[E ][0] =                         i  ; pos[E ][1] = (j+1) == life->w ? -1 : j+1;
     319           0 :                 pos[SW][0] = (i+1) == life->h ? -1 : i+1; pos[SW][1] = (j-1) < 0 ? -1        : j-1;
     320           0 :                 pos[S ][0] = (i+1) == life->h ? -1 : i+1; pos[S ][1] =                         j  ;
     321           0 :                 pos[SE][0] = (i+1) == life->h ? -1 : i+1; pos[SE][1] = (j+1) == life->w ? -1 : j+1;
     322             :             }
     323             : 
     324             :             /* compute the number of live neighbor cells */
     325       52800 :             n = (pos[NW][0] == -1 || pos[NW][1] == -1 ? 0 : oldbuf[pos[NW][0]*life->w + pos[NW][1]] == ALIVE_CELL) +
     326       35200 :                 (pos[N ][0] == -1 || pos[N ][1] == -1 ? 0 : oldbuf[pos[N ][0]*life->w + pos[N ][1]] == ALIVE_CELL) +
     327       35200 :                 (pos[NE][0] == -1 || pos[NE][1] == -1 ? 0 : oldbuf[pos[NE][0]*life->w + pos[NE][1]] == ALIVE_CELL) +
     328       35200 :                 (pos[W ][0] == -1 || pos[W ][1] == -1 ? 0 : oldbuf[pos[W ][0]*life->w + pos[W ][1]] == ALIVE_CELL) +
     329       35200 :                 (pos[E ][0] == -1 || pos[E ][1] == -1 ? 0 : oldbuf[pos[E ][0]*life->w + pos[E ][1]] == ALIVE_CELL) +
     330       35200 :                 (pos[SW][0] == -1 || pos[SW][1] == -1 ? 0 : oldbuf[pos[SW][0]*life->w + pos[SW][1]] == ALIVE_CELL) +
     331       17600 :                 (pos[S ][0] == -1 || pos[S ][1] == -1 ? 0 : oldbuf[pos[S ][0]*life->w + pos[S ][1]] == ALIVE_CELL) +
     332       17600 :                 (pos[SE][0] == -1 || pos[SE][1] == -1 ? 0 : oldbuf[pos[SE][0]*life->w + pos[SE][1]] == ALIVE_CELL);
     333       17600 :             cell  = oldbuf[i*life->w + j];
     334       17600 :             alive = 1<<n & (cell == ALIVE_CELL ? life->stay_rule : life->born_rule);
     335       17600 :             if (alive)     *newbuf = ALIVE_CELL; // new cell is alive
     336       16415 :             else if (cell) *newbuf = cell - 1;   // new cell is dead and in the process of mold
     337       14002 :             else           *newbuf = 0;          // new cell is definitely dead
     338             :             ff_dlog(ctx, "i:%d j:%d live_neighbors:%d cell:%d -> cell:%d\n", i, j, n, cell, *newbuf);
     339       17600 :             newbuf++;
     340             :         }
     341             :     }
     342             : 
     343          11 :     life->buf_idx = !life->buf_idx;
     344          11 : }
     345             : 
     346           0 : static void fill_picture_monoblack(AVFilterContext *ctx, AVFrame *picref)
     347             : {
     348           0 :     LifeContext *life = ctx->priv;
     349           0 :     uint8_t *buf = life->buf[life->buf_idx];
     350             :     int i, j, k;
     351             : 
     352             :     /* fill the output picture with the old grid buffer */
     353           0 :     for (i = 0; i < life->h; i++) {
     354           0 :         uint8_t byte = 0;
     355           0 :         uint8_t *p = picref->data[0] + i * picref->linesize[0];
     356           0 :         for (k = 0, j = 0; j < life->w; j++) {
     357           0 :             byte |= (buf[i*life->w+j] == ALIVE_CELL)<<(7-k++);
     358           0 :             if (k==8 || j == life->w-1) {
     359           0 :                 k = 0;
     360           0 :                 *p++ = byte;
     361           0 :                 byte = 0;
     362             :             }
     363             :         }
     364             :     }
     365           0 : }
     366             : 
     367             : // divide by 255 and round to nearest
     368             : // apply a fast variant: (X+127)/255 = ((X+127)*257+257)>>16 = ((X+128)*257)>>16
     369             : #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
     370             : 
     371          11 : static void fill_picture_rgb(AVFilterContext *ctx, AVFrame *picref)
     372             : {
     373          11 :     LifeContext *life = ctx->priv;
     374          11 :     uint8_t *buf = life->buf[life->buf_idx];
     375             :     int i, j;
     376             : 
     377             :     /* fill the output picture with the old grid buffer */
     378         451 :     for (i = 0; i < life->h; i++) {
     379         440 :         uint8_t *p = picref->data[0] + i * picref->linesize[0];
     380       18040 :         for (j = 0; j < life->w; j++) {
     381       17600 :             uint8_t v = buf[i*life->w + j];
     382       33956 :             if (life->mold && v != ALIVE_CELL) {
     383       16356 :                 const uint8_t *c1 = life-> mold_color;
     384       16356 :                 const uint8_t *c2 = life->death_color;
     385       16356 :                 int death_age = FFMIN((0xff - v) * life->mold, 0xff);
     386       16356 :                 *p++ = FAST_DIV255((c2[0] << 8) + ((int)c1[0] - (int)c2[0]) * death_age);
     387       16356 :                 *p++ = FAST_DIV255((c2[1] << 8) + ((int)c1[1] - (int)c2[1]) * death_age);
     388       16356 :                 *p++ = FAST_DIV255((c2[2] << 8) + ((int)c1[2] - (int)c2[2]) * death_age);
     389             :             } else {
     390        1244 :                 const uint8_t *c = v == ALIVE_CELL ? life->life_color : life->death_color;
     391        1244 :                 AV_WB24(p, c[0]<<16 | c[1]<<8 | c[2]);
     392        1244 :                 p += 3;
     393             :             }
     394             :         }
     395             :     }
     396          11 : }
     397             : 
     398          11 : static int request_frame(AVFilterLink *outlink)
     399             : {
     400          11 :     LifeContext *life = outlink->src->priv;
     401          11 :     AVFrame *picref = ff_get_video_buffer(outlink, life->w, life->h);
     402          11 :     if (!picref)
     403           0 :         return AVERROR(ENOMEM);
     404          11 :     picref->sample_aspect_ratio = (AVRational) {1, 1};
     405          11 :     picref->pts = life->pts++;
     406             : 
     407          11 :     life->draw(outlink->src, picref);
     408          11 :     evolve(outlink->src);
     409             : #ifdef DEBUG
     410             :     show_life_grid(outlink->src);
     411             : #endif
     412          11 :     return ff_filter_frame(outlink, picref);
     413             : }
     414             : 
     415           1 : static int query_formats(AVFilterContext *ctx)
     416             : {
     417           1 :     LifeContext *life = ctx->priv;
     418           1 :     enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_NONE, AV_PIX_FMT_NONE };
     419             :     AVFilterFormats *fmts_list;
     420             : 
     421           1 :     if (life->mold || memcmp(life-> life_color, "\xff\xff\xff", 3)
     422           0 :                    || memcmp(life->death_color, "\x00\x00\x00", 3)) {
     423           1 :         pix_fmts[0] = AV_PIX_FMT_RGB24;
     424           1 :         life->draw = fill_picture_rgb;
     425             :     } else {
     426           0 :         pix_fmts[0] = AV_PIX_FMT_MONOBLACK;
     427           0 :         life->draw = fill_picture_monoblack;
     428             :     }
     429             : 
     430           1 :     fmts_list = ff_make_format_list(pix_fmts);
     431           1 :     return ff_set_common_formats(ctx, fmts_list);
     432             : }
     433             : 
     434             : static const AVFilterPad life_outputs[] = {
     435             :     {
     436             :         .name          = "default",
     437             :         .type          = AVMEDIA_TYPE_VIDEO,
     438             :         .request_frame = request_frame,
     439             :         .config_props  = config_props,
     440             :     },
     441             :     { NULL}
     442             : };
     443             : 
     444             : AVFilter ff_vsrc_life = {
     445             :     .name          = "life",
     446             :     .description   = NULL_IF_CONFIG_SMALL("Create life."),
     447             :     .priv_size     = sizeof(LifeContext),
     448             :     .priv_class    = &life_class,
     449             :     .init          = init,
     450             :     .uninit        = uninit,
     451             :     .query_formats = query_formats,
     452             :     .inputs        = NULL,
     453             :     .outputs       = life_outputs,
     454             : };

Generated by: LCOV version 1.13