git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2216
d7cf8633-e32d-0410-b094-
e92efae38249
*/
qbyte *LoadTGA (qbyte *f, int matchwidth, int matchheight)
{
*/
qbyte *LoadTGA (qbyte *f, int matchwidth, int matchheight)
{
- int columns, rows, row, column;
+ int columns, rows, row, column, row_inc;
qbyte *pixbuf, *image_rgba, *fin, *enddata;
if (loadsize < 18+3)
qbyte *pixbuf, *image_rgba, *fin, *enddata;
if (loadsize < 18+3)
if (targa_header.id_length != 0)
fin += targa_header.id_length; // skip TARGA image comment
if (targa_header.id_length != 0)
fin += targa_header.id_length; // skip TARGA image comment
+ // If bit 5 of attributes isn't set, the image has been stored from bottom to top
+ if ((targa_header.attributes & 0x20) == 0)
+ {
+ pixbuf = image_rgba + (rows - 1)*columns*4;
+ row_inc = -columns*4*2;
+ }
+ else
+ {
+ pixbuf = image_rgba;
+ row_inc = 0;
+ }
+
if (targa_header.image_type == 2)
{
// Uncompressed, RGB images
if (targa_header.image_type == 2)
{
// Uncompressed, RGB images
- for(row = rows - 1;row >= 0;row--)
+ for(row = 0;row < rows;row++)
- pixbuf = image_rgba + row*columns*4;
for(column = 0;column < columns;column++)
{
switch (targa_header.pixel_size)
for(column = 0;column < columns;column++)
{
switch (targa_header.pixel_size)
}
}
else if (targa_header.image_type==10)
{
// Runlength encoded RGB images
unsigned char red = 0, green = 0, blue = 0, alphabyte = 0, packetHeader, packetSize, j;
}
}
else if (targa_header.image_type==10)
{
// Runlength encoded RGB images
unsigned char red = 0, green = 0, blue = 0, alphabyte = 0, packetHeader, packetSize, j;
- for(row = rows - 1;row >= 0;row--)
+ for(row = 0;row < rows;row++)
- pixbuf = image_rgba + row * columns * 4;
for(column = 0;column < columns;)
{
if (fin >= enddata)
for(column = 0;column < columns;)
{
if (fin >= enddata)
{
// run spans across rows
column = 0;
{
// run spans across rows
column = 0;
+ if (row < rows - 1)
+ row++;
- pixbuf = image_rgba + row * columns * 4;
{
// pixel packet run spans across rows
column = 0;
{
// pixel packet run spans across rows
column = 0;
+ if (row < rows - 1)
+ row++;
- pixbuf = image_rgba + row * columns * 4;