mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-19 00:15:30 +00:00
IMAGE: Don't perform color conversion when decoding PNGs
This commit is contained in:
parent
0d5d04ca3a
commit
9f98cddf8d
@ -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.
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user