Converting RGB to a single numeric value

Started by
3 comments, last by QuadMV 18 years, 10 months ago
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
3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.
Advertisement
Value = (R<<16) | (G<<8) | B;

yeah, seems almost too simple, but yeah, I can see it. Let me check it out. Thanks
3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.
FYI there's a happy prebuilt function to do just this:

//Read r, g, and b from your heightmapunsigned 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 heightmapunsigned 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 ;-).
I knew of those functions but didn’t put two and two together when I was thinking of what I wanted, argh. Thanks
3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.

This topic is closed to new replies.

Advertisement