[Scummvm-git-logs] scummvm master -> efdf96517072445c07f17fdef17efd86e2bdc68c

dreammaster paulfgilbert at gmail.com
Fri Aug 2 07:06:27 CEST 2019


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
d680b0b029 GLK: Added Blorb mapping to the optional adaptive palette list
8a8ac63636 IMAGE: Add a paletted transparency mode flag to PNGDecoder
efdf965170 GLK: Properly handle Blorb images that have an adaptive palette


Commit: d680b0b02983350c16e106c50aea152eefc6b585
    https://github.com/scummvm/scummvm/commit/d680b0b02983350c16e106c50aea152eefc6b585
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-08-01T22:05:40-07:00

Commit Message:
GLK: Added Blorb mapping to the optional adaptive palette list

Changed paths:
    engines/glk/blorb.cpp
    engines/glk/blorb.h


diff --git a/engines/glk/blorb.cpp b/engines/glk/blorb.cpp
index 849e686..b97ee31 100644
--- a/engines/glk/blorb.cpp
+++ b/engines/glk/blorb.cpp
@@ -162,6 +162,27 @@ Common::ErrorCode Blorb::load() {
 		}
 	}
 
+	// Check through any optional remaining chunks for an adaptive palette list
+	while (f.pos() < f.size()) {
+		uint chunkId = f.readUint32BE();
+		uint chunkSize = f.readUint32BE();
+
+		if (chunkId == ID_APal) {
+			// Found one, so create an entry so it can be opened as file named "apal"
+			ChunkEntry ce;
+			ce._filename = "apal";
+			ce._offset = f.pos();
+			ce._size = chunkSize;
+			ce._type = ID_APal;
+			_chunks.push_back(ce);
+			break;
+		}
+
+		if (chunkSize & 1)
+			++chunkSize;
+		f.skip(chunkSize);
+	}
+
 	return Common::kNoError;
 }
 
