GRAPHICS: MACGUI: add cache for inverted color.

This commit is contained in:
ysj1173886760 2021-08-16 16:58:48 +08:00
parent 50bfc4e521
commit 4133592992
3 changed files with 9 additions and 4 deletions

View File

@ -100,7 +100,6 @@ void Window::invertChannel(Channel *channel, const Common::Rect &destRect) {
byte *src = (byte *)_composeSurface->getBasePtr(srcRect.left, srcRect.top + i);
const byte *msk = mask ? (const byte *)mask->getBasePtr(xoff, yoff + i) : nullptr;
// if this will cause efficiency problem, then we shall cache the inverted color in wm
for (int j = 0; j < srcRect.width(); j++, src++)
if (!mask || (msk && !(*msk++)))
*src = _wm->inverter(*src);

View File

@ -1295,6 +1295,7 @@ void MacWindowManager::passPalette(const byte *pal, uint size) {
_paletteSize = size;
_colorHash.clear();
_invertColorHash.clear();
LOOKUPCOLOR(White);
LOOKUPCOLOR(Gray80);
@ -1355,17 +1356,21 @@ void MacWindowManager::decomposeColor(uint32 color, byte &r, byte &g, byte &b) {
}
uint MacWindowManager::inverter(uint src) {
if (_invertColorHash.contains(src))
return _invertColorHash[src];
if (_pixelformat.bytesPerPixel == 1) {
byte r, g, b;
decomposeColor(src, r, g, b);
r = ~r;
g = ~g;
b = ~b;
return findBestColor(r, g, b);
_invertColorHash[src] = findBestColor(r, g, b);
} else {
uint32 alpha = _pixelformat.ARGBToColor(255, 0, 0, 0);
return ~(src & ~alpha) | alpha;
_invertColorHash[src] = ~(src & ~alpha) | alpha;
}
return _invertColorHash[src];
}
PauseToken MacWindowManager::pauseEngine() {

View File

@ -432,7 +432,8 @@ private:
PauseToken *_screenCopyPauseToken;
Common::Array<ZoomBox *> _zoomBoxes;
Common::HashMap<uint32, uint> _colorHash;
Common::HashMap<uint, uint> _colorHash;
Common::HashMap<uint, uint> _invertColorHash;
Common::Archive *_dataBundle;