Search code examples
c++c++11directx-11heightmap

How to get hight (int16) value back to rgb form?


I have int16 * heights[width * height] array, that hold the terrain height, i load them form a file directly as int16 *.

I need to write the heights into a bmp file.

How do i get int16 back into rgb format considering they came form a bmp file (rgb format) in the first place?

Thanks.


Solution

  • you need to loop through your array and convert each int16 to RGB value. If terrainis your array

    for (auto i=0; i<width * height; i++)
    {
        auto Color = terrain[i];
        auto red = GetRValue16(color);
        auto green = GetGValue16(color);
        auto blue = GetBValue16(color);
    }
    

    Critical point is your definition of the three functions GetXValue16 as RGB is usually in 4-byte representation of integer, ie int32. See also Extracting rgb color components from integer value