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

clone2727 clone2727 at gmail.com
Tue Jun 12 05:17:42 CEST 2012


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

Summary:
3324aef8d0 MOHAWK: Make sure we convert video surfaces if they're not in the screen format
e16ad39e53 VIDEO: Cleanup QTRLE


Commit: 3324aef8d0972d713f4fcfe09b2ada65dca365a8
    https://github.com/scummvm/scummvm/commit/3324aef8d0972d713f4fcfe09b2ada65dca365a8
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2012-06-11T20:14:26-07:00

Commit Message:
MOHAWK: Make sure we convert video surfaces if they're not in the screen format

Changed paths:
    engines/mohawk/video.cpp



diff --git a/engines/mohawk/video.cpp b/engines/mohawk/video.cpp
index c10b986..15103b2 100644
--- a/engines/mohawk/video.cpp
+++ b/engines/mohawk/video.cpp
@@ -227,17 +227,19 @@ bool VideoManager::updateMovies() {
 			Graphics::Surface *convertedFrame = 0;
 
 			if (frame && _videoStreams[i].enabled) {
-				// Convert from 8bpp to the current screen format if necessary
 				Graphics::PixelFormat pixelFormat = _vm->_system->getScreenFormat();
 
-				if (frame->format.bytesPerPixel == 1) {
-					if (pixelFormat.bytesPerPixel == 1) {
-						if (_videoStreams[i]->hasDirtyPalette())
-							_videoStreams[i]->setSystemPalette();
-					} else {
-						convertedFrame = frame->convertTo(pixelFormat, _videoStreams[i]->getPalette());
-						frame = convertedFrame;
-					}
+				if (frame->format != pixelFormat) {
+					// We don't support downconverting to 8bpp
+					if (pixelFormat.bytesPerPixel == 1)
+						error("Cannot convert high color video frame to 8bpp");
+
+					// Convert to the current screen format
+					convertedFrame = frame->convertTo(pixelFormat, _videoStreams[i]->getPalette());
+					frame = convertedFrame;
+				} else if (pixelFormat.bytesPerPixel == 1 && _videoStreams[i]->hasDirtyPalette()) {
+					// Set the palette when running in 8bpp mode only
+					_videoStreams[i]->setSystemPalette();
 				}
 
 				// Clip the width/height to make sure we stay on the screen (Myst does this a few times)


Commit: e16ad39e533608d5bfac9bfba167e7e2dfb606cb
    https://github.com/scummvm/scummvm/commit/e16ad39e533608d5bfac9bfba167e7e2dfb606cb
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2012-06-11T20:16:30-07:00

Commit Message:
VIDEO: Cleanup QTRLE

In particular, the colors are not converted to the screen format upon decoding. The code should also now work with 32bpp screen formats.

Changed paths:
    video/codecs/qtrle.cpp
    video/codecs/qtrle.h



diff --git a/video/codecs/qtrle.cpp b/video/codecs/qtrle.cpp
index f01720e..d2cdea2 100644
--- a/video/codecs/qtrle.cpp
+++ b/video/codecs/qtrle.cpp
@@ -37,28 +37,25 @@ namespace Video {
 
 QTRLEDecoder::QTRLEDecoder(uint16 width, uint16 height, byte bitsPerPixel) : Codec() {
 	_bitsPerPixel = bitsPerPixel;
-	_pixelFormat = g_system->getScreenFormat();
 
-	// We need to increase the surface size to a multiple of 4
+	// We need to ensure the width is a multiple of 4
 	uint16 wMod = width % 4;
-	if(wMod != 0)
+	if (wMod != 0)
 		width += 4 - wMod;
 
-	debug(2, "QTRLE corrected width: %d", width);
-
 	_surface = new Graphics::Surface();
-	_surface->create(width, height, _bitsPerPixel <= 8 ? Graphics::PixelFormat::createFormatCLUT8() : _pixelFormat);
+	_surface->create(width, height, getPixelFormat());
 }
 
 #define CHECK_STREAM_PTR(n) \
   if ((stream->pos() + n) > stream->size()) { \
-    warning ("Problem: stream out of bounds (%d >= %d)", stream->pos() + n, stream->size()); \
+    warning("QTRLE Problem: stream out of bounds (%d > %d)", stream->pos() + n, stream->size()); \
     return; \
   }
 
 #define CHECK_PIXEL_PTR(n) \
   if ((int32)pixelPtr + n > _surface->w * _surface->h) { \
-    warning ("Problem: pixel ptr = %d, pixel limit = %d", pixelPtr + n, _surface->w * _surface->h); \
+    warning("QTRLE Problem: pixel ptr = %d, pixel limit = %d", pixelPtr + n, _surface->w * _surface->h); \
     return; \
   } \
 
@@ -132,8 +129,6 @@ void QTRLEDecoder::decode2_4(Common::SeekableReadStream *stream, uint32 rowPtr,
 				for (int8 i = numPixels - 1; i >= 0; i--) {
 					pi[numPixels - 1 - i] = (stream->readByte() >> ((i * bpp) & 0x07)) & ((1 << bpp) - 1);
 
-					// FIXME: Is this right?
-					//stream_ptr += ((i & ((num_pixels>>2)-1)) == 0);
 					if ((i & ((numPixels >> 2) - 1)) == 0)
 						stream->readByte();
 				}
@@ -215,7 +210,7 @@ void QTRLEDecoder::decode8(Common::SeekableReadStream *stream, uint32 rowPtr, ui
 
 void QTRLEDecoder::decode16(Common::SeekableReadStream *stream, uint32 rowPtr, uint32 linesToChange) {
 	uint32 pixelPtr = 0;
-	OverlayColor *rgb = (OverlayColor *)_surface->pixels;
+	uint16 *rgb = (uint16 *)_surface->pixels;
 
 	while (linesToChange--) {
 		CHECK_STREAM_PTR(2);
@@ -235,25 +230,15 @@ void QTRLEDecoder::decode16(Common::SeekableReadStream *stream, uint32 rowPtr, u
 
 				CHECK_PIXEL_PTR(rleCode);
 
-				while (rleCode--) {
-					// Convert from RGB555 to the format specified by the Overlay
-					byte r = 0, g = 0, b = 0;
-					Graphics::colorToRGB<Graphics::ColorMasks<555> >(rgb16, r, g, b);
-					rgb[pixelPtr++] = _pixelFormat.RGBToColor(r, g, b);
-				}
+				while (rleCode--)
+					rgb[pixelPtr++] = rgb16;
 			} else {
 				CHECK_STREAM_PTR(rleCode * 2);
 				CHECK_PIXEL_PTR(rleCode);
 
 				// copy pixels directly to output
-				while (rleCode--) {
-					uint16 rgb16 = stream->readUint16BE();
-
-					// Convert from RGB555 to the format specified by the Overlay
-					byte r = 0, g = 0, b = 0;
-					Graphics::colorToRGB<Graphics::ColorMasks<555> >(rgb16, r, g, b);
-					rgb[pixelPtr++] = _pixelFormat.RGBToColor(r, g, b);
-				}
+				while (rleCode--)
+					rgb[pixelPtr++] = stream->readUint16BE();
 			}
 		}
 
@@ -263,7 +248,7 @@ void QTRLEDecoder::decode16(Common::SeekableReadStream *stream, uint32 rowPtr, u
 
 void QTRLEDecoder::decode24(Common::SeekableReadStream *stream, uint32 rowPtr, uint32 linesToChange) {
 	uint32 pixelPtr = 0;
-	OverlayColor *rgb = (OverlayColor *)_surface->pixels;
+	uint32 *rgb = (uint32 *)_surface->pixels;
 
 	while (linesToChange--) {
 		CHECK_STREAM_PTR(2);
@@ -283,11 +268,12 @@ void QTRLEDecoder::decode24(Common::SeekableReadStream *stream, uint32 rowPtr, u
 				byte r = stream->readByte();
 				byte g = stream->readByte();
 				byte b = stream->readByte();
+				uint32 color = _surface->format.RGBToColor(r, g, b);
 
 				CHECK_PIXEL_PTR(rleCode);
 
 				while (rleCode--)
-					rgb[pixelPtr++] = _pixelFormat.RGBToColor(r, g, b);
+					rgb[pixelPtr++] = color;
 			} else {
 				CHECK_STREAM_PTR(rleCode * 3);
 				CHECK_PIXEL_PTR(rleCode);
@@ -297,7 +283,7 @@ void QTRLEDecoder::decode24(Common::SeekableReadStream *stream, uint32 rowPtr, u
 					byte r = stream->readByte();
 					byte g = stream->readByte();
 					byte b = stream->readByte();
-					rgb[pixelPtr++] = _pixelFormat.RGBToColor(r, g, b);
+					rgb[pixelPtr++] = _surface->format.RGBToColor(r, g, b);
 				}
 			}
 		}
@@ -308,7 +294,7 @@ void QTRLEDecoder::decode24(Common::SeekableReadStream *stream, uint32 rowPtr, u
 
 void QTRLEDecoder::decode32(Common::SeekableReadStream *stream, uint32 rowPtr, uint32 linesToChange) {
 	uint32 pixelPtr = 0;
-	OverlayColor *rgb = (OverlayColor *)_surface->pixels;
+	uint32 *rgb = (uint32 *)_surface->pixels;
 
 	while (linesToChange--) {
 		CHECK_STREAM_PTR(2);
@@ -329,11 +315,12 @@ void QTRLEDecoder::decode32(Common::SeekableReadStream *stream, uint32 rowPtr, u
 				byte r = stream->readByte();
 				byte g = stream->readByte();
 				byte b = stream->readByte();
+				uint32 color = _surface->format.ARGBToColor(a, r, g, b);
 
 				CHECK_PIXEL_PTR(rleCode);
 
 				while (rleCode--)
-					rgb[pixelPtr++] = _pixelFormat.ARGBToColor(a, r, g, b);
+					rgb[pixelPtr++] = color;
 			} else {
 				CHECK_STREAM_PTR(rleCode * 4);
 				CHECK_PIXEL_PTR(rleCode);
@@ -344,7 +331,7 @@ void QTRLEDecoder::decode32(Common::SeekableReadStream *stream, uint32 rowPtr, u
 					byte r = stream->readByte();
 					byte g = stream->readByte();
 					byte b = stream->readByte();
-					rgb[pixelPtr++] = _pixelFormat.ARGBToColor(a, r, g, b);
+					rgb[pixelPtr++] = _surface->format.ARGBToColor(a, r, g, b);
 				}
 			}
 		}
@@ -354,7 +341,7 @@ void QTRLEDecoder::decode32(Common::SeekableReadStream *stream, uint32 rowPtr, u
 }
 
 const Graphics::Surface *QTRLEDecoder::decodeImage(Common::SeekableReadStream *stream) {
-	uint16 start_line = 0;
+	uint16 startLine = 0;
 	uint16 height = _surface->h;
 
 	// check if this frame is even supposed to change
@@ -369,44 +356,45 @@ const Graphics::Surface *QTRLEDecoder::decodeImage(Common::SeekableReadStream *s
 
 	// if a header is present, fetch additional decoding parameters
 	if (header & 8) {
-		if(stream->size() < 14)
+		if (stream->size() < 14)
 			return _surface;
-		start_line = stream->readUint16BE();
+
+		startLine = stream->readUint16BE();
 		stream->readUint16BE(); // Unknown
 		height = stream->readUint16BE();
 		stream->readUint16BE(); // Unknown
 	}
 
-	uint32 row_ptr = _surface->w * start_line;
+	uint32 rowPtr = _surface->w * startLine;
 
 	switch (_bitsPerPixel) {
-		case 1:
-		case 33:
-			decode1(stream, row_ptr, height);
-			break;
-		case 2:
-		case 34:
-			decode2_4(stream, row_ptr, height, 2);
-			break;
-		case 4:
-		case 36:
-			decode2_4(stream, row_ptr, height, 4);
-			break;
-		case 8:
-		case 40:
-			decode8(stream, row_ptr, height);
-			break;
-		case 16:
-			decode16(stream, row_ptr, height);
-			break;
-		case 24:
-			decode24(stream, row_ptr, height);
-			break;
-		case 32:
-			decode32(stream, row_ptr, height);
-			break;
-		default:
-			error ("Unsupported bits per pixel %d", _bitsPerPixel);
+	case 1:
+	case 33:
+		decode1(stream, rowPtr, height);
+		break;
+	case 2:
+	case 34:
+		decode2_4(stream, rowPtr, height, 2);
+		break;
+	case 4:
+	case 36:
+		decode2_4(stream, rowPtr, height, 4);
+		break;
+	case 8:
+	case 40:
+		decode8(stream, rowPtr, height);
+		break;
+	case 16:
+		decode16(stream, rowPtr, height);
+		break;
+	case 24:
+		decode24(stream, rowPtr, height);
+		break;
+	case 32:
+		decode32(stream, rowPtr, height);
+		break;
+	default:
+		error("Unsupported QTRLE bits per pixel %d", _bitsPerPixel);
 	}
 
 	return _surface;
@@ -417,4 +405,27 @@ QTRLEDecoder::~QTRLEDecoder() {
 	delete _surface;
 }
 
+Graphics::PixelFormat QTRLEDecoder::getPixelFormat() const {
+	switch (_bitsPerPixel) {
+	case 1:
+	case 33:
+	case 2:
+	case 34:
+	case 4:
+	case 36:
+	case 8:
+	case 40:
+		return Graphics::PixelFormat::createFormatCLUT8();
+	case 16:
+		return Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0);
+	case 24:
+	case 32:
+		return Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24);
+	default:
+		error("Unsupported QTRLE bits per pixel %d", _bitsPerPixel);
+	}
+
+	return Graphics::PixelFormat();
+}
+
 } // End of namespace Video
diff --git a/video/codecs/qtrle.h b/video/codecs/qtrle.h
index 6f8e113..d9db58a 100644
--- a/video/codecs/qtrle.h
+++ b/video/codecs/qtrle.h
@@ -34,13 +34,12 @@ public:
 	~QTRLEDecoder();
 
 	const Graphics::Surface *decodeImage(Common::SeekableReadStream *stream);
-	Graphics::PixelFormat getPixelFormat() const { return _pixelFormat; }
+	Graphics::PixelFormat getPixelFormat() const;
 
 private:
 	byte _bitsPerPixel;
 
 	Graphics::Surface *_surface;
-	Graphics::PixelFormat _pixelFormat;
 
 	void decode1(Common::SeekableReadStream *stream, uint32 rowPtr, uint32 linesToChange);
 	void decode2_4(Common::SeekableReadStream *stream, uint32 rowPtr, uint32 linesToChange, byte bpp);






More information about the Scummvm-git-logs mailing list