@@ -169,8 +190,9 @@ bool Blorb::readRIdx(Common::SeekableReadStream &stream, Common::Array<ChunkEntr
 	if (stream.readUint32BE() != ID_RIdx)
 		return false;
 
-	stream.readUint32BE();
+	uint chunkLen = stream.readUint32BE();
 	uint count = stream.readUint32BE();
+	assert(count == (chunkLen - 4) / 12);
 
 	// First read in the resource index
 	for (uint idx = 0; idx < count; ++idx) {
@@ -182,6 +204,9 @@ bool Blorb::readRIdx(Common::SeekableReadStream &stream, Common::Array<ChunkEntr
 		chunks.push_back(ce);
 	}
 
+	// Temporarily store the start of the next chunk of the file (if any)
+	size_t nextChunkOffset = stream.pos();
+
 	// Further iterate through the resources
 	for (uint idx = 0; idx < chunks.size(); ++idx) {
 		ChunkEntry &ce = chunks[idx];
@@ -192,6 +217,8 @@ bool Blorb::readRIdx(Common::SeekableReadStream &stream, Common::Array<ChunkEntr
 		ce._size = stream.readUint32BE();
 	}
 
+	// Reset back to the next chunk, and return that the index was successfully read
+	stream.seek(nextChunkOffset);
 	return true;
 }
 
diff --git a/engines/glk/blorb.h b/engines/glk/blorb.h
index 5d72e2c..6076428 100644
--- a/engines/glk/blorb.h
+++ b/engines/glk/blorb.h
@@ -46,6 +46,7 @@ enum {
 	ID_FORM = MKTAG('F', 'O', 'R', 'M'),
 	ID_IFRS = MKTAG('I', 'F', 'R', 'S'),
 	ID_RIdx = MKTAG('R', 'I', 'd', 'x'),
+	ID_APal = MKTAG('A', 'P', 'a', 'l'),
 
 	ID_Snd = MKTAG('S', 'n', 'd', ' '),
 	ID_Exec = MKTAG('E', 'x', 'e', 'c'),


Commit: 8a8ac63636850e18043fb5314c570b672eba2d6e
    https://github.com/scummvm/scummvm/commit/8a8ac63636850e18043fb5314c570b672eba2d6e
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-08-01T22:05:40-07:00

Commit Message:
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

Changed paths:
    image/png.cpp
    image/png.h


diff --git a/image/png.cpp b/image/png.cpp
index d835171..e854651 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 adbc6d7..f983da4 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;
 };
 


Commit: efdf96517072445c07f17fdef17efd86e2bdc68c
    https://github.com/scummvm/scummvm/commit/efdf96517072445c07f17fdef17efd86e2bdc68c
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-08-01T22:05:40-07:00

Commit Message:
GLK: Properly handle Blorb images that have an adaptive palette

Changed paths:
    engines/glk/picture.cpp
    engines/glk/picture.h


diff --git a/engines/glk/picture.cpp b/engines/glk/picture.cpp
index 1663fa4..5cb44c8 100644
--- a/engines/glk/picture.cpp
+++ b/engines/glk/picture.cpp
@@ -30,6 +30,14 @@
 
 namespace Glk {
 
+Pictures::Pictures() : _refCount(0) {
+	Common::File f;
+	if (f.open("apal")) {
+		while (f.pos() < f.size())
+			_adaptivePics.push_back(f.readUint32BE());
+	}
+}
+
 void Pictures::clear() {
 	for (uint idx = 0; idx < _store.size(); ++idx) {
 		if (_store[idx]._picture)
@@ -120,10 +128,12 @@ Picture *Pictures::load(uint32 id) {
 
 	Common::File f;
 	if (f.open(Common::String::format("pic%u.png", id))) {
+		png.setKeepTransparencyPaletted(true);
 		png.loadStream(f);
 		img = png.getSurface();
 		palette = png.getPalette();
 		palCount = png.getPaletteColorCount();
+		transColor = png.getTransparentColor();
 	} else if (f.open(Common::String::format("pic%u.jpg", id))) {
 		jpg.setOutputPixelFormat(g_system->getScreenFormat());
 		jpg.loadStream(f);
@@ -143,6 +153,23 @@ Picture *Pictures::load(uint32 id) {
 		return nullptr;
 	}
 
+	// Also check if it's going to be an adaptive pic
+	bool isAdaptive = false;
+	for (uint idx = 0; idx < _adaptivePics.size() && !isAdaptive; ++idx)
+		isAdaptive = _adaptivePics[idx] == id;
+
+	if (isAdaptive) {
+		// It is, so used previously saved palette
+		assert(!_savedPalette.empty());
+		palette = &_savedPalette[0];
+		palCount = _savedPalette.size() / 3;
+	} else if (palette) {
+		// It's a picture with a valid palette, so save a copy of it for later
+		_savedPalette.resize(palCount * 3);
+		Common::copy(palette, palette + palCount * 3, &_savedPalette[0]);
+	}
+
+	// Create new picture based on the image
 	pic = new Picture(img->w, img->h, g_system->getScreenFormat());
 	pic->_refCount = 1;
     pic->_id = id;
diff --git a/engines/glk/picture.h b/engines/glk/picture.h
index e3b6560..a8b7e0a 100644
--- a/engines/glk/picture.h
+++ b/engines/glk/picture.h
@@ -90,6 +90,8 @@ class Pictures {
 private:
 	int _refCount;
 	Common::Array<PictureEntry> _store;
+	Common::Array<uint> _adaptivePics;
+	Common::Array<byte> _savedPalette;
 private:
 	/**
 	 * Stores an original picture in the store
@@ -104,7 +106,7 @@ public:
 	/**
 	 * Constructor
 	 */
-	Pictures() : _refCount(0) {}
+	Pictures();
 
 	/**
 	 * Destructor





More information about the Scummvm-git-logs mailing list