aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp')
-rw-r--r--engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp42
1 files changed, 29 insertions, 13 deletions
diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp
index bee876bb65..0572ef2f6e 100644
--- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp
+++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp
@@ -47,9 +47,9 @@ namespace Wintermute {
//////////////////////////////////////////////////////////////////////////
BaseSurfaceOSystem::BaseSurfaceOSystem(BaseGame *inGame) : BaseSurface(inGame) {
_surface = new Graphics::Surface();
- _alphaMask = NULL;
+ _alphaMask = nullptr;
_hasAlpha = true;
- _lockPixels = NULL;
+ _lockPixels = nullptr;
_lockPitch = 0;
_loaded = false;
}
@@ -59,11 +59,11 @@ BaseSurfaceOSystem::~BaseSurfaceOSystem() {
if (_surface) {
_surface->free();
delete _surface;
- _surface = NULL;
+ _surface = nullptr;
}
delete[] _alphaMask;
- _alphaMask = NULL;
+ _alphaMask = nullptr;
_gameRef->addMem(-_width * _height * 4);
BaseRenderOSystem *renderer = static_cast<BaseRenderOSystem *>(_gameRef->_renderer);
@@ -120,6 +120,7 @@ bool BaseSurfaceOSystem::create(const Common::String &filename, bool defaultCK,
bool BaseSurfaceOSystem::finishLoad() {
BaseImage *image = new BaseImage();
if (!image->loadFile(_filename)) {
+ delete image;
return false;
}
@@ -140,23 +141,32 @@ bool BaseSurfaceOSystem::finishLoad() {
// Well, actually, we don't convert via 24-bit as the color-key application overwrites the Alpha-channel anyhow.
_surface->free();
delete _surface;
+
+ bool needsColorKey = false;
+ bool replaceAlpha = true;
if (_filename.hasSuffix(".bmp") && image->getSurface()->format.bytesPerPixel == 4) {
_surface = image->getSurface()->convertTo(g_system->getScreenFormat(), image->getPalette());
- TransparentSurface trans(*_surface);
- trans.applyColorKey(_ckRed, _ckGreen, _ckBlue);
+ needsColorKey = true;
+ replaceAlpha = false;
} else if (image->getSurface()->format.bytesPerPixel == 1 && image->getPalette()) {
_surface = image->getSurface()->convertTo(g_system->getScreenFormat(), image->getPalette());
- TransparentSurface trans(*_surface);
- trans.applyColorKey(_ckRed, _ckGreen, _ckBlue, true);
+ needsColorKey = true;
} else if (image->getSurface()->format.bytesPerPixel >= 3 && image->getSurface()->format != g_system->getScreenFormat()) {
_surface = image->getSurface()->convertTo(g_system->getScreenFormat());
if (image->getSurface()->format.bytesPerPixel == 3) {
- TransparentSurface trans(*_surface);
- trans.applyColorKey(_ckRed, _ckGreen, _ckBlue, true);
+ needsColorKey = true;
}
} else {
_surface = new Graphics::Surface();
_surface->copyFrom(*image->getSurface());
+ if (_surface->format.aBits() == 0) {
+ needsColorKey = true;
+ }
+ }
+
+ if (needsColorKey) {
+ TransparentSurface trans(*_surface);
+ trans.applyColorKey(_ckRed, _ckGreen, _ckBlue, replaceAlpha);
}
_hasAlpha = hasTransparency(_surface);
@@ -177,7 +187,7 @@ void BaseSurfaceOSystem::genAlphaMask(Graphics::Surface *surface) {
return;
// TODO: Reimplement this
delete[] _alphaMask;
- _alphaMask = NULL;
+ _alphaMask = nullptr;
if (!surface) {
return;
}
@@ -214,7 +224,7 @@ void BaseSurfaceOSystem::genAlphaMask(Graphics::Surface *surface) {
if (!hasTransparency) {
delete[] _alphaMask;
- _alphaMask = NULL;
+ _alphaMask = nullptr;
}
}
@@ -293,7 +303,7 @@ bool BaseSurfaceOSystem::isTransparentAtLite(int x, int y) {
//////////////////////////////////////////////////////////////////////////
bool BaseSurfaceOSystem::startPixelOp() {
- //SDL_LockTexture(_texture, NULL, &_lockPixels, &_lockPitch);
+ //SDL_LockTexture(_texture, nullptr, &_lockPixels, &_lockPitch);
// Any pixel-op makes the caching useless:
BaseRenderOSystem *renderer = static_cast<BaseRenderOSystem *>(_gameRef->_renderer);
renderer->invalidateTicketsFromSurface(this);
@@ -414,6 +424,12 @@ bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, float zoomX, flo
return STATUS_OK;
}
+bool BaseSurfaceOSystem::repeatLastDisplayOp(int offsetX, int offsetY, int numTimesX, int numTimesY) {
+ BaseRenderOSystem *renderer = static_cast<BaseRenderOSystem *>(_gameRef->_renderer);
+ renderer->repeatLastDraw(offsetX, offsetY, numTimesX, numTimesY);
+ return STATUS_OK;
+}
+
bool BaseSurfaceOSystem::putSurface(const Graphics::Surface &surface, bool hasAlpha) {
_loaded = true;
_surface->free();