nvidia-texture-tools icon indicating copy to clipboard operation
nvidia-texture-tools copied to clipboard

Reading a two channel PNG (greyscale + alpha) via ImageIO::loadSTB() strips the alpha channel

Open awefers opened this issue 7 years ago • 0 comments

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.

awefers avatar Nov 08 '18 03:11 awefers