[Scummvm-git-logs] scummvm master -> 853290890fcfce14813051dac12c84484a2344c8
OMGPizzaGuy
noreply at scummvm.org
Thu Dec 15 00:08:35 UTC 2022
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
853290890f ULTIMA8: Add keycolor to shape frame in place of a mask array
Commit: 853290890fcfce14813051dac12c84484a2344c8
https://github.com/scummvm/scummvm/commit/853290890fcfce14813051dac12c84484a2344c8
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2022-12-14T18:08:02-06:00
Commit Message:
ULTIMA8: Add keycolor to shape frame in place of a mask array
The keycolor is detected on frame load, but will be 0xFF by default as that value is not known to be used in Ultima or Crusader for any shape. This saves around 3mb in Ultima and 10mb on Crusader of memory that was previously used for the mask arrays. Additionally, with this change the shape frames are easier to use with other graphics methods such as cursors.
Changed paths:
engines/ultima/ultima8/graphics/shape_frame.cpp
engines/ultima/ultima8/graphics/shape_frame.h
engines/ultima/ultima8/graphics/soft_render_surface.inl
diff --git a/engines/ultima/ultima8/graphics/shape_frame.cpp b/engines/ultima/ultima8/graphics/shape_frame.cpp
index 9adb79f0a3b..b62c900876d 100644
--- a/engines/ultima/ultima8/graphics/shape_frame.cpp
+++ b/engines/ultima/ultima8/graphics/shape_frame.cpp
@@ -29,10 +29,27 @@ namespace Ultima8 {
ShapeFrame::ShapeFrame(const RawShapeFrame *rawframe) :
_xoff(rawframe->_xoff), _yoff(rawframe->_yoff),
- _width(rawframe->_width), _height(rawframe->_height) {
+ _width(rawframe->_width), _height(rawframe->_height),
+ _keycolor(0xFF) {
_pixels = new uint8[_width * _height]();
- _mask = new uint8[_width * _height]();
+
+ // load adjusting keycolor until success
+ if (!load(rawframe, _keycolor)) {
+ _keycolor = 0;
+ while (!load(rawframe, _keycolor) && _keycolor < 0xFF) {
+ _keycolor++;
+ }
+ }
+}
+
+ShapeFrame::~ShapeFrame() {
+ delete [] _pixels;
+}
+
+bool ShapeFrame::load(const RawShapeFrame *rawframe, uint8 keycolor) {
+ bool result = true;
+ memset(_pixels, keycolor, _width * _height);
for (int y = 0; y < _height; y++) {
int32 xpos = 0;
@@ -53,8 +70,9 @@ ShapeFrame::ShapeFrame(const RawShapeFrame *rawframe) :
}
for (int doff = 0; doff < dlen; doff++) {
+ if (*linedata == keycolor)
+ result = false;
_pixels[y * _width + xpos + doff] = *linedata;
- _mask[y * _width + xpos + doff] = 1;
if (!type) {
linedata++;
}
@@ -66,14 +84,8 @@ ShapeFrame::ShapeFrame(const RawShapeFrame *rawframe) :
}
} while (xpos < _width);
-
}
-
-}
-
-ShapeFrame::~ShapeFrame() {
- delete [] _pixels;
- delete [] _mask;
+ return result;
}
// Checks to see if the frame has a pixel at the point
@@ -86,7 +98,7 @@ bool ShapeFrame::hasPoint(int32 x, int32 y) const {
if (x < 0 || y < 0 || x >= _width || y >= _height)
return false;
- return _mask[y * _width + x] != 0;
+ return _pixels[y * _width + x] != _keycolor;
}
// Get the pixel at the point
@@ -97,7 +109,7 @@ uint8 ShapeFrame::getPixelAtPoint(int32 x, int32 y) const {
// First gross culling based on dims
if (x < 0 || y < 0 || x >= _width || y >= _height)
- return 0xFF;
+ return _keycolor;
return _pixels[y * _width + x];
}
diff --git a/engines/ultima/ultima8/graphics/shape_frame.h b/engines/ultima/ultima8/graphics/shape_frame.h
index f3dee252e84..a4098c78194 100644
--- a/engines/ultima/ultima8/graphics/shape_frame.h
+++ b/engines/ultima/ultima8/graphics/shape_frame.h
@@ -38,11 +38,20 @@ public:
int32 _xoff, _yoff;
uint8 *_pixels;
- uint8 *_mask;
+ uint8 _keycolor;
bool hasPoint(int32 x, int32 y) const; // Check to see if a point is in the frame
uint8 getPixelAtPoint(int32 x, int32 y) const; // Get the pixel at the point
+
+private:
+ /**
+ * Load the pixel data from the raw shape rle data using key color for transparency
+ * @param rawframe the raw shape to load rle data
+ * @param keycolor the color representing transparency
+ * @return false if the keycolor is found in the raw shape frame data
+ */
+ bool load(const RawShapeFrame *rawframe, uint8 keycolor);
};
} // End of namespace Ultima8
diff --git a/engines/ultima/ultima8/graphics/soft_render_surface.inl b/engines/ultima/ultima8/graphics/soft_render_surface.inl
index c7af6ba6081..064283693e4 100644
--- a/engines/ultima/ultima8/graphics/soft_render_surface.inl
+++ b/engines/ultima/ultima8/graphics/soft_render_surface.inl
@@ -174,7 +174,7 @@ const int32 neg = (FLIP_CONDITIONAL)?-1:0;
if (!frame)
return;
const uint8 *srcpixels = frame->_pixels;
- const uint8 *srcmask = frame->_mask;
+ const uint8 keycolor = frame->_keycolor;
const uint32 *pal = untformed_pal ?
s->getPalette()->_native_untransformed:
s->getPalette()->_native;
@@ -190,19 +190,18 @@ const int32 neg = (FLIP_CONDITIONAL)?-1:0;
x -= XNEG(frame->_xoff);
y -= frame->_yoff;
- assert(_pixels00 && _pixels && srcpixels && srcmask);
+ assert(_pixels00 && _pixels && srcpixels);
for (int i = 0; i < height_; i++) {
const int line = y + i;
if (NOT_CLIPPED_Y) {
const uint8 *srcline = srcpixels + i * width_;
- const uint8 *srcmaskline = srcmask + i * width_;
uintX *dst_line_start = reinterpret_cast<uintX *>(OFFSET_PIXELS + _pitch * line);
LINE_END_ASSIGN;
for (int xpos = 0; xpos < width_; xpos++) {
- if (srcmaskline[xpos] == 0)
+ if (srcline[xpos] == keycolor)
continue;
uintX *dstpix = dst_line_start + x + XNEG(xpos);
More information about the Scummvm-git-logs
mailing list