- fixed what looks like a wrongly braced 'for' loop in 4 bit PCX.

The code looks wrong, unfortunately I cannot test it due to lack of an image in that format
This commit is contained in:
Christoph Oelckers 2018-03-22 23:14:43 +01:00
parent 6fcf1e0149
commit 5466e2c7c5

View file

@ -111,6 +111,7 @@ FTexture * PCXTexture_TryCreate(FileReader & file, int lumpnum)
{
PCXHeader hdr;
file.Seek(0, FileReader::SeekSet);
if (file.Read(&hdr, sizeof(hdr)) != sizeof(hdr))
{
@ -123,8 +124,9 @@ FTexture * PCXTexture_TryCreate(FileReader & file, int lumpnum)
if (hdr.manufacturer != 10 || hdr.encoding != 1) return NULL;
if (hdr.version != 0 && hdr.version != 2 && hdr.version != 3 && hdr.version != 4 && hdr.version != 5) return NULL;
if (hdr.bitsPerPixel != 1 && hdr.bitsPerPixel != 8) return NULL;
if (hdr.bitsPerPixel != 1 && hdr.bitsPerPixel != 8 && hdr.bitsPerPixel != 4) return NULL;
if (hdr.bitsPerPixel == 1 && hdr.numColorPlanes !=1 && hdr.numColorPlanes != 4) return NULL;
if (hdr.bitsPerPixel == 4 && hdr.numColorPlanes != 1) return NULL;
if (hdr.bitsPerPixel == 8 && hdr.bytesPerScanLine != ((hdr.xmax - hdr.xmin + 2)&~1)) return NULL;
for (int i = 0; i < 54; i++)
@ -205,7 +207,9 @@ void FPCXTexture::ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr)
for (i = 7; i >= 0; --i, ptr ++)
{
*ptr = ((rle_value & (1 << i)) > 0);
// This can overflow for the last byte if not checked.
if (ptr < dst+Width*Height)
*ptr = ((rle_value & (1 << i)) > 0);
}
}
}
@ -259,13 +263,13 @@ void FPCXTexture::ReadPCX4bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr)
rle_count--;
*(pLine++) = rle_value;
}
}
/* compute line's color indexes */
for (x = 0; x < Width; ++x)
{
if (line[x / 8] & (128 >> (x % 8)))
ptr[x] += (1 << c);
}
/* compute line's color indexes */
for (x = 0; x < Width; ++x)
{
if (line[x / 8] & (128 >> (x % 8)))
ptr[x] += (1 << c);
}
}
@ -479,19 +483,20 @@ int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo
Pixels = new uint8_t[Width*Height];
if (bitcount < 8)
{
for (int i=0;i<16;i++)
{
pe[i] = PalEntry(header.palette[i*3],header.palette[i*3+1],header.palette[i*3+2]);
}
switch (bitcount)
{
default:
case 1:
pe[0] = PalEntry(255, 0, 0, 0);
pe[1] = PalEntry(255, 255, 255, 255);
ReadPCX1bit (Pixels, lump, &header);
break;
case 4:
for (int i = 0; i<16; i++)
{
pe[i] = PalEntry(255, header.palette[i * 3], header.palette[i * 3 + 1], header.palette[i * 3 + 2]);
}
ReadPCX4bits (Pixels, lump, &header);
break;
}