diff options
author | Bastien Bouclet | 2019-01-31 18:47:29 +0100 |
---|---|---|
committer | Bastien Bouclet | 2019-04-28 07:59:14 +0200 |
commit | 9f98cddf8dc015e0cdc6b57e303b693bba3cc1fc (patch) | |
tree | df6f5359fd5f793ec38a5d2a10a0148c08895a9f /image | |
parent | 0d5d04ca3a5473f24f45112bb40a009679024acc (diff) | |
download | scummvm-rg350-9f98cddf8dc015e0cdc6b57e303b693bba3cc1fc.tar.gz scummvm-rg350-9f98cddf8dc015e0cdc6b57e303b693bba3cc1fc.tar.bz2 scummvm-rg350-9f98cddf8dc015e0cdc6b57e303b693bba3cc1fc.zip |
IMAGE: Don't perform color conversion when decoding PNGs
Diffstat (limited to 'image')
-rw-r--r-- | image/png.cpp | 29 | ||||
-rw-r--r-- | image/png.h | 4 |
2 files changed, 19 insertions, 14 deletions
diff --git a/image/png.cpp b/image/png.cpp index 50a53b0a46..d8351711d9 100644 --- a/image/png.cpp +++ b/image/png.cpp @@ -39,7 +39,11 @@ namespace Image { -PNGDecoder::PNGDecoder() : _outputSurface(0), _palette(0), _paletteColorCount(0), _skipSignature(false) { +PNGDecoder::PNGDecoder() : + _outputSurface(0), + _palette(0), + _paletteColorCount(0), + _skipSignature(false) { } PNGDecoder::~PNGDecoder() { @@ -56,6 +60,14 @@ void PNGDecoder::destroy() { _palette = NULL; } +Graphics::PixelFormat PNGDecoder::getByteOrderRgbaPixelFormat() const { +#ifdef SCUMM_BIG_ENDIAN + return Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0); +#else + return Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24); +#endif +} + #ifdef USE_PNG // libpng-error-handling: void pngError(png_structp pngptr, png_const_charp errorMsg) { @@ -166,13 +178,11 @@ bool PNGDecoder::loadStream(Common::SeekableReadStream &stream) { _outputSurface->create(width, height, Graphics::PixelFormat::createFormatCLUT8()); png_set_packing(pngPtr); } else { - bool isAlpha = (colorType & PNG_COLOR_MASK_ALPHA); if (png_get_valid(pngPtr, infoPtr, PNG_INFO_tRNS)) { - isAlpha = true; png_set_expand(pngPtr); } - _outputSurface->create(width, height, Graphics::PixelFormat(4, - 8, 8, 8, isAlpha ? 8 : 0, 24, 16, 8, 0)); + + _outputSurface->create(width, height, getByteOrderRgbaPixelFormat()); if (!_outputSurface->getPixels()) { error("Could not allocate memory for output image."); } @@ -184,17 +194,8 @@ bool PNGDecoder::loadStream(Common::SeekableReadStream &stream) { colorType == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(pngPtr); - // PNGs are Big-Endian: -#ifdef SCUMM_LITTLE_ENDIAN - png_set_bgr(pngPtr); - png_set_swap_alpha(pngPtr); - if (colorType != PNG_COLOR_TYPE_RGB_ALPHA) - png_set_filler(pngPtr, 0xff, PNG_FILLER_BEFORE); -#else if (colorType != PNG_COLOR_TYPE_RGB_ALPHA) png_set_filler(pngPtr, 0xff, PNG_FILLER_AFTER); -#endif - } // After the transformations have been registered, the image data is read again. diff --git a/image/png.h b/image/png.h index cdc3e3faf1..adbc6d7a68 100644 --- a/image/png.h +++ b/image/png.h @@ -33,6 +33,7 @@ #include "common/scummsys.h" #include "common/textconsole.h" +#include "graphics/pixelformat.h" #include "image/image_decoder.h" namespace Common { @@ -57,7 +58,10 @@ public: const byte *getPalette() const { return _palette; } uint16 getPaletteColorCount() const { return _paletteColorCount; } void setSkipSignature(bool skip) { _skipSignature = skip; } + private: + Graphics::PixelFormat getByteOrderRgbaPixelFormat() const; + byte *_palette; uint16 _paletteColorCount; |