Sign in to follow this  
QuadMV

Converting RGB to a single numeric value

Recommended Posts

Does anyone know what the formula would be to convert the three color channels (RGB) of an image to a single color value? I want to use this as a heightmap, but I don't want to be limitted to 256 values of a grayscale image. Since an RGB image can many thousands of colors, I thought this would make for a more detailed heightmap, but I'm not sure of the formula to convert it? Thanks, QUAD

Share this post


Link to post
Share on other sites
FYI there's a happy prebuilt function to do just this:


//Read r, g, and b from your heightmap
unsigned long Color = D3DCOLOR_XRGB(r, g, b);


If you wanted even more precision you could use an alpha channel and do this:

//Read a, r, g, and b from your heightmap
unsigned long Color = D3DXCOLOR_ARGB(a, r, g, b);


The first example will produce numbers from 0 to 16,777,215 and the second will range from 0 to 4,294,967,295. Hope a little over four billion possible values is satisfactory ;-).

Share this post


Link to post
Share on other sites
I knew of those functions but didn’t put two and two together when I was thinking of what I wanted, argh. Thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this