Hello,
I'm trying to load a mouse cursor for windows from an image-file. How do I calculate the correct and + xor-masks for transparent images? I'm using the method from CodeProject.com, which works fine for simple cursors without an alpha-channel:
gfx::TextureAccessorX32 accessor(texture, true);
const gfx::Color3 transparent(254, 254, 254);
for(unsigned int x = 0; x < (unsigned int)vSize.x; x++)
{
for(unsigned int y = 0; y < (unsigned int)vSize.y; y++)
{
auto& pixel = accessor.GetPixel(x, y);
if(pixel == transparent)
{
SetPixel(hAndMaskDC, x, y, RGB(255, 255, 255));
SetPixel(hXorMaskDC, x, y, RGB(0, 0, 0));
}
else
{
SetPixel(hAndMaskDC, x, y, RGB(0, 0, 0));
SetPixel(hXorMaskDC, x, y, RGB(pixel.r, pixel.g, pixel.b));
}
}
}
One color is marked transparent and everything is fine. But for alpha-channel-textures, the best I got was:
gfx::TextureAccessorA32 accessor(texture, true);
for(unsigned int x = 0; x < (unsigned int)vSize.x; x++)
{
for(unsigned int y = 0; y < (unsigned int)vSize.y; y++)
{
auto& pixel = accessor.GetPixel(x, y);
const unsigned int invAlpha = 255 - pixel.a;
SetPixel(hAndMaskDC, x, y, RGB(invAlpha, invAlpha, invAlpha));
SetPixel(hXorMaskDC, x, y, RGB(pixel.r, pixel.g, pixel.b));
}
}
Which doesn't even produce results near what I'm expecting. Anyone familiar with the algorithm I need here?