I got that wrong. Sorry. top-down-rle tgas work a bit better now.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@471 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2004-11-19 03:09:38 +00:00
parent ac284a1b94
commit 5360ef0097

View file

@ -141,7 +141,7 @@ qbyte *ReadTargaFile(qbyte *buf, int length, int *width, int *height, int asgrey
#define NTSC_GREEN 0.587 #define NTSC_GREEN 0.587
#define NTSC_BLUE 0.114 #define NTSC_BLUE 0.114
char *data; unsigned char *data;
qboolean flipped; qboolean flipped;
@ -201,7 +201,7 @@ qbyte *ReadTargaFile(qbyte *buf, int length, int *width, int *height, int asgrey
pixbuf = targa_rgba + ((rows-1)-row)*columns*(asgrey?1:4); pixbuf = targa_rgba + ((rows-1)-row)*columns*(asgrey?1:4);
for(column=0; column<columns; ) for(column=0; column<columns; )
{ {
packetHeader=getc(fin); packetHeader=*data++;
packetSize = 1 + (packetHeader & 0x7f); packetSize = 1 + (packetHeader & 0x7f);
if (packetHeader & 0x80) if (packetHeader & 0x80)
{ // run-length packet { // run-length packet
@ -216,16 +216,16 @@ qbyte *ReadTargaFile(qbyte *buf, int length, int *width, int *height, int asgrey
alphabyte = (int)(inrow[1]&0x80)*2-1; //alpha? alphabyte = (int)(inrow[1]&0x80)*2-1; //alpha?
break; break;
case 24: case 24:
blue = getc(fin); blue = *data++;
green = getc(fin); green = *data++;
red = getc(fin); red = *data++;
alphabyte = 255; alphabyte = 255;
break; break;
case 32: case 32:
blue = getc(fin); blue = *data++;
green = getc(fin); green = *data++;
red = getc(fin); red = *data++;
alphabyte = getc(fin); alphabyte = *data++;
break; break;
default: default:
blue = 127; blue = 127;
@ -251,7 +251,10 @@ qbyte *ReadTargaFile(qbyte *buf, int length, int *width, int *height, int asgrey
row--; row--;
else else
goto breakOut; goto breakOut;
pixbuf = targa_rgba + row*columns*4; if (flipped)
pixbuf = targa_rgba + row*columns*4;
else
pixbuf = targa_rgba + ((rows-1)-row)*columns*4;
} }
} }
} }
@ -268,7 +271,10 @@ qbyte *ReadTargaFile(qbyte *buf, int length, int *width, int *height, int asgrey
row--; row--;
else else
goto breakOut; goto breakOut;
pixbuf = targa_rgba + row*columns; if (flipped)
pixbuf = targa_rgba + row*columns*1;
else
pixbuf = targa_rgba + ((rows-1)-row)*columns*1;
} }
} }
} }
@ -295,19 +301,19 @@ qbyte *ReadTargaFile(qbyte *buf, int length, int *width, int *height, int asgrey
*pixbuf++ = alphabyte; *pixbuf++ = alphabyte;
break; break;
case 24: case 24:
blue = getc(fin); blue = *data++;
green = getc(fin); green = *data++;
red = getc(fin); red = *data++;
*pixbuf++ = red; *pixbuf++ = red;
*pixbuf++ = green; *pixbuf++ = green;
*pixbuf++ = blue; *pixbuf++ = blue;
*pixbuf++ = 255; *pixbuf++ = 255;
break; break;
case 32: case 32:
blue = getc(fin); blue = *data++;
green = getc(fin); green = *data++;
red = getc(fin); red = *data++;
alphabyte = getc(fin); alphabyte = *data++;
*pixbuf++ = red; *pixbuf++ = red;
*pixbuf++ = green; *pixbuf++ = green;
*pixbuf++ = blue; *pixbuf++ = blue;
@ -328,7 +334,10 @@ qbyte *ReadTargaFile(qbyte *buf, int length, int *width, int *height, int asgrey
row--; row--;
else else
goto breakOut; goto breakOut;
pixbuf = targa_rgba + row*columns*4; if (flipped)
pixbuf = targa_rgba + row*columns*4;
else
pixbuf = targa_rgba + ((rows-1)-row)*columns*4;
} }
} }
} }
@ -349,16 +358,16 @@ qbyte *ReadTargaFile(qbyte *buf, int length, int *width, int *height, int asgrey
*pixbuf++ = red*NTSC_RED + green*NTSC_GREEN + blue*NTSC_BLUE; *pixbuf++ = red*NTSC_RED + green*NTSC_GREEN + blue*NTSC_BLUE;
break; break;
case 24: case 24:
blue = getc(fin); blue = *data++;
green = getc(fin); green = *data++;
red = getc(fin); red = *data++;
*pixbuf++ = red*NTSC_RED + green*NTSC_GREEN + blue*NTSC_BLUE; *pixbuf++ = red*NTSC_RED + green*NTSC_GREEN + blue*NTSC_BLUE;
break; break;
case 32: case 32:
blue = getc(fin); blue = *data++;
green = getc(fin); green = *data++;
red = getc(fin); red = *data++;
alphabyte = getc(fin); alphabyte = *data++;
*pixbuf++ = red*NTSC_RED + green*NTSC_GREEN + blue*NTSC_BLUE; *pixbuf++ = red*NTSC_RED + green*NTSC_GREEN + blue*NTSC_BLUE;
break; break;
default: default:
@ -376,7 +385,10 @@ qbyte *ReadTargaFile(qbyte *buf, int length, int *width, int *height, int asgrey
row--; row--;
else else
goto breakOut; goto breakOut;
pixbuf = targa_rgba + row*columns; if (flipped)
pixbuf = targa_rgba + row*columns*1;
else
pixbuf = targa_rgba + ((rows-1)-row)*columns*1;
} }
} }
} }