mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
darn, broke the reverse direction and fixing it produces horrid code
This commit is contained in:
parent
1a18044b31
commit
4222c501a0
1 changed files with 94 additions and 36 deletions
130
libs/util/tga.c
130
libs/util/tga.c
|
@ -51,57 +51,115 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
|
||||
|
||||
static inline byte *
|
||||
blit_rgb (byte *buf, int count, byte red, byte green, byte blue, int dir)
|
||||
blit_rgb (byte *buf, int count, byte red, byte green, byte blue)
|
||||
{
|
||||
while (count--) {
|
||||
*buf = red;
|
||||
buf += dir;
|
||||
*buf = green;
|
||||
buf += dir;
|
||||
*buf = blue;
|
||||
buf += dir;
|
||||
*buf = 255;
|
||||
buf += dir;
|
||||
*buf++ = red;
|
||||
*buf++ = green;
|
||||
*buf++ = blue;
|
||||
*buf++ = 255;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static inline byte *
|
||||
blit_rgba (byte *buf, int count, byte red, byte green, byte blue, byte alpha,
|
||||
int dir)
|
||||
blit_rgba (byte *buf, int count, byte red, byte green, byte blue, byte alpha)
|
||||
{
|
||||
while (count--) {
|
||||
*buf = red;
|
||||
buf += dir;
|
||||
*buf = green;
|
||||
buf += dir;
|
||||
*buf = blue;
|
||||
buf += dir;
|
||||
*buf = alpha;
|
||||
buf += dir;
|
||||
*buf++ = red;
|
||||
*buf++ = green;
|
||||
*buf++ = blue;
|
||||
*buf++ = alpha;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static inline byte *
|
||||
read_bgr (byte *buf, int count, byte **data, int dir)
|
||||
reverse_blit_rgb (byte *buf, int count, byte red, byte green, byte blue)
|
||||
{
|
||||
while (count--) {
|
||||
*buf-- = 255;
|
||||
*buf-- = blue;
|
||||
*buf-- = green;
|
||||
*buf-- = red;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static inline byte *
|
||||
reverse_blit_rgba (byte *buf, int count, byte red, byte green, byte blue,
|
||||
byte alpha)
|
||||
{
|
||||
while (count--) {
|
||||
*buf-- = alpha;
|
||||
*buf-- = blue;
|
||||
*buf-- = green;
|
||||
*buf-- = red;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static inline byte *
|
||||
read_bgr (byte *buf, int count, byte **data)
|
||||
{
|
||||
byte blue = *(*data)++;
|
||||
byte green = *(*data)++;
|
||||
byte red = *(*data)++;
|
||||
|
||||
return blit_rgb (buf, count, red, green, blue, dir);
|
||||
return blit_rgb (buf, count, red, green, blue);
|
||||
}
|
||||
|
||||
static inline byte *
|
||||
read_bgra (byte *buf, int count, byte **data, int dir)
|
||||
read_bgra (byte *buf, int count, byte **data)
|
||||
{
|
||||
byte blue = *(*data)++;
|
||||
byte green = *(*data)++;
|
||||
byte red = *(*data)++;
|
||||
byte alpha = *(*data)++;
|
||||
|
||||
return blit_rgba (buf, count, red, green, blue, alpha, dir);
|
||||
return blit_rgba (buf, count, red, green, blue, alpha);
|
||||
}
|
||||
|
||||
static inline byte *
|
||||
read_rgb (byte *buf, int count, byte **data)
|
||||
{
|
||||
byte red = *(*data)++;
|
||||
byte green = *(*data)++;
|
||||
byte blue = *(*data)++;
|
||||
|
||||
return blit_rgb (buf, count, red, green, blue);
|
||||
}
|
||||
|
||||
static inline byte *
|
||||
read_rgba (byte *buf, int count, byte **data)
|
||||
{
|
||||
byte red = *(*data)++;
|
||||
byte green = *(*data)++;
|
||||
byte blue = *(*data)++;
|
||||
byte alpha = *(*data)++;
|
||||
|
||||
return blit_rgba (buf, count, red, green, blue, alpha);
|
||||
}
|
||||
|
||||
static inline byte *
|
||||
reverse_read_bgr (byte *buf, int count, byte **data)
|
||||
{
|
||||
byte blue = *(*data)++;
|
||||
byte green = *(*data)++;
|
||||
byte red = *(*data)++;
|
||||
|
||||
return reverse_blit_rgb (buf, count, red, green, blue);
|
||||
}
|
||||
|
||||
static inline byte *
|
||||
reverse_read_bgra (byte *buf, int count, byte **data)
|
||||
{
|
||||
byte blue = *(*data)++;
|
||||
byte green = *(*data)++;
|
||||
byte red = *(*data)++;
|
||||
byte alpha = *(*data)++;
|
||||
|
||||
return reverse_blit_rgba (buf, count, red, green, blue, alpha);
|
||||
}
|
||||
|
||||
struct tex_s *
|
||||
|
@ -166,14 +224,14 @@ LoadTGA (QFile *fin)
|
|||
for (row = rows - 1; row >= 0; row--, pixrow -= span) {
|
||||
pixcol = pixrow;
|
||||
for (column = 0; column < columns; column++)
|
||||
pixcol = read_bgr (pixcol, 1, &dataByte, 1);
|
||||
pixcol = read_bgr (pixcol, 1, &dataByte);
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
for (row = rows - 1; row >= 0; row--, pixrow -= span) {
|
||||
pixcol = pixrow;
|
||||
for (column = 0; column < columns; column++)
|
||||
pixcol = read_bgra (pixcol, 1, &dataByte, 1);
|
||||
pixcol = read_bgra (pixcol, 1, &dataByte);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -185,14 +243,14 @@ LoadTGA (QFile *fin)
|
|||
for (row = rows - 1; row >= 0; row--, pixrow -= span) {
|
||||
pixcol = pixrow;
|
||||
for (column = columns - 1; column >= 0; column--)
|
||||
pixcol = read_bgr (pixcol, 1, &dataByte, -1);
|
||||
pixcol = reverse_read_bgr (pixcol, 1, &dataByte);
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
for (row = rows - 1; row >= 0; row--, pixrow -= span) {
|
||||
pixcol = pixrow;
|
||||
for (column = columns - 1; column >= 0; column--)
|
||||
pixcol = read_bgra (pixcol, 1, &dataByte, -1);
|
||||
pixcol = reverse_read_bgra (pixcol, 1, &dataByte);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -204,14 +262,14 @@ LoadTGA (QFile *fin)
|
|||
for (row = 0; row < rows; row++, pixrow += span) {
|
||||
pixcol = pixrow;
|
||||
for (column = 0; column < columns; column++)
|
||||
pixcol = read_bgr (pixcol, 1, &dataByte, 1);
|
||||
pixcol = read_bgr (pixcol, 1, &dataByte);
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
for (row = 0; row < rows; row++, pixrow += span) {
|
||||
pixcol = pixrow;
|
||||
for (column = 0; column < columns; column++)
|
||||
pixcol = read_bgra (pixcol, 1, &dataByte, 1);
|
||||
pixcol = read_bgra (pixcol, 1, &dataByte);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -223,14 +281,14 @@ LoadTGA (QFile *fin)
|
|||
for (row = 0; row < rows; row++, pixrow += span) {
|
||||
pixcol = pixrow;
|
||||
for (column = columns - 1; column >= 0; column--)
|
||||
pixcol = read_bgr (pixcol, 1, &dataByte, -1);
|
||||
pixcol = reverse_read_bgr (pixcol, 1, &dataByte);
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
for (row = 0; row < rows; row++, pixrow += span) {
|
||||
pixcol = pixrow;
|
||||
for (column = columns - 1; column >= 0; column--)
|
||||
pixcol = read_bgra (pixcol, 1, &dataByte, -1);
|
||||
pixcol = reverse_read_bgra (pixcol, 1, &dataByte);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -239,7 +297,7 @@ LoadTGA (QFile *fin)
|
|||
} else if (targa->image_type == 10) { // RLE compressed image
|
||||
unsigned char packetHeader, packetSize;
|
||||
|
||||
byte *(*expand) (byte *buf, int count, byte **data, int dir);
|
||||
byte *(*expand) (byte *buf, int count, byte **data);
|
||||
|
||||
pixrow = tex->data + (rows - 1) * span;
|
||||
|
||||
|
@ -258,10 +316,10 @@ LoadTGA (QFile *fin)
|
|||
|
||||
packetSize -= count;
|
||||
if (packetHeader & 0x80) { // run-length packet
|
||||
expand (pixcol, count, &dataByte, 1);
|
||||
expand (pixcol, count, &dataByte);
|
||||
} else { // non run-length packet
|
||||
while (count--)
|
||||
expand (pixcol, 1, &dataByte, 1);
|
||||
expand (pixcol, 1, &dataByte);
|
||||
}
|
||||
column = 0;
|
||||
pixcol = (pixrow -= span);
|
||||
|
@ -270,10 +328,10 @@ LoadTGA (QFile *fin)
|
|||
}
|
||||
column += packetSize;
|
||||
if (packetHeader & 0x80) { // run-length packet
|
||||
pixcol = expand (pixcol, packetSize, &dataByte, 1);
|
||||
pixcol = expand (pixcol, packetSize, &dataByte);
|
||||
} else { // non run-length packet
|
||||
while (packetSize--)
|
||||
pixcol = expand (pixcol, 1, &dataByte, 1);
|
||||
pixcol = expand (pixcol, 1, &dataByte);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue