aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2016-03-17 13:11:01 -0400
committerPaul Gilbert2016-03-17 13:11:01 -0400
commit8a1d238fd59a6aef21f74721f039cc0375c18a24 (patch)
tree2f7c6677005ebdddb0bc77d2219251823dac3e7e
parent5a3aa81ab628fce76a33a07dc97010bd4d439a4e (diff)
downloadscummvm-rg350-8a1d238fd59a6aef21f74721f039cc0375c18a24.tar.gz
scummvm-rg350-8a1d238fd59a6aef21f74721f039cc0375c18a24.tar.bz2
scummvm-rg350-8a1d238fd59a6aef21f74721f039cc0375c18a24.zip
TITANIC: Implemented the CJPEGDecode and CTargaDecode classes
Thank goodness for the existing ScummVM image decoders for these types.. it made implementing the classes sooooo much easier
-rw-r--r--engines/titanic/direct_draw.cpp4
-rw-r--r--engines/titanic/direct_draw.h2
-rw-r--r--engines/titanic/image_decoders.cpp47
-rw-r--r--engines/titanic/image_decoders.h45
-rw-r--r--engines/titanic/simple_file.h5
-rw-r--r--engines/titanic/video_surface.cpp24
-rw-r--r--engines/titanic/video_surface.h6
7 files changed, 77 insertions, 56 deletions
diff --git a/engines/titanic/direct_draw.cpp b/engines/titanic/direct_draw.cpp
index 1d0ddab4fb..d5a8cf2409 100644
--- a/engines/titanic/direct_draw.cpp
+++ b/engines/titanic/direct_draw.cpp
@@ -110,9 +110,9 @@ DirectDrawSurface *DirectDrawManager::createSurface(int w, int h, int surfaceNum
/*------------------------------------------------------------------------*/
-void *DirectDrawSurface::lock(const Common::Rect *bounds, int flags) {
+Graphics::Surface *DirectDrawSurface::lock(const Common::Rect *bounds, int flags) {
assert(w != 0 && h != 0);
- return getPixels();
+ return this;
}
void DirectDrawSurface::unlock() {
diff --git a/engines/titanic/direct_draw.h b/engines/titanic/direct_draw.h
index 4bd723bcd3..5ec0f3d5c7 100644
--- a/engines/titanic/direct_draw.h
+++ b/engines/titanic/direct_draw.h
@@ -50,7 +50,7 @@ public:
/**
* Lock the surface for access
*/
- void *lock(const Common::Rect *bounds, int flags);
+ Graphics::Surface *lock(const Common::Rect *bounds, int flags);
/**
* Unlocks the surface at the end of direct accesses
diff --git a/engines/titanic/image_decoders.cpp b/engines/titanic/image_decoders.cpp
index bf941f83b5..e6e547f009 100644
--- a/engines/titanic/image_decoders.cpp
+++ b/engines/titanic/image_decoders.cpp
@@ -24,21 +24,54 @@
namespace Titanic {
-CJPEGDecode::CJPEGDecode(const CString &name) : _width(0), _height(0) {
- _file.open(name);
-}
+void CJPEGDecode::decode(OSVideoSurface &surface, const CString &name) {
+ // Open up the resource
+ StdCWadFile file;
+ file.open(name);
+
+ // Use the ScucmmVM deoder to decode it
+ loadStream(*file.readStream());
+ const Graphics::Surface *srcSurf = getSurface();
+
+ // Resize the surface if necessary
+ if (surface.getWidth() != srcSurf->w || surface.getHeight() != srcSurf->h)
+ surface.resize(srcSurf->w, srcSurf->h);
-void CJPEGDecode::decode(OSVideoSurface &surface) {
+ // Convert the decoded surface to the correct pixel format, and then copy it over
+ surface.lock();
+ Graphics::Surface *convertedSurface = srcSurf->convertTo(surface._rawSurface->format);
+ Common::copy((byte *)convertedSurface->getPixels(), (byte *)convertedSurface->getPixels() +
+ surface.getPitch() * surface.getHeight(), (byte *)surface._rawSurface->getPixels());
+
+ delete convertedSurface;
+ surface.unlock();
}
/*------------------------------------------------------------------------*/
+void CTargaDecode::decode(OSVideoSurface &surface, const CString &name) {
+ // Open up the resource
+ StdCWadFile file;
+ file.open(name);
-CTargaDecode::CTargaDecode(const CString &name) : _width(0), _height(0) {
-}
+ // Use the ScucmmVM deoder to decode it
+ loadStream(*file.readStream());
+ const Graphics::Surface *srcSurf = getSurface();
+
+ // Resize the surface if necessary
+ if (surface.getWidth() != srcSurf->w || surface.getHeight() != srcSurf->h)
+ surface.resize(srcSurf->w, srcSurf->h);
+
+ // Convert the decoded surface to the correct pixel format, and then copy it over
+ surface.lock();
+ Graphics::Surface *convertedSurface = srcSurf->convertTo(surface._rawSurface->format);
+
+ Common::copy((byte *)convertedSurface->getPixels(), (byte *)convertedSurface->getPixels() +
+ surface.getPitch() * surface.getHeight(), (byte *)surface._rawSurface->getPixels());
-void CTargaDecode::decode(OSVideoSurface &surface) {
+ delete convertedSurface;
+ surface.unlock();
}
} // End of namespace Titanic
diff --git a/engines/titanic/image_decoders.h b/engines/titanic/image_decoders.h
index 258595846c..d72d6fee5d 100644
--- a/engines/titanic/image_decoders.h
+++ b/engines/titanic/image_decoders.h
@@ -23,57 +23,28 @@
#ifndef TITANIC_IMAGE_DECODERS_H
#define TITANIC_IMAGE_DECODERS_H
+#include "image/jpeg.h"
+#include "image/tga.h"
#include "titanic/string.h"
#include "titanic/simple_file.h"
#include "titanic/video_surface.h"
namespace Titanic {
-class CJPEGDecode {
-private:
- StdCWadFile _file;
- int _width, _height;
+class CJPEGDecode : public Image::JPEGDecoder {
public:
- CJPEGDecode(const CString &name);
-
- /**
- * Return the width of the JPEG
- */
- int getWidth() const { return _width; }
-
/**
- * Return the height of the JPEG
+ * Decode the image file onto the passed surface
*/
- int getHeight() const { return _height; }
-
- /**
- * Decode the image onto the passed surface
- */
- void decode(OSVideoSurface &surface);
+ void decode(OSVideoSurface &surface, const CString &name);
};
-class CTargaDecode {
-private:
- StdCWadFile _file;
- int _width, _height;
+class CTargaDecode : public Image::TGADecoder {
public:
- CTargaDecode(const CString &name);
-
/**
- * Return the width of the JPEG
+ * Decode the image file onto the passed surface
*/
- int getWidth() const { return _width; }
-
- /**
- * Return the height of the JPEG
- */
- int getHeight() const { return _height; }
-
- /**
- * Decode the image onto the passed surface
- */
- void decode(OSVideoSurface &surface);
-
+ void decode(OSVideoSurface &surface, const CString &name);
};
} // End of namespace Titanic
diff --git a/engines/titanic/simple_file.h b/engines/titanic/simple_file.h
index b779fd0a35..815896fc7e 100644
--- a/engines/titanic/simple_file.h
+++ b/engines/titanic/simple_file.h
@@ -224,6 +224,11 @@ public:
* Open up the specified file
*/
void open(const CString &name);
+
+ /**
+ * Return a reference to the read stream
+ */
+ Common::SeekableReadStream *readStream() const { return _inStream; }
};
} // End of namespace Titanic
diff --git a/engines/titanic/video_surface.cpp b/engines/titanic/video_surface.cpp
index 840680070c..fdb9224001 100644
--- a/engines/titanic/video_surface.cpp
+++ b/engines/titanic/video_surface.cpp
@@ -29,7 +29,7 @@ namespace Titanic {
int CVideoSurface::_videoSurfaceCounter = 0;
CVideoSurface::CVideoSurface(CScreenManager *screenManager) :
- _screenManager(screenManager), _pixels(nullptr),
+ _screenManager(screenManager), _rawSurface(nullptr),
_field34(nullptr), _pendingLoad(false), _field3C(0), _field40(0),
_field44(4), _field48(0), _field50(1) {
_videoSurfaceNum = _videoSurfaceCounter++;
@@ -75,13 +75,21 @@ void OSVideoSurface::loadResource(const CResourceKey &key) {
}
void OSVideoSurface::loadTarga(const CResourceKey &key) {
- warning("TODO");
+ // Decode the image
+ CTargaDecode decoder;
+ decoder.decode(*this, key.getString());
+
+ if (proc26() == 2)
+ shiftColors();
+
+ _resourceKey = key;
+
}
void OSVideoSurface::loadJPEG(const CResourceKey &key) {
// Decode the image
- CJPEGDecode decoder(key.getString());
- decoder.decode(*this);
+ CJPEGDecode decoder;
+ decoder.decode(*this, key.getString());
if (proc26() == 2)
shiftColors();
@@ -98,14 +106,14 @@ bool OSVideoSurface::lock() {
return false;
++_lockCount;
- _pixels = (uint16 *)_ddSurface->lock(nullptr, 0);
+ _rawSurface = _ddSurface->lock(nullptr, 0);
return true;
}
void OSVideoSurface::unlock() {
- if (_pixels)
+ if (_rawSurface)
_ddSurface->unlock();
- _pixels = nullptr;
+ _rawSurface = nullptr;
--_lockCount;
}
@@ -181,7 +189,7 @@ void OSVideoSurface::shiftColors() {
int width = getWidth();
int height = getHeight();
int pitch = getPitch();
- uint16 *pixels = _pixels;
+ uint16 *pixels = (uint16 *)_rawSurface->getPixels();
uint16 *p;
int x, y;
diff --git a/engines/titanic/video_surface.h b/engines/titanic/video_surface.h
index 838529f770..412b50f66c 100644
--- a/engines/titanic/video_surface.h
+++ b/engines/titanic/video_surface.h
@@ -33,15 +33,19 @@
namespace Titanic {
class CScreenManager;
+class CJPEGDecode;
+class CTargaDecode;
class CVideoSurface : public ListItem {
+ friend class CJPEGDecode;
+ friend class CTargaDecode;
protected:
static int _videoSurfaceCounter;
protected:
CScreenManager *_screenManager;
CResourceKey _resourceKey;
DirectDrawSurface *_ddSurface;
- uint16 *_pixels;
+ Graphics::Surface *_rawSurface;
void *_field34;
bool _pendingLoad;
int _field3C;