Skip to content

Commit 5e44e65

Browse files
committed
Fix reading 16-bit (5551) tga images. According to Wikipedia "if the pixel depth is 16 bits, the topmost bit is reserved for transparency." Note that it says transparency and not opacity. Opacity is normally how an alpha channel is interpreted but I've changes the reading code to treat the 1-bit alpha channel as transparency. A zero yields no transparency (i.e. fully opaque).
1 parent eab0aeb commit 5e44e65

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Modules/Image/Src/tImageTGA.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,24 @@ namespace tImage
2222
{
2323

2424

25-
// Helper functions, enums, and types for parsing DDS files.
25+
// Helper functions, enums, and types for parsing TGA files.
2626
namespace tTGA
2727
{
2828
#pragma pack(push, r1, 1)
2929
struct Header
3030
{
3131
int8 IDLength;
3232
int8 ColourMapType;
33+
34+
// 0 - No image data included.
35+
// 1 - Uncompressed, color-mapped images.
36+
// 2 - [Supported] Uncompressed, RGB images.
37+
// 3 - Uncompressed, black and white images.
38+
// 9 - Runlength encoded color-mapped images.
39+
// 10 - [Supported] Runlength encoded RGB images.
40+
// 11 - Compressed, black and white images.
41+
// 32 - Compressed color-mapped data, using Huffman, Delta, and runlength encoding.
42+
// 33 - Compressed color-mapped data, using Huffman, Delta, and runlength encoding. 4-pass quadtree-type process.
3343
int8 DataTypeCode;
3444
int16 ColourMapOrigin;
3545
int16 ColourMapLength;
@@ -247,7 +257,11 @@ void tImageTGA::ReadColourBytes(tColour4b& dest, const uint8* src, int bytesPerP
247257
dest.R = (src[1] & 0x7c) << 1;
248258
dest.G = ((src[1] & 0x03) << 6) | ((src[0] & 0xe0) >> 2);
249259
dest.B = (src[0] & 0x1f) << 3;
250-
dest.A = (src[1] & 0x80);
260+
261+
// According to Wikipedia: If the pixel depth is 16 bits, the topmost bit is reserved for transparency.
262+
// Me: Note that it says transparency and not opacity. Opacity is normally how an alpha channel is interpreted.
263+
// The code below treats the 1-bit alpha channel as transparency. A zero yields no transparency (fully opaque).
264+
dest.A = (src[1] & 0x80) ? 0 : 255;
251265
break;
252266

253267
default:

0 commit comments

Comments
 (0)