[FFmpeg-devel] [PATCH] Add negate filter.

Stefano Sabatini stefano.sabatini-lala
Wed Dec 1 20:57:19 CET 2010


On date Wednesday 2010-12-01 03:25:47 +0100, Michael Niedermayer encoded:
> On Tue, Nov 30, 2010 at 11:22:43PM +0100, Stefano Sabatini wrote:
> > On date Monday 2010-11-29 11:02:53 +0100, Stefano Sabatini encoded:
> > > On date Monday 2010-11-29 03:21:22 +0100, Michael Niedermayer encoded:
> > > > On Sun, Nov 28, 2010 at 12:30:09PM +0100, Stefano Sabatini wrote:
> > > [...]
> > > > > +static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
> > > > > +{
> > > > > +    NegContext *neg = inlink->dst->priv;
> > > > > +    AVFilterLink *outlink = inlink->dst->outputs[0];
> > > > > +    AVFilterBufferRef *inpic  = inlink ->cur_buf;
> > > > > +    AVFilterBufferRef *outpic = outlink->out_buf;
> > > > > +    uint8_t *inrow, *outrow;
> > > > > +    int i, j, plane;
> > > > > +
> > > > > +    for (plane = 0; inpic->data[plane]; plane++) {
> > > > > +        int vsub = plane == 1 || plane == 2 ? neg->vsub : 0;
> > > > > +        int hsub = plane == 1 || plane == 2 ? neg->hsub : 0;
> > > > > +
> > > > > +        inrow  = inpic ->data[plane] + (y>>vsub) * inpic ->linesize[plane];
> > > > > +        outrow = outpic->data[plane] + (y>>vsub) * outpic->linesize[plane];
> > > > > +
> > > > > +        if (neg->plane_neg[plane]) {
> > > > > +            if (inlink->format == PIX_FMT_MONOWHITE || inlink->format == PIX_FMT_MONOBLACK) {
> > > > > +                for (i = 0; i < inlink->h; i++) {
> > > > > +                    for (j = 0; j < inlink->w >> 3; j++)
> > > > > +                        outrow[j] = ~inrow[j];
> > > > > +                    inrow  += inpic ->linesize[0];
> > > > > +                    outrow += outpic->linesize[0];
> > > > > +                }
> > > > > +            } else {
> > > > > +                for (i = 0; i < (h>>vsub); i ++) {
> > > > > +                    for (j = 0; j < (inlink->w>>hsub); j++)
> > > > > +                        outrow[j] = 255 - inrow[j] + neg->plane_off[plane];
> > > > 
> > > > can overflow and others likely too
> > > 
> > > Fixed by clipping out-of-range values.
> > > 
> > > Also relevant:
> > > http://thread.gmane.org/gmane.comp.video.ffmpeg.devel/94136/focus=94154
> > > -- 
> > > FFmpeg = Faithful & Fascinating Murdering Pacific Ecumenical God
> > 
> > > From 3c16bf49c0f9f4c3c72d9eea49ae35a47d58d961 Mon Sep 17 00:00:00 2001
> > > From: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> > > Date: Fri, 26 Nov 2010 17:31:11 +0100
> > > Subject: [PATCH] Add negate filter.
> > > 
> > > Ported from the libavfilter-soc repo with per-component negation
> > > addition.
> > > ---
> > >  doc/filters.texi         |   22 ++++++
> > >  libavfilter/Makefile     |    1 +
> > >  libavfilter/allfilters.c |    1 +
> > >  libavfilter/vf_negate.c  |  184 ++++++++++++++++++++++++++++++++++++++++++++++
> > >  4 files changed, 208 insertions(+), 0 deletions(-)
> > >  create mode 100644 libavfilter/vf_negate.c
> > 
> > I'll apply in three days unless objections.
> 
> is it faster than using a LUT ?

32246490 dezicycles in nolut, 1 runs, 0 skips
27420150 dezicycles in nolut, 2 runs, 0 skips
29323650 dezicycles in nolut, 4 runs, 0 skips
36039801 dezicycles in nolut, 8 runs, 0 skips
34124634 dezicycles in nolut, 16 runs, 0 skips
39557091 dezicycles in nolut, 32 runs, 0 skips
37006964 dezicycles in nolut, 64 runs, 0 skips
37271243 dezicycles in nolut, 128 runs, 0 skips
36437873 dezicycles in nolut, 256 runs, 0 skips
37591370 dezicycles in nolut, 512 runs, 0 skips
37119779 dezicycles in nolut, 1024 runs, 0 skips
37390082 dezicycles in nolut, 2048 runs, 0 skips

22483590 dezicycles in lut, 1 runs, 0 skips
16486965 dezicycles in lut, 2 runs, 0 skips
14703345 dezicycles in lut, 4 runs, 0 skips
13340126 dezicycles in lut, 8 runs, 0 skips
14286336 dezicycles in lut, 16 runs, 0 skips
17345394 dezicycles in lut, 32 runs, 0 skips
18178503 dezicycles in lut, 64 runs, 0 skips
18047690 dezicycles in lut, 128 runs, 0 skips
18159589 dezicycles in lut, 256 runs, 0 skips
17833263 dezicycles in lut, 512 runs, 0 skips
17624724 dezicycles in lut, 1024 runs, 0 skips
17303343 dezicycles in lut, 2048 runs, 0 skips

Updated (with some simplifications).
-- 
FFmpeg = Fast Funny Muttering Portentous Elegant Ghost



More information about the ffmpeg-devel mailing list