diff --git a/widget/include/Cevo/CevoScreenTools.h b/widget/include/Cevo/CevoScreenTools.h index 3bb060c..4c45b02 100644 --- a/widget/include/Cevo/CevoScreenTools.h +++ b/widget/include/Cevo/CevoScreenTools.h @@ -113,6 +113,9 @@ enum class RasterOp { Copy, And, Paint, Invert }; void bitBltBitmap(Dpi::Bitmap &dest, int x, int y, int width, int height, Dpi::Bitmap &src, int xSrc, int ySrc, RasterOp rop = RasterOp::Copy); void unshareBitmap(Dpi::Bitmap &bitmap); +// Replaces every pixel equal to oldColor with newColor within the given +// rectangle (both already-resolved QColors, not raw Delphi ints). +void bitmapReplaceColor(Dpi::Bitmap &dst, int x, int y, int width, int height, QColor oldColor, QColor newColor); // Draws a masked sprite (AND then OR, via an internal scratch buffer since // Qt's QPainter has no raster-op compositing against the live canvas). diff --git a/widget/src/CevoScreenTools.cpp b/widget/src/CevoScreenTools.cpp index ae90512..a4b75c3 100644 --- a/widget/src/CevoScreenTools.cpp +++ b/widget/src/CevoScreenTools.cpp @@ -217,6 +217,21 @@ void bitBltBitmap(Dpi::Bitmap &dest, int x, int y, int width, int height, void unshareBitmap(Dpi::Bitmap &) {} +void bitmapReplaceColor(Dpi::Bitmap &dst, int x, int y, int width, int height, QColor oldColor, QColor newColor) +{ + const QRgb oldRgb = oldColor.rgb() & 0xFFFFFFu; + const QRgb newRgb = newColor.rgb() & 0xFFFFFFu; + Dpi::PixelPointer pixel(&dst.image(), x, y); + for (int yy = 0; yy < height; ++yy) { + for (int xx = 0; xx < width; ++xx) { + if ((pixel.pixelRGB() & 0xFFFFFFu) == oldRgb) + pixel.setPixelRGB(newRgb); + pixel.nextPixel(); + } + pixel.nextLine(); + } +} + void sprite(Dpi::Canvas &canvas, GraphicSet &graphicSet, int xDst, int yDst, int width, int height, int xGr, int yGr) {