[Scummvm-cvs-logs] scummvm master -> d521ece7cb46ade23cdb2d342a0537716dd11400

clone2727 clone2727 at gmail.com
Mon Apr 13 02:20:40 CEST 2015


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:
383c0bf3fa IMAGE: Make the createQuickTimeDitherTable function public
49885d686e VIDEO: Implement fallback dithering for QuickTime videos
d521ece7cb MOHAWK: Set dithering on any original Myst video


Commit: 383c0bf3fa094ca3ea2935220ac9e5746ccf8a3d
    https://github.com/scummvm/scummvm/commit/383c0bf3fa094ca3ea2935220ac9e5746ccf8a3d
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2015-04-12T20:11:47-04:00

Commit Message:
IMAGE: Make the createQuickTimeDitherTable function public

Needed for access by QuickTime directly

Changed paths:
    image/codecs/codec.h



diff --git a/image/codecs/codec.h b/image/codecs/codec.h
index 8845754..5c07213 100644
--- a/image/codecs/codec.h
+++ b/image/codecs/codec.h
@@ -111,7 +111,6 @@ public:
 	 */
 	virtual void setDither(DitherType type, const byte *palette) {}
 
-protected:
 	/**
 	 * Create a dither table, as used by QuickTime codecs.
 	 */


Commit: 49885d686edd522442b035986a4994c20fcc6cb2
    https://github.com/scummvm/scummvm/commit/49885d686edd522442b035986a4994c20fcc6cb2
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2015-04-12T20:12:38-04:00

Commit Message:
VIDEO: Implement fallback dithering for QuickTime videos

Used for any codec without direct dithering support

Changed paths:
    video/qt_decoder.cpp
    video/qt_decoder.h



diff --git a/video/qt_decoder.cpp b/video/qt_decoder.cpp
index cab7372..324bf65 100644
--- a/video/qt_decoder.cpp
+++ b/video/qt_decoder.cpp
@@ -292,6 +292,9 @@ QuickTimeDecoder::VideoTrackHandler::VideoTrackHandler(QuickTimeDecoder *decoder
 	_curPalette = 0;
 	_dirtyPalette = false;
 	_reversed = false;
+	_forcedDitherPalette = 0;
+	_ditherTable = 0;
+	_ditherFrame = 0;
 }
 
 QuickTimeDecoder::VideoTrackHandler::~VideoTrackHandler() {
@@ -299,6 +302,14 @@ QuickTimeDecoder::VideoTrackHandler::~VideoTrackHandler() {
 		_scaledSurface->free();
 		delete _scaledSurface;
 	}
+
+	delete[] _forcedDitherPalette;
+	delete[] _ditherTable;
+
+	if (_ditherFrame) {
+		_ditherFrame->free();
+		delete _ditherFrame;
+	}
 }
 
 bool QuickTimeDecoder::VideoTrackHandler::endOfTrack() const {
@@ -382,6 +393,9 @@ uint16 QuickTimeDecoder::VideoTrackHandler::getHeight() const {
 }
 
 Graphics::PixelFormat QuickTimeDecoder::VideoTrackHandler::getPixelFormat() const {
+	if (_forcedDitherPalette)
+		return Graphics::PixelFormat::createFormatCLUT8();
+
 	return ((VideoSampleDesc *)_parent->sampleDescs[0])->_videoCodec->getPixelFormat();
 }
 
@@ -463,6 +477,10 @@ const Graphics::Surface *QuickTimeDecoder::VideoTrackHandler::decodeNextFrame()
 		}
 	}
 
