[Ffmpeg-devel] [RFC] .tga decoder

Kostya kostya.shishkov
Wed Oct 11 06:22:58 CEST 2006


On Tue, Oct 10, 2006 at 09:32:47AM +0200, Michael Niedermayer wrote:
> Hi
> 
> On Mon, Oct 09, 2006 at 02:08:20PM +0300, Kostya wrote:
> > Here is my Targa files decoder. It tested to work on .tga files
> > created with ImageMagick and on movs with different depth which can
> > be found here: http://www.openquicktime.org/files.php (named aletrek-*.mov)
> 
> [...]
> > +static void targa_decode_rle(AVCodecContext *avctx, TargaContext *s, uint8_t *src, uint8_t *dst, int w, int h, int stride, int bpp)
> > +{
> > +    int i, x, y;
> > +    int depth = (bpp + 1) / 8;
> > +    int type, count;
> > +    int diff;
> > +
> > +    diff = stride - w * depth;
> > +    x = y = 0;
> > +    while(y < h){
> > +        type = *src++;
> > +        count = (type & 0x7F) + 1;
> > +        if((x + count > w) && (y + (x + count + 1)/w > h)){
> 
> x + count + 1 > (h - y)*w
> avoids the /
> 
> 

[RLE decoding skipped]
> > +        }
> 
> for(i = 0; i < count; i++){
>     switch(depth){
>     case 1:
>         *dst = *src;
>         break;
>     case 2:
>         *((uint16_t*)dst) = LE_16(src);
>         break;
>     case 3:
>         dst[0] = src[0];
>         dst[1] = src[1];
>         dst[2] = src[2];
>         break;
>     }
>     dst += depth;
>     if(!(type & 0x80))
>         src += depth;
>     x++;
>     if(x == w){
>         x = 0;
>         y++;
>         dst += diff;
>     }
> }
> 
> and if speed matters then an always_inline function which has type&0x80 and
> depth as "constant" arguments should help
> 
> 
> [...]
[old raw image read skipped]
> > +            }
> 
> #ifdef WORDS_BIGENDIAN
>     if(s->bpp>>3 == 2){
>         uint16_t *dst16 = (uint16_t*)dst;
>         for(x = 0; x < s->width; x++)
>             dst16[x] = LE_16(buf + x*2);
>     }else
> #endif
>         memcpy(dst, buf, s->width*(s->bpp>>3));
> 

Committed with all these corrections

> [...]
> -- 
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> In the past you could go to a library and read, borrow or copy any book
> Today you'd get arrested for mere telling someone where the library is
> 




More information about the ffmpeg-devel mailing list