Advertisement Jump to content
Sign in to follow this  

RGB to bit data

This topic is 4577 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know how to convert bit data to rgb... #define getR(c) (((c)&0x00ff0000)>>16) #define getG(c) (((c)&0x0000ff00)>>8) #define getB(c) ((c)&0x000000ff) But how do I go the other way...rgb to bit data??? Thanks, Thomo

Share this post

Link to post
Share on other sites
Straight out of my own code:
#define RED32(clr) (((clr)>>16)&0xFF)
#define GREEN32(clr) (((clr)>>8)&0xFF)
#define BLUE32(clr) ((clr)&0xFF)
#define RGB32(r,g,b) ((unsigned long)((((r)<<8)|(g))<<8)|(b))
Beter to do the shifts first, so that you don't have such large constants in your program.
Also, all uppercase is preferred for macros.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!