diff options
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/scaler.cpp | 14 | ||||
-rw-r--r-- | graphics/scaler/2xsai.cpp | 87 | ||||
-rw-r--r-- | graphics/scaler/aspect.cpp | 18 | ||||
-rw-r--r-- | graphics/scaler/intern.h | 23 | ||||
-rw-r--r-- | graphics/scaler/thumbnail.cpp | 4 |
5 files changed, 74 insertions, 72 deletions
diff --git a/graphics/scaler.cpp b/graphics/scaler.cpp index 1f32d4cea6..9a42dcb324 100644 --- a/graphics/scaler.cpp +++ b/graphics/scaler.cpp @@ -178,8 +178,8 @@ void Normal3x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPit } } -#define INTERPOLATE INTERPOLATE<bitFormat> -#define Q_INTERPOLATE Q_INTERPOLATE<bitFormat> +#define interpolate32_1_1 interpolate32_1_1<bitFormat> +#define interpolate32_1_1_1_1 interpolate32_1_1_1_1<bitFormat> /** * Trivial nearest-neighbour 1.5x scaler. @@ -202,13 +202,13 @@ void Normal1o5xTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uin uint16 color3 = *(((const uint16 *)(srcPtr + srcPitch)) + i + 1); *(uint16 *)(r + 0) = color0; - *(uint16 *)(r + 2) = INTERPOLATE(color0, color1); + *(uint16 *)(r + 2) = interpolate32_1_1(color0, color1); *(uint16 *)(r + 4) = color1; - *(uint16 *)(r + 0 + dstPitch) = INTERPOLATE(color0, color2); - *(uint16 *)(r + 2 + dstPitch) = Q_INTERPOLATE(color0, color1, color2, color3); - *(uint16 *)(r + 4 + dstPitch) = INTERPOLATE(color1, color3); + *(uint16 *)(r + 0 + dstPitch) = interpolate32_1_1(color0, color2); + *(uint16 *)(r + 2 + dstPitch) = interpolate32_1_1_1_1(color0, color1, color2, color3); + *(uint16 *)(r + 4 + dstPitch) = interpolate32_1_1(color1, color3); *(uint16 *)(r + 0 + dstPitch2) = color2; - *(uint16 *)(r + 2 + dstPitch2) = INTERPOLATE(color2, color3); + *(uint16 *)(r + 2 + dstPitch2) = interpolate32_1_1(color2, color3); *(uint16 *)(r + 4 + dstPitch2) = color3; } srcPtr += srcPitch2; diff --git a/graphics/scaler/2xsai.cpp b/graphics/scaler/2xsai.cpp index 539f90ab60..7ed60bc6dd 100644 --- a/graphics/scaler/2xsai.cpp +++ b/graphics/scaler/2xsai.cpp @@ -44,8 +44,9 @@ static inline int GetResult(uint32 A, uint32 B, uint32 C, uint32 D) { return rmap[y][x]; } -#define INTERPOLATE INTERPOLATE<bitFormat> -#define Q_INTERPOLATE Q_INTERPOLATE<bitFormat> +#define interpolate32_1_1 interpolate32_1_1<bitFormat> +#define interpolate32_3_1 interpolate32_3_1<bitFormat> +#define interpolate32_1_1_1_1 interpolate32_1_1_1_1<bitFormat> template<int bitFormat> void Super2xSaITemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { @@ -108,35 +109,35 @@ void Super2xSaITemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uin else if (r < 0) product2b = product1b = color5; else { - product2b = product1b = INTERPOLATE(color5, color6); + product2b = product1b = interpolate32_1_1(color5, color6); } } else { if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0) - product2b = Q_INTERPOLATE(color3, color3, color3, color2); + product2b = interpolate32_3_1(color3, color2); else if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3) - product2b = Q_INTERPOLATE(color2, color2, color2, color3); + product2b = interpolate32_3_1(color2, color3); else - product2b = INTERPOLATE(color2, color3); + product2b = interpolate32_1_1(color2, color3); if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0) - product1b = Q_INTERPOLATE(color6, color6, color6, color5); + product1b = interpolate32_3_1(color6, color5); else if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3) - product1b = Q_INTERPOLATE(color6, color5, color5, color5); + product1b = interpolate32_3_1(color5, color6); else - product1b = INTERPOLATE(color5, color6); + product1b = interpolate32_1_1(color5, color6); } if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2) - product2a = INTERPOLATE(color2, color5); + product2a = interpolate32_1_1(color2, color5); else if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0) - product2a = INTERPOLATE(color2, color5); + product2a = interpolate32_1_1(color2, color5); else product2a = color2; if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2) - product1a = INTERPOLATE(color2, color5); + product1a = interpolate32_1_1(color2, color5); else if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0) - product1a = INTERPOLATE(color2, color5); + product1a = interpolate32_1_1(color2, color5); else product1a = color5; @@ -192,43 +193,43 @@ void SuperEagleTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uin if (color2 == color6) { product1b = product2a = color2; if ((color1 == color2) || (color6 == colorB2)) { - product1a = INTERPOLATE(color2, color5); - product1a = INTERPOLATE(color2, product1a); + product1a = interpolate32_1_1(color2, color5); + product1a = interpolate32_1_1(color2, product1a); } else { - product1a = INTERPOLATE(color5, color6); + product1a = interpolate32_1_1(color5, color6); } if ((color6 == colorS2) || (color2 == colorA1)) { - product2b = INTERPOLATE(color2, color3); - product2b = INTERPOLATE(color2, product2b); + product2b = interpolate32_1_1(color2, color3); + product2b = interpolate32_1_1(color2, product2b); } else { - product2b = INTERPOLATE(color2, color3); + product2b = interpolate32_1_1(color2, color3); } } else { - product2b = product1a = INTERPOLATE(color2, color6); - product2b = Q_INTERPOLATE(color3, color3, color3, product2b); - product1a = Q_INTERPOLATE(color5, color5, color5, product1a); + product2b = product1a = interpolate32_1_1(color2, color6); + product2b = interpolate32_3_1(color3, product2b); + product1a = interpolate32_3_1(color5, product1a); - product2a = product1b = INTERPOLATE(color5, color3); - product2a = Q_INTERPOLATE(color2, color2, color2, product2a); - product1b = Q_INTERPOLATE(color6, color6, color6, product1b); + product2a = product1b = interpolate32_1_1(color5, color3); + product2a = interpolate32_3_1(color2, product2a); + product1b = interpolate32_3_1(color6, product1b); } } else { if (color2 != color6) { product2b = product1a = color5; if ((colorB1 == color5) || (color3 == colorS1)) { - product1b = INTERPOLATE(color5, color6); - product1b = INTERPOLATE(color5, product1b); + product1b = interpolate32_1_1(color5, color6); + product1b = interpolate32_1_1(color5, product1b); } else { - product1b = INTERPOLATE(color5, color6); + product1b = interpolate32_1_1(color5, color6); } if ((color3 == colorA2) || (color4 == color5)) { - product2a = INTERPOLATE(color5, color2); - product2a = INTERPOLATE(color5, product2a); + product2a = interpolate32_1_1(color5, color2); + product2a = interpolate32_1_1(color5, product2a); } else { - product2a = INTERPOLATE(color2, color3); + product2a = interpolate32_1_1(color2, color3); } } else { register int r = 0; @@ -240,10 +241,10 @@ void SuperEagleTemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uin if (r > 0) { product1b = product2a = color2; - product1a = product2b = INTERPOLATE(color5, color6); + product1a = product2b = interpolate32_1_1(color5, color6); } else if (r < 0) { product2b = product1a = color5; - product1b = product2a = INTERPOLATE(color5, color6); + product1b = product2a = interpolate32_1_1(color5, color6); } else { product2b = product1a = color5; product1b = product2a = color2; @@ -314,14 +315,14 @@ void _2xSaITemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 ((colorA == colorC) && (colorA == colorF) && (colorB != colorE) && (colorB == colorJ))) { product = colorA; } else { - product = INTERPOLATE(colorA, colorB); + product = interpolate32_1_1(colorA, colorB); } if (((colorA == colorG) && (colorC == colorO)) || ((colorA == colorB) && (colorA == colorH) && (colorG != colorC) && (colorC == colorM))) { product1 = colorA; } else { - product1 = INTERPOLATE(colorA, colorC); + product1 = interpolate32_1_1(colorA, colorC); } product2 = colorA; } else if ((colorB == colorC) && (colorA != colorD)) { @@ -329,14 +330,14 @@ void _2xSaITemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI))) { product = colorB; } else { - product = INTERPOLATE(colorA, colorB); + product = interpolate32_1_1(colorA, colorB); } if (((colorC == colorH) && (colorA == colorF)) || ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI))) { product1 = colorC; } else { - product1 = INTERPOLATE(colorA, colorC); + product1 = interpolate32_1_1(colorA, colorC); } product2 = colorB; } else if ((colorA == colorD) && (colorB == colorC)) { @@ -347,8 +348,8 @@ void _2xSaITemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 } else { register int r = 0; - product1 = INTERPOLATE(colorA, colorC); - product = INTERPOLATE(colorA, colorB); + product1 = interpolate32_1_1(colorA, colorC); + product = interpolate32_1_1(colorA, colorB); r += GetResult(colorA, colorB, colorG, colorE); r -= GetResult(colorB, colorA, colorK, colorF); @@ -360,11 +361,11 @@ void _2xSaITemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 else if (r < 0) product2 = colorB; else { - product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD); + product2 = interpolate32_1_1_1_1(colorA, colorB, colorC, colorD); } } } else { - product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD); + product2 = interpolate32_1_1_1_1(colorA, colorB, colorC, colorD); if ((colorA == colorC) && (colorA == colorF) && (colorB != colorE) && (colorB == colorJ)) { @@ -373,7 +374,7 @@ void _2xSaITemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 && (colorA != colorF) && (colorA == colorI)) { product = colorB; } else { - product = INTERPOLATE(colorA, colorB); + product = interpolate32_1_1(colorA, colorB); } if ((colorA == colorB) && (colorA == colorH) @@ -383,7 +384,7 @@ void _2xSaITemplate(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 && (colorA != colorH) && (colorA == colorI)) { product1 = colorC; } else { - product1 = INTERPOLATE(colorA, colorC); + product1 = interpolate32_1_1(colorA, colorC); } } diff --git a/graphics/scaler/aspect.cpp b/graphics/scaler/aspect.cpp index 45939b922d..575a117295 100644 --- a/graphics/scaler/aspect.cpp +++ b/graphics/scaler/aspect.cpp @@ -55,20 +55,6 @@ static inline void interpolate5Line(uint16 *dst, const uint16 *srcA, const uint1 #if ASPECT_MODE == kFastAndNiceAspectMode -template<int bitFormat> -static inline uint32 INTERPOLATE_1_1(uint32 A, uint32 B) { - 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 & qhighBits) >> 2) + ((B & qhighBits) >> 2) * 3; - register uint32 y = ((A & qlowBits) + (B & qlowBits) * 3) >> 2; - - y &= qlowBits; - return x + y; -} - 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 @@ -90,11 +76,11 @@ static inline void interpolate5Line(uint16 *dst, const uint16 *srcA, const uint1 uint32 *d = (uint32 *)dst; if (scale == 1) { while (width--) { - *d++ = INTERPOLATE_1_3<bitFormat>(*sA++, *sB++); + *d++ = interpolate32_3_1<bitFormat>(*sB++, *sA++); } } else { while (width--) { - *d++ = INTERPOLATE_1_1<bitFormat>(*sA++, *sB++); + *d++ = interpolate32_1_1<bitFormat>(*sB++, *sA++); } } } diff --git a/graphics/scaler/intern.h b/graphics/scaler/intern.h index e618d46a42..cf8fa9b285 100644 --- a/graphics/scaler/intern.h +++ b/graphics/scaler/intern.h @@ -38,23 +38,36 @@ /** - * Interpolate two 16 bit pixel pairs at once with equal weights 1. + * Interpolate two 16 bit pixel *pairs* at once with equal weights 1. * In particular, A and B can contain two pixels/each in the upper * and lower halves. */ template<int bitFormat> -static inline uint32 INTERPOLATE(uint32 A, uint32 B) { - +static inline uint32 interpolate32_1_1(uint32 A, uint32 B) { return (((A & highBits) >> 1) + ((B & highBits) >> 1) + (A & B & lowBits)); } /** + * Interpolate two 16 bit pixel *pairs* at once with weights 3 resp. 1. + * In particular, A and B can contain two pixels/each in the upper + * and lower halves. + */ +template<int bitFormat> +static inline uint32 interpolate32_3_1(uint32 A, uint32 B) { + register uint32 x = ((A & qhighBits) >> 2) * 3 + ((B & qhighBits) >> 2); + register uint32 y = ((A & qlowBits) * 3 + (B & qlowBits)) >> 2; + + y &= qlowBits; + return x + y; +} + +/** * Interpolate four 16 bit pixel pairs at once with equal weights 1. * In particular, A and B can contain two pixels/each in the upper * and lower halves. */ template<int bitFormat> -static inline uint32 Q_INTERPOLATE(uint32 A, uint32 B, uint32 C, uint32 D) { +static inline uint32 interpolate32_1_1_1_1(uint32 A, uint32 B, uint32 C, uint32 D) { 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; @@ -66,6 +79,7 @@ static inline uint32 Q_INTERPOLATE(uint32 A, uint32 B, uint32 C, uint32 D) { /** * Interpolate two 16 bit pixels with the weights specified in the template * parameters. Used by the hq scaler family. + * @note w1 and w2 must sum up to 2, 4, 8 or 16. */ template<int bitFormat, int w1, int w2> static inline uint16 interpolate16_2(uint16 p1, uint16 p2) { @@ -76,6 +90,7 @@ static inline uint16 interpolate16_2(uint16 p1, uint16 p2) { /** * Interpolate three 16 bit pixels with the weights specified in the template * parameters. Used by the hq scaler family. + * @note w1, w2 and w3 must sum up to 2, 4, 8 or 16. */ template<int bitFormat, int w1, int w2, int w3> static inline uint16 interpolate16_3(uint16 p1, uint16 p2, uint16 p3) { diff --git a/graphics/scaler/thumbnail.cpp b/graphics/scaler/thumbnail.cpp index 38e31c40fc..998cc11dbe 100644 --- a/graphics/scaler/thumbnail.cpp +++ b/graphics/scaler/thumbnail.cpp @@ -36,7 +36,7 @@ uint16 quadBlockInterpolate(const uint8* src, uint32 srcPitch) { uint16 colorx1y2 = *(((const uint16*)(src + srcPitch))); uint16 colorx2y2 = *(((const uint16*)(src + srcPitch)) + 1); - return Q_INTERPOLATE<bitFormat>(colorx1y1, colorx2y1, colorx1y2, colorx2y2); + return interpolate32_1_1_1_1<bitFormat>(colorx1y1, colorx2y1, colorx1y2, colorx2y2); } template<int bitFormat> @@ -63,7 +63,7 @@ void createThumbnail_4(const uint8* src, uint32 srcPitch, uint8* dstPtr, uint32 uint16 downleft = quadBlockInterpolate<bitFormat>(src + srcPitch * 2 + 2 * x, srcPitch); uint16 downright = quadBlockInterpolate<bitFormat>(src + srcPitch * 2 + 2 * (x + 2), srcPitch); - *((uint16*)dstPtr) = Q_INTERPOLATE<bitFormat>(upleft, upright, downleft, downright); + *((uint16*)dstPtr) = interpolate32_1_1_1_1<bitFormat>(upleft, upright, downleft, downright); } dstPtr += (dstPitch - 2 * width / 4); src += 4 * srcPitch; |