darn, broke the reverse direction and fixing it produces horrid code

This commit is contained in:
Bill Currie 2003-03-20 21:24:04 +00:00
parent 1a18044b31
commit 4222c501a0

View file

@ -51,57 +51,115 @@ static __attribute__ ((unused)) const char rcsid[] =
static inline byte * 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--) { while (count--) {
*buf = red; *buf++ = red;
buf += dir; *buf++ = green;
*buf = green; *buf++ = blue;
buf += dir; *buf++ = 255;
*buf = blue;
buf += dir;
*buf = 255;
buf += dir;
} }
return buf; return buf;
} }
static inline byte * static inline byte *
blit_rgba (byte *buf, int count, byte red, byte green, byte blue, byte alpha, blit_rgba (byte *buf, int count, byte red, byte green, byte blue, byte alpha)
int dir)
{ {
while (count--) { while (count--) {
*buf = red; *buf++ = red;
buf += dir; *buf++ = green;
*buf = green; *buf++ = blue;
buf += dir; *buf++ = alpha;
*buf = blue;
buf += dir;
*buf = alpha;
buf += dir;
} }
return buf; return buf;
} }
static inline byte * 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 blue = *(*data)++;
byte green = *(*data)++; byte green = *(*data)++;
byte red = *(*data)++; byte red = *(*data)++;
return blit_rgb (buf, count, red, green, blue, dir); return blit_rgb (buf, count, red, green, blue);
} }
static inline byte * 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 blue = *(*data)++;
byte green = *(*data)++; byte green = *(*data)++;
byte red = *(*data)++; byte red = *(*data)++;
byte alpha = *(*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 * struct tex_s *
@ -166,14 +224,14 @@ LoadTGA (QFile *fin)
for (row = rows - 1; row >= 0; row--, pixrow -= span) { for (row = rows - 1; row >= 0; row--, pixrow -= span) {
pixcol = pixrow; pixcol = pixrow;
for (column = 0; column < columns; column++) for (column = 0; column < columns; column++)
pixcol = read_bgr (pixcol, 1, &dataByte, 1); pixcol = read_bgr (pixcol, 1, &dataByte);
} }
break; break;
case 32: case 32:
for (row = rows - 1; row >= 0; row--, pixrow -= span) { for (row = rows - 1; row >= 0; row--, pixrow -= span) {
pixcol = pixrow; pixcol = pixrow;
for (column = 0; column < columns; column++) for (column = 0; column < columns; column++)
pixcol = read_bgra (pixcol, 1, &dataByte, 1); pixcol = read_bgra (pixcol, 1, &dataByte);
} }
break; break;
} }
@ -185,14 +243,14 @@ LoadTGA (QFile *fin)
for (row = rows - 1; row >= 0; row--, pixrow -= span) { for (row = rows - 1; row >= 0; row--, pixrow -= span) {
pixcol = pixrow; pixcol = pixrow;
for (column = columns - 1; column >= 0; column--) for (column = columns - 1; column >= 0; column--)
pixcol = read_bgr (pixcol, 1, &dataByte, -1); pixcol = reverse_read_bgr (pixcol, 1, &dataByte);
} }
break; break;
case 32: case 32:
for (row = rows - 1; row >= 0; row--, pixrow -= span) { for (row = rows - 1; row >= 0; row--, pixrow -= span) {
pixcol = pixrow; pixcol = pixrow;
for (column = columns - 1; column >= 0; column--) for (column = columns - 1; column >= 0; column--)
pixcol = read_bgra (pixcol, 1, &dataByte, -1); pixcol = reverse_read_bgra (pixcol, 1, &dataByte);
} }
break; break;
} }
@ -204,14 +262,14 @@ LoadTGA (QFile *fin)
for (row = 0; row < rows; row++, pixrow += span) { for (row = 0; row < rows; row++, pixrow += span) {
pixcol = pixrow; pixcol = pixrow;
for (column = 0; column < columns; column++) for (column = 0; column < columns; column++)
pixcol = read_bgr (pixcol, 1, &dataByte, 1); pixcol = read_bgr (pixcol, 1, &dataByte);
} }
break; break;
case 32: case 32:
for (row = 0; row < rows; row++, pixrow += span) { for (row = 0; row < rows; row++, pixrow += span) {
pixcol = pixrow; pixcol = pixrow;
for (column = 0; column < columns; column++) for (column = 0; column < columns; column++)
pixcol = read_bgra (pixcol, 1, &dataByte, 1); pixcol = read_bgra (pixcol, 1, &dataByte);
} }
break; break;
} }
@ -223,14 +281,14 @@ LoadTGA (QFile *fin)
for (row = 0; row < rows; row++, pixrow += span) { for (row = 0; row < rows; row++, pixrow += span) {
pixcol = pixrow; pixcol = pixrow;
for (column = columns - 1; column >= 0; column--) for (column = columns - 1; column >= 0; column--)
pixcol = read_bgr (pixcol, 1, &dataByte, -1); pixcol = reverse_read_bgr (pixcol, 1, &dataByte);
} }
break; break;
case 32: case 32:
for (row = 0; row < rows; row++, pixrow += span) { for (row = 0; row < rows; row++, pixrow += span) {
pixcol = pixrow; pixcol = pixrow;
for (column = columns - 1; column >= 0; column--) for (column = columns - 1; column >= 0; column--)
pixcol = read_bgra (pixcol, 1, &dataByte, -1); pixcol = reverse_read_bgra (pixcol, 1, &dataByte);
} }
break; break;
} }
@ -239,7 +297,7 @@ LoadTGA (QFile *fin)
} else if (targa->image_type == 10) { // RLE compressed image } else if (targa->image_type == 10) { // RLE compressed image
unsigned char packetHeader, packetSize; 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; pixrow = tex->data + (rows - 1) * span;
@ -258,10 +316,10 @@ LoadTGA (QFile *fin)
packetSize -= count; packetSize -= count;
if (packetHeader & 0x80) { // run-length packet if (packetHeader & 0x80) { // run-length packet
expand (pixcol, count, &dataByte, 1); expand (pixcol, count, &dataByte);
} else { // non run-length packet } else { // non run-length packet
while (count--) while (count--)
expand (pixcol, 1, &dataByte, 1); expand (pixcol, 1, &dataByte);
} }
column = 0; column = 0;
pixcol = (pixrow -= span); pixcol = (pixrow -= span);
@ -270,10 +328,10 @@ LoadTGA (QFile *fin)
} }
column += packetSize; column += packetSize;
if (packetHeader & 0x80) { // run-length packet if (packetHeader & 0x80) { // run-length packet
pixcol = expand (pixcol, packetSize, &dataByte, 1); pixcol = expand (pixcol, packetSize, &dataByte);
} else { // non run-length packet } else { // non run-length packet
while (packetSize--) while (packetSize--)
pixcol = expand (pixcol, 1, &dataByte, 1); pixcol = expand (pixcol, 1, &dataByte);
} }
} }
} }