AARRGGBB to BBGGRRAA

Started by
2 comments, last by Austrian Coder 19 years, 11 months ago
Hi. I need a fast way to convert a aarrbbgg to bbggrraa. The colorvalues are a 32-bit-word. So maybe somebody can help me to find a general c way and maybe later an optimized mmx functions. I am developing a mpeg based menu system for a dvb (digital video bordcast) system on linux. So i make a unsigned char framebuffer, where i save everything. So the host application gives the colors in aarrggbb but i need a framebuffer, which is field with bbggrraa values. So i thought, that i use a convert function in the basic funtion DrawPixel, which is used by all other drawing functions. Thanks for your help, Christian
Advertisement
int convert(int col) {    int a = (col&0xff000000)>>24;    int r = (col&0x00ff0000)>>16;    int g = (col&0x0000ff00)>>8;        int b = (col&0x000000ff);    return (b<<24) | (g<<16) | (b<<8) | a;}


As long as you''re only converting each image once, and it isn''t very large in size, you shouldn''t worry much about performance. It''s only a few million integer operations per second for an 1000x1000 image. You''re playing back video, which has very few frames per second anyway.
Probably the fastest way (on an x86) is to use inline assembly and the BSWAP instruction. If you want to be cross platform, you can do it with the bitwise operators, specifically shift and AND.
@Matei: Thanks.

The framebuffer has a size of 720 x 576 pixels.

@DukeAtreides076:

I will try the BSWAP way. The function must run ony all linux supported platforms also on 64 bit systmes.

This topic is closed to new replies.

Advertisement