[FFmpeg-devel] [PATCH] life: add slow_death, life_color and death_color options.

Clément Bœsch ubitux at gmail.com
Fri Dec 9 17:53:43 CET 2011


On Fri, Dec 09, 2011 at 03:24:59PM +0100, Stefano Sabatini wrote:
[...]
> > +            *newbuf = v ? ALIVE_CELL : *newbuf - (*newbuf != 0);
> 
> Maybe a bit too convoluted, possible suggestion:
> if (v == ALIVE_CELL) *newbuf = v;
> else if (*newbuf)   (*newbuf)--;
> 

As you prefer, changed locally.

[...]
> > +static void fill_picture_rgb(AVFilterContext *ctx, AVFilterBufferRef *picref)
> > +{
> > +    LifeContext *life = ctx->priv;
> > +    uint8_t *buf = life->buf[life->buf_idx];
> > +    int i, j;
> > +
> > +    /* fill the output picture with the old grid buffer */
> > +    for (i = 0; i < life->h; i++) {
> > +        uint8_t *p = picref->data[0] + i * picref->linesize[0];
> > +        for (j = 0; j < life->w; j++) {
> > +            uint8_t  v = buf[i*life->w + j];
> > +            uint8_t *c = v == ALIVE_CELL ? life->life_color : life->death_color;
> > +            if (life->mold) {
> 
> > +                int death_age = (0xff - v) * life->mold;
> > +                *p++ = FFMAX((int)c[0] - death_age, life->mold_color[0]);
> > +                *p++ = FFMAX((int)c[1] - death_age, life->mold_color[1]);
> > +                *p++ = FFMAX((int)c[2] - death_age, life->mold_color[2]);
> 
> why not a proper interpolation? The above doesn't work if for example death_color < mold_color
> 
> double left_energy = (double)(0xff - v) / 256;
> *p++ = mold_color[comp] + ((int)death_color[comp] - (int)mold_color[comp]) * left_energy;
> 

Well, I wanted to avoid the different speed between the color components.
With that interpolation, if you have a difference of 10 for the red
component but 200 for the blue, the red will very slightly decrease while
the blue will take more cycles to reach the final state. I'm not sure how
much it will affect the visual output, but it was more logical to me to
have a "symmetric" decreasing. I'll try the interpolation method.

> For avoiding divisions (not tested):
> int left_energy = 0xff - v;
> *p++ = ((mold_color[comp]<<8) + ((int)death_color[comp] - (int)mold_color[comp]) * left_energy)>>8;
> 

I'll try that. Also note the mold & death color are inverted: the cell
goes from death color to mold color. While this makes a little awkward
when you enable the mold, it makes more sense semantically speaking IMO.

> > +            } else {
> > +                *p++ = c[0];
> > +                *p++ = c[1];
> > +                *p++ = c[2];
> > +            }
> 
> AV_WB24(p, c); p += 3;
> 

You mean AV_WB24(p, c[0]<<16 | c[1]<<8 | c[2])? maybe a memcpy?

> also you can drop the obfuscating c temporary, and directly use
> life/death_color.
> 

I might do that with the interpolation version for mold case.

[...]

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20111209/82373da4/attachment.asc>


More information about the ffmpeg-devel mailing list