[FFmpeg-devel] [PATCH] vf_ass: add yuv overlay

yann.lepetitcorps at free.fr yann.lepetitcorps at free.fr
Thu Mar 15 00:55:34 CET 2012


> > Le quintidi 25 ventôse, an CCXX, Jean First a écrit :
> > +#define SET_PIXEL_YUV(picref, yuva_color, val, x, y, hsub, vsub) {
> >   \
> > +    luma_pos    = ((x)          ) + ((y)          ) * picref->linesize[0];
> > \
> > +    alpha = yuva_color[A] * (val) * 129;                               \
> > +    picref->data[0][luma_pos]    = (alpha * yuva_color[Y] + (255*255*129 -
> > alpha) * picref->data[0][luma_pos]   ) >> 23; \
> > +    if (((x) & ((1<<(hsub)) - 1)) == 0 && ((y) & ((1<<(vsub)) - 1)) == 0)
> > {\
> > +        chroma_pos1 = ((x) >> (hsub)) + ((y) >> (vsub)) *
> > picref->linesize[1]; \
> > +        chroma_pos2 = ((x) >> (hsub)) + ((y) >> (vsub)) *
> > picref->linesize[2]; \
> > +        picref->data[1][chroma_pos1] = (alpha * yuva_color[U] +
> > (255*255*129 - alpha) * picref->data[1][chroma_pos1]) >> 23; \
> > +        picref->data[2][chroma_pos2] = (alpha * yuva_color[V] +
> > (255*255*129 - alpha) * picref->data[2][chroma_pos2]) >> 23; \
> > +    }\

> This looks like a copy-paste from drawtext.
>
> Code duplication is evil. Please join us in our reflection on how to make
> drawutils more useful: maybe
>
> ff_draw_bitmap(FFDrawContext *draw, FFDrawColor *color
>                uint8_t *dst[], int dst_stride[],
>                uint8_t *src, int src_stride, int src_depth,
>                int x, int y);
>
> ?
>
> Regards,
>
> --
>   Nicolas George
>

Are the width and height of the bitmap stored into the FFDrawContext ?

On other side, I think tat the luma and chroma calculations can be a little
optimised by the use of big table that to can be precomputed with something like
this

AlphaLumaChromaTable[256][256][256];

void InitAlphaLumaChromaTables()
{
    int alpha, src, value, bigAlpha;

    for(alpha=0;alpha<256; alpha++)
    {
        for(value=0;value<256;value++)
        {
		for(src=0;src<256;src++)
		{
			AlphaLumaChromaTable[alpha][value][src] = (alpha * value + (255 -alpha) *
src) >> 8;
		}
	}
}

And then

    picref->data[0][luma_pos] = AlphaLumaChromaTab[ alpha ][ yuva_color[Y] ][
picref->data[0][luma_pos] ];

    picref->data[1][chroma_pos1] = AlphaLumaChromaTab[ alpha ][ yuva_color[U] ][
picref->data[1][chroma_pos1] ];

    picref->data[2][chroma_pos2] = AlphaLumaChromaTab[ alpha ][ yuva_color[V] ][
picref->data[2][chroma_pos2] ];


Note too that a part of the computation of chroma_pos1 and chroma_pos2 can to be
precomputed using ChromaPosTabX[0..width-1] and ChromaPosY[0..height-1]  because
the values of picref, hsub and vusb are certainly exactely the same for a long
run of successives SET_PIXEL_YUV((picref, yuva_color, val, x, y, hsub, vsub)



@+
Yannoo




More information about the ffmpeg-devel mailing list