Game Development Reference
In-Depth Information
class that will take some texture and extract its data into the same format as we used to
generate the heatmap, this will make the calculations easier to do.
class color_lut
{
public:
color_lut(render::device_direct3d* device, const std::wstring& path)
{
std::unique_ptr<render::texture> texture = std::unique_ptr<render::texture>(new render::texture(device, path) );
if ( texture->Width() != 256 && texture->Height() != 1 )
{
throw std::out_of_range("The color look up table texture must be 256x1");
}
auto& image = texture->GetImage();
const auto& pixels = image.GetPixels();
memcpy(m_data, pixels, image.GetPixelsSize());
}
unsigned int operator [](const unsigned char i) const
{ return m_data[i]; }
private:
unsigned int m_data[256];
};
This is a Direct3D specific example, however it should illustrate well the idea behind it,
we need to load a texture, access its color data, its pixels and make a copy of them for
ourselves,wecanthendiscardthetexture,wewon'tneeditanymore.Therequirementthat
the texture should be 256x1 is in the interest of keeping things simple though it could be
removed with some slight modifications if desired. Once we have captured a copy of the
pixel data into our 256 element array, we implement the [] operator to let us access it by
index.
void heatmap::Colorize()
{
for (int i = 0; i < m_size*m_size; ++i )
{
auto& source = m_data[i];
unsigned char a = ( source >> 24 );
unsigned int finalColor = (*m_colorLUT)[a];
finalColor = ( (*m_colorLUT)[a] & 0x00ffffff) | ( a << 24 );
render::color c = render::color(finalColor);
source = c.ToU32ABGR();
}
}
To colorize the intensity map we will iterate over every pixel in the heatmap, read its alpha
channel (at this point, all pixels are grayscale we could take any channel except that we
Search WWH ::




Custom Search