[Scummvm-cvs-logs] SF.net SVN: scummvm:[55301] scummvm/trunk

mthreepwood at users.sourceforge.net mthreepwood at users.sourceforge.net
Tue Jan 18 17:18:11 CET 2011


Revision: 55301
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55301&view=rev
Author:   mthreepwood
Date:     2011-01-18 16:18:10 +0000 (Tue, 18 Jan 2011)

Log Message:
-----------
GRAPHICS: Add a getSurface() function to JPEG to automatically convert to RGB

Modified Paths:
--------------
    scummvm/trunk/engines/mohawk/graphics.cpp
    scummvm/trunk/engines/mohawk/graphics.h
    scummvm/trunk/graphics/jpeg.cpp
    scummvm/trunk/graphics/jpeg.h
    scummvm/trunk/graphics/pict.cpp
    scummvm/trunk/graphics/video/codecs/mjpeg.cpp

Modified: scummvm/trunk/engines/mohawk/graphics.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/graphics.cpp	2011-01-18 14:51:03 UTC (rev 55300)
+++ scummvm/trunk/engines/mohawk/graphics.cpp	2011-01-18 16:18:10 UTC (rev 55301)
@@ -30,9 +30,8 @@
 #include "mohawk/livingbooks.h"
 
 #include "common/substream.h"
-
 #include "engines/util.h"
-
+#include "graphics/jpeg.h"
 #include "graphics/primitives.h"
 #include "gui/message.h"
 
