2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-04-17 10:22:05 +00:00
|
|
|
#ifndef GRAPHICS_SCALER_INTERN_H
|
|
|
|
#define GRAPHICS_SCALER_INTERN_H
|
2003-09-29 16:02:47 +00:00
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
2006-04-17 10:22:05 +00:00
|
|
|
#include "graphics/colormasks.h"
|
2003-09-29 16:02:47 +00:00
|
|
|
|
2003-09-29 18:38:51 +00:00
|
|
|
|
2009-01-25 04:29:25 +00:00
|
|
|
#define kHighBitsMask Graphics::ColorMasks<bitFormat>::kHighBitsMask
|
|
|
|
#define kLowBitsMask Graphics::ColorMasks<bitFormat>::kLowBitsMask
|
2008-11-03 13:44:59 +00:00
|
|
|
#define qhighBits Graphics::ColorMasks<bitFormat>::qhighBits
|
|
|
|
#define qlowBits Graphics::ColorMasks<bitFormat>::qlowBits
|
|
|
|
#define redblueMask Graphics::ColorMasks<bitFormat>::kRedBlueMask
|
|
|
|
#define greenMask Graphics::ColorMasks<bitFormat>::kGreenMask
|
2003-09-29 16:02:47 +00:00
|
|
|
|
|
|
|
|
2003-10-01 16:47:49 +00:00
|
|
|
/**
|
2006-04-17 18:17:02 +00:00
|
|
|
* Interpolate two 16 bit pixel *pairs* at once with equal weights 1.
|
2009-01-26 16:45:21 +00:00
|
|
|
* In particular, p1 and p2 can contain two pixels each in the upper
|
2009-01-27 00:55:28 +00:00
|
|
|
* and lower halves.
|
2003-10-01 16:47:49 +00:00
|
|
|
*/
|
|
|
|
template<int bitFormat>
|
2009-01-26 16:45:21 +00:00
|
|
|
static inline uint32 interpolate32_1_1(uint32 p1, uint32 p2) {
|
2009-01-27 00:55:28 +00:00
|
|
|
return (((p1 & kHighBitsMask) >> 1) + ((p2 & kHighBitsMask) >> 1) + (p1 & p2 & kLowBitsMask));
|
2003-10-01 16:47:49 +00:00
|
|
|
}
|
|
|
|
|
2006-04-17 18:17:02 +00:00
|
|
|
/**
|
|
|
|
* Interpolate two 16 bit pixel *pairs* at once with weights 3 resp. 1.
|
2009-01-27 00:55:28 +00:00
|
|
|
* In particular, p1 and p2 can contain two pixels/each in the upper
|
2006-04-17 18:17:02 +00:00
|
|
|
* and lower halves.
|
|
|
|
*/
|
|
|
|
template<int bitFormat>
|
2009-01-27 00:55:28 +00:00
|
|
|
static inline uint32 interpolate32_3_1(uint32 p1, uint32 p2) {
|
|
|
|
register uint32 x = ((p1 & qhighBits) >> 2) * 3 + ((p2 & qhighBits) >> 2);
|
|
|
|
register uint32 y = ((p1 & qlowBits) * 3 + (p2 & qlowBits)) >> 2;
|
2006-04-17 18:17:02 +00:00
|
|
|
|
|
|
|
y &= qlowBits;
|
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
|
2003-10-01 16:47:49 +00:00
|
|
|
/**
|
|
|
|
* Interpolate four 16 bit pixel pairs at once with equal weights 1.
|
2009-01-27 00:55:28 +00:00
|
|
|
* In particular, p1, p2, p3 and p3 can each contain two pixels in the upper
|
2003-10-01 16:47:49 +00:00
|
|
|
* and lower halves.
|
|
|
|
*/
|
|
|
|
template<int bitFormat>
|
2009-01-27 00:55:28 +00:00
|
|
|
static inline uint32 interpolate32_1_1_1_1(uint32 p1, uint32 p2, uint32 p3, uint32 p4) {
|
|
|
|
register uint32 x = ((p1 & qhighBits) >> 2) + ((p2 & qhighBits) >> 2) + ((p3 & qhighBits) >> 2) + ((p4 & qhighBits) >> 2);
|
|
|
|
register uint32 y = ((p1 & qlowBits) + (p2 & qlowBits) + (p3 & qlowBits) + (p4 & qlowBits)) >> 2;
|
2003-10-01 16:47:49 +00:00
|
|
|
|
|
|
|
y &= qlowBits;
|
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
|
2003-09-29 16:02:47 +00:00
|
|
|
/**
|
|
|
|
* Interpolate two 16 bit pixels with the weights specified in the template
|
|
|
|
* parameters. Used by the hq scaler family.
|
2006-04-17 18:17:02 +00:00
|
|
|
* @note w1 and w2 must sum up to 2, 4, 8 or 16.
|
2003-09-29 16:02:47 +00:00
|
|
|
*/
|
|
|
|
template<int bitFormat, int w1, int w2>
|
|
|
|
static inline uint16 interpolate16_2(uint16 p1, uint16 p2) {
|
2003-09-29 18:38:51 +00:00
|
|
|
return ((((p1 & redblueMask) * w1 + (p2 & redblueMask) * w2) / (w1 + w2)) & redblueMask) |
|
|
|
|
((((p1 & greenMask) * w1 + (p2 & greenMask) * w2) / (w1 + w2)) & greenMask);
|
2003-09-29 16:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interpolate three 16 bit pixels with the weights specified in the template
|
|
|
|
* parameters. Used by the hq scaler family.
|
2006-04-17 18:17:02 +00:00
|
|
|
* @note w1, w2 and w3 must sum up to 2, 4, 8 or 16.
|
2003-09-29 16:02:47 +00:00
|
|
|
*/
|
|
|
|
template<int bitFormat, int w1, int w2, int w3>
|
|
|
|
static inline uint16 interpolate16_3(uint16 p1, uint16 p2, uint16 p3) {
|
2003-09-29 18:38:51 +00:00
|
|
|
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);
|
2003-09-29 16:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare two YUV values (encoded 8-8-8) and check if they differ by more than
|
|
|
|
* a certain hard coded threshold. Used by the hq scaler family.
|
|
|
|
*/
|
|
|
|
static inline bool diffYUV(int yuv1, int yuv2) {
|
|
|
|
static const int Ymask = 0x00FF0000;
|
|
|
|
static const int Umask = 0x0000FF00;
|
|
|
|
static const int Vmask = 0x000000FF;
|
|
|
|
static const int trY = 0x00300000;
|
|
|
|
static const int trU = 0x00000700;
|
|
|
|
static const int trV = 0x00000006;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-09-29 23:34:43 +00:00
|
|
|
int diff;
|
2003-10-01 16:47:49 +00:00
|
|
|
int mask;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-09-29 23:34:43 +00:00
|
|
|
diff = ((yuv1 & Umask) - (yuv2 & Umask));
|
2005-07-30 21:11:48 +00:00
|
|
|
mask = diff >> 31; // -1 if value < 0, 0 otherwise
|
|
|
|
diff = (diff ^ mask) - mask; //-1: ~value + 1; 0: value
|
2003-09-29 23:34:43 +00:00
|
|
|
if (diff > trU) return true;
|
|
|
|
|
|
|
|
diff = ((yuv1 & Vmask) - (yuv2 & Vmask));
|
2005-07-30 21:11:48 +00:00
|
|
|
mask = diff >> 31; // -1 if value < 0, 0 otherwise
|
|
|
|
diff = (diff ^ mask) - mask; //-1: ~value + 1; 0: value
|
2003-09-29 23:34:43 +00:00
|
|
|
if (diff > trV) return true;
|
|
|
|
|
2009-01-22 06:41:57 +00:00
|
|
|
diff = ((yuv1 & Ymask) - (yuv2 & Ymask));
|
|
|
|
mask = diff >> 31; // -1 if value < 0, 0 otherwise
|
|
|
|
diff = (diff ^ mask) - mask; //-1: ~value + 1; 0: value
|
|
|
|
if (diff > trY) return true;
|
|
|
|
|
2003-09-29 23:34:43 +00:00
|
|
|
return false;
|
|
|
|
/*
|
2003-09-29 16:02:47 +00:00
|
|
|
return
|
|
|
|
( ( ABS((yuv1 & Ymask) - (yuv2 & Ymask)) > trY ) ||
|
|
|
|
( ABS((yuv1 & Umask) - (yuv2 & Umask)) > trU ) ||
|
|
|
|
( ABS((yuv1 & Vmask) - (yuv2 & Vmask)) > trV ) );
|
2003-09-29 23:34:43 +00:00
|
|
|
*/
|
2003-09-29 16:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 16bit RGB to YUV conversion table. This table is setup by InitLUT().
|
|
|
|
* Used by the hq scaler family.
|
|
|
|
*/
|
2006-04-21 20:56:53 +00:00
|
|
|
extern "C" uint32 *RGBtoYUV;
|
2003-09-29 16:02:47 +00:00
|
|
|
|
2003-09-29 18:38:51 +00:00
|
|
|
/** 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) \
|
2003-10-02 23:29:58 +00:00
|
|
|
FUNC ## Template<565>(srcPtr, srcPitch, dstPtr, dstPitch, width, height); \
|
2003-09-29 18:38:51 +00:00
|
|
|
else \
|
2003-10-02 23:29:58 +00:00
|
|
|
FUNC ## Template<555>(srcPtr, srcPitch, dstPtr, dstPitch, width, height); \
|
2003-10-02 15:00:36 +00:00
|
|
|
}
|
|
|
|
|
2003-10-02 23:29:58 +00:00
|
|
|
/** Specifies the currently active 16bit pixel format, 555 or 565. */
|
2003-10-02 15:00:36 +00:00
|
|
|
extern int gBitFormat;
|
|
|
|
|
2003-09-29 16:02:47 +00:00
|
|
|
#endif
|