[Scummvm-cvs-logs] CVS: scummvm/common/scaler 2xsai.cpp,1.1,1.2 aspect.cpp,1.1,1.2 hq2x.cpp,1.1,1.2 hq3x.cpp,1.1,1.2 intern.h,1.1,1.2
Max Horn
fingolfin at users.sourceforge.net
Mon Sep 29 11:40:06 CEST 2003
Update of /cvsroot/scummvm/scummvm/common/scaler
In directory sc8-pr-cvs1:/tmp/cvs-serv5779/scaler
Modified Files:
2xsai.cpp aspect.cpp hq2x.cpp hq3x.cpp intern.h
Log Message:
templatized more of the scalers; also introduced template struct ColorMasks (shortens/simplifies other code a bit)
Index: 2xsai.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/scaler/2xsai.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- 2xsai.cpp 29 Sep 2003 16:02:47 -0000 1.1
+++ 2xsai.cpp 29 Sep 2003 18:38:51 -0000 1.2
@@ -22,6 +22,8 @@
#include "common/scaler/intern.h"
+
+
static inline int GetResult(uint32 A, uint32 B, uint32 C, uint32 D) {
const bool ac = (A==C);
const bool bc = (B==C);
@@ -41,18 +43,25 @@
return rmap[y][x];
}
+template<int bitFormat>
static inline uint32 INTERPOLATE(uint32 A, uint32 B) {
- return (((A & colorMask) >> 1) + ((B & colorMask) >> 1) + (A & B & lowPixelMask));
+
+ return (((A & highBits) >> 1) + ((B & highBits) >> 1) + (A & B & lowBits));
}
+template<int bitFormat>
static inline uint32 Q_INTERPOLATE(uint32 A, uint32 B, uint32 C, uint32 D) {
- register uint32 x = ((A & qcolorMask) >> 2) + ((B & qcolorMask) >> 2) + ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2);
- register uint32 y = ((A & qlowpixelMask) + (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask)) >> 2;
+ register uint32 x = ((A & qhighBits) >> 2) + ((B & qhighBits) >> 2) + ((C & qhighBits) >> 2) + ((D & qhighBits) >> 2);
+ register uint32 y = ((A & qlowBits) + (B & qlowBits) + (C & qlowBits) + (D & qlowBits)) >> 2;
- y &= qlowpixelMask;
+ y &= qlowBits;
return x + y;
}
+#define INTERPOLATE INTERPOLATE<bitFormat>
+#define Q_INTERPOLATE Q_INTERPOLATE<bitFormat>
+
+template<int bitFormat>
void Super2xSaI(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) {
const uint16 *bP;
uint16 *dP;
@@ -159,6 +168,9 @@
}
}
+MAKE_WRAPPER(Super2xSaI)
+
+template<int bitFormat>
void SuperEagle(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) {
const uint16 *bP;
uint16 *dP;
@@ -267,6 +279,9 @@
}
}
+MAKE_WRAPPER(SuperEagle)
+
+template<int bitFormat>
void _2xSaI(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) {
const uint16 *bP;
uint16 *dP;
@@ -399,3 +414,5 @@
dstPtr += dstPitch * 2;
}
}
+
+MAKE_WRAPPER(_2xSaI)
Index: aspect.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/scaler/aspect.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- aspect.cpp 29 Sep 2003 16:02:47 -0000 1.1
+++ aspect.cpp 29 Sep 2003 18:38:51 -0000 1.2
@@ -32,7 +32,7 @@
#if ASPECT_MODE == kSlowAndPerfectAspectMode
-template<int scale>
+template<int bitFormat, int scale>
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);
@@ -42,30 +42,32 @@
}
-template<int scale>
+template<int bitFormat, int scale>
static inline void interpolate5Line(uint16 *dst, const uint16 *srcA, const uint16 *srcB, int width) {
// Accurate but slightly slower code
while (width--) {
- *dst++ = interpolate5<scale>(*srcA++, *srcB++);
+ *dst++ = interpolate5<bitFormat, scale>(*srcA++, *srcB++);
}
}
#endif
#if ASPECT_MODE == kFastAndNiceAspectMode
+template<int bitFormat>
static inline uint32 INTERPOLATE_1_1(uint32 A, uint32 B) {
- return (((A & colorMask) >> 1) + ((B & colorMask) >> 1) + (A & B & lowPixelMask));
+ return (((A & highBits) >> 1) + ((B & highBits) >> 1) + (A & B & lowBits));
}
+template<int bitFormat>
static inline uint32 INTERPOLATE_1_3(uint32 A, uint32 B) {
- register uint32 x = ((A & qcolorMask) >> 2) + ((B & qcolorMask) >> 2) * 3;
- register uint32 y = ((A & qlowpixelMask) + (B & qlowpixelMask) * 3) >> 2;
+ register uint32 x = ((A & qhighBits) >> 2) + ((B & qhighBits) >> 2) * 3;
+ register uint32 y = ((A & qlowBits) + (B & qlowBits) * 3) >> 2;
- y &= qlowpixelMask;
+ y &= qlowBits;
return x + y;
}
-template<int scale>
+template<int bitFormat, int scale>
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
@@ -86,11 +88,11 @@
uint32 *d = (uint32 *)dst;
if (scale == 1) {
while (width--) {
- *d++ = INTERPOLATE_1_3(*sA++, *sB++);
+ *d++ = INTERPOLATE_1_3<bitFormat>(*sA++, *sB++);
}
} else {
while (width--) {
- *d++ = INTERPOLATE_1_1(*sA++, *sB++);
+ *d++ = INTERPOLATE_1_1<bitFormat>(*sA++, *sB++);
}
}
}
@@ -141,6 +143,7 @@
* srcY + height - 1, and it should be stretched to Y coordinates srcY
* through real2Aspect(srcY + height - 1).
*/
+template<int bitFormat>
int stretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY) {
int maxDstY = real2Aspect(origSrcY + height - 1);
int y;
@@ -163,16 +166,16 @@
memcpy(dstPtr, srcPtr, width * 2);
break;
case 1:
- interpolate5Line<1>((uint16 *)dstPtr, (const uint16 *)(srcPtr - pitch), (const uint16 *)srcPtr, width);
+ interpolate5Line<bitFormat, 1>((uint16 *)dstPtr, (const uint16 *)(srcPtr - pitch), (const uint16 *)srcPtr, width);
break;
case 2:
- interpolate5Line<2>((uint16 *)dstPtr, (const uint16 *)(srcPtr - pitch), (const uint16 *)srcPtr, width);
+ interpolate5Line<bitFormat, 2>((uint16 *)dstPtr, (const uint16 *)(srcPtr - pitch), (const uint16 *)srcPtr, width);
break;
case 3:
- interpolate5Line<2>((uint16 *)dstPtr, (const uint16 *)srcPtr, (const uint16 *)(srcPtr - pitch), width);
+ interpolate5Line<bitFormat, 2>((uint16 *)dstPtr, (const uint16 *)srcPtr, (const uint16 *)(srcPtr - pitch), width);
break;
case 4:
- interpolate5Line<1>((uint16 *)dstPtr, (const uint16 *)srcPtr, (const uint16 *)(srcPtr - pitch), width);
+ interpolate5Line<bitFormat, 1>((uint16 *)dstPtr, (const uint16 *)srcPtr, (const uint16 *)(srcPtr - pitch), width);
break;
}
#endif
@@ -181,3 +184,11 @@
return 1 + maxDstY - srcY;
}
+
+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);
+}
+
Index: hq2x.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/scaler/hq2x.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- hq2x.cpp 29 Sep 2003 16:02:47 -0000 1.1
+++ hq2x.cpp 29 Sep 2003 18:38:51 -0000 1.2
@@ -1929,9 +1929,4 @@
}
}
-void HQ2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) {
- if (gBitFormat == 565)
- HQ2x<565>(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
- else // gBitFormat == 555
- HQ2x<555>(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
-}
+MAKE_WRAPPER(HQ2x)
Index: hq3x.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/scaler/hq3x.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- hq3x.cpp 29 Sep 2003 16:02:47 -0000 1.1
+++ hq3x.cpp 29 Sep 2003 18:38:51 -0000 1.2
@@ -2927,9 +2927,4 @@
}
}
-void HQ3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) {
- if (gBitFormat == 565)
- HQ3x<565>(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
- else // gBitFormat == 555
- HQ3x<555>(srcPtr, srcPitch, dstPtr, dstPitch, width, height);
-}
+MAKE_WRAPPER(HQ3x)
Index: intern.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/scaler/intern.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- intern.h 29 Sep 2003 16:02:47 -0000 1.1
+++ intern.h 29 Sep 2003 18:38:51 -0000 1.2
@@ -30,16 +30,35 @@
#include "common/util.h"
-static const uint32 redblueMask_565 = 0xF81F;
-static const uint32 greenMask_565 = 0x07E0;
-static const uint32 redblueMask_555 = 0x7C1F;
-static const uint32 greenMask_555 = 0x03E0;
+template<int bitFormat>
+struct ColorMasks {
+};
+
+struct ColorMasks<565> {
+ static const int highBits = 0xF7DEF7DE;
+ static const int lowBits = 0x08210821;
+ static const int qhighBits = 0xE79CE79C;
+ static const int qlowBits = 0x18631863;
+ static const int redblueMask = 0xF81F;
+ static const int greenMask = 0x07E0;
+};
+struct ColorMasks<555> {
+ static const int highBits = 0x04210421;
+ static const int lowBits = 0x04210421;
+ static const int qhighBits = 0x739C739C;
+ static const int qlowBits = 0x0C630C63;
+ static const int redblueMask = 0x7C1F;
+ static const int greenMask = 0x03E0;
+};
+
+#define highBits ColorMasks<bitFormat>::highBits
+#define lowBits ColorMasks<bitFormat>::lowBits
+#define qhighBits ColorMasks<bitFormat>::qhighBits
+#define qlowBits ColorMasks<bitFormat>::qlowBits
+#define redblueMask ColorMasks<bitFormat>::redblueMask
+#define greenMask ColorMasks<bitFormat>::greenMask
-extern uint32 colorMask;
-extern uint32 lowPixelMask;
-extern uint32 qcolorMask;
-extern uint32 qlowpixelMask;
extern int gBitFormat;
@@ -50,12 +69,8 @@
*/
template<int bitFormat, int w1, int w2>
static inline uint16 interpolate16_2(uint16 p1, uint16 p2) {
- if (bitFormat == 565)
- return ((((p1 & redblueMask_565) * w1 + (p2 & redblueMask_565) * w2) / (w1 + w2)) & redblueMask_565) |
- ((((p1 & greenMask_565) * w1 + (p2 & greenMask_565) * w2) / (w1 + w2)) & greenMask_565);
- else // bitFormat == 555
- return ((((p1 & redblueMask_555) * w1 + (p2 & redblueMask_555) * w2) / (w1 + w2)) & redblueMask_555) |
- ((((p1 & greenMask_555) * w1 + (p2 & greenMask_555) * w2) / (w1 + w2)) & greenMask_555);
+ return ((((p1 & redblueMask) * w1 + (p2 & redblueMask) * w2) / (w1 + w2)) & redblueMask) |
+ ((((p1 & greenMask) * w1 + (p2 & greenMask) * w2) / (w1 + w2)) & greenMask);
}
/**
@@ -64,12 +79,8 @@
*/
template<int bitFormat, int w1, int w2, int w3>
static inline uint16 interpolate16_3(uint16 p1, uint16 p2, uint16 p3) {
- if (bitFormat == 565)
- return ((((p1 & redblueMask_565) * w1 + (p2 & redblueMask_565) * w2 + (p3 & redblueMask_565) * w3) / (w1 + w2 + w3)) & redblueMask_565) |
- ((((p1 & greenMask_565) * w1 + (p2 & greenMask_565) * w2 + (p3 & greenMask_565) * w3) / (w1 + w2 + w3)) & greenMask_565);
- else // bitFormat == 555
- return ((((p1 & redblueMask_555) * w1 + (p2 & redblueMask_555) * w2 + (p3 & redblueMask_555) * w3) / (w1 + w2 + w3)) & redblueMask_555) |
- ((((p1 & greenMask_555) * w1 + (p2 & greenMask_555) * w2 + (p3 & greenMask_555) * w3) / (w1 + w2 + w3)) & greenMask_555);
+ return ((((p1 & redblueMask) * w1 + (p2 & redblueMask) * w2 + (p3 & redblueMask) * w3) / (w1 + w2 + w3)) & redblueMask) |
+ ((((p1 & greenMask) * w1 + (p2 & greenMask) * w2 + (p3 & greenMask) * w3) / (w1 + w2 + w3)) & greenMask);
}
@@ -96,5 +107,14 @@
* Used by the hq scaler family.
*/
extern int RGBtoYUV[65536];
+
+/** Auxiliary macro to simplify creating those template function wrappers. */
+#define MAKE_WRAPPER(FUNC) \
+ void FUNC(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { \
+ if (gBitFormat == 565) \
+ FUNC<565>(srcPtr, srcPitch, dstPtr, dstPitch, width, height); \
+ else \
+ FUNC<555>(srcPtr, srcPitch, dstPtr, dstPitch, width, height); \
+ }
#endif
More information about the Scummvm-git-logs
mailing list