IMAGE: Don't perform color conversion when decoding PNGs
This commit is contained in:
parent
0d5d04ca3a
commit
9f98cddf8d
2 changed files with 19 additions and 14 deletions
|
@ -39,7 +39,11 @@
|
||||||
|
|
||||||
namespace Image {
|
namespace Image {
|
||||||
|
|
||||||
PNGDecoder::PNGDecoder() : _outputSurface(0), _palette(0), _paletteColorCount(0), _skipSignature(false) {
|
PNGDecoder::PNGDecoder() :
|
||||||
|
_outputSurface(0),
|
||||||
|
_palette(0),
|
||||||
|
_paletteColorCount(0),
|
||||||
|
_skipSignature(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PNGDecoder::~PNGDecoder() {
|
PNGDecoder::~PNGDecoder() {
|
||||||
|
@ -56,6 +60,14 @@ void PNGDecoder::destroy() {
|
||||||
_palette = NULL;
|
_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
|
#ifdef USE_PNG
|
||||||
// libpng-error-handling:
|
// libpng-error-handling:
|
||||||
void pngError(png_structp pngptr, png_const_charp errorMsg) {
|
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());
|
_outputSurface->create(width, height, Graphics::PixelFormat::createFormatCLUT8());
|
||||||
png_set_packing(pngPtr);
|
png_set_packing(pngPtr);
|
||||||
} else {
|
} else {
|
||||||
bool isAlpha = (colorType & PNG_COLOR_MASK_ALPHA);
|
|
||||||
if (png_get_valid(pngPtr, infoPtr, PNG_INFO_tRNS)) {
|
if (png_get_valid(pngPtr, infoPtr, PNG_INFO_tRNS)) {
|
||||||
isAlpha = true;
|
|
||||||
png_set_expand(pngPtr);
|
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()) {
|
if (!_outputSurface->getPixels()) {
|
||||||
error("Could not allocate memory for output image.");
|
error("Could not allocate memory for output image.");
|
||||||
}
|
}
|
||||||
|
@ -184,17 +194,8 @@ bool PNGDecoder::loadStream(Common::SeekableReadStream &stream) {
|
||||||
colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
|
colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||||
png_set_gray_to_rgb(pngPtr);
|
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)
|
if (colorType != PNG_COLOR_TYPE_RGB_ALPHA)
|
||||||
png_set_filler(pngPtr, 0xff, PNG_FILLER_AFTER);
|
png_set_filler(pngPtr, 0xff, PNG_FILLER_AFTER);
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// After the transformations have been registered, the image data is read again.
|
// After the transformations have been registered, the image data is read again.
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
#include "common/scummsys.h"
|
#include "common/scummsys.h"
|
||||||
#include "common/textconsole.h"
|
#include "common/textconsole.h"
|
||||||
|
#include "graphics/pixelformat.h"
|
||||||
#include "image/image_decoder.h"
|
#include "image/image_decoder.h"
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
@ -57,7 +58,10 @@ public:
|
||||||
const byte *getPalette() const { return _palette; }
|
const byte *getPalette() const { return _palette; }
|
||||||
uint16 getPaletteColorCount() const { return _paletteColorCount; }
|
uint16 getPaletteColorCount() const { return _paletteColorCount; }
|
||||||
void setSkipSignature(bool skip) { _skipSignature = skip; }
|
void setSkipSignature(bool skip) { _skipSignature = skip; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Graphics::PixelFormat getByteOrderRgbaPixelFormat() const;
|
||||||
|
|
||||||
byte *_palette;
|
byte *_palette;
|
||||||
uint16 _paletteColorCount;
|
uint16 _paletteColorCount;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue