Converting RGB to a single numeric value
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
FYI there's a happy prebuilt function to do just this:
If you wanted even more precision you could use an alpha channel and do this:
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 ;-).
//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 ;-).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement