2003-09-29 16:02:47 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2001-2006 The ScummVM project
|
2003-09-29 16:02:47 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-09-29 16:02:47 +00:00
|
|
|
*
|
2006-02-11 09:53:53 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-09-29 16:02:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/scaler/intern.h"
|
2003-11-06 23:54:12 +00:00
|
|
|
#include "common/scaler.h"
|
2003-09-29 16:02:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define kVeryFastAndUglyAspectMode 0 // No interpolation at all, but super-fast
|
|
|
|
#define kFastAndNiceAspectMode 1 // Quite good quality with good speed
|
|
|
|
#define kSlowAndPerfectAspectMode 2 // Accurate but slow code
|
|
|
|
|
|
|
|
#define ASPECT_MODE kFastAndNiceAspectMode
|
|
|
|
|
|
|
|
|
|
|
|
#if ASPECT_MODE == kSlowAndPerfectAspectMode
|
|
|
|
|
2003-09-29 18:38:51 +00:00
|
|
|
template<int bitFormat, int scale>
|
2003-09-29 16:02:47 +00:00
|
|
|
static inline uint16 interpolate5(uint16 A, uint16 B) {
|
|
|
|
uint16 r = (uint16)(((A & redblueMask & 0xFF00) * scale + (B & redblueMask & 0xFF00) * (5 - scale)) / 5);
|
|
|
|
uint16 g = (uint16)(((A & greenMask) * scale + (B & greenMask) * (5 - scale)) / 5);
|
|
|
|
uint16 b = (uint16)(((A & redblueMask & 0x00FF) * scale + (B & redblueMask & 0x00FF) * (5 - scale)) / 5);
|
|
|
|
|
|
|
|
return (uint16)((r & redblueMask & 0xFF00) | (g & greenMask) | (b & redblueMask & 0x00FF));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-29 18:38:51 +00:00
|
|
|
template<int bitFormat, int scale>
|
2003-09-29 16:02:47 +00:00
|
|
|
static inline void interpolate5Line(uint16 *dst, const uint16 *srcA, const uint16 *srcB, int width) {
|
|
|
|
// Accurate but slightly slower code
|
|
|
|
while (width--) {
|
2003-09-29 18:38:51 +00:00
|
|
|
*dst++ = interpolate5<bitFormat, scale>(*srcA++, *srcB++);
|
2003-09-29 16:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ASPECT_MODE == kFastAndNiceAspectMode
|
|
|
|
|
2003-09-29 18:38:51 +00:00
|
|
|
template<int bitFormat>
|
2003-09-29 16:02:47 +00:00
|
|
|
static inline uint32 INTERPOLATE_1_1(uint32 A, uint32 B) {
|
2003-09-29 18:38:51 +00:00
|
|
|
return (((A & highBits) >> 1) + ((B & highBits) >> 1) + (A & B & lowBits));
|
2003-09-29 16:02:47 +00:00
|
|
|
}
|
|
|
|
|
2003-09-29 18:38:51 +00:00
|
|
|
template<int bitFormat>
|
2003-09-29 16:02:47 +00:00
|
|
|
static inline uint32 INTERPOLATE_1_3(uint32 A, uint32 B) {
|
2003-09-29 18:38:51 +00:00
|
|
|
register uint32 x = ((A & qhighBits) >> 2) + ((B & qhighBits) >> 2) * 3;
|
|
|
|
register uint32 y = ((A & qlowBits) + (B & qlowBits) * 3) >> 2;
|
2003-09-29 16:02:47 +00:00
|
|
|
|
2003-09-29 18:38:51 +00:00
|
|
|
y &= qlowBits;
|
2003-09-29 16:02:47 +00:00
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
|
2003-09-29 18:38:51 +00:00
|
|
|
template<int bitFormat, int scale>
|
2003-09-29 16:02:47 +00:00
|
|
|
static inline void interpolate5Line(uint16 *dst, const uint16 *srcA, const uint16 *srcB, int width) {
|
|
|
|
// For efficiency reasons we blit two pixels at a time, so it is important
|
|
|
|
// that makeRectStretchable() guarantees that the width is even and that
|
|
|
|
// the rect starts on a well-aligned address. (Even where unaligned memory
|
|
|
|
// access is allowed there may be a speed penalty for it.)
|
|
|
|
|
|
|
|
// These asserts are disabled for maximal speed; but I leave them in here
|
|
|
|
// in case other people want to test if the memory alignment (to an
|
|
|
|
// address divisible by 4) is really working properly.
|
|
|
|
//assert(((int)dst & 3) == 0);
|
|
|
|
//assert(((int)srcA & 3) == 0);
|
|
|
|
//assert(((int)srcB & 3) == 0);
|
|
|
|
//assert((width & 1) == 0);
|
|
|
|
|
|
|
|
width /= 2;
|
|
|
|
const uint32 *sA = (const uint32 *)srcA;
|
|
|
|
const uint32 *sB = (const uint32 *)srcB;
|
|
|
|
uint32 *d = (uint32 *)dst;
|
|
|
|
if (scale == 1) {
|
|
|
|
while (width--) {
|
2003-09-29 18:38:51 +00:00
|
|
|
*d++ = INTERPOLATE_1_3<bitFormat>(*sA++, *sB++);
|
2003-09-29 16:02:47 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (width--) {
|
2003-09-29 18:38:51 +00:00
|
|
|
*d++ = INTERPOLATE_1_1<bitFormat>(*sA++, *sB++);
|
2003-09-29 16:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void makeRectStretchable(int &x, int &y, int &w, int &h) {
|
|
|
|
#if ASPECT_MODE != kVeryFastAndUglyAspectMode
|
|
|
|
int m = real2Aspect(y) % 6;
|
|
|
|
|
|
|
|
// Ensure that the rect will start on a line that won't have its
|
|
|
|
// colours changed by the stretching function.
|
|
|
|
if (m != 0 && m != 5) {
|
|
|
|
y -= m;
|
|
|
|
h += m;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ASPECT_MODE == kFastAndNiceAspectMode
|
|
|
|
// Force x to be even, to ensure aligned memory access (this assumes
|
|
|
|
// that each line starts at an even memory location, but that should
|
|
|
|
// be the case on every target anyway).
|
|
|
|
if (x & 1) {
|
|
|
|
x--;
|
|
|
|
w++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally force the width to be even, since we blit 2 pixels at a time.
|
|
|
|
// While this means we may sometimes blit one column more than necessary,
|
2005-07-30 21:11:48 +00:00
|
|
|
// this should actually be faster than having the check for the
|
2003-09-29 16:02:47 +00:00
|
|
|
if (w & 1)
|
|
|
|
w++;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stretch a 16bpp image vertically by factor 1.2. Used to correct the
|
|
|
|
* aspect-ratio in games using 320x200 pixel graphics with non-qudratic
|
|
|
|
* pixels. Applying this method effectively turns that into 320x240, which
|
|
|
|
* provides the correct aspect-ratio on modern displays.
|
|
|
|
*
|
|
|
|
* The image would normally have occupied y coordinates origSrcY through
|
|
|
|
* origSrcY + height - 1.
|
|
|
|
*
|
|
|
|
* However, we have already placed it at srcY - the aspect-corrected y
|
|
|
|
* coordinate - to allow in-place stretching.
|
|
|
|
*
|
|
|
|
* Therefore, the source image now occupies Y coordinates srcY through
|
|
|
|
* srcY + height - 1, and it should be stretched to Y coordinates srcY
|
|
|
|
* through real2Aspect(srcY + height - 1).
|
|
|
|
*/
|
2003-09-29 18:38:51 +00:00
|
|
|
template<int bitFormat>
|
2003-09-29 16:02:47 +00:00
|
|
|
int stretch200To240(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;
|
|
|
|
|
|
|
|
#if ASPECT_MODE == kVeryFastAndUglyAspectMode
|
|
|
|
if (srcPtr == dstPtr)
|
|
|
|
break;
|
|
|
|
memcpy(dstPtr, srcPtr, width * 2);
|
|
|
|
#else
|
|
|
|
// Bilinear filter
|
|
|
|
switch (y % 6) {
|
|
|
|
case 0:
|
|
|
|
case 5:
|
|
|
|
if (srcPtr != dstPtr)
|
|
|
|
memcpy(dstPtr, srcPtr, width * 2);
|
|
|
|
break;
|
|
|
|
case 1:
|
2003-09-29 18:38:51 +00:00
|
|
|
interpolate5Line<bitFormat, 1>((uint16 *)dstPtr, (const uint16 *)(srcPtr - pitch), (const uint16 *)srcPtr, width);
|
2003-09-29 16:02:47 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2003-09-29 18:38:51 +00:00
|
|
|
interpolate5Line<bitFormat, 2>((uint16 *)dstPtr, (const uint16 *)(srcPtr - pitch), (const uint16 *)srcPtr, width);
|
2003-09-29 16:02:47 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2003-09-29 18:38:51 +00:00
|
|
|
interpolate5Line<bitFormat, 2>((uint16 *)dstPtr, (const uint16 *)srcPtr, (const uint16 *)(srcPtr - pitch), width);
|
2003-09-29 16:02:47 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2003-09-29 18:38:51 +00:00
|
|
|
interpolate5Line<bitFormat, 1>((uint16 *)dstPtr, (const uint16 *)srcPtr, (const uint16 *)(srcPtr - pitch), width);
|
2003-09-29 16:02:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
dstPtr -= pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1 + maxDstY - srcY;
|
|
|
|
}
|
2003-09-29 18:38:51 +00:00
|
|
|
|
|
|
|
int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY) {
|
|
|
|
if (gBitFormat == 565)
|
|
|
|
return stretch200To240<565>(buf, pitch, width, height, srcX, srcY, origSrcY);
|
|
|
|
else // gBitFormat == 555
|
|
|
|
return stretch200To240<555>(buf, pitch, width, height, srcX, srcY, origSrcY);
|
|
|
|
}
|
|
|
|
|