diff options
author | Eugene Sandulenko | 2011-06-26 21:17:28 +0300 |
---|---|---|
committer | Eugene Sandulenko | 2011-06-26 21:19:27 +0300 |
commit | d2962531cbdfdfc3cdec7af2487add21a056295b (patch) | |
tree | 4cf6fb3cb2bf1cc28aac3381d2bfae9a22877646 /graphics | |
parent | 55a7bbf86abce9bd44b11fceed7e2a6a8bc49b51 (diff) | |
download | scummvm-rg350-d2962531cbdfdfc3cdec7af2487add21a056295b.tar.gz scummvm-rg350-d2962531cbdfdfc3cdec7af2487add21a056295b.tar.bz2 scummvm-rg350-d2962531cbdfdfc3cdec7af2487add21a056295b.zip |
GRAPHICS: Generalized arbitrary bit depth images processing in PNG decoder.
This fixes 1bpp image rengering.
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/png.cpp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/graphics/png.cpp b/graphics/png.cpp index 6ffc53bd92..2189fd333f 100644 --- a/graphics/png.cpp +++ b/graphics/png.cpp @@ -166,18 +166,26 @@ Graphics::Surface *PNG::getSurface(const PixelFormat &format) { } } else { byte index, r, g, b; + uint32 mask = (0xff >> (8 - _header.bitDepth)) << (8 - _header.bitDepth); // Convert the indexed surface to the target pixel format for (uint16 i = 0; i < output->h; i++) { - bool otherPixel = false; + int data = 0; + int bitCount = 8; + byte *src1 = src; for (uint16 j = 0; j < output->w; j++) { - if (_header.bitDepth != 4) - index = *src; - else if (!otherPixel) - index = (*src) >> 4; - else - index = (*src) & 0xf; + if (bitCount == 8) { + data = *src; + src++; + } + + index = (data & mask) >> (8 - _header.bitDepth); + data = (data << _header.bitDepth) & 0xff; + bitCount -= _header.bitDepth; + + if (bitCount == 0) + bitCount = 8; r = _palette[index * 4 + 0]; g = _palette[index * 4 + 1]; @@ -188,14 +196,8 @@ Graphics::Surface *PNG::getSurface(const PixelFormat &format) { *((uint16 *)output->getBasePtr(j, i)) = format.ARGBToColor(a, r, g, b); else *((uint32 *)output->getBasePtr(j, i)) = format.ARGBToColor(a, r, g, b); - - if (_header.bitDepth != 4 || otherPixel) - src++; - otherPixel = !otherPixel; } - // The surface is a whole scanline wide, skip the rest of it. - if (_header.bitDepth == 4) - src += output->w / 2 + output->w % 2; + src = src1 + output->w; } } |