[FFmpeg-devel] [PATCH] lavfi: port boxblur filter from libmpcodecs

Stefano Sabatini stefano.sabatini-lala at poste.it
Sun Jul 10 01:24:48 CEST 2011


On date Saturday 2011-07-09 23:33:22 +0200, Michael Niedermayer encoded:
> On Sat, Jul 09, 2011 at 06:41:44PM +0200, Stefano Sabatini wrote:
> [...]
> > +static inline void blur(uint8_t *dst, int dst_linesize, uint8_t *src, int src_linesize,
> > +                        int w, int radius)
> > +{
> 
> linesizes represent the size in bytes of a horizintal line everywhere
> in ffmpeg.
> here they dont, thus IMHO the original that used step is less confusing.

Changed back.

> > +    int x, sum = 0;
> > +    const int length = radius*2 + 1;
> > +    const int inv = ((1<<16) + length/2)/length;
> > +
> > +    for (x = 0; x < radius; x++)
> > +        sum += src[x*src_linesize]<<1;
> > +    sum += src[radius*src_linesize];
> > +
> > +    for (x = 0; x <= radius; x++) {
> > +        sum += src[(radius+x)*src_linesize] - src[(radius-x)*src_linesize];
> > +        dst[x*dst_linesize] = (sum*inv + (1<<15))>>16;
> > +    }
> > +
> > +    for (; x < w-radius; x++) {
> > +        sum += src[(radius+x)*src_linesize] - src[(x-radius-1)*src_linesize];
> > +        dst[x*dst_linesize] = (sum*inv + (1<<15))>>16;
> > +    }
> > +
> > +    for (; x < w; x++) {
> > +        sum += src[(2*w-radius-x-1)*src_linesize] - src[(x-radius-1)*src_linesize];
> > +        dst[x*dst_linesize] = (sum*inv + (1<<15))>>16;
> > +    }
> > +}

BTW would you mind to explain the algorithm in this function? I can't
grasp it, but surely this will crash if radius is big enough.

> > +
> > +static inline void blur2(uint8_t *dst, int dst_linesize, uint8_t *src, int src_linesize,
> > +                         int w, int radius, int power)
> > +{
> > +    uint8_t temp[2][4096];
> > +    uint8_t *a = temp[0], *b = temp[1];
> 
> A Fixed 4096 looks like a stack overflow exploit here
> but even if not, it may become an annoying limit

Alloc'ed.

Other changes:
* redesigned for using the draw_slice API
* added alpha and gray support
-- 
FFmpeg = Fancy & Fierce Multimedia Peaceless Elfic Geek
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-lavfi-port-boxblur-filter-from-libmpcodecs.patch
Type: text/x-diff
Size: 12752 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110710/880f31dd/attachment.bin>


More information about the ffmpeg-devel mailing list