[PATCH] New rgb32tobgr32 (was: Re: [Ffmpeg-devel] [PATCH] have cs_test check for sigsegv at smaller widths and sigill)

Trent Piepho xyzzy
Sat Apr 14 05:14:46 CEST 2007


On Sat, 14 Apr 2007, Michael Niedermayer wrote:
> > -	}
> > -#endif
> > +    for (; s<end; s+=4, d+=4) {
> > +        int v = *(uint32_t *)s;
> > +        int r = v & 0xff, g = (v>>8) & 0xff, b = (v>>16) & 0xff;
> > +        *(uint32_t *)d = b + (g<<8) + (r<<16);
>
> int v = *(uint32_t *)s;
> int g = v&0xFF00;
> v &= 0xFF00FF;
> *(uint32_t *)d = (v>>16) + (v<<16) + g
>
> 2 shift less
> 1 and less

asm("bswapl %0 ; shrl $8, %0" : "+r"(*(uint32_t *)s));

In the linux kernel, you could do this:

  *(uint32_t *)d = swab32p((uint32_t *)s) >> 8;

It would probably expand to exact the same code as the asm statement on
x86.  Does ffmpeg have a useful byte-swap function?

Could also do this, which avoids the shift instrunction, but it probably
slower due to the overlapping unaligned accesses.

uint32_t scratch;
asm("movl %2, %1; bswapl %1; movl %1, %0"
    : "=g"(*(uint32_t *)(s-1)), "=r"(scratch)
    : "=g"(*(uint32_t *)d));




More information about the ffmpeg-devel mailing list