aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--image/png.cpp16
-rw-r--r--image/png.h7
2 files changed, 20 insertions, 3 deletions
diff --git a/image/png.cpp b/image/png.cpp
index d8351711d9..e854651da6 100644
--- a/image/png.cpp
+++ b/image/png.cpp
@@ -43,7 +43,9 @@ PNGDecoder::PNGDecoder() :
_outputSurface(0),
_palette(0),
_paletteColorCount(0),
- _skipSignature(false) {
+ _skipSignature(false),
+ _keepTransparencyPaletted(false),
+ _transparentColor(-1) {
}
PNGDecoder::~PNGDecoder() {
@@ -159,7 +161,7 @@ bool PNGDecoder::loadStream(Common::SeekableReadStream &stream) {
// Images of all color formats except PNG_COLOR_TYPE_PALETTE
// will be transformed into ARGB images
- if (colorType == PNG_COLOR_TYPE_PALETTE && !png_get_valid(pngPtr, infoPtr, PNG_INFO_tRNS)) {
+ if (colorType == PNG_COLOR_TYPE_PALETTE && (_keepTransparencyPaletted || !png_get_valid(pngPtr, infoPtr, PNG_INFO_tRNS))) {
int numPalette = 0;
png_colorp palette = NULL;
uint32 success = png_get_PLTE(pngPtr, infoPtr, &palette, &numPalette);
@@ -175,6 +177,16 @@ bool PNGDecoder::loadStream(Common::SeekableReadStream &stream) {
_palette[(i * 3) + 2] = palette[i].blue;
}
+
+ if (png_get_valid(pngPtr, infoPtr, PNG_INFO_tRNS)) {
+ png_bytep trans;
+ int numTrans;
+ png_color_16p transColor;
+ png_get_tRNS(pngPtr, infoPtr, &trans, &numTrans, &transColor);
+ assert(numTrans == 1);
+ _transparentColor = *trans;
+ }
+
_outputSurface->create(width, height, Graphics::PixelFormat::createFormatCLUT8());
png_set_packing(pngPtr);
} else {
diff --git a/image/png.h b/image/png.h
index adbc6d7a68..f983da467e 100644
--- a/image/png.h
+++ b/image/png.h
@@ -57,8 +57,9 @@ public:
const Graphics::Surface *getSurface() const { return _outputSurface; }
const byte *getPalette() const { return _palette; }
uint16 getPaletteColorCount() const { return _paletteColorCount; }
+ int getTransparentColor() const { return _transparentColor; }
void setSkipSignature(bool skip) { _skipSignature = skip; }
-
+ void setKeepTransparencyPaletted(bool keep) { _keepTransparencyPaletted = keep; }
private:
Graphics::PixelFormat getByteOrderRgbaPixelFormat() const;
@@ -68,6 +69,10 @@ private:
// flag to skip the png signature check for headless png files
bool _skipSignature;
+ // Flag to keep paletted images paletted, even when the image has transparency
+ bool _keepTransparencyPaletted;
+ int _transparentColor;
+
Graphics::Surface *_outputSurface;
};