Jump to content
  • Advertisement
Sign in to follow this  
Thomo

RGB to bit data

This topic is 4422 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
Advertisement
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 GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!