aboutsummaryrefslogtreecommitdiff
path: root/image/png.cpp
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/png.cpp
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/png.cpp')
-rw-r--r--image/png.cpp16
1 files changed, 14 insertions, 2 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 {