nvidia-texture-tools
nvidia-texture-tools copied to clipboard
Reading a two channel PNG (greyscale + alpha) via ImageIO::loadSTB() strips the alpha channel
Reading a two channel PNG (greyscale + alpha) via ImageIO::loadSTB() strips the alpha channel. In ImageIO.cpp:
static Image * loadSTB(Stream & s)
{
// ...
int w, h, n;
uint8 * data = stbi_load_from_memory(buffer, size, &w, &h, &n, 4);
// ...
img->setFormat(n == 4 ? Image::Format_ARGB : Image::Format_RGB);
When loading a two channel PNG, n is set to 2 by stbi_load_from_memory(), so the check inside setFormat() is not valid for this case. A simple fix could be to set the format fo img always to Format_ARGB. The "desired_channels" to the call to stbi_load_from_memory() are set to 4 and hence STB always decodes to 4 channels.