From b493d8e823dace4247f63f03c68e24771c3d2ddc Mon Sep 17 00:00:00 2001 From: Braden Obrzut Date: Sun, 26 May 2013 04:56:52 +0000 Subject: [PATCH] - 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) --- src/m_png.cpp | 30 ++++++++++++++++++++++++++---- src/textures/pngtexture.cpp | 24 ++++-------------------- src/textures/texture.cpp | 16 ---------------- src/textures/textures.h | 3 --- 4 files changed, 30 insertions(+), 43 deletions(-) diff --git a/src/m_png.cpp b/src/m_png.cpp index dd2e469708..1e1a331af8 100644 --- a/src/m_png.cpp +++ b/src/m_png.cpp @@ -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; + } + } + } } diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index 8120df9688..7927c0a93c 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -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<