[FFmpeg-devel] [PATCH] Rl2 Video decoder

Sascha Sommer saschasommer
Mon Mar 17 13:56:08 CET 2008


Hi,

> > +static void rl2_rle_decode(Rl2Context *s,const unsigned char* buf,int
> > size, +                               unsigned char* out,int stride){
> > +     int row_inc = stride - s->avctx->width;
> > +     /* calculate additional video_base offset due to stride != width */
> > +     int offset = (s->video_base / s->avctx->width) * row_inc;
> > +     int frame_size = s->avctx->width * s->avctx->height - offset;
> > +     int pos_in = 0;
> > +     int pos_out = s->video_base;
> > +     unsigned char* back_frame = s->back_frame - s->video_base;
> > +     out += offset;
> > +
> > +     while(pos_in < size){
> > +         unsigned char tag = buf[pos_in++];
> > +         int len = 1;
> > +         unsigned char val = 0;
> > +         int i;
> > +         if(tag >= 0x80){
> > +             if(pos_in >= size)
> > +                 break;
> > +             len = buf[pos_in++];
> > +             if(!len)
> > +                 break;
> > +         }
> > +         if(s->back_frame)
> > +             val = tag | 0x80;
> > +         else
> > +             val = tag & ~0x80;
> > +
> > +         for(i=0;i<len && pos_out < frame_size; i++){
> > +             if(s->back_frame && (!tag || tag == 0x80))
> > +                 val = back_frame[pos_out];
> > +             out[pos_out] = val;
> > +             ++pos_out;
> > +             if(!(pos_out % s->avctx->width))
> > +                  out += row_inc;
> > +         }
>
> modulo is as division a very slow operation so it should be avoided
> and yes the 0x80 was what i meant
> But there are still a few simplifcations possible
> Theres are several  redundant variables, there are some checks which are
> redundant as well
> And i would check len against the remaining size instead of checking
> against both len and the size in every iteration.
> Then i also would use pointers like in / in_end instead of buf/pos_in/size
> it avoids the buf+pos_in addition.
>

New patch attached.

Regards

Sascha
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rl2_decoder_try5.patch
Type: text/x-diff
Size: 7978 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080317/8c6873f8/attachment.patch>



More information about the ffmpeg-devel mailing list