From 35a2fc402811b1dd047d62e571164f3d50d86393 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 17 Apr 2006 11:11:07 +0000 Subject: Modify InitLUT to make use of ColorMasks, making it easier to add support for other color modes eventually. This also fixes the computation of LUT16to32 which so far always assumed 565 mode. svn-id: r21970 --- graphics/scaler.cpp | 56 ++++++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 31 deletions(-) (limited to 'graphics/scaler.cpp') diff --git a/graphics/scaler.cpp b/graphics/scaler.cpp index 3311ba22e2..1853742ce2 100644 --- a/graphics/scaler.cpp +++ b/graphics/scaler.cpp @@ -73,46 +73,40 @@ uint RGBtoYUVstorage[65536]; uint *RGBtoYUV = RGBtoYUVstorage; uint LUT16to32[65536]; } -#endif - -static void InitLUT(uint32 BitFormat); -void InitScalers(uint32 BitFormat) { - gBitFormat = BitFormat; - InitLUT(gBitFormat); -} - -void InitLUT(uint32 BitFormat) { -#ifndef DISABLE_HQ_SCALERS +template +void InitLUT() { int r, g, b; int Y, u, v; - int gInc, gShift; - - for (int i = 0; i < 65536; i++) { - LUT16to32[i] = ((i & 0xF800) << 8) + ((i & 0x07E0) << 5) + ((i & 0x001F) << 3); + + assert(T::kBytesPerPixel == 2); + + for (int color = 0; color < 65536; ++color) { + r = ((color & T::kRedMask) >> T::kRedShift) << (8 - T::kRedBits); + g = ((color & T::kGreenMask) >> T::kGreenShift) << (8 - T::kGreenBits); + b = ((color & T::kBlueMask) >> T::kBlueShift) << (8 - T::kBlueBits); + LUT16to32[color] = (r << 16) | (g << 8) | b; + + Y = (r + g + b) >> 2; + u = 128 + ((r - b) >> 2); + v = 128 + ((-r + 2 * g - b) >> 3); + RGBtoYUV[color] = (Y << 16) | (u << 8) | v; } +} +#endif - if (BitFormat == 565) { - gInc = 256 >> 6; - gShift = 6 - 3; - } else { - gInc = 256 >> 5; - gShift = 5 - 3; - } - for (r = 0; r < 256; r += 8) { - for (g = 0; g < 256; g += gInc) { - for (b = 0; b < 256; b += 8) { - Y = (r + g + b) >> 2; - u = 128 + ((r - b) >> 2); - v = 128 + ((-r + 2 * g - b) >> 3); - RGBtoYUV[ (r << (5 + gShift)) + (g << gShift) + (b >> 3) ] = (Y << 16) + (u << 8) + v; - } - } - } +void InitScalers(uint32 BitFormat) { + gBitFormat = BitFormat; +#ifndef DISABLE_HQ_SCALERS + if (gBitFormat == 555) + InitLUT >(); + if (gBitFormat == 565) + InitLUT >(); #endif } + /** * Trivial 'scaler' - in fact it doesn't do any scaling but just copies the * source to the destionation. -- cgit v1.2.3