@@ -253,7 +252,7 @@
 		error("Myst requires greater than 256 colors to run");
 
 	if (_vm->getFeatures() & GF_ME) {
-		_jpegDecoder = new Graphics::JPEGDecoder();
+		_jpegDecoder = new Graphics::JPEG();
 		_pictDecoder = new Graphics::PictDecoder(_pixelFormat);
 	} else {
 		_jpegDecoder = NULL;
@@ -327,9 +326,13 @@
 		for (uint32 i = 0; i < _pictureFile.pictureCount; i++)
 			if (_pictureFile.entries[i].id == id) {
 				if (_pictureFile.entries[i].type == 0) {
-					Graphics::Surface *surface = new Graphics::Surface();
-					surface->copyFrom(*_jpegDecoder->decodeImage(new Common::SeekableSubReadStream(&_pictureFile.picFile, _pictureFile.entries[i].offset, _pictureFile.entries[i].offset + _pictureFile.entries[i].size)));
-					mhkSurface = new MohawkSurface(surface);
+					Common::SeekableReadStream *stream = new Common::SeekableSubReadStream(&_pictureFile.picFile, _pictureFile.entries[i].offset, _pictureFile.entries[i].offset + _pictureFile.entries[i].size);
+
+					if (!_jpegDecoder->read(stream))
+						error("Could not decode Myst ME Mac JPEG");
+
+					mhkSurface = new MohawkSurface(_jpegDecoder->getSurface(_pixelFormat));
+					delete stream;
 				} else if (_pictureFile.entries[i].type == 1) {
 					mhkSurface = new MohawkSurface(_pictDecoder->decodeImage(new Common::SeekableSubReadStream(&_pictureFile.picFile, _pictureFile.entries[i].offset, _pictureFile.entries[i].offset + _pictureFile.entries[i].size)));
 				} else

Modified: scummvm/trunk/engines/mohawk/graphics.h
===================================================================
--- scummvm/trunk/engines/mohawk/graphics.h	2011-01-18 14:51:03 UTC (rev 55300)
+++ scummvm/trunk/engines/mohawk/graphics.h	2011-01-18 16:18:10 UTC (rev 55301)
@@ -31,8 +31,13 @@
 #include "common/file.h"
 #include "common/hashmap.h"
 #include "graphics/pict.h"
-#include "graphics/video/codecs/mjpeg.h"
 
+namespace Graphics {
+
+class JPEG;
+
+}
+
 namespace Mohawk {
 
 class MohawkEngine;
@@ -132,7 +137,7 @@
 	MohawkEngine_Myst *_vm;
 	MystBitmap *_bmpDecoder;
 	Graphics::PictDecoder *_pictDecoder;
-	Graphics::JPEGDecoder *_jpegDecoder;
+	Graphics::JPEG *_jpegDecoder;
 
 	struct PictureFile {
 		uint32 pictureCount;

Modified: scummvm/trunk/graphics/jpeg.cpp
===================================================================
--- scummvm/trunk/graphics/jpeg.cpp	2011-01-18 14:51:03 UTC (rev 55300)
+++ scummvm/trunk/graphics/jpeg.cpp	2011-01-18 16:18:10 UTC (rev 55301)
@@ -23,7 +23,9 @@
  *
  */
 
+#include "graphics/conversion.h"
 #include "graphics/jpeg.h"
+#include "graphics/pixelformat.h"
 
 #include "common/endian.h"
 #include "common/util.h"
@@ -73,6 +75,37 @@
 	reset();
 }
 
+Surface *JPEG::getSurface(const PixelFormat &format) {
+	// Make sure we have loaded data
+	if (!isLoaded())
+		return 0;
+
+	// Only accept >8bpp surfaces
+	if (format.bytesPerPixel == 1)
+		return 0;
+
+	// Get our component surfaces
+	Graphics::Surface *yComponent = getComponent(1);
+	Graphics::Surface *uComponent = getComponent(2);
+	Graphics::Surface *vComponent = getComponent(3);
+
+	Graphics::Surface *output = new Graphics::Surface();
+	output->create(yComponent->w, yComponent->h, format.bytesPerPixel);
+
+	for (uint16 i = 0; i < output->h; i++) {
+		for (uint16 j = 0; j < output->w; j++) {
+			byte r = 0, g = 0, b = 0;
+			YUV2RGB(*((byte *)yComponent->getBasePtr(j, i)), *((byte *)uComponent->getBasePtr(j, i)), *((byte *)vComponent->getBasePtr(j, i)), r, g, b);
+			if (format.bytesPerPixel == 2)
+				*((uint16 *)output->getBasePtr(j, i)) = format.RGBToColor(r, g, b);
+			else
+				*((uint32 *)output->getBasePtr(j, i)) = format.RGBToColor(r, g, b);
+		}
+	}
+
+	return output;
+}
+
 void JPEG::reset() {
 	// Reset member variables
 	_str = NULL;

Modified: scummvm/trunk/graphics/jpeg.h
===================================================================
--- scummvm/trunk/graphics/jpeg.h	2011-01-18 14:51:03 UTC (rev 55300)
+++ scummvm/trunk/graphics/jpeg.h	2011-01-18 16:18:10 UTC (rev 55301)
@@ -34,6 +34,8 @@
 
 namespace Graphics {
 
+struct PixelFormat;
+
 #define JPEG_MAX_QUANT_TABLES 4
 #define JPEG_MAX_HUFF_TABLES 2
 
@@ -43,7 +45,12 @@
 	~JPEG();
 
 	bool read(Common::SeekableReadStream *str);
+	bool isLoaded() const { return _numComp && _w && _h; }
+	uint16 getWidth() const { return _w; }
+	uint16 getHeight() const { return _h; }
+
 	Surface *getComponent(uint c);
+	Surface *getSurface(const PixelFormat &format);
 
 private:
 	void reset();

Modified: scummvm/trunk/graphics/pict.cpp
===================================================================
--- scummvm/trunk/graphics/pict.cpp	2011-01-18 14:51:03 UTC (rev 55300)
+++ scummvm/trunk/graphics/pict.cpp	2011-01-18 16:18:10 UTC (rev 55301)
@@ -334,24 +334,8 @@
 	if (!_jpeg->read(jpegStream))
 		error("PictDecoder::decodeCompressedQuickTime(): Could not decode JPEG data");
 
-	Surface *yComponent = _jpeg->getComponent(1);
-	Surface *uComponent = _jpeg->getComponent(2);
-	Surface *vComponent = _jpeg->getComponent(3);
+	_outputSurface = _jpeg->getSurface(_pixelFormat);
 
-	_outputSurface = new Graphics::Surface();
-	_outputSurface->create(yComponent->w, yComponent->h, _pixelFormat.bytesPerPixel);
-
-	for (uint16 i = 0; i < _outputSurface->h; i++) {
-		for (uint16 j = 0; j < _outputSurface->w; j++) {
-			byte r = 0, g = 0, b = 0;
-			YUV2RGB(*((byte *)yComponent->getBasePtr(j, i)), *((byte *)uComponent->getBasePtr(j, i)), *((byte *)vComponent->getBasePtr(j, i)), r, g, b);
-			if (_pixelFormat.bytesPerPixel == 2)
-				*((uint16 *)_outputSurface->getBasePtr(j, i)) = _pixelFormat.RGBToColor(r, g, b);
-			else
-				*((uint32 *)_outputSurface->getBasePtr(j, i)) = _pixelFormat.RGBToColor(r, g, b);
-		}
-	}
-
 	stream->seek(startPos + dataSize);
 	delete jpegStream;
 }

Modified: scummvm/trunk/graphics/video/codecs/mjpeg.cpp
===================================================================
--- scummvm/trunk/graphics/video/codecs/mjpeg.cpp	2011-01-18 14:51:03 UTC (rev 55300)
+++ scummvm/trunk/graphics/video/codecs/mjpeg.cpp	2011-01-18 16:18:10 UTC (rev 55301)
@@ -46,27 +46,24 @@
 }
 
 const Surface *JPEGDecoder::decodeImage(Common::SeekableReadStream* stream) {
-	_jpeg->read(stream);
-	Surface *ySurface = _jpeg->getComponent(1);
-	Surface *uSurface = _jpeg->getComponent(2);
-	Surface *vSurface = _jpeg->getComponent(3);
+	if (!_jpeg->read(stream)) {
+		warning("Failed to decode JPEG frame");
+		return 0;
+	}
 
 	if (!_surface) {
 		_surface = new Surface();
-		_surface->create(ySurface->w, ySurface->h, _pixelFormat.bytesPerPixel);
+		_surface->create(_jpeg->getWidth(), _jpeg->getHeight(), _pixelFormat.bytesPerPixel);
 	}
 
-	for (uint16 i = 0; i < _surface->h; i++) {
-		for (uint16 j = 0; j < _surface->w; j++) {
-			byte r = 0, g = 0, b = 0;
-			YUV2RGB(*((byte *)ySurface->getBasePtr(j, i)), *((byte *)uSurface->getBasePtr(j, i)), *((byte *)vSurface->getBasePtr(j, i)), r, g, b);
-			if (_pixelFormat.bytesPerPixel == 2)
-				*((uint16 *)_surface->getBasePtr(j, i)) = _pixelFormat.RGBToColor(r, g, b);
-			else
-				*((uint32 *)_surface->getBasePtr(j, i)) = _pixelFormat.RGBToColor(r, g, b);
-		}
-	}
+	Graphics::Surface *frame = _jpeg->getSurface(_pixelFormat);
+	assert(frame);
 
+	_surface->copyFrom(*frame);
+
+	frame->free();
+	delete frame;
+
 	return _surface;
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list