FREESCAPE: use managed surfaces for border and title images

This commit is contained in:
neuromancer 2023-03-07 08:55:43 +01:00
parent 1c96737ae1
commit 3c9cbb3fe0
6 changed files with 78 additions and 88 deletions

View File

@ -194,7 +194,7 @@ void FreescapeEngine::drawBorder() {
void FreescapeEngine::drawTitle() {
_gfx->setViewport(_fullscreenViewArea);
if (isSpectrum()) {
Graphics::Surface *title = new Graphics::Surface();
Graphics::ManagedSurface *title = new Graphics::ManagedSurface();
title->create(320, 200, _title->format);
title->copyRectToSurface(*_title, (320 - _title->w) / 2, (200 - _title->h) / 2, Common::Rect(_title->w, _title->h));
_title->free();
@ -202,7 +202,7 @@ void FreescapeEngine::drawTitle() {
_title = title;
}
if (!_titleTexture)
_titleTexture = _gfx->createTexture(_title);
_titleTexture = _gfx->createTexture(&_title->rawSurface());
_gfx->drawTexturedRect2D(_fullscreenViewArea, _fullscreenViewArea, _titleTexture);
_gfx->setViewport(_viewArea);
}
@ -598,7 +598,7 @@ void FreescapeEngine::borderScreen() {}
void FreescapeEngine::loadBorder() {
if (_border)
_borderTexture = _gfx->createTexture(_border);
_borderTexture = _gfx->createTexture(&_border->rawSurface());
}
void FreescapeEngine::processBorder() {
@ -618,7 +618,7 @@ void FreescapeEngine::processBorder() {
_border->setPixel(i, j, transparent);
}
}
_borderTexture = _gfx->createTexture(_border);
_borderTexture = _gfx->createTexture(&_border->rawSurface());
}
}
@ -850,20 +850,20 @@ byte *FreescapeEngine::getPaletteFromNeoImage(Common::SeekableReadStream *stream
return palette;
}
Graphics::Surface *FreescapeEngine::loadAndConvertNeoImage(Common::SeekableReadStream *stream, int offset, byte *palette) {
Graphics::ManagedSurface *FreescapeEngine::loadAndConvertNeoImage(Common::SeekableReadStream *stream, int offset, byte *palette) {
stream->seek(offset);
NeoDecoder decoder(palette);
decoder.loadStream(*stream);
Graphics::Surface *surface = new Graphics::Surface();
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->copyFrom(*decoder.getSurface());
surface->convertToInPlace(_gfx->_currentPixelFormat, decoder.getPalette());
return surface;
}
Graphics::Surface *FreescapeEngine::loadAndCenterScrImage(Common::SeekableReadStream *stream) {
Graphics::ManagedSurface *FreescapeEngine::loadAndCenterScrImage(Common::SeekableReadStream *stream) {
ScrDecoder decoder;
decoder.loadStream(*stream);
Graphics::Surface *surface = new Graphics::Surface();
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
const Graphics::Surface *decoded = decoder.getSurface();
surface->create(320, 200, decoded->format);
surface->copyRectToSurface(*decoded, (320 - decoded->w) / 2, (200 - decoded->h) / 2, Common::Rect(decoded->w, decoded->h));

View File

@ -25,6 +25,7 @@
#include "common/bitarray.h"
#include "common/events.h"
#include "engines/advancedDetector.h"
#include "graphics/managed_surface.h"
#include "graphics/surface.h"
#include "audio/decoders/wave.h"
@ -124,8 +125,8 @@ public:
virtual void drawInfoMenu();
virtual void drawCrossair(Graphics::Surface *surface);
Graphics::Surface *_border;
Graphics::Surface *_title;
Graphics::ManagedSurface *_border;
Graphics::ManagedSurface *_title;
Texture *_borderTexture;
Texture *_titleTexture;
Texture *_uiTexture;
@ -139,8 +140,8 @@ public:
void loadDataBundle();
void loadBundledImages();
byte *getPaletteFromNeoImage(Common::SeekableReadStream *stream, int offset);
Graphics::Surface *loadAndConvertNeoImage(Common::SeekableReadStream *stream, int offset, byte *palette = nullptr);
Graphics::Surface *loadAndCenterScrImage(Common::SeekableReadStream *stream);
Graphics::ManagedSurface *loadAndConvertNeoImage(Common::SeekableReadStream *stream, int offset, byte *palette = nullptr);
Graphics::ManagedSurface *loadAndCenterScrImage(Common::SeekableReadStream *stream);
void loadPalettes(Common::SeekableReadStream *file, int offset);
void swapPalette(uint16 areaID);
Common::HashMap<uint16, byte *> _paletteByArea;
@ -165,12 +166,12 @@ public:
void load8bitBinary(Common::SeekableReadStream *file, int offset, int ncolors);
Area *load8bitArea(Common::SeekableReadStream *file, uint16 ncolors);
Object *load8bitObject(Common::SeekableReadStream *file);
void renderPixels8bitBinImage(Graphics::Surface *surface, int &i, int &j, uint8 pixels, int color);
void renderPixels8bitBinImage(Graphics::ManagedSurface *surface, int &i, int &j, uint8 pixels, int color);
void renderPixels8bitBinCGAImage(Graphics::Surface *surface, int &i, int &j, uint8 pixels, int color);
void renderPixels8bitBinEGAImage(Graphics::Surface *surface, int &i, int &j, uint8 pixels, int color);
void renderPixels8bitBinCGAImage(Graphics::ManagedSurface *surface, int &i, int &j, uint8 pixels, int color);
void renderPixels8bitBinEGAImage(Graphics::ManagedSurface *surface, int &i, int &j, uint8 pixels, int color);
Graphics::Surface *load8bitBinImage(Common::SeekableReadStream *file, int offset);
Graphics::ManagedSurface *load8bitBinImage(Common::SeekableReadStream *file, int offset);
// Areas
uint16 _startArea;
@ -460,9 +461,9 @@ private:
void drawC64UI(Graphics::Surface *surface);
void drawAmigaAtariSTUI(Graphics::Surface *surface);
Graphics::Surface *load8bitTitleImage(Common::SeekableReadStream *file, int offset);
Graphics::ManagedSurface *load8bitTitleImage(Common::SeekableReadStream *file, int offset);
uint32 getPixel8bitTitleImage(int index);
void renderPixels8bitTitleImage(Graphics::Surface *surface, int &i, int &j, int pixels);
void renderPixels8bitTitleImage(Graphics::ManagedSurface *surface, int &i, int &j, int pixels);
};
class DarkEngine : public FreescapeEngine {

View File

@ -35,16 +35,13 @@ extern byte kEGADefaultPaletteData[16][3];
*/
uint32 DrillerEngine::getPixel8bitTitleImage(int index) {
uint8 r, g, b;
if (index < 4 || _renderMode == Common::kRenderEGA) {
_gfx->readFromPalette(index, r, g, b);
return _gfx->_currentPixelFormat.ARGBToColor(0xFF, r, g, b);
return index;
}
_gfx->readFromPalette(index / 4, r, g, b);
return _gfx->_currentPixelFormat.ARGBToColor(0xFF, r, g, b);
return index / 4;
}
void DrillerEngine::renderPixels8bitTitleImage(Graphics::Surface *surface, int &i, int &j, int pixels) {
void DrillerEngine::renderPixels8bitTitleImage(Graphics::ManagedSurface *surface, int &i, int &j, int pixels) {
int c1 = pixels >> 4;
int c2 = pixels & 0xf;
@ -80,17 +77,10 @@ void DrillerEngine::renderPixels8bitTitleImage(Graphics::Surface *surface, int &
i++;
}
Graphics::Surface *DrillerEngine::load8bitTitleImage(Common::SeekableReadStream *file, int offset) {
Graphics::Surface *surface = new Graphics::Surface();
if (_renderMode == Common::kRenderCGA)
_gfx->_palette = (byte *)kCGAPalettePinkBlueWhiteData;
else if (_renderMode == Common::kRenderEGA)
_gfx->_palette = (byte *)kEGADefaultPaletteData;
else
error("Invalid render mode: %d", _renderMode);
surface->create(_screenW, _screenH, _gfx->_currentPixelFormat);
uint32 black = _gfx->_currentPixelFormat.ARGBToColor(0xFF, 0, 0, 0);
surface->fillRect(Common::Rect(0, 0, 320, 200), black);
Graphics::ManagedSurface *DrillerEngine::load8bitTitleImage(Common::SeekableReadStream *file, int offset) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->create(_screenW, _screenH, Graphics::PixelFormat::createFormatCLUT8());
surface->fillRect(Common::Rect(0, 0, 320, 200), 0);
int i = 0;
int j = 0;
@ -180,17 +170,45 @@ Graphics::Surface *DrillerEngine::load8bitTitleImage(Common::SeekableReadStream
}
return surface;
}
byte kCGAPalettePinkBlueWhiteData[4][3] = {
{0x00, 0x00, 0x00},
{0x55, 0xff, 0xff},
{0xff, 0x55, 0xff},
{0xff, 0xff, 0xff},
};
byte kEGADefaultPaletteData[16][3] = {
{0x00, 0x00, 0x00},
{0x00, 0x00, 0xaa},
{0x00, 0xaa, 0x00},
{0xaa, 0x00, 0x00},
{0xaa, 0x00, 0xaa},
{0xaa, 0x55, 0x00},
{0x55, 0xff, 0x55},
{0xff, 0x55, 0x55},
{0x12, 0x34, 0x56},
{0xff, 0xff, 0x55},
{0xff, 0xff, 0xff},
{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00}
};
void DrillerEngine::loadAssetsDOSFullGame() {
Common::File file;
if (_renderMode == Common::kRenderEGA) {
file.open("SCN1E.DAT");
if (file.isOpen()) {
_title = load8bitBinImage(&file, 0x0);
_title->setPalette((byte*)&kEGADefaultPaletteData, 0, 16);
}
file.close();
file.open("EGATITLE.RL");
if (file.isOpen()) {
_title = load8bitTitleImage(&file, 0x1b3);
_title->setPalette((byte*)&kEGADefaultPaletteData, 0, 16);
}
file.close();
@ -204,15 +222,18 @@ void DrillerEngine::loadAssetsDOSFullGame() {
loadGlobalObjects(&file, 0x3b42);
load8bitBinary(&file, 0x9b40, 16);
_border = load8bitBinImage(&file, 0x210);
_border->setPalette((byte*)&kEGADefaultPaletteData, 0, 16);
} else if (_renderMode == Common::kRenderCGA) {
file.open("SCN1C.DAT");
if (file.isOpen()) {
_title = load8bitBinImage(&file, 0x0);
_title->setPalette((byte*)&kCGAPalettePinkBlueWhiteData, 0, 4);
}
file.close();
file.open("CGATITLE.RL");
if (file.isOpen()) {
_title = load8bitTitleImage(&file, 0x1b3);
_title->setPalette((byte*)&kCGAPalettePinkBlueWhiteData, 0, 4);
}
file.close();
file.open("DRILLC.EXE");
@ -225,6 +246,7 @@ void DrillerEngine::loadAssetsDOSFullGame() {
load8bitBinary(&file, 0x7bb0, 4);
loadGlobalObjects(&file, 0x1fa2);
_border = load8bitBinImage(&file, 0x210);
_border->setPalette((byte*)&kCGAPalettePinkBlueWhiteData, 0, 4);
} else
error("Unsupported video mode for DOS");
}

View File

@ -76,7 +76,7 @@ bool Renderer::getRGBAtCGA(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &
return false;
assert (_renderMode == Common::kRenderCGA);
if (index <= 4) { // Solid colors
if (index <= 4) { // Solid colors
readFromPalette(index - 1, r1, g1, b1);
r2 = r1;
g2 = g1;
@ -164,7 +164,7 @@ bool Renderer::getRGBAtZX(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r
return false;
byte *entry = (*_colorMap)[index - 1];
if (entry[0] == 0 && entry[1] == 0 && entry[2] == 0 && entry[3] == 0) {
if (entry[0] == 0 && entry[1] == 0 && entry[2] == 0 && entry[3] == 0) {
readFromPalette(_paperColor, r1, g1, b1);
readFromPalette(_paperColor, r2, g2, b2);
return true;
@ -342,12 +342,16 @@ void Renderer::flipVertical(Graphics::Surface *s) {
}
}
void Renderer::convertImageFormatIfNecessary(Graphics::Surface *surface) {
void Renderer::convertImageFormatIfNecessary(Graphics::ManagedSurface *surface) {
if (!surface)
return;
if (surface->format != _texturePixelFormat)
surface->convertToInPlace(_texturePixelFormat);
if (surface->format != _texturePixelFormat) {
byte *palette = (byte *)malloc(sizeof(byte) * 16 * 3);
surface->grabPalette(palette, 0, 16); // Maximum should be 16 colours
surface->convertToInPlace(_texturePixelFormat, palette);
free(palette);
}
}
Common::Rect Renderer::viewport() const {

View File

@ -26,6 +26,7 @@
#include "common/rect.h"
#include "graphics/pixelformat.h"
#include "graphics/managed_surface.h"
#include "graphics/renderer.h"
#include "math/frustum.h"
#include "math/vector3d.h"
@ -76,7 +77,7 @@ public:
virtual void polygonOffset(bool enabled) = 0;
virtual Texture *createTexture(const Graphics::Surface *surface) = 0;
void convertImageFormatIfNecessary(Graphics::Surface *surface);
void convertImageFormatIfNecessary(Graphics::ManagedSurface *surface);
virtual void freeTexture(Texture *texture) = 0;
virtual void drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect, Texture *texture) = 0;

View File

@ -298,32 +298,7 @@ static const char *eclipseRoomName[] = {
"ILLUSION",
"????????"};
byte kCGAPalettePinkBlueWhiteData[4][3] = {
{0x00, 0x00, 0x00},
{0x55, 0xff, 0xff},
{0xff, 0x55, 0xff},
{0xff, 0xff, 0xff},
};
byte kEGADefaultPaletteData[16][3] = {
{0x00, 0x00, 0x00},
{0x00, 0x00, 0xaa},
{0x00, 0xaa, 0x00},
{0xaa, 0x00, 0x00},
{0xaa, 0x00, 0xaa},
{0xaa, 0x55, 0x00},
{0x55, 0xff, 0x55},
{0xff, 0x55, 0x55},
{0x12, 0x34, 0x56},
{0xff, 0xff, 0x55},
{0xff, 0xff, 0xff},
{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00}
};
void FreescapeEngine::renderPixels8bitBinImage(Graphics::Surface *surface, int &i, int &j, uint8 pixels, int color) {
void FreescapeEngine::renderPixels8bitBinImage(Graphics::ManagedSurface *surface, int &i, int &j, uint8 pixels, int color) {
if (i >= 320) {
//debug("cannot continue, stopping here at row %d!", j);
return;
@ -333,13 +308,8 @@ void FreescapeEngine::renderPixels8bitBinImage(Graphics::Surface *surface, int &
while (acc > 0) {
assert(i < 320);
if (acc & pixels) {
uint8 r, g, b;
uint32 previousPixel = surface->getPixel(i, j);
_gfx->_currentPixelFormat.colorToRGB(previousPixel, r, g, b);
int previousColor = _gfx->indexFromColor(r, g, b);
//debug("index: %d", previousColor + color);
_gfx->readFromPalette(previousColor + color, r, g, b);
surface->setPixel(i, j, _gfx->_currentPixelFormat.ARGBToColor(0xFF, r, g, b));
int previousColor = surface->getPixel(i, j);
surface->setPixel(i, j, previousColor + color);
}
i++;
acc = acc >> 1;
@ -347,18 +317,10 @@ void FreescapeEngine::renderPixels8bitBinImage(Graphics::Surface *surface, int &
}
Graphics::Surface *FreescapeEngine::load8bitBinImage(Common::SeekableReadStream *file, int offset) {
Graphics::Surface *surface = new Graphics::Surface();
if (_renderMode == Common::kRenderCGA)
_gfx->_palette = (byte *)kCGAPalettePinkBlueWhiteData;
else if (_renderMode == Common::kRenderEGA)
_gfx->_palette = (byte *)kEGADefaultPaletteData;
else
error("Invalid render mode: %d", _renderMode);
surface->create(_screenW, _screenH, _gfx->_currentPixelFormat);
uint32 black = _gfx->_currentPixelFormat.ARGBToColor(0xFF, 0, 0, 0);
surface->fillRect(Common::Rect(0, 0, 320, 200), black);
Graphics::ManagedSurface *FreescapeEngine::load8bitBinImage(Common::SeekableReadStream *file, int offset) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->create(_screenW, _screenH, Graphics::PixelFormat::createFormatCLUT8());
surface->fillRect(Common::Rect(0, 0, 320, 200), 0);
file->seek(offset);
int imageSize = file->readUint16BE();
@ -735,7 +697,7 @@ void FreescapeEngine::load8bitBinary(Common::SeekableReadStream *file, int offse
}
void FreescapeEngine::loadBundledImages() {
Image::BitmapDecoder decoder;
/*Image::BitmapDecoder decoder;
Common::String targetName = Common::String(_gameDescription->gameId);
if (isDOS() && isDemo())
Common::replace(targetName, "-demo", "");
@ -757,7 +719,7 @@ void FreescapeEngine::loadBundledImages() {
_title = new Graphics::Surface();
_title->copyFrom(*decoder.getSurface());
decoder.destroy();
}
}*/
}
void FreescapeEngine::loadFonts(Common::SeekableReadStream *file, int offset) {