- fixed startup and font init crashes.
This commit is contained in:
parent
028cc6a828
commit
3fd4d08004
15 changed files with 271 additions and 132 deletions
|
|
@ -102,6 +102,8 @@ void AnimTextures::SetSize(int width, int height)
|
|||
{
|
||||
static_cast<AnimTexture*>(tex[0]->GetTexture())->SetFrameSize(width, height);
|
||||
static_cast<AnimTexture*>(tex[1]->GetTexture())->SetFrameSize(width, height);
|
||||
tex[0]->SetSize(width, height);
|
||||
tex[1]->SetSize(width, height);
|
||||
}
|
||||
|
||||
void AnimTextures::SetFrame(const uint8_t *palette, const void* data)
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ public:
|
|||
|
||||
protected:
|
||||
void ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap);
|
||||
void SetupPalette(FileReader &lump);
|
||||
|
||||
uint8_t BitDepth;
|
||||
uint8_t ColorType;
|
||||
|
|
@ -152,11 +153,6 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height,
|
|||
: FImageSource(lumpnum),
|
||||
BitDepth(depth), ColorType(colortype), Interlace(interlace), HaveTrans(false)
|
||||
{
|
||||
union
|
||||
{
|
||||
uint32_t palette[256];
|
||||
uint8_t pngpal[256][3];
|
||||
} p;
|
||||
uint8_t trans[256];
|
||||
uint32_t len, id;
|
||||
int i;
|
||||
|
|
@ -210,15 +206,7 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height,
|
|||
case MAKE_ID('P','L','T','E'):
|
||||
PaletteSize = MIN<int> (len / 3, 256);
|
||||
StartOfPalette = (uint32_t)lump.Tell();
|
||||
lump.Read (p.pngpal, PaletteSize * 3);
|
||||
if (PaletteSize * 3 != (int)len)
|
||||
{
|
||||
lump.Seek (len - PaletteSize * 3, FileReader::SeekCur);
|
||||
}
|
||||
for (i = PaletteSize - 1; i >= 0; --i)
|
||||
{
|
||||
p.palette[i] = MAKERGB(p.pngpal[i][0], p.pngpal[i][1], p.pngpal[i][2]);
|
||||
}
|
||||
lump.Seek(len, FileReader::SeekCur);
|
||||
break;
|
||||
|
||||
case MAKE_ID('t','R','N','S'):
|
||||
|
|
@ -248,9 +236,6 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height,
|
|||
{
|
||||
bMasked = true;
|
||||
PaletteSize = 256;
|
||||
PaletteMap = (uint8_t*)ImageArena.Alloc(PaletteSize);
|
||||
memcpy (PaletteMap, GPalette.GrayMap, 256);
|
||||
PaletteMap[NonPaletteTrans[0]] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -259,14 +244,11 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height,
|
|||
break;
|
||||
|
||||
case 3: // Paletted
|
||||
PaletteMap = (uint8_t*)ImageArena.Alloc(PaletteSize);
|
||||
MakeRemap ((uint32_t*)GPalette.BaseColors, p.palette, PaletteMap, trans, PaletteSize);
|
||||
for (i = 0; i < PaletteSize; ++i)
|
||||
{
|
||||
if (trans[i] == 0)
|
||||
{
|
||||
bMasked = true;
|
||||
PaletteMap[i] = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -281,6 +263,87 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height,
|
|||
}
|
||||
}
|
||||
|
||||
void FPNGTexture::SetupPalette(FileReader &lump)
|
||||
{
|
||||
union
|
||||
{
|
||||
uint32_t palette[256];
|
||||
uint8_t pngpal[256][3];
|
||||
} p;
|
||||
uint8_t trans[256];
|
||||
uint32_t len, id;
|
||||
int i;
|
||||
|
||||
auto pos = lump.Tell();
|
||||
|
||||
memset(trans, 255, 256);
|
||||
|
||||
// Parse pre-IDAT chunks. I skip the CRCs. Is that bad?
|
||||
lump.Seek(33, FileReader::SeekSet);
|
||||
|
||||
lump.Read(&len, 4);
|
||||
lump.Read(&id, 4);
|
||||
while (id != MAKE_ID('I', 'D', 'A', 'T') && id != MAKE_ID('I', 'E', 'N', 'D'))
|
||||
{
|
||||
len = BigLong((unsigned int)len);
|
||||
switch (id)
|
||||
{
|
||||
default:
|
||||
lump.Seek(len, FileReader::SeekCur);
|
||||
break;
|
||||
|
||||
case MAKE_ID('P', 'L', 'T', 'E'):
|
||||
lump.Read(p.pngpal, PaletteSize * 3);
|
||||
if (PaletteSize * 3 != (int)len)
|
||||
{
|
||||
lump.Seek(len - PaletteSize * 3, FileReader::SeekCur);
|
||||
}
|
||||
for (i = PaletteSize - 1; i >= 0; --i)
|
||||
{
|
||||
p.palette[i] = MAKERGB(p.pngpal[i][0], p.pngpal[i][1], p.pngpal[i][2]);
|
||||
}
|
||||
break;
|
||||
|
||||
case MAKE_ID('t', 'R', 'N', 'S'):
|
||||
lump.Read(trans, len);
|
||||
break;
|
||||
}
|
||||
lump.Seek(4, FileReader::SeekCur); // Skip CRC
|
||||
lump.Read(&len, 4);
|
||||
id = MAKE_ID('I', 'E', 'N', 'D');
|
||||
lump.Read(&id, 4);
|
||||
}
|
||||
StartOfIDAT = (uint32_t)lump.Tell() - 8;
|
||||
|
||||
switch (ColorType)
|
||||
{
|
||||
case 0: // Grayscale
|
||||
if (HaveTrans && NonPaletteTrans[0] < 256)
|
||||
{
|
||||
PaletteMap = (uint8_t*)ImageArena.Alloc(PaletteSize);
|
||||
memcpy(PaletteMap, GPalette.GrayMap, 256);
|
||||
PaletteMap[NonPaletteTrans[0]] = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 3: // Paletted
|
||||
PaletteMap = (uint8_t*)ImageArena.Alloc(PaletteSize);
|
||||
MakeRemap((uint32_t*)GPalette.BaseColors, p.palette, PaletteMap, trans, PaletteSize);
|
||||
for (i = 0; i < PaletteSize; ++i)
|
||||
{
|
||||
if (trans[i] == 0)
|
||||
{
|
||||
PaletteMap[i] = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
lump.Seek(pos, FileReader::SeekSet);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
|
|
@ -336,6 +399,7 @@ TArray<uint8_t> FPNGTexture::CreatePalettedPixels(int conversion)
|
|||
{
|
||||
if (conversion != luminance)
|
||||
{
|
||||
if (!PaletteMap) SetupPalette(lfr);
|
||||
ImageHelpers::FlipSquareBlockRemap (Pixels.Data(), Width, PaletteMap);
|
||||
}
|
||||
else if (ColorType == 0)
|
||||
|
|
@ -354,6 +418,7 @@ TArray<uint8_t> FPNGTexture::CreatePalettedPixels(int conversion)
|
|||
TArray<uint8_t> newpix(Width*Height, true);
|
||||
if (conversion != luminance)
|
||||
{
|
||||
if (!PaletteMap) SetupPalette(lfr);
|
||||
ImageHelpers::FlipNonSquareBlockRemap (newpix.Data(), Pixels.Data(), Width, Height, Width, PaletteMap);
|
||||
}
|
||||
else if (ColorType == 0)
|
||||
|
|
@ -408,6 +473,7 @@ TArray<uint8_t> FPNGTexture::CreatePalettedPixels(int conversion)
|
|||
case 4: // Grayscale + Alpha
|
||||
pitch = Width * 2;
|
||||
backstep = Height * pitch - 2;
|
||||
if (!PaletteMap) SetupPalette(lfr);
|
||||
for (x = Width; x > 0; --x)
|
||||
{
|
||||
for (y = Height; y > 0; --y)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue