GRAPHICS: Ensure that creating a ManagedSurface from another preserves the palette

This commit is contained in:
Cameron Cawley 2020-05-06 23:16:45 +01:00 committed by Eugene Sandulenko
parent 731596b5f7
commit 80430b4756
2 changed files with 19 additions and 0 deletions

View File

@ -90,6 +90,12 @@ ManagedSurface &ManagedSurface::operator=(const ManagedSurface &surf) {
_innerSurface.h = surf.h;
_innerSurface.pitch = surf.pitch;
this->format = surf.format;
// Copy miscellaneous properties
_transparentColorSet = surf._transparentColorSet;
_transparentColor = surf._transparentColor;
_paletteSet = surf._paletteSet;
Common::copy(&surf._palette[0], &surf._palette[256], _palette);
}
return *this;
@ -123,6 +129,12 @@ void ManagedSurface::create(ManagedSurface &surf, const Common::Rect &bounds) {
_innerSurface.h = bounds.height();
_owner = &surf;
_disposeAfterUse = DisposeAfterUse::NO;
// Copy miscellaneous properties
_transparentColorSet = surf._transparentColorSet;
_transparentColor = surf._transparentColor;
_paletteSet = surf._paletteSet;
Common::copy(&surf._palette[0], &surf._palette[256], _palette);
}
void ManagedSurface::free() {
@ -568,12 +580,18 @@ void ManagedSurface::setPalette(const byte *colors, uint start, uint num) {
}
_paletteSet = true;
if (_owner)
_owner->setPalette(colors, start, num);
}
void ManagedSurface::setPalette(const uint32 *colors, uint start, uint num) {
assert(start < 256 && (start + num) <= 256);
Common::copy(colors, colors + num, &_palette[start]);
_paletteSet = true;
if (_owner)
_owner->setPalette(colors, start, num);
}
} // End of namespace Graphics

View File

@ -122,6 +122,7 @@ void Screen::setPalette(const byte palette[PALETTE_SIZE]) {
void Screen::setPalette(const byte *palette, uint start, uint num) {
assert(format.bytesPerPixel == 1);
g_system->getPaletteManager()->setPalette(palette, start, num);
ManagedSurface::setPalette(palette, start, num);
}
void Screen::clearPalette() {