• Advertisement
Sign in to follow this  

Converting RGB to a single numeric value

This topic is 4691 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

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
Advertisement
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
Sign in to follow this  

  • Advertisement