[FFmpeg-devel] [PATCH]Simplify targa decoding

yann.lepetitcorps at free.fr yann.lepetitcorps at free.fr
Fri Jan 20 04:05:01 CET 2012


> >          for(i = 0; i < count; i++){
> > -            switch(depth){
> > -            case 1:
> > -                *dst = *src;
> > -                break;
> > -            case 2:
> > -                *((uint16_t*)dst) = AV_RL16(src);
> > -                break;
> > -            case 3:
> > -                dst[0] = src[0];
> > -                dst[1] = src[1];
> > -                dst[2] = src[2];
> > -                break;
> > -            case 4:
> > -                *((uint32_t*)dst) = AV_RL32(src);
> > -                break;
> > -            }
> > +            memcpy(dst, src, count * depth);
> >              dst += depth;
> >              if(!type)
> >                  src += depth;
>
> Without having looked properly, I suspect something isn't right here,
> you memcpy count*depth but increment only by depth and loop
> around all this count times, or am I missing something?

I think that the idea is to make only one memcpy for each chunk instead of a lot
of switchs (one for each pixel) that use always the same path.

One problem seem to be the case where x+count > width
=> we have to handle multiples lines **and** the necessary padding at each line

Another problem is src pointer "incrementation" logic (per pixel or per chunk)
that is handled into the while(y < h) and for( i=0; i <count ; i++) loops

=> I see if all this can to be reorganised for to make only one test of the type
value at the beginning (insteead at each pixel) and for to  copy pixels per
chunk (instead per pixel) with the necessary padding (if needed) at each line


I have too see this test :

      if((x + count > w) && (x + count + 1 > (h - y) * w)){

Is really the "x + count > w" necessary and why not to  use ">=" instead "+ 1 >"
 for to test if the chunk can effectivly to be contained into remaining pixels
until the end of the image ?
(because since h is always > y, (h - y) * w is always >= w)

=> isn't the same test that   if( x + count >= (h-y) * w ) ???


@+
Yannoo


More information about the ffmpeg-devel mailing list