From 0e2cf28d99a79a9ae84a4d48cf0e607deacb6653 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Sat, 5 Oct 2013 00:05:25 +0200 Subject: WINTERMUTE: Speed up scale() This is a tweaked version of a patch from eriktorbjorn. --- .../wintermute/graphics/transparent_surface.cpp | 26 ++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index b03bc4264b..64102d7eb0 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -715,20 +715,28 @@ TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight) target->create((uint16)dstW, (uint16)dstH, this->format); - - float projX; - float projY; +#if ENABLE_BILINEAR for (int y = 0; y < dstH; y++) { + float projY = y / (float)dstH * srcH; for (int x = 0; x < dstW; x++) { - projX = x / (float)dstW * srcW; - projY = y / (float)dstH * srcH; -#if ENABLE_BILINEAR + float projX = x / (float)dstW * srcW; copyPixelBilinear(projX, projY, x, y, srcRect, dstRect, this, target); -#else - copyPixelNearestNeighbor(projX, projY, x, y, srcRect, dstRect, this, target); -#endif } } +#else + int *scaleCacheX = new int[dstW]; + for (int x = 0; x < dstW; x++) + scaleCacheX[x] = (x * srcW) / dstW; + + for (int y = 0; y < dstH; y++) { + uint32 *destP = (uint32 *)target->getBasePtr(0, y); + const uint32 *srcP = (const uint32 *)getBasePtr(0, (y * srcH) / dstH); + for (int x = 0; x < dstW; x++) + *destP++ = srcP[scaleCacheX[x]]; + } + delete[] scaleCacheX; +#endif + return target; } -- cgit v1.2.3