aboutsummaryrefslogtreecommitdiff
path: root/image
diff options
context:
space:
mode:
authorPaul Gilbert2019-08-01 22:00:29 -0700
committerPaul Gilbert2019-08-01 22:05:40 -0700
commit8a8ac63636850e18043fb5314c570b672eba2d6e (patch)
tree13f87e7ed0c25762a431a143d9e8c3ec9e4a8acf /image
parentd680b0b02983350c16e106c50aea152eefc6b585 (diff)
downloadscummvm-rg350-8a8ac63636850e18043fb5314c570b672eba2d6e.tar.gz
scummvm-rg350-8a8ac63636850e18043fb5314c570b672eba2d6e.tar.bz2
scummvm-rg350-8a8ac63636850e18043fb5314c570b672eba2d6e.zip
IMAGE: Add a paletted transparency mode flag to PNGDecoder
Previously, the PNGDecoder would always convert images that have a palette with a transparent color(s) to a full RGBA surface automatically. There needed to be a way to diable this and keep the image paletted for the Glk engine, since some Infocom V6 game Blorb files reuse the palettes from previous images, so I couldn't have the decoder using the dummy palette that comes with the image
Diffstat (limited to 'image')
-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;
};