[FFmpeg-devel] [PATCH]Prepare rawdec.c for 2bpp support

Reimar Döffinger Reimar.Doeffinger
Wed Dec 30 21:16:12 CET 2009


On Wed, Dec 30, 2009 at 09:12:20PM +0100, Carl Eugen Hoyos wrote:
> Hi!
> 
> Reimar suggested this patch on roundup (issue 1528).
> 
> Please comment, Carl Eugen

> Index: libavcodec/rawdec.c
> ===================================================================
> --- libavcodec/rawdec.c	(revision 20962)
> +++ libavcodec/rawdec.c	(working copy)
> @@ -117,12 +117,13 @@
>      if(avctx->bits_per_coded_sample == 4 && avctx->pix_fmt==PIX_FMT_PAL8 &&
>         (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))){
>          int i;
> -        for(i=256*2; i+1 < context->length>>1; i++){
> -            context->buffer[2*i+0]= buf[i-256*2]>>4;
> -            context->buffer[2*i+1]= buf[i-256*2]&15;
> +        uint8_t *dst = context->buffer + 256*4;
> +        buf_size = context->length - 256*4;
> +        for(i=0; 2*i+1 < buf_size; i++){
> +            dst[2*i+0]= buf[i]>>4;
> +            dst[2*i+1]= buf[i]&15;
>          }
> -        buf= context->buffer + 256*4;
> -        buf_size= context->length - 256*4;
> +        buf= dst;

Note that I think the unreadable mess that the previous code is I think
hides the fact that the last 2 pixels are silently dropped.
E.g. for a 2x1 image, context->length would be 1026.
After the initialization the condition
i+1 < context->length>>1
is already false since
i+1 == 513
and
context->length>>1 == 513
so nothing is ever written into context->buffer



More information about the ffmpeg-devel mailing list