- Just remembered that the true color stuff generates textures differently. Changed the previous commit to expand 1, 2, and 4 bit grayscale images while reading the PNG instead of changing the palette.

SVN r4289 (trunk)
This commit is contained in:
Braden Obrzut 2013-05-26 04:56:52 +00:00
parent dabd48ab81
commit b493d8e823
4 changed files with 30 additions and 43 deletions

View file

@ -103,7 +103,7 @@ static inline void MakeChunk (void *where, DWORD type, size_t len);
static inline void StuffPalette (const PalEntry *from, BYTE *to);
static bool WriteIDAT (FILE *file, const BYTE *data, int len);
static void UnfilterRow (int width, BYTE *dest, BYTE *stream, BYTE *prev, int bpp);
static void UnpackPixels (int width, int bytesPerRow, int bitdepth, const BYTE *rowin, BYTE *rowout);
static void UnpackPixels (int width, int bytesPerRow, int bitdepth, const BYTE *rowin, BYTE *rowout, bool grayscale);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
@ -604,7 +604,7 @@ bool M_ReadIDAT (FileReader *file, BYTE *buffer, int width, int height, int pitc
in = prev;
if (bitdepth < 8)
{
UnpackPixels (passwidth, bytesPerRowIn, bitdepth, in, adam7buff[2]);
UnpackPixels (passwidth, bytesPerRowIn, bitdepth, in, adam7buff[2], colortype == 0);
in = adam7buff[2];
}
// Distribute pixels into the output buffer
@ -688,7 +688,7 @@ bool M_ReadIDAT (FileReader *file, BYTE *buffer, int width, int height, int pitc
passpitch = pitch << interlace;
for (curr = buffer + pitch * interlace; curr <= prev; curr += passpitch)
{
UnpackPixels (width, bytesPerRowIn, bitdepth, curr, curr);
UnpackPixels (width, bytesPerRowIn, bitdepth, curr, curr, colortype == 0);
}
}
return true;
@ -1155,7 +1155,7 @@ void UnfilterRow (int width, BYTE *dest, BYTE *row, BYTE *prev, int bpp)
//
//==========================================================================
static void UnpackPixels (int width, int bytesPerRow, int bitdepth, const BYTE *rowin, BYTE *rowout)
static void UnpackPixels (int width, int bytesPerRow, int bitdepth, const BYTE *rowin, BYTE *rowout, bool grayscale)
{
const BYTE *in;
BYTE *out;
@ -1242,4 +1242,26 @@ static void UnpackPixels (int width, int bytesPerRow, int bitdepth, const BYTE *
}
break;
}
// Expand gray scale to 8bpp
if(grayscale)
{
out = rowout + width;
while(--out >= rowout)
{
switch(bitdepth)
{
case 1:
*out *= 0xFF;
break;
case 2:
*out |= (*out<<2)|(*out<<4)|(*out<<6);
break;
case 4:
*out |= (*out<<4);
break;
default: break;
}
}
}
}

View file

@ -297,33 +297,17 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename
case 0: // Grayscale
if (!bAlphaTexture)
{
BYTE *GrayMapSrc;
switch(BitDepth)
{
default:
GrayMapSrc = GrayMap;
break;
case 4:
GrayMapSrc = GrayMap4bit;
break;
case 2:
GrayMapSrc = GrayMap2bit;
break;
case 1:
GrayMapSrc = GrayMap1bit;
break;
}
if (colortype == 0 && havetRNS && trans[0] != 0)
{
bMasked = true;
PaletteSize = 1<<BitDepth;
PaletteMap = new BYTE[PaletteSize];
memcpy (PaletteMap, GrayMapSrc, 256);
PaletteSize = 256;
PaletteMap = new BYTE[256];
memcpy (PaletteMap, GrayMap, 256);
PaletteMap[trans[0]] = 0;
}
else
{
PaletteMap = GrayMapSrc;
PaletteMap = GrayMap;
}
}
break;

View file

@ -56,29 +56,13 @@ struct TexCreateInfo
};
BYTE FTexture::GrayMap[256];
BYTE FTexture::GrayMap4bit[16];
BYTE FTexture::GrayMap2bit[4];
BYTE FTexture::GrayMap1bit[2];
void FTexture::InitGrayMap()
{
for (int i = 0; i < 256; ++i)
{
GrayMap[i] = ColorMatcher.Pick (i, i, i);
if(i < 16)
{
const int i4 = i|(i<<4);
GrayMap4bit[i] = ColorMatcher.Pick (i4, i4, i4);
}
if(i < 4)
{
const int i2 = i|(i<<2)|(i<<4)|(i<<6);
GrayMap4bit[i] = ColorMatcher.Pick (i2, i2, i2);
}
}
GrayMap1bit[0] = ColorMatcher.Pick (0, 0, 0);
GrayMap1bit[1] = ColorMatcher.Pick (255, 255, 255);
}
FTexture *IMGZTexture_TryCreate(FileReader &, int lumpnum);

View file

@ -283,9 +283,6 @@ public:
protected:
WORD Width, Height, WidthMask;
static BYTE GrayMap[256];
static BYTE GrayMap4bit[16];
static BYTE GrayMap2bit[4];
static BYTE GrayMap1bit[2];
FNativeTexture *Native;
FTexture (const char *name = NULL, int lumpnum = -1);