GRAPHICS: Ensure that ManagedSurface transparent colours are converted

This commit is contained in:
Cameron Cawley
2025-10-14 14:26:25 +01:00
committed by Filippos Karapetis
parent 1c25b17517
commit 18e4df9a8f
2 changed files with 28 additions and 4 deletions
+25 -1
View File
@@ -245,6 +245,20 @@ void ManagedSurface::copyFrom(const Surface &surf) {
}
}
uint32 ManagedSurface::convertTransparentColor(const ManagedSurface &surf, const PixelFormat &dstFmt) const {
if (surf.format == dstFmt) {
return surf._transparentColor;
} else if (surf.format.isCLUT8()) {
byte r, g, b;
surf._palette->get(surf._transparentColor, r, g, b);
return dstFmt.RGBToColor(r, g, b);
} else {
byte a, r, g, b;
surf.format.colorToARGB(surf._transparentColor, a, r, g, b);
return dstFmt.ARGBToColor(a, r, g, b);
}
}
void ManagedSurface::convertFrom(const ManagedSurface &surf, const PixelFormat &fmt) {
// Surface::copyFrom frees pixel pointer so let's free up ManagedSurface to be coherent
free();
@@ -258,7 +272,7 @@ void ManagedSurface::convertFrom(const ManagedSurface &surf, const PixelFormat &
// Copy miscellaneous properties
_transparentColorSet = surf._transparentColorSet;
_transparentColor = surf._transparentColor;
_transparentColor = convertTransparentColor(surf, fmt);
_palette = (fmt.isCLUT8() && surf._palette) ? new Palette(*surf._palette) : nullptr;
}
@@ -282,6 +296,16 @@ void ManagedSurface::convertFrom(const Surface &surf, const PixelFormat &fmt) {
}
}
void ManagedSurface::convertToInPlace(const PixelFormat &dstFormat) {
// Convert miscellaneous properties
_transparentColor = convertTransparentColor(*this, dstFormat);
if (_palette)
_innerSurface.convertToInPlace(dstFormat, _palette->data(), _palette->size());
else
_innerSurface.convertToInPlace(dstFormat);
}
Graphics::ManagedSurface *ManagedSurface::scale(int16 newWidth, int16 newHeight, bool filtering) const {
Graphics::ManagedSurface *target = new Graphics::ManagedSurface();
+3 -3
View File
@@ -120,6 +120,8 @@ protected:
const Common::Rect &destRect, const int flipping, const uint colorMod,
const TSpriteBlendMode blend, const AlphaType alphaType);
uint32 convertTransparentColor(const ManagedSurface &surf, const PixelFormat &dstFmt) const;
public:
/**
* Clip the given source bounds so the passed destBounds will be entirely on-screen.
@@ -994,9 +996,7 @@ public:
*
* @param dstFormat The desired format.
*/
void convertToInPlace(const PixelFormat &dstFormat) {
_innerSurface.convertToInPlace(dstFormat);
}
void convertToInPlace(const PixelFormat &dstFormat);
/**
* Convert the data to another pixel format.