From 3b542cea53b94bc10592a618f60c4f813e518b60 Mon Sep 17 00:00:00 2001 From: Thierry Crozat Date: Sun, 21 Oct 2018 18:35:40 +0100 Subject: SURFACESDL: Respect filtering setting when performing aspect ratio correction --- graphics/scaler/aspect.cpp | 50 ++++++++++++++++++++++++++++++++++------------ graphics/scaler/aspect.h | 6 ++++-- 2 files changed, 41 insertions(+), 15 deletions(-) (limited to 'graphics') diff --git a/graphics/scaler/aspect.cpp b/graphics/scaler/aspect.cpp index b923442163..f85d043a83 100644 --- a/graphics/scaler/aspect.cpp +++ b/graphics/scaler/aspect.cpp @@ -158,8 +158,10 @@ static inline void interpolate5Line(uint16 *dst, const uint16 *srcA, const uint1 } #endif -void makeRectStretchable(int &x, int &y, int &w, int &h) { +void makeRectStretchable(int &x, int &y, int &w, int &h, bool interpolate) { #if ASPECT_MODE != kSuperFastAndUglyAspectMode + if (!interpolate) + return; int m = real2Aspect(y) % 6; // Ensure that the rect will start on a line that won't have its @@ -203,8 +205,9 @@ void makeRectStretchable(int &x, int &y, int &w, int &h) { * srcY + height - 1, and it should be stretched to Y coordinates srcY * through real2Aspect(srcY + height - 1). */ + template -int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY) { +int stretch200To240Nearest(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY) { int maxDstY = real2Aspect(origSrcY + height - 1); int y; const uint8 *startSrcPtr = buf + srcX * 2 + (srcY - origSrcY) * pitch; @@ -212,13 +215,25 @@ int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, i for (y = maxDstY; y >= srcY; y--) { const uint8 *srcPtr = startSrcPtr + aspect2Real(y) * pitch; - -#if ASPECT_MODE == kSuperFastAndUglyAspectMode if (srcPtr == dstPtr) break; memcpy(dstPtr, srcPtr, sizeof(uint16) * width); -#else - // Bilinear filter + dstPtr -= pitch; + } + + return 1 + maxDstY - srcY; +} + + +template +int stretch200To240Interpolated(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY) { + int maxDstY = real2Aspect(origSrcY + height - 1); + int y; + const uint8 *startSrcPtr = buf + srcX * 2 + (srcY - origSrcY) * pitch; + uint8 *dstPtr = buf + srcX * 2 + maxDstY * pitch; + + for (y = maxDstY; y >= srcY; y--) { + const uint8 *srcPtr = startSrcPtr + aspect2Real(y) * pitch; switch (y % 6) { case 0: case 5: @@ -238,22 +253,31 @@ int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, i interpolate5Line((uint16 *)dstPtr, (const uint16 *)srcPtr, (const uint16 *)(srcPtr - pitch), width); break; } -#endif dstPtr -= pitch; } return 1 + maxDstY - srcY; } -int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY) { +int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY, bool interpolate) { extern int gBitFormat; - if (gBitFormat == 565) - return stretch200To240 >(buf, pitch, width, height, srcX, srcY, origSrcY); - else // gBitFormat == 555 - return stretch200To240 >(buf, pitch, width, height, srcX, srcY, origSrcY); +#if ASPECT_MODE != kSuperFastAndUglyAspectMode + if (interpolate) { + if (gBitFormat == 565) + return stretch200To240Interpolated >(buf, pitch, width, height, srcX, srcY, origSrcY); + else // gBitFormat == 555 + return stretch200To240Interpolated >(buf, pitch, width, height, srcX, srcY, origSrcY); + } else { +#endif + if (gBitFormat == 565) + return stretch200To240Nearest >(buf, pitch, width, height, srcX, srcY, origSrcY); + else // gBitFormat == 555 + return stretch200To240Nearest >(buf, pitch, width, height, srcX, srcY, origSrcY); +#if ASPECT_MODE != kSuperFastAndUglyAspectMode + } +#endif } - template void Normal1xAspectTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { diff --git a/graphics/scaler/aspect.h b/graphics/scaler/aspect.h index 30e13c93cd..bb082ebba0 100644 --- a/graphics/scaler/aspect.h +++ b/graphics/scaler/aspect.h @@ -43,18 +43,20 @@ FORCEINLINE int aspect2Real(int y) { /** * TODO: explain */ -void makeRectStretchable(int &x, int &y, int &w, int &h); +void makeRectStretchable(int &x, int &y, int &w, int &h, bool interpolate); /** * TODO: explain */ + int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, - int origSrcY); + int origSrcY, + bool interpolate); /** -- cgit v1.2.3