[FFmpeg-devel] [PATCH] Rl2 Video decoder
Michael Niedermayer
michaelni
Sun Mar 16 18:41:35 CET 2008
On Sun, Mar 16, 2008 at 05:44:21PM +0100, Sascha Sommer wrote:
[...]
> +/**
> + * Run Length Decode a single 320x200 frame
> + * @param s rl2 context
> + * @param buf input buffer
> + * @param size input buffer size
> + * @param out ouput buffer
> + * @param stride stride of the output buffer
> + */
> +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.
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080316/cd83d785/attachment.pgp>
More information about the ffmpeg-devel
mailing list