ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

intern.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef GRAPHICS_SCALER_INTERN_H
00024 #define GRAPHICS_SCALER_INTERN_H
00025 
00026 #include "common/scummsys.h"
00027 #include "graphics/colormasks.h"
00028 
00029 
00035 template<typename ColorMask>
00036 static inline uint32 interpolate32_1_1(uint32 p1, uint32 p2) {
00037     return (((p1 & ColorMask::kHighBitsMask) >> 1) +
00038             ((p2 & ColorMask::kHighBitsMask) >> 1) +
00039              (p1 & p2 & ColorMask::kLowBitsMask));
00040 }
00041 
00047 template<typename ColorMask>
00048 static inline uint32 interpolate32_3_1(uint32 p1, uint32 p2) {
00049     uint32 x = ((p1 & ColorMask::qhighBits) >> 2) * 3 + ((p2 & ColorMask::qhighBits) >> 2);
00050     uint32 y = ((p1 & ColorMask::qlowBits) * 3 + (p2 & ColorMask::qlowBits)) >> 2;
00051 
00052     y &= ColorMask::qlowBits;
00053     return x + y;
00054 }
00055 
00060 template<typename ColorMask>
00061 static inline unsigned interpolate16_1_1(unsigned p1, unsigned p2) {
00062     const unsigned lowbits = (p1 ^ p2) & ColorMask::kLowBits;
00063     return ((p1 + p2) - lowbits) >> 1;
00064 }
00065 
00069 template<typename ColorMask>
00070 static inline unsigned interpolate16_3_1(unsigned p1, unsigned p2) {
00071     const unsigned lowbits = (((p1 & ColorMask::kLowBits) << 1) + (p1 & ColorMask::kLow2Bits)
00072                            + (p2 & ColorMask::kLow2Bits)) & ColorMask::kLow2Bits;
00073     return ((p1*3 + p2) - lowbits) >> 2;
00074 }
00075 
00079 template<typename ColorMask>
00080 static inline unsigned interpolate16_5_3(unsigned p1, unsigned p2) {
00081     const unsigned lowbits = (((p1 & ColorMask::kLowBits) << 2) + (p1 & ColorMask::kLow3Bits)
00082                            + ((p2 & ColorMask::kLow2Bits) << 1) + (p2 & ColorMask::kLow3Bits)) & ColorMask::kLow3Bits;
00083     return ((p1*5 + p2*3) - lowbits) >> 3;
00084 }
00085 
00089 template<typename ColorMask>
00090 static inline unsigned interpolate16_7_1(unsigned p1, unsigned p2) {
00091     const unsigned lowbits = (((p1 & ColorMask::kLowBits) << 2) + ((p1 & ColorMask::kLow2Bits) << 1) + (p1 & ColorMask::kLow3Bits)
00092                            +  (p2 & ColorMask::kLow3Bits)) & ColorMask::kLow3Bits;
00093     return ((p1*7+p2) - lowbits) >> 3;
00094 }
00095 
00099 template<typename ColorMask>
00100 static inline unsigned interpolate16_2_1_1(unsigned p1, unsigned p2, unsigned p3) {
00101     p1<<=1;
00102     const unsigned lowbits = ((p1 & (ColorMask::kLowBits << 1))
00103                            +  (p2 & ColorMask::kLow2Bits)
00104                            +  (p3 & ColorMask::kLow2Bits)) & ColorMask::kLow2Bits;
00105     return ((p1+p2+p3) - lowbits) >> 2;
00106 }
00107 
00111 template<typename ColorMask>
00112 static inline unsigned interpolate16_5_2_1(unsigned p1, unsigned p2, unsigned p3) {
00113     p2<<=1;
00114     const unsigned lowbits = (((p1 & ColorMask::kLowBits) << 2) + (p1 & ColorMask::kLow3Bits)
00115                            +  (p2 & (ColorMask::kLow2Bits << 1))
00116                            +  (p3 & ColorMask::kLow3Bits)) & ColorMask::kLow3Bits;
00117     return ((p1*5 + p2 + p3) - lowbits) >> 3;
00118 }
00119 
00123 template<typename ColorMask>
00124 static inline unsigned interpolate16_6_1_1(unsigned p1, unsigned p2, unsigned p3) {
00125     const unsigned lowbits = (((((p1 & ColorMask::kLowBits) << 1) + (p1 & ColorMask::kLow2Bits)) << 1)
00126                            + (p2 & ColorMask::kLow3Bits)
00127                            + (p3 & ColorMask::kLow3Bits)) & ColorMask::kLow3Bits;
00128     return ((p1*6 + p2 + p3) - lowbits) >> 3;
00129 }
00130 
00134 template<typename ColorMask>
00135 static inline unsigned interpolate16_2_3_3(unsigned p1, unsigned p2, unsigned p3) {
00136     p1 <<= 1;
00137     const unsigned rb = (p1 & (ColorMask::kRedBlueMask<<1))
00138                       + ((p2 & ColorMask::kRedBlueMask) + (p3 & ColorMask::kRedBlueMask))*3;
00139     const unsigned  g = (p1 & (ColorMask::kGreenMask<<1))
00140                       + ((p2 & ColorMask::kGreenMask) + (p3 & ColorMask::kGreenMask))*3;
00141     return ((rb & (ColorMask::kRedBlueMask<<3)) | (g & (ColorMask::kGreenMask<<3))) >> 3;
00142 }
00143 
00147 template<typename ColorMask>
00148 static inline unsigned interpolate16_2_7_7(unsigned p1, unsigned p2, unsigned p3) {
00149     p1 <<= 1;
00150     const unsigned rb = (p1 & (ColorMask::kRedBlueMask<<1))
00151                       + ((p2 & ColorMask::kRedBlueMask) + (p3 & ColorMask::kRedBlueMask))*7;
00152     const unsigned  g = (p1 & (ColorMask::kGreenMask<<1))
00153                       + ((p2 & ColorMask::kGreenMask) + (p3 & ColorMask::kGreenMask))*7;
00154     return ((rb & (ColorMask::kRedBlueMask<<4)) | (g & (ColorMask::kGreenMask<<4))) >> 4;
00155 }
00156 
00160 template<typename ColorMask>
00161 static inline unsigned interpolate16_14_1_1(unsigned p1, unsigned p2, unsigned p3) {
00162     const unsigned rb = (p1&ColorMask::kRedBlueMask)*14
00163                       + (p2&ColorMask::kRedBlueMask)
00164                       + (p3&ColorMask::kRedBlueMask);
00165     const unsigned  g = (p1&ColorMask::kGreenMask)*14
00166                       + (p2&ColorMask::kGreenMask) + (p3&ColorMask::kGreenMask);
00167     return ((rb&(ColorMask::kRedBlueMask<<4)) | (g&(ColorMask::kGreenMask<<4))) >> 4;
00168 }
00169 
00173 template<typename ColorMask>
00174 static inline unsigned interpolate16_1_1_1_1(unsigned p1, unsigned p2, unsigned p3, unsigned p4) {
00175     const unsigned lowbits = ((p1 & ColorMask::kLow2Bits)
00176                            +  (p2 & ColorMask::kLow2Bits)
00177                            +  (p3 & ColorMask::kLow2Bits)
00178                            +  (p4 & ColorMask::kLow2Bits)) & ColorMask::kLow2Bits;
00179     return ((p1+p2+p3+p4) - lowbits) >> 2;
00180 }
00181 
00186 static inline bool diffYUV(int yuv1, int yuv2) {
00187     static const int Ymask = 0x00FF0000;
00188     static const int Umask = 0x0000FF00;
00189     static const int Vmask = 0x000000FF;
00190     static const int trY   = 0x00300000;
00191     static const int trU   = 0x00000700;
00192     static const int trV   = 0x00000006;
00193 
00194     int diff;
00195     int mask;
00196 
00197     diff = ((yuv1 & Umask) - (yuv2 & Umask));
00198     mask = diff >> 31;           // -1 if value < 0, 0 otherwise
00199     diff = (diff ^ mask) - mask; // -1: ~value + 1; 0: value
00200     if (diff > trU) return true;
00201 
00202     diff = ((yuv1 & Vmask) - (yuv2 & Vmask));
00203     mask = diff >> 31;           // -1 if value < 0, 0 otherwise
00204     diff = (diff ^ mask) - mask; // -1: ~value + 1; 0: value
00205     if (diff > trV) return true;
00206 
00207     diff = ((yuv1 & Ymask) - (yuv2 & Ymask));
00208     mask = diff >> 31;           // -1 if value < 0, 0 otherwise
00209     diff = (diff ^ mask) - mask; // -1: ~value + 1; 0: value
00210     if (diff > trY) return true;
00211 
00212     return false;
00213 /*
00214     return
00215       ( ( ABS((yuv1 & Ymask) - (yuv2 & Ymask)) > trY ) ||
00216         ( ABS((yuv1 & Umask) - (yuv2 & Umask)) > trU ) ||
00217         ( ABS((yuv1 & Vmask) - (yuv2 & Vmask)) > trV ) );
00218 */
00219 }
00220 
00221 #endif


Generated on Sat Feb 16 2019 05:00:55 for ResidualVM by doxygen 1.7.1
curved edge   curved edge