Hi everybody,
i'm posting here to explain the issue I found and share possible fixes,
if need be i can create an account on GitHub to make a pull request of
the modifications.
To resume all the tests I've done on TGA images: the plugin does not
check if actual data matches the attributes that can be set in the
header. We've had several visual bugs, depending on machines, and in the
worst case scenario, we had random data being returned.
The general issue is that the plugin uses some information to retrieve
data, and other, that does not match to decide which channels should be
create, compute offsets.
For example, after opening the file, I can get a spec with a channel
count of 2 on a TGA file that has a pixel size of 8bits, ie one channel
only.
The grey channel is filled with correct data, and the alpha channel with
random (uninitialised) data.
So far i've done two fixes. One to fix the randomness issue, and another
one to fix the alpha channel creation issue. The second fix prevent the
first one from occuring, btw.)
First fix: initialised the output buffer at the beginning of the
decode_pixel function. ( out[0] = out[1] = out[2] = out[3] = 0 ) The
alpha channel is created, but at least contains stable data.
Second fix: it's the one I talk about yesterday:
replacing
m_alpha = (m_tga.attr & 0x0F) > 0 ? TGA_ALPHA_USEFUL : TGA_ALPHA_NONE;
by
m_alpha = TGA_ALPHA_NONE;
if (((m_tga.type == TYPE_RGB || m_tga.type == TYPE_RGB_RLE) &&
m_tga.bpp == 32 )
|| ((m_tga.type == TYPE_GRAY || m_tga.type == TYPE_GRAY_RLE) &&
m_tga.bpp > 8 )) {
m_alpha = (m_tga.attr & 0x08) > 0 ? TGA_ALPHA_USEFUL :
TGA_ALPHA_NONE;
}
Those two fixes make things work, but the code seems still dangerous to
me: the number of channels, which is used in every index calculus,
should be directly linked to the number of bytes read from the file.
If someone wants to talk about it off the mailing list to avoid spamming
it, I'd be happy to.
_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org