[Scummvm-git-logs] scummvm master -> ce989104f5a9e26cae37d282f0884e731bc992fa
sev-
noreply at scummvm.org
Thu Jun 19 22:55:55 UTC 2025
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
ce989104f5 CRAB: Support additional pixel formats
Commit: ce989104f5a9e26cae37d282f0884e731bc992fa
https://github.com/scummvm/scummvm/commit/ce989104f5a9e26cae37d282f0884e731bc992fa
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2025-06-20T00:55:53+02:00
Commit Message:
CRAB: Support additional pixel formats
Changed paths:
engines/crab/Polygon.cpp
engines/crab/Rectangle.cpp
engines/crab/crab.cpp
engines/crab/crab.h
engines/crab/image/Image.cpp
engines/crab/level/level_draw.cpp
engines/crab/text/TextManager.cpp
engines/crab/ui/slider.cpp
diff --git a/engines/crab/Polygon.cpp b/engines/crab/Polygon.cpp
index 55e8b23a339..6bfe0470285 100644
--- a/engines/crab/Polygon.cpp
+++ b/engines/crab/Polygon.cpp
@@ -268,7 +268,7 @@ void Polygon2D::draw(const int &xOffset, const int &yOffset, const uint8 &r, con
else
p2 = _point[i + 1];
- g_engine->_screen->drawLine(p1.x + xOffset, p1.y + yOffset, p2.x + xOffset, p2.y + yOffset, g_engine->_format->ARGBToColor(a, r, g, b));
+ g_engine->_screen->drawLine(p1.x + xOffset, p1.y + yOffset, p2.x + xOffset, p2.y + yOffset, g_engine->_format.ARGBToColor(a, r, g, b));
}
}
diff --git a/engines/crab/Rectangle.cpp b/engines/crab/Rectangle.cpp
index 3540158e57a..9a77ce293f6 100644
--- a/engines/crab/Rectangle.cpp
+++ b/engines/crab/Rectangle.cpp
@@ -112,11 +112,12 @@ void Rect::flip(const TextureFlipType &flip, const Vector2i &axis) {
void Rect::draw(const int &xOffset, const int &yOffset, const uint8 &r, const uint8 &g, const uint8 &b, const uint8 &a) {
int X = x + xOffset, Y = y + yOffset;
+ uint32 col = g_engine->_format.ARGBToColor(a, r, g, b);
- g_engine->_screen->drawLine(X, Y, X + w, Y, g_engine->_format->ARGBToColor(a, r, g, b));
- g_engine->_screen->drawLine(X, Y, X, Y + h, g_engine->_format->ARGBToColor(a, r, g, b));
- g_engine->_screen->drawLine(X + w, Y, X + w, Y + h, g_engine->_format->ARGBToColor(a, r, g, b));
- g_engine->_screen->drawLine(X, Y + h, X + w, Y + h, g_engine->_format->ARGBToColor(a, r, g, b));
+ g_engine->_screen->drawLine(X, Y, X + w, Y, col);
+ g_engine->_screen->drawLine(X, Y, X, Y + h, col);
+ g_engine->_screen->drawLine(X + w, Y, X + w, Y + h, col);
+ g_engine->_screen->drawLine(X, Y + h, X + w, Y + h, col);
}
void Rect::saveState(rapidxml::xml_document<> &doc, rapidxml::xml_node<char> *root, const char *name) {
diff --git a/engines/crab/crab.cpp b/engines/crab/crab.cpp
index 25735fd9d1e..0eb6593f158 100644
--- a/engines/crab/crab.cpp
+++ b/engines/crab/crab.cpp
@@ -70,7 +70,6 @@ CrabEngine::~CrabEngine() {
delete _thumbnail;
delete _screen;
- delete _format;
}
uint32 CrabEngine::getFeatures() const {
@@ -82,10 +81,34 @@ Common::String CrabEngine::getGameId() const {
}
Common::Error CrabEngine::run() {
- _format = new Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24);
- initGraphics(1280, 720, _format);
- _screen = new Graphics::Screen(1280, 720, *_format);
- _thumbnail = new Graphics::ManagedSurface(1280, 720, *_format);
+ // Prefer this format to avoid converting PNG files.
+ const Graphics::PixelFormat bestFormat = Graphics::PixelFormat::createFormatRGBA32();
+
+ // Find a suitable 32-bit format with alpha, currently we don't support other color depths
+ Common::List<Graphics::PixelFormat> formats = g_system->getSupportedFormats();
+ for (Common::List<Graphics::PixelFormat>::iterator it = formats.begin(); it != formats.end(); ++it) {
+ if (it->bytesPerPixel != 4 || it->aBits() == 0) {
+ it = formats.reverse_erase(it);
+ } else if (*it == bestFormat) {
+ formats.clear();
+ formats.push_back(bestFormat);
+ break;
+ }
+ }
+
+ // Even if no formats are found, it's possible that the backend
+ // can handle software conversion.
+ if (formats.empty())
+ formats.push_back(bestFormat);
+
+ initGraphics(1280, 720, formats);
+
+ _format = g_system->getScreenFormat();
+ if (_format.bytesPerPixel != 4)
+ return Common::kUnsupportedColorMode;
+
+ _screen = new Graphics::Screen(1280, 720, _format);
+ _thumbnail = new Graphics::ManagedSurface(1280, 720, _format);
_imageManager = new pyrodactyl::image::ImageManager();
_textManager = new pyrodactyl::text::TextManager();
diff --git a/engines/crab/crab.h b/engines/crab/crab.h
index a6ecb79b4f3..8d548241124 100644
--- a/engines/crab/crab.h
+++ b/engines/crab/crab.h
@@ -24,12 +24,12 @@
#include "common/random.h"
#include "common/serializer.h"
+#include "graphics/pixelformat.h"
#include "crab/detection.h"
namespace Graphics {
class ManagedSurface;
-struct PixelFormat;
class Screen;
} // End of namespace Graphics
@@ -99,7 +99,7 @@ protected:
public:
Graphics::Screen *_screen = nullptr;
- Graphics::PixelFormat *_format = nullptr;
+ Graphics::PixelFormat _format;
pyrodactyl::image::ImageManager *_imageManager = nullptr;
pyrodactyl::text::TextManager *_textManager = nullptr;
diff --git a/engines/crab/image/Image.cpp b/engines/crab/image/Image.cpp
index 3e72b28f8cf..e4c678754a1 100644
--- a/engines/crab/image/Image.cpp
+++ b/engines/crab/image/Image.cpp
@@ -67,7 +67,7 @@ bool Image::load(const Common::Path &path) {
if (fileOpen(path, &file) && decoder.loadStream(file)) {
_texture = new Graphics::ManagedSurface();
- _texture->convertFrom(*decoder.getSurface(), *g_engine->_format);
+ _texture->convertFrom(*decoder.getSurface(), g_engine->_format);
_w = _texture->w;
_h = _texture->h;
diff --git a/engines/crab/level/level_draw.cpp b/engines/crab/level/level_draw.cpp
index 7bf38b0d75a..4729703405b 100644
--- a/engines/crab/level/level_draw.cpp
+++ b/engines/crab/level/level_draw.cpp
@@ -44,7 +44,7 @@ using namespace pyrodactyl::input;
// Purpose: Pre render the terrain layer
void Level::preDraw() {
- Graphics::ManagedSurface *surf = new Graphics::ManagedSurface(_terrain.w(), _terrain.h(), *g_engine->_format);
+ Graphics::ManagedSurface *surf = new Graphics::ManagedSurface(_terrain.w(), _terrain.h(), g_engine->_format);
uint layerCount = 0u;
for (auto l = _terrain._layer.begin(); l != _terrain._layer.end(); ++l, ++layerCount) {
g_engine->_imageManager->_tileset.preDraw(*l, _terrain._tileSize, surf);
diff --git a/engines/crab/text/TextManager.cpp b/engines/crab/text/TextManager.cpp
index 37441ec1350..a35f572ae86 100644
--- a/engines/crab/text/TextManager.cpp
+++ b/engines/crab/text/TextManager.cpp
@@ -113,19 +113,19 @@ int TextManager::findFreeSlot() {
//------------------------------------------------------------------------
Graphics::ManagedSurface *TextManager::renderTextBlended(const FontKey &fKey, const Common::String &text, const int &color) {
Color pooledColor = _colpool.get(color);
- uint32 col = g_engine->_format->ARGBToColor(255, pooledColor.r, pooledColor.g, pooledColor.b);
+ uint32 col = g_engine->_format.ARGBToColor(255, pooledColor.r, pooledColor.g, pooledColor.b);
Graphics::ManagedSurface *surf = nullptr;
if (text.empty()) {
Common::Rect rec = getFont(fKey)->getBoundingBox(" ");
int h = rec.height();
- surf = new Graphics::ManagedSurface(rec.width(), h + (h / 2), *g_engine->_format);
+ surf = new Graphics::ManagedSurface(rec.width(), h + (h / 2), g_engine->_format);
getFont(fKey)->drawString(surf, " ", 0, 0, rec.width(), col);
} else {
Common::Rect rec = getFont(fKey)->getBoundingBox(text);
int h = rec.height();
- surf = new Graphics::ManagedSurface(rec.width(), h + (h / 2), *g_engine->_format);
+ surf = new Graphics::ManagedSurface(rec.width(), h + (h / 2), g_engine->_format);
getFont(fKey)->drawString(surf, text, 0, 0, rec.width(), col);
}
@@ -159,9 +159,9 @@ void TextManager::draw(const int &x, const int &y, const Common::String &text, c
_rect.w = _cache[pos]._img.w() + (2 * _padBg.x);
_rect.h = _cache[pos]._img.h() + (2 * _padBg.y);
- uint32 col = g_engine->_format->ARGBToColor(128, 0, 0, 0);
+ uint32 col = g_engine->_format.ARGBToColor(128, 0, 0, 0);
Graphics::Surface surf;
- surf.create(_rect.w, _rect.h, *g_engine->_format);
+ surf.create(_rect.w, _rect.h, g_engine->_format);
surf.fillRect(Common::Rect(_rect.w, _rect.h), col);
if (align == ALIGN_LEFT) {
diff --git a/engines/crab/ui/slider.cpp b/engines/crab/ui/slider.cpp
index 266b83947a8..636bc4caf9c 100644
--- a/engines/crab/ui/slider.cpp
+++ b/engines/crab/ui/slider.cpp
@@ -111,17 +111,17 @@ void Slider::greyOut() {
for (int y = _caption.y; y < _caption.y + h; y++) {
uint32 *ptr = (uint32 *)g_engine->_screen->getBasePtr(_caption.x, y);
for (int x = 0; x < w; x++, ptr++) {
- g_engine->_format->colorToARGB(*ptr, a, r, g, b);
+ g_engine->_format.colorToARGB(*ptr, a, r, g, b);
if (x >= _knob.x - _caption.x && x <= _knob.w + _knob.x - _caption.x) {
r /= 3;
g /= 3;
b /= 2;
- *ptr = g_engine->_format->ARGBToColor(a, r, g, b);
+ *ptr = g_engine->_format.ARGBToColor(a, r, g, b);
} else if (g > 0x37) {
r >>= 1;
g >>= 1;
b >>= 1;
- *ptr = g_engine->_format->ARGBToColor(a, r, g, b);
+ *ptr = g_engine->_format.ARGBToColor(a, r, g, b);
}
}
}
More information about the Scummvm-git-logs
mailing list