[MPlayer-dev-eng] Packed YUV -> RGB Conversion; Speed Freak

Daniel Egger degger at fhm.edu
Fri Mar 1 16:00:33 CET 2002


Am Fre, 2002-03-01 um 06.17 schrieb Mike Melanson:

>   unsigned char *out_ptr;
>   unsigned int pixel1, pixel2;
>   (unsigned int *)out_ptr = pixel1;
>   out_ptr += 3;
>   (unsigned int *)out_ptr = pixel2;
 
> Or would this net a performance hit because of not transferring data on
> neat 32-bit memory boundaries? No big deal, just curious.

On some architectures writing values to memory not having the correct
alignment will result in severe performance degradation if not even
an exception which would have to be handled by the operating system
and thus be even slower.

If you can bundle 4 BGR24 pixels together you could do the following
trick (assuming pixel[1...4] are layouted like 0xBBGGRR00):

unsigned char *out_ptr;
unsigned int pixel1, pixel2, pixel3, pixel4;
(unsigned int *)out_ptr++ = pixel1 | (pixel2 >> 24);
(unsigned int *)out_ptr++ = (pixel2 << 8) | (pixel3 >> 16);
(unsigned int *)out_ptr++ = (pixel3 << 16) | (pixel4 >> 8);

This is the fastest solution I can think of at the moment though 
could probably be tweaked another bit.

-- 
Servus,
       Daniel




More information about the MPlayer-dev-eng mailing list