Graphics: Add flipHorizontal to Surface

This complements flipVertical and is needed for the AGS engine.
This commit is contained in:
Thierry Crozat 2022-12-15 18:46:48 +01:00
parent 54e99b36e9
commit 31d76cd039
2 changed files with 20 additions and 0 deletions

View file

@ -419,6 +419,19 @@ void Surface::flipVertical(const Common::Rect &r) {
delete[] temp;
}
void Surface::flipHorizontal(const Common::Rect &r) {
uint32 tmp = 0;
const int width = r.width() * format.bytesPerPixel;
for (int y = r.top; y < r.bottom; ++y) {
byte *row = (byte *)getBasePtr(r.left, y);
for (int x = 0; x < width / 2; x += format.bytesPerPixel) {
memcpy(&tmp, row + x, format.bytesPerPixel);
memcpy(row + x, row + width - format.bytesPerPixel - x, format.bytesPerPixel);
memcpy(row + width - format.bytesPerPixel - x, &tmp, format.bytesPerPixel);
}
}
}
Graphics::Surface *Surface::scale(int16 newWidth, int16 newHeight, bool filtering) const {
Graphics::Surface *target = new Graphics::Surface();