Archived

This topic is now archived and is closed to further replies.

Austrian Coder

AARRGGBB to BBGGRRAA

Recommended Posts

Austrian Coder    122
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

Share this post


Link to post
Share on other sites
Matei    190

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Austrian Coder    122
@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.

Share this post


Link to post
Share on other sites