aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorEinar Johan Trøan Sømåen2012-06-13 20:17:36 +0200
committerEinar Johan Trøan Sømåen2012-06-13 20:17:36 +0200
commitc081d40c961ef61549b4485d79fcb62fc2e2ad73 (patch)
tree232382ae4d313acccd910347b96a619bd4598a86 /engines
parentb8a6dce3988e3599463f56fe401feadc451d5bf0 (diff)
downloadscummvm-rg350-c081d40c961ef61549b4485d79fcb62fc2e2ad73.tar.gz
scummvm-rg350-c081d40c961ef61549b4485d79fcb62fc2e2ad73.tar.bz2
scummvm-rg350-c081d40c961ef61549b4485d79fcb62fc2e2ad73.zip
WINTERMUTE: Move image-loading to BImage, and cleanup some relevant code.
Diffstat (limited to 'engines')
-rw-r--r--engines/wintermute/Base/BFontTT.cpp2
-rw-r--r--engines/wintermute/Base/BImage.cpp51
-rw-r--r--engines/wintermute/Base/BImage.h18
-rw-r--r--engines/wintermute/Base/BRenderSDL.cpp20
-rw-r--r--engines/wintermute/Base/BRenderSDL.h7
-rw-r--r--engines/wintermute/Base/BSurface.h2
-rw-r--r--engines/wintermute/Base/BSurfaceSDL.cpp62
-rw-r--r--engines/wintermute/Base/BSurfaceSDL.h2
8 files changed, 114 insertions, 50 deletions
diff --git a/engines/wintermute/Base/BFontTT.cpp b/engines/wintermute/Base/BFontTT.cpp
index 3c72d974ab..449767e359 100644
--- a/engines/wintermute/Base/BFontTT.cpp
+++ b/engines/wintermute/Base/BFontTT.cpp
@@ -278,7 +278,7 @@ CBSurface *CBFontTT::RenderTextToTexture(const WideString &text, int width, TTex
}
CBSurfaceSDL *retSurface = new CBSurfaceSDL(Game);
- retSurface->putSurface(*surface->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8 ,0)));
+ retSurface->putSurface(*surface->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8 ,0)), true);
delete surface;
return retSurface;
#if 0 //TODO
diff --git a/engines/wintermute/Base/BImage.cpp b/engines/wintermute/Base/BImage.cpp
index 7561e65adc..bacfd9ece5 100644
--- a/engines/wintermute/Base/BImage.cpp
+++ b/engines/wintermute/Base/BImage.cpp
@@ -28,6 +28,18 @@
#include "engines/wintermute/dcgf.h"
#include "engines/wintermute/Base/BImage.h"
+#include "engines/wintermute/Base/BSurfaceSDL.h"
+#include "engines/wintermute/Base/BGame.h"
+#include "engines/wintermute/Base/BFileManager.h"
+#include "engines/wintermute/graphics/transparentSurface.h"
+#include "graphics/decoders/png.h"
+#include "graphics/decoders/jpeg.h"
+#include "graphics/decoders/bmp.h"
+#include "graphics/surface.h"
+#include "engines/wintermute/graphics/tga.h"
+#include "common/textconsole.h"
+#include "common/stream.h"
+#include "common/system.h"
//#include "FreeImage.h"
namespace WinterMute {
@@ -38,16 +50,55 @@ CBImage::CBImage(CBGame *inGame, FIBITMAP *bitmap): CBBase(inGame) {
_bitmap = bitmap;
#endif
_bitmap = NULL;
+ _palette = NULL;
+ _surface = NULL;
+ _decoder = NULL;
}
//////////////////////////////////////////////////////////////////////
CBImage::~CBImage() {
+ delete _bitmap;
+ delete _decoder;
#if 0
if (_bitmap) FreeImage_Unload(_bitmap);
#endif
}
+HRESULT CBImage::loadFile(const Common::String &filename) {
+ _filename = filename;
+ Graphics::ImageDecoder *imgDecoder;
+
+ if (filename.hasSuffix(".png")) {
+ imgDecoder = new Graphics::PNGDecoder();
+ } else if (filename.hasSuffix(".bmp")) {
+ imgDecoder = new Graphics::BitmapDecoder();
+ } else if (filename.hasSuffix(".tga")) {
+ imgDecoder = new WinterMute::TGA();
+ } else if (filename.hasSuffix(".jpg")) {
+ imgDecoder = new Graphics::JPEGDecoder();
+ } else {
+ error("CBImage::loadFile : Unsupported fileformat %s", filename.c_str());
+ }
+
+ Common::SeekableReadStream *file = Game->_fileManager->OpenFile(filename.c_str());
+ if (!file) return E_FAIL;
+
+ imgDecoder->loadStream(*file);
+ _surface = imgDecoder->getSurface();
+ _palette = imgDecoder->getPalette();
+ Game->_fileManager->CloseFile(file);
+
+ return S_OK;
+}
+
+byte CBImage::getAlphaAt(int x, int y) {
+ if (!_surface) return 0xFF;
+ uint32 color = *(uint32*)_surface->getBasePtr(x, y);
+ byte r, g, b, a;
+ _surface->format.colorToARGB(color, a, r, g, b);
+ return a;
+}
//////////////////////////////////////////////////////////////////////////
HRESULT CBImage::SaveBMPFile(const char *Filename) {
diff --git a/engines/wintermute/Base/BImage.h b/engines/wintermute/Base/BImage.h
index cabc155723..2cc1a448f8 100644
--- a/engines/wintermute/Base/BImage.h
+++ b/engines/wintermute/Base/BImage.h
@@ -32,29 +32,37 @@
//#include "FreeImage.h"
#include "engines/wintermute/Base/BBase.h"
+#include "graphics/surface.h"
+#include "graphics/pixelformat.h"
+#include "graphics/decoders/image_decoder.h"
#include "common/endian.h"
+#include "common/str.h"
struct FIBITMAP;
namespace WinterMute {
-
+class CBSurface;
class CBImage: CBBase {
public:
CBImage(CBGame *inGame, FIBITMAP *bitmap = NULL);
~CBImage();
-
+ HRESULT loadFile(const Common::String &filename);
+ const Graphics::Surface *getSurface() const { return _surface; };
+ const byte *getPalette() const { return _palette; }
+ byte getAlphaAt(int x, int y);
byte *CreateBMPBuffer(uint32 *BufferSize = NULL);
HRESULT Resize(int NewWidth, int NewHeight);
HRESULT SaveBMPFile(const char *Filename);
HRESULT CopyFrom(CBImage *OrigImage, int NewWidth = 0, int NewHeight = 0);
- FIBITMAP *GetBitmap() const {
- return _bitmap;
- }
private:
+ Common::String _filename;
+ Graphics::ImageDecoder *_decoder;
FIBITMAP *_bitmap;
+ const Graphics::Surface *_surface;
+ const byte *_palette;
};
} // end of namespace WinterMute
diff --git a/engines/wintermute/Base/BRenderSDL.cpp b/engines/wintermute/Base/BRenderSDL.cpp
index da35408142..86aa518de2 100644
--- a/engines/wintermute/Base/BRenderSDL.cpp
+++ b/engines/wintermute/Base/BRenderSDL.cpp
@@ -50,6 +50,8 @@ CBRenderSDL::CBRenderSDL(CBGame *inGame) : CBRenderer(inGame) {
_borderLeft = _borderRight = _borderTop = _borderBottom = 0;
_ratioX = _ratioY = 1.0f;
+ setAlphaMod(255);
+ setColorMod(255, 255, 255);
}
//////////////////////////////////////////////////////////////////////////
@@ -178,6 +180,18 @@ HRESULT CBRenderSDL::InitRenderer(int width, int height, bool windowed) {
return S_OK;
}
+void CBRenderSDL::setAlphaMod(byte alpha) {
+ byte r = D3DCOLGetR(_colorMod);
+ byte g = D3DCOLGetB(_colorMod);
+ byte b = D3DCOLGetB(_colorMod);
+ _colorMod = BS_ARGB(alpha, r, g, b);
+}
+
+void CBRenderSDL::setColorMod(byte r, byte g, byte b) {
+ byte alpha = D3DCOLGetA(_colorMod);
+ _colorMod = BS_ARGB(alpha, r, g, b);
+}
+
//////////////////////////////////////////////////////////////////////////
HRESULT CBRenderSDL::Flip() {
@@ -296,17 +310,17 @@ HRESULT CBRenderSDL::FadeToColor(uint32 Color, Common::Rect *rect) {
}
// Replacement for SDL2's SDL_RenderCopy
-void CBRenderSDL::drawFromSurface(Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, byte r, byte g, byte b, byte a, bool mirrorX, bool mirrorY) {
+void CBRenderSDL::drawFromSurface(Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, bool mirrorX, bool mirrorY) {
TransparentSurface src(*surf, false);
int mirror = TransparentSurface::FLIP_NONE;
if (mirrorX)
mirror |= TransparentSurface::FLIP_V;
if (mirrorY)
mirror |= TransparentSurface::FLIP_H;
- src.blit(*_renderSurface, dstRect->left, dstRect->top, mirror, srcRect,BS_ARGB(a, r, g, b), dstRect->width(), dstRect->height() );
+ src.blit(*_renderSurface, dstRect->left, dstRect->top, mirror, srcRect, _colorMod, dstRect->width(), dstRect->height() );
}
-void CBRenderSDL::drawOpaqueFromSurface(Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, byte r, byte g, byte b, byte a, bool mirrorX, bool mirrorY) {
+void CBRenderSDL::drawOpaqueFromSurface(Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, bool mirrorX, bool mirrorY) {
TransparentSurface src(*surf, false);
TransparentSurface *img = NULL;
TransparentSurface *imgScaled = NULL;
diff --git a/engines/wintermute/Base/BRenderSDL.h b/engines/wintermute/Base/BRenderSDL.h
index efcdc5cc4a..2a1910790a 100644
--- a/engines/wintermute/Base/BRenderSDL.h
+++ b/engines/wintermute/Base/BRenderSDL.h
@@ -58,8 +58,10 @@ public:
CBImage *TakeScreenshot();
- void drawFromSurface(Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRest, byte r = 255, byte g = 255, byte b = 255, byte a = 255, bool mirrorX = false, bool mirrorY = false);
- void drawOpaqueFromSurface(Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRest, byte r = 255, byte g = 255, byte b = 255, byte a = 255, bool mirrorX = false, bool mirrorY = false);
+ void setAlphaMod(byte alpha);
+ void setColorMod(byte r, byte g, byte b);
+ void drawFromSurface(Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRest, bool mirrorX = false, bool mirrorY = false);
+ void drawOpaqueFromSurface(Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRest, bool mirrorX = false, bool mirrorY = false);
HRESULT SetViewport(int left, int top, int right, int bottom);
@@ -89,6 +91,7 @@ private:
float _ratioX;
float _ratioY;
+ uint32 _colorMod;
};
} // end of namespace WinterMute
diff --git a/engines/wintermute/Base/BSurface.h b/engines/wintermute/Base/BSurface.h
index 469923bcdd..e91f03ca02 100644
--- a/engines/wintermute/Base/BSurface.h
+++ b/engines/wintermute/Base/BSurface.h
@@ -63,7 +63,7 @@ public:
virtual HRESULT restore();
virtual HRESULT create(const char *Filename, bool default_ck, byte ck_red, byte ck_green, byte ck_blue, int LifeTime = -1, bool KeepLoaded = false) = 0;
virtual HRESULT create(int Width, int Height);
- virtual HRESULT putSurface(const Graphics::Surface &surface) { return E_FAIL; }
+ virtual HRESULT putSurface(const Graphics::Surface &surface, bool hasAlpha = false) { return E_FAIL; }
virtual HRESULT putPixel(int x, int y, byte r, byte g, byte b, int a = -1);
virtual HRESULT getPixel(int x, int y, byte *r, byte *g, byte *b, byte *a = NULL);
virtual bool comparePixel(int x, int y, byte r, byte g, byte b, int a = -1);
diff --git a/engines/wintermute/Base/BSurfaceSDL.cpp b/engines/wintermute/Base/BSurfaceSDL.cpp
index 715c057783..5c4e6952d7 100644
--- a/engines/wintermute/Base/BSurfaceSDL.cpp
+++ b/engines/wintermute/Base/BSurfaceSDL.cpp
@@ -31,6 +31,7 @@
#include "engines/wintermute/Base/BGame.h"
#include "engines/wintermute/Base/BSurfaceSDL.h"
#include "engines/wintermute/Base/BRenderSDL.h"
+#include "engines/wintermute/Base/BImage.h"
#include "engines/wintermute/PlatformSDL.h"
#include "graphics/decoders/png.h"
#include "graphics/decoders/bmp.h"
@@ -99,28 +100,10 @@ bool hasTransparency(Graphics::Surface *surf) {
HRESULT CBSurfaceSDL::create(const char *filename, bool default_ck, byte ck_red, byte ck_green, byte ck_blue, int lifeTime, bool keepLoaded) {
/* CBRenderSDL *renderer = static_cast<CBRenderSDL *>(Game->_renderer); */
Common::String strFileName(filename);
-
- Graphics::ImageDecoder *imgDecoder;
-
- if (strFileName.hasSuffix(".png")) {
- imgDecoder = new Graphics::PNGDecoder();
- } else if (strFileName.hasSuffix(".bmp")) {
- imgDecoder = new Graphics::BitmapDecoder();
- } else if (strFileName.hasSuffix(".tga")) {
- imgDecoder = new WinterMute::TGA();
- } else if (strFileName.hasSuffix(".jpg")) {
- imgDecoder = new Graphics::JPEGDecoder();
- } else {
- error("CBSurfaceSDL::Create : Unsupported fileformat %s", filename);
- }
-
- Common::SeekableReadStream *file = Game->_fileManager->OpenFile(filename);
- if (!file) return E_FAIL;
-
- imgDecoder->loadStream(*file);
- const Graphics::Surface *surface = imgDecoder->getSurface();
- const byte* palette = imgDecoder->getPalette();
- Game->_fileManager->CloseFile(file);
+ warning("CBSurfaceSDL::create(%s, %d, %d, %d, %d, %d, %d", filename, default_ck, ck_red, ck_green, ck_blue, lifeTime, keepLoaded);
+ CBImage *image = new CBImage(Game);
+ image->loadFile(strFileName);
+// const Graphics::Surface *surface = image->getSurface();
if (default_ck) {
ck_red = 255;
@@ -128,8 +111,8 @@ HRESULT CBSurfaceSDL::create(const char *filename, bool default_ck, byte ck_red,
ck_blue = 255;
}
- _width = surface->w;
- _height = surface->h;
+ _width = image->getSurface()->w;
+ _height = image->getSurface()->h;
bool isSaveGameGrayscale = scumm_strnicmp(filename, "savegame:", 9) == 0 && (filename[strFileName.size() - 1] == 'g' || filename[strFileName.size() - 1] == 'G');
if (isSaveGameGrayscale) {
@@ -169,19 +152,19 @@ HRESULT CBSurfaceSDL::create(const char *filename, bool default_ck, byte ck_red,
// convert 32-bit BMPs to 24-bit or they appear totally transparent (does any app actually write alpha in BMP properly?)
// Well, actually, we don't convert via 24-bit as the color-key application overwrites the Alpha-channel anyhow.
- if (strFileName.hasSuffix(".bmp") && surface->format.bytesPerPixel == 4) {
- _surface = surface->convertTo(g_system->getScreenFormat(), palette);
+ if (strFileName.hasSuffix(".bmp") && image->getSurface()->format.bytesPerPixel == 4) {
+ _surface = image->getSurface()->convertTo(g_system->getScreenFormat(), image->getPalette());
TransparentSurface trans(*_surface);
trans.applyColorKey(ck_red, ck_green, ck_blue);
- } else if (surface->format.bytesPerPixel == 1 && palette) {
- _surface = surface->convertTo(g_system->getScreenFormat(), palette);
+ } else if (image->getSurface()->format.bytesPerPixel == 1 && image->getPalette()) {
+ _surface = image->getSurface()->convertTo(g_system->getScreenFormat(), image->getPalette());
TransparentSurface trans(*_surface);
trans.applyColorKey(ck_red, ck_green, ck_blue, true);
- } else if (surface->format.bytesPerPixel == 4 && surface->format != g_system->getScreenFormat()) {
- _surface = surface->convertTo(g_system->getScreenFormat());
+ } else if (image->getSurface()->format.bytesPerPixel == 4 && image->getSurface()->format != g_system->getScreenFormat()) {
+ _surface = image->getSurface()->convertTo(g_system->getScreenFormat());
} else {
_surface = new Graphics::Surface();
- _surface->copyFrom(*surface);
+ _surface->copyFrom(*image->getSurface());
}
_hasAlpha = hasTransparency(_surface);
@@ -195,7 +178,7 @@ HRESULT CBSurfaceSDL::create(const char *filename, bool default_ck, byte ck_red,
warning("Surface-textures not fully ported yet");
hasWarned = true;
}
- delete imgDecoder;
+ //delete imgDecoder;
#if 0
_texture = SDL_CreateTextureFromSurface(renderer->GetSdlRenderer(), surf);
if (!_texture) {
@@ -226,9 +209,10 @@ HRESULT CBSurfaceSDL::create(const char *filename, bool default_ck, byte ck_red,
if (_keepLoaded) _lifeTime = -1;
_valid = true;
-#if 0
+
Game->AddMem(_width * _height * 4);
-#endif
+
+ delete image;
return S_OK;
}
@@ -493,6 +477,9 @@ HRESULT CBSurfaceSDL::drawSprite(int x, int y, RECT *Rect, float ZoomX, float Zo
byte g = D3DCOLGetG(Alpha);
byte b = D3DCOLGetB(Alpha);
byte a = D3DCOLGetA(Alpha);
+
+ renderer->setAlphaMod(a);
+ renderer->setColorMod(r, g, b);
#if 0
SDL_SetTextureColorMod(_texture, r, g, b);
SDL_SetTextureAlphaMod(_texture, a);
@@ -551,9 +538,9 @@ HRESULT CBSurfaceSDL::drawSprite(int x, int y, RECT *Rect, float ZoomX, float Zo
srcRect.setHeight(drawSrc.h);
if (_hasAlpha && !AlphaDisable) {
- renderer->drawFromSurface(&drawSrc, &srcRect, &position, r, g, b, a, mirrorX, mirrorY);
+ renderer->drawFromSurface(&drawSrc, &srcRect, &position, mirrorX, mirrorY);
} else {
- renderer->drawOpaqueFromSurface(&drawSrc, &srcRect, &position, r, g, b, a, mirrorX, mirrorY);
+ renderer->drawOpaqueFromSurface(&drawSrc, &srcRect, &position, mirrorX, mirrorY);
}
#if 0
SDL_RenderCopy(renderer->GetSdlRenderer(), _texture, &srcRect, &position);
@@ -562,8 +549,9 @@ HRESULT CBSurfaceSDL::drawSprite(int x, int y, RECT *Rect, float ZoomX, float Zo
return S_OK;
}
-HRESULT CBSurfaceSDL::putSurface(const Graphics::Surface &surface) {
+HRESULT CBSurfaceSDL::putSurface(const Graphics::Surface &surface, bool hasAlpha) {
_surface->copyFrom(surface);
+ _hasAlpha = hasAlpha;
return S_OK;
}
diff --git a/engines/wintermute/Base/BSurfaceSDL.h b/engines/wintermute/Base/BSurfaceSDL.h
index 34d25b43b5..6301310f01 100644
--- a/engines/wintermute/Base/BSurfaceSDL.h
+++ b/engines/wintermute/Base/BSurfaceSDL.h
@@ -58,7 +58,7 @@ public:
HRESULT display(int x, int y, RECT rect, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false);
HRESULT displayZoom(int x, int y, RECT rect, float zoomX, float zoomY, uint32 alpha = 0xFFFFFFFF, bool Transparent = false, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false);
HRESULT displayTransform(int x, int y, int HotX, int HotY, RECT Rect, float zoomX, float zoomY, uint32 alpha, float Rotate, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false);
- virtual HRESULT putSurface(const Graphics::Surface &surface);
+ virtual HRESULT putSurface(const Graphics::Surface &surface, bool hasAlpha = false);
/* static unsigned DLL_CALLCONV ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle);
static int DLL_CALLCONV SeekProc(fi_handle handle, long offset, int origin);
static long DLL_CALLCONV TellProc(fi_handle handle);*/