+	// Handle forced dithering
+	if (frame && _forcedDitherPalette)
+		frame = forceDither(*frame);
+
 	if (frame && (_parent->scaleFactorX != 1 || _parent->scaleFactorY != 1)) {
 		if (!_scaledSurface) {
 			_scaledSurface = new Graphics::Surface();
@@ -476,6 +494,11 @@ const Graphics::Surface *QuickTimeDecoder::VideoTrackHandler::decodeNextFrame()
 	return frame;
 }
 
+const byte *QuickTimeDecoder::VideoTrackHandler::getPalette() const {
+	_dirtyPalette = false;
+	return _forcedDitherPalette ? _forcedDitherPalette : _curPalette;
+}
+
 bool QuickTimeDecoder::VideoTrackHandler::setReverse(bool reverse) {
 	_reversed = reverse;
 
@@ -757,9 +780,6 @@ bool QuickTimeDecoder::VideoTrackHandler::canDither() const {
 
 		if (!desc || !desc->_videoCodec)
 			return false;
-
-		if (!desc->_videoCodec->canDither(Image::Codec::kDitherTypeQT))
-			return false;
 	}
 
 	return true;
@@ -770,8 +790,85 @@ void QuickTimeDecoder::VideoTrackHandler::setDither(const byte *palette) {
 
 	for (uint i = 0; i < _parent->sampleDescs.size(); i++) {
 		VideoSampleDesc *desc = (VideoSampleDesc *)_parent->sampleDescs[i];
-		desc->_videoCodec->setDither(Image::Codec::kDitherTypeQT, palette);
+
+		if (desc->_videoCodec->canDither(Image::Codec::kDitherTypeQT)) {
+			// Codec dither
+			desc->_videoCodec->setDither(Image::Codec::kDitherTypeQT, palette);
+		} else {
+			// Forced dither
+			_forcedDitherPalette = new byte[256 * 3];
+			memcpy(_forcedDitherPalette, palette, 256 * 3);
+			_ditherTable = Image::Codec::createQuickTimeDitherTable(_forcedDitherPalette, 256);
+			_dirtyPalette = true;
+		}
+	}
+}
+
+namespace {
+
+// Return a pixel in RGB554
+uint16 makeDitherColor(byte r, byte g, byte b) {
+	return ((r & 0xF8) << 6) | ((g & 0xF8) << 1) | (b >> 4);
+}
+
+// Default template to convert a dither color
+template<typename PixelInt>
+inline uint16 readDitherColor(PixelInt srcColor, const Graphics::PixelFormat& format, const byte *palette) {
+	byte r, g, b;
+	format.colorToRGB(srcColor, r, g, b);
+	return makeDitherColor(r, g, b);
+}
+
+// Specialized version for 8bpp
+template<>
+inline uint16 readDitherColor(byte srcColor, const Graphics::PixelFormat& format, const byte *palette) {
+	return makeDitherColor(palette[srcColor * 3], palette[srcColor * 3 + 1], palette[srcColor * 3 + 2]);
+}
+
+template<typename PixelInt>
+void ditherFrame(const Graphics::Surface &src, Graphics::Surface &dst, const byte *ditherTable, const byte *palette = 0) {
+	static const uint16 colorTableOffsets[] = { 0x0000, 0xC000, 0x4000, 0x8000 };
+
+	for (int y = 0; y < dst.h; y++) {
+		const PixelInt *srcPtr = (const PixelInt *)src.getBasePtr(0, y);
+		byte *dstPtr = (byte *)dst.getBasePtr(0, y);
+		uint16 colorTableOffset = colorTableOffsets[y & 3];
+
+		for (int x = 0; x < dst.w; x++) {
+			uint16 color = readDitherColor(*srcPtr++, src.format, palette);
+			*dstPtr++ = ditherTable[colorTableOffset + color];
+			colorTableOffset += 0x4000;
+		}
 	}
 }
 
+} // End of anonymous namespace
+
+const Graphics::Surface *QuickTimeDecoder::VideoTrackHandler::forceDither(const Graphics::Surface &frame) {
+	if (frame.format.bytesPerPixel == 1) {
+		// This should always be true, but this is for sanity
+		if (!_curPalette)
+			return &frame;
+
+		// If the palettes match, bail out
+		if (memcmp(_forcedDitherPalette, _curPalette, 256 * 3) == 0)
+			return &frame;
+	}
+
+	// Need to create a new one
+	if (!_ditherFrame) {
+		_ditherFrame = new Graphics::Surface();
+		_ditherFrame->create(frame.w, frame.h, Graphics::PixelFormat::createFormatCLUT8());
+	}
+
+	if (frame.format.bytesPerPixel == 1)
+		ditherFrame<byte>(frame, *_ditherFrame, _ditherTable, _curPalette);
+	else if (frame.format.bytesPerPixel == 2)
+		ditherFrame<uint16>(frame, *_ditherFrame, _ditherTable);
+	else if (frame.format.bytesPerPixel == 4)
+		ditherFrame<uint32>(frame, *_ditherFrame, _ditherTable);
+
+	return _ditherFrame;
+}
+
 } // End of namespace Video
diff --git a/video/qt_decoder.h b/video/qt_decoder.h
index 99980a3..5a6c5ee 100644
--- a/video/qt_decoder.h
+++ b/video/qt_decoder.h
@@ -136,7 +136,7 @@ private:
 		int getFrameCount() const;
 		uint32 getNextFrameStartTime() const;
 		const Graphics::Surface *decodeNextFrame();
-		const byte *getPalette() const { _dirtyPalette = false; return _curPalette; }
+		const byte *getPalette() const;
 		bool hasDirtyPalette() const { return _curPalette; }
 		bool setReverse(bool reverse);
 		bool isReversed() const { return _reversed; }
@@ -158,6 +158,12 @@ private:
 		mutable bool _dirtyPalette;
 		bool _reversed;
 
+		// Forced dithering of frames
+		byte *_forcedDitherPalette;
+		byte *_ditherTable;
+		Graphics::Surface *_ditherFrame;
+		const Graphics::Surface *forceDither(const Graphics::Surface &frame);
+
 		Common::SeekableReadStream *getNextFramePacket(uint32 &descId);
 		uint32 getFrameDuration();
 		uint32 findKeyFrame(uint32 frame) const;


Commit: d521ece7cb46ade23cdb2d342a0537716dd11400
    https://github.com/scummvm/scummvm/commit/d521ece7cb46ade23cdb2d342a0537716dd11400
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2015-04-12T20:18:31-04:00

Commit Message:
MOHAWK: Set dithering on any original Myst video

Fixes display of the library "swirl" video

Changed paths:
    engines/mohawk/video.cpp



diff --git a/engines/mohawk/video.cpp b/engines/mohawk/video.cpp
index ca38f22..3f27e4a 100644
--- a/engines/mohawk/video.cpp
+++ b/engines/mohawk/video.cpp
@@ -572,10 +572,6 @@ void VideoManager::checkEnableDither(VideoEntry &entry) {
 	if (!_enableDither)
 		return;
 
-	// Ignore any video which is already 8bpp
-	if (entry->getPixelFormat().bytesPerPixel == 1)
-		return;
-
 	// Set the palette
 	byte palette[256 * 3];
 	g_system->getPaletteManager()->grabPalette(palette, 0, 256);






More information about the Scummvm-git-logs mailing list