1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Mupen64plus - TextureFilters_hq4x.cpp *
3 * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4 * Copyright (C) 2003 MaxSt ( maxst@hiend3d.com ) *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
26 static int RGBtoYUV[4096];
27 //#define RGB32toYUV(val) (RGBtoYUV[((val&0x00FF0000)>>20)+((val&0x0000FF00)>>12)+((val&0x000000FF)>>4)])
28 inline int RGB32toYUV(uint32 val)
31 //r = (val&0x00FF0000)>>16;
32 //g = (val&0x0000FF00)>>8;
33 //b = (val&0x000000FF);
35 r = (val&0x00FF0000)>>16;
36 g = (val&0x0000FF00)>>8;
38 //r = (val&0x00F80000)>>16;
39 //g = (val&0x0000FC00)>>8;
40 //b = (val&0x000000F8);
42 u = 128 + ((r - b) >> 2);
43 v = 128 + ((-r + 2*g -b)>>3);
44 return a + (Y<<16) + (u<<8) + v;
46 #define RGB16toYUV(val) (RGBtoYUV[(val&0x0FFF)])
47 static int YUV1, YUV2;
48 const int Amask = 0xFF000000;
49 const int Ymask = 0x00FF0000;
50 const int Umask = 0x0000FF00;
51 const int Vmask = 0x000000FF;
52 const int trA = 0x20000000;
53 const int trY = 0x00300000;
54 const int trU = 0x00000700;
55 const int trV = 0x00000006;
56 //const int trU = 0x00001800;
57 //const int trV = 0x00000018;
59 #define INTERP_16_MASK_1_3(v) ((v)&0x0F0F)
60 #define INTERP_16_MASK_SHIFT_2_4(v) (((v)&0xF0F0)>>4)
61 #define INTERP_16_MASK_SHIFTBACK_2_4(v) ((INTERP_16_MASK_1_3(v))<<4)
63 inline void hq4x_Interp1_16(unsigned char * pc, uint16 p1, uint16 p2)
65 *((uint16*)pc) = INTERP_16_MASK_1_3((INTERP_16_MASK_1_3(p1)*3 + INTERP_16_MASK_1_3(p2)) / 4)
66 | INTERP_16_MASK_SHIFTBACK_2_4((INTERP_16_MASK_SHIFT_2_4(p1)*3 + INTERP_16_MASK_SHIFT_2_4(p2)) / 4 );
69 inline void hq4x_Interp2_16(unsigned char * pc, uint16 p1, uint16 p2, uint16 p3)
71 *((uint16*)pc) = INTERP_16_MASK_1_3((INTERP_16_MASK_1_3(p1)*2 + INTERP_16_MASK_1_3(p2) + INTERP_16_MASK_1_3(p3)) / 4)
72 | INTERP_16_MASK_SHIFTBACK_2_4((INTERP_16_MASK_SHIFT_2_4(p1)*2 + INTERP_16_MASK_SHIFT_2_4(p2) + INTERP_16_MASK_SHIFT_2_4(p3)) / 4);
75 inline void hq4x_Interp3_16(unsigned char * pc, uint16 p1, uint16 p2)
77 *((uint16*)pc) = INTERP_16_MASK_1_3((INTERP_16_MASK_1_3(p1)*7 + INTERP_16_MASK_1_3(p2)) / 8)
78 | INTERP_16_MASK_SHIFTBACK_2_4((INTERP_16_MASK_SHIFT_2_4(p1)*7 + INTERP_16_MASK_SHIFT_2_4(p2)) / 8);
81 inline void hq4x_Interp5_16(unsigned char * pc, uint16 p1, uint16 p2)
83 *((uint16*)pc) = INTERP_16_MASK_1_3((INTERP_16_MASK_1_3(p1) + INTERP_16_MASK_1_3(p2)) / 2)
84 | INTERP_16_MASK_SHIFTBACK_2_4((INTERP_16_MASK_SHIFT_2_4(p1) + INTERP_16_MASK_SHIFT_2_4(p2)) / 2);
87 inline void hq4x_Interp6_16(unsigned char * pc, uint16 p1, uint16 p2, uint16 p3)
89 *((uint16*)pc) = INTERP_16_MASK_1_3((INTERP_16_MASK_1_3(p1)*5 + INTERP_16_MASK_1_3(p2)*2 + INTERP_16_MASK_1_3(p3)*1) / 8)
90 | INTERP_16_MASK_SHIFTBACK_2_4((INTERP_16_MASK_SHIFT_2_4(p1)*5 + INTERP_16_MASK_SHIFT_2_4(p2)*2 + INTERP_16_MASK_SHIFT_2_4(p3)*1) / 8);
93 inline void hq4x_Interp7_16(unsigned char * pc, uint16 p1, uint16 p2, uint16 p3)
95 *((uint16*)pc) = INTERP_16_MASK_1_3((INTERP_16_MASK_1_3(p1)*6 + INTERP_16_MASK_1_3(p2) + INTERP_16_MASK_1_3(p3)) / 8)
96 | INTERP_16_MASK_SHIFTBACK_2_4((INTERP_16_MASK_SHIFT_2_4(p1)*6 + INTERP_16_MASK_SHIFT_2_4(p2) + INTERP_16_MASK_SHIFT_2_4(p3)) / 8);
99 inline void hq4x_Interp8_16(unsigned char * pc, uint16 p1, uint16 p2)
101 //*((int*)pc) = (c1*5+c2*3)/8;
102 *((uint16*)pc) = INTERP_16_MASK_1_3((INTERP_16_MASK_1_3(p1)*5 + INTERP_16_MASK_1_3(p2)*3) / 8)
103 | INTERP_16_MASK_SHIFTBACK_2_4((INTERP_16_MASK_SHIFT_2_4(p1)*5 + INTERP_16_MASK_SHIFT_2_4(p2)*3) / 8);
106 #define INTERP_32_MASK_1_3(v) ((v)&0x00FF00FF)
107 #define INTERP_32_MASK_SHIFT_2_4(v) (((v)&0xFF00FF00)>>8)
108 #define INTERP_32_MASK_SHIFTBACK_2_4(v) (((INTERP_32_MASK_1_3(v))<<8))
110 inline void hq4x_Interp1_32(unsigned char * pc, uint32 p1, uint32 p2)
112 *((uint32*)pc) = INTERP_32_MASK_1_3((INTERP_32_MASK_1_3(p1)*3 + INTERP_32_MASK_1_3(p2)) / 4)
113 | INTERP_32_MASK_SHIFTBACK_2_4((INTERP_32_MASK_SHIFT_2_4(p1)*3 + INTERP_32_MASK_SHIFT_2_4(p2)) / 4 );
116 inline void hq4x_Interp2_32(unsigned char * pc, uint32 p1, uint32 p2, uint32 p3)
118 *((uint32*)pc) = INTERP_32_MASK_1_3((INTERP_32_MASK_1_3(p1)*2 + INTERP_32_MASK_1_3(p2) + INTERP_32_MASK_1_3(p3)) / 4)
119 | INTERP_32_MASK_SHIFTBACK_2_4((INTERP_32_MASK_SHIFT_2_4(p1)*2 + INTERP_32_MASK_SHIFT_2_4(p2) + INTERP_32_MASK_SHIFT_2_4(p3)) / 4);
122 inline void hq4x_Interp3_32(unsigned char * pc, uint32 p1, uint32 p2)
124 *((uint32*)pc) = INTERP_32_MASK_1_3((INTERP_32_MASK_1_3(p1)*7 + INTERP_32_MASK_1_3(p2)) / 8)
125 | INTERP_32_MASK_SHIFTBACK_2_4((INTERP_32_MASK_SHIFT_2_4(p1)*7 + INTERP_32_MASK_SHIFT_2_4(p2)) / 8);
128 inline void hq4x_Interp5_32(unsigned char * pc, uint32 p1, uint32 p2)
130 *((uint32*)pc) = INTERP_32_MASK_1_3((INTERP_32_MASK_1_3(p1) + INTERP_32_MASK_1_3(p2)) / 2)
131 | INTERP_32_MASK_SHIFTBACK_2_4((INTERP_32_MASK_SHIFT_2_4(p1) + INTERP_32_MASK_SHIFT_2_4(p2)) / 2);
134 inline void hq4x_Interp6_32(unsigned char * pc, uint32 p1, uint32 p2, uint32 p3)
136 *((uint32*)pc) = INTERP_32_MASK_1_3((INTERP_32_MASK_1_3(p1)*5 + INTERP_32_MASK_1_3(p2)*2 + INTERP_32_MASK_1_3(p3)*1) / 8)
137 | INTERP_32_MASK_SHIFTBACK_2_4((INTERP_32_MASK_SHIFT_2_4(p1)*5 + INTERP_32_MASK_SHIFT_2_4(p2)*2 + INTERP_32_MASK_SHIFT_2_4(p3)*1) / 8);
140 inline void hq4x_Interp7_32(unsigned char * pc, uint32 p1, uint32 p2, uint32 p3)
142 *((uint32*)pc) = INTERP_32_MASK_1_3((INTERP_32_MASK_1_3(p1)*6 + INTERP_32_MASK_1_3(p2) + INTERP_32_MASK_1_3(p3)) / 8)
143 | INTERP_32_MASK_SHIFTBACK_2_4((INTERP_32_MASK_SHIFT_2_4(p1)*6 + INTERP_32_MASK_SHIFT_2_4(p2) + INTERP_32_MASK_SHIFT_2_4(p3)) / 8);
146 inline void hq4x_Interp8_32(unsigned char * pc, uint32 p1, uint32 p2)
148 //*((int*)pc) = (c1*5+c2*3)/8;
149 *((uint32*)pc) = INTERP_32_MASK_1_3((INTERP_32_MASK_1_3(p1)*5 + INTERP_32_MASK_1_3(p2)*3) / 8)
150 | INTERP_32_MASK_SHIFTBACK_2_4((INTERP_32_MASK_SHIFT_2_4(p1)*5 + INTERP_32_MASK_SHIFT_2_4(p2)*3) / 8);
153 #define PIXEL00_0 *((int*)(pOut)) = c[5];
154 #define PIXEL00_11 hq4x_Interp1(pOut, c[5], c[4]);
155 #define PIXEL00_12 hq4x_Interp1(pOut, c[5], c[2]);
156 #define PIXEL00_20 hq4x_Interp2(pOut, c[5], c[2], c[4]);
157 #define PIXEL00_50 hq4x_Interp5(pOut, c[2], c[4]);
158 #define PIXEL00_80 hq4x_Interp8(pOut, c[5], c[1]);
159 #define PIXEL00_81 hq4x_Interp8(pOut, c[5], c[4]);
160 #define PIXEL00_82 hq4x_Interp8(pOut, c[5], c[2]);
161 #define PIXEL01_0 *((int*)(pOut+BPP)) = c[5];
162 #define PIXEL01_10 hq4x_Interp1(pOut+BPP, c[5], c[1]);
163 #define PIXEL01_12 hq4x_Interp1(pOut+BPP, c[5], c[2]);
164 #define PIXEL01_14 hq4x_Interp1(pOut+BPP, c[2], c[5]);
165 #define PIXEL01_21 hq4x_Interp2(pOut+BPP, c[2], c[5], c[4]);
166 #define PIXEL01_31 hq4x_Interp3(pOut+BPP, c[5], c[4]);
167 #define PIXEL01_50 hq4x_Interp5(pOut+BPP, c[2], c[5]);
168 #define PIXEL01_60 hq4x_Interp6(pOut+BPP, c[5], c[2], c[4]);
169 #define PIXEL01_61 hq4x_Interp6(pOut+BPP, c[5], c[2], c[1]);
170 #define PIXEL01_82 hq4x_Interp8(pOut+BPP, c[5], c[2]);
171 #define PIXEL01_83 hq4x_Interp8(pOut+BPP, c[2], c[4]);
172 #define PIXEL02_0 *((int*)(pOut+BPP2)) = c[5];
173 #define PIXEL02_10 hq4x_Interp1(pOut+BPP2, c[5], c[3]);
174 #define PIXEL02_11 hq4x_Interp1(pOut+BPP2, c[5], c[2]);
175 #define PIXEL02_13 hq4x_Interp1(pOut+BPP2, c[2], c[5]);
176 #define PIXEL02_21 hq4x_Interp2(pOut+BPP2, c[2], c[5], c[6]);
177 #define PIXEL02_32 hq4x_Interp3(pOut+BPP2, c[5], c[6]);
178 #define PIXEL02_50 hq4x_Interp5(pOut+BPP2, c[2], c[5]);
179 #define PIXEL02_60 hq4x_Interp6(pOut+BPP2, c[5], c[2], c[6]);
180 #define PIXEL02_61 hq4x_Interp6(pOut+BPP2, c[5], c[2], c[3]);
181 #define PIXEL02_81 hq4x_Interp8(pOut+BPP2, c[5], c[2]);
182 #define PIXEL02_83 hq4x_Interp8(pOut+BPP2, c[2], c[6]);
183 #define PIXEL03_0 *((int*)(pOut+BPP3)) = c[5];
184 #define PIXEL03_11 hq4x_Interp1(pOut+BPP3, c[5], c[2]);
185 #define PIXEL03_12 hq4x_Interp1(pOut+BPP3, c[5], c[6]);
186 #define PIXEL03_20 hq4x_Interp2(pOut+BPP3, c[5], c[2], c[6]);
187 #define PIXEL03_50 hq4x_Interp5(pOut+BPP3, c[2], c[6]);
188 #define PIXEL03_80 hq4x_Interp8(pOut+BPP3, c[5], c[3]);
189 #define PIXEL03_81 hq4x_Interp8(pOut+BPP3, c[5], c[2]);
190 #define PIXEL03_82 hq4x_Interp8(pOut+BPP3, c[5], c[6]);
191 #define PIXEL10_0 *((int*)(pOut+BpL)) = c[5];
192 #define PIXEL10_10 hq4x_Interp1(pOut+BpL, c[5], c[1]);
193 #define PIXEL10_11 hq4x_Interp1(pOut+BpL, c[5], c[4]);
194 #define PIXEL10_13 hq4x_Interp1(pOut+BpL, c[4], c[5]);
195 #define PIXEL10_21 hq4x_Interp2(pOut+BpL, c[4], c[5], c[2]);
196 #define PIXEL10_32 hq4x_Interp3(pOut+BpL, c[5], c[2]);
197 #define PIXEL10_50 hq4x_Interp5(pOut+BpL, c[4], c[5]);
198 #define PIXEL10_60 hq4x_Interp6(pOut+BpL, c[5], c[4], c[2]);
199 #define PIXEL10_61 hq4x_Interp6(pOut+BpL, c[5], c[4], c[1]);
200 #define PIXEL10_81 hq4x_Interp8(pOut+BpL, c[5], c[4]);
201 #define PIXEL10_83 hq4x_Interp8(pOut+BpL, c[4], c[2]);
202 #define PIXEL11_0 *((int*)(pOut+BpL+BPP)) = c[5];
203 #define PIXEL11_30 hq4x_Interp3(pOut+BpL+BPP, c[5], c[1]);
204 #define PIXEL11_31 hq4x_Interp3(pOut+BpL+BPP, c[5], c[4]);
205 #define PIXEL11_32 hq4x_Interp3(pOut+BpL+BPP, c[5], c[2]);
206 #define PIXEL11_70 hq4x_Interp7(pOut+BpL+BPP, c[5], c[4], c[2]);
207 #define PIXEL12_0 *((int*)(pOut+BpL+BPP2)) = c[5];
208 #define PIXEL12_30 hq4x_Interp3(pOut+BpL+BPP2, c[5], c[3]);
209 #define PIXEL12_31 hq4x_Interp3(pOut+BpL+BPP2, c[5], c[2]);
210 #define PIXEL12_32 hq4x_Interp3(pOut+BpL+BPP2, c[5], c[6]);
211 #define PIXEL12_70 hq4x_Interp7(pOut+BpL+BPP2, c[5], c[6], c[2]);
212 #define PIXEL13_0 *((int*)(pOut+BpL+BPP3)) = c[5];
213 #define PIXEL13_10 hq4x_Interp1(pOut+BpL+BPP3, c[5], c[3]);
214 #define PIXEL13_12 hq4x_Interp1(pOut+BpL+BPP3, c[5], c[6]);
215 #define PIXEL13_14 hq4x_Interp1(pOut+BpL+BPP3, c[6], c[5]);
216 #define PIXEL13_21 hq4x_Interp2(pOut+BpL+BPP3, c[6], c[5], c[2]);
217 #define PIXEL13_31 hq4x_Interp3(pOut+BpL+BPP3, c[5], c[2]);
218 #define PIXEL13_50 hq4x_Interp5(pOut+BpL+BPP3, c[6], c[5]);
219 #define PIXEL13_60 hq4x_Interp6(pOut+BpL+BPP3, c[5], c[6], c[2]);
220 #define PIXEL13_61 hq4x_Interp6(pOut+BpL+BPP3, c[5], c[6], c[3]);
221 #define PIXEL13_82 hq4x_Interp8(pOut+BpL+BPP3, c[5], c[6]);
222 #define PIXEL13_83 hq4x_Interp8(pOut+BpL+BPP3, c[6], c[2]);
223 #define PIXEL20_0 *((int*)(pOut+BpL+BpL)) = c[5];
224 #define PIXEL20_10 hq4x_Interp1(pOut+BpL+BpL, c[5], c[7]);
225 #define PIXEL20_12 hq4x_Interp1(pOut+BpL+BpL, c[5], c[4]);
226 #define PIXEL20_14 hq4x_Interp1(pOut+BpL+BpL, c[4], c[5]);
227 #define PIXEL20_21 hq4x_Interp2(pOut+BpL+BpL, c[4], c[5], c[8]);
228 #define PIXEL20_31 hq4x_Interp3(pOut+BpL+BpL, c[5], c[8]);
229 #define PIXEL20_50 hq4x_Interp5(pOut+BpL+BpL, c[4], c[5]);
230 #define PIXEL20_60 hq4x_Interp6(pOut+BpL+BpL, c[5], c[4], c[8]);
231 #define PIXEL20_61 hq4x_Interp6(pOut+BpL+BpL, c[5], c[4], c[7]);
232 #define PIXEL20_82 hq4x_Interp8(pOut+BpL+BpL, c[5], c[4]);
233 #define PIXEL20_83 hq4x_Interp8(pOut+BpL+BpL, c[4], c[8]);
234 #define PIXEL21_0 *((int*)(pOut+BpL+BpL+BPP)) = c[5];
235 #define PIXEL21_30 hq4x_Interp3(pOut+BpL+BpL+BPP, c[5], c[7]);
236 #define PIXEL21_31 hq4x_Interp3(pOut+BpL+BpL+BPP, c[5], c[8]);
237 #define PIXEL21_32 hq4x_Interp3(pOut+BpL+BpL+BPP, c[5], c[4]);
238 #define PIXEL21_70 hq4x_Interp7(pOut+BpL+BpL+BPP, c[5], c[4], c[8]);
239 #define PIXEL22_0 *((int*)(pOut+BpL+BpL+BPP2)) = c[5];
240 #define PIXEL22_30 hq4x_Interp3(pOut+BpL+BpL+BPP2, c[5], c[9]);
241 #define PIXEL22_31 hq4x_Interp3(pOut+BpL+BpL+BPP2, c[5], c[6]);
242 #define PIXEL22_32 hq4x_Interp3(pOut+BpL+BpL+BPP2, c[5], c[8]);
243 #define PIXEL22_70 hq4x_Interp7(pOut+BpL+BpL+BPP2, c[5], c[6], c[8]);
244 #define PIXEL23_0 *((int*)(pOut+BpL+BpL+BPP3)) = c[5];
245 #define PIXEL23_10 hq4x_Interp1(pOut+BpL+BpL+BPP3, c[5], c[9]);
246 #define PIXEL23_11 hq4x_Interp1(pOut+BpL+BpL+BPP3, c[5], c[6]);
247 #define PIXEL23_13 hq4x_Interp1(pOut+BpL+BpL+BPP3, c[6], c[5]);
248 #define PIXEL23_21 hq4x_Interp2(pOut+BpL+BpL+BPP3, c[6], c[5], c[8]);
249 #define PIXEL23_32 hq4x_Interp3(pOut+BpL+BpL+BPP3, c[5], c[8]);
250 #define PIXEL23_50 hq4x_Interp5(pOut+BpL+BpL+BPP3, c[6], c[5]);
251 #define PIXEL23_60 hq4x_Interp6(pOut+BpL+BpL+BPP3, c[5], c[6], c[8]);
252 #define PIXEL23_61 hq4x_Interp6(pOut+BpL+BpL+BPP3, c[5], c[6], c[9]);
253 #define PIXEL23_81 hq4x_Interp8(pOut+BpL+BpL+BPP3, c[5], c[6]);
254 #define PIXEL23_83 hq4x_Interp8(pOut+BpL+BpL+BPP3, c[6], c[8]);
255 #define PIXEL30_0 *((int*)(pOut+BpL+BpL+BpL)) = c[5];
256 #define PIXEL30_11 hq4x_Interp1(pOut+BpL+BpL+BpL, c[5], c[8]);
257 #define PIXEL30_12 hq4x_Interp1(pOut+BpL+BpL+BpL, c[5], c[4]);
258 #define PIXEL30_20 hq4x_Interp2(pOut+BpL+BpL+BpL, c[5], c[8], c[4]);
259 #define PIXEL30_50 hq4x_Interp5(pOut+BpL+BpL+BpL, c[8], c[4]);
260 #define PIXEL30_80 hq4x_Interp8(pOut+BpL+BpL+BpL, c[5], c[7]);
261 #define PIXEL30_81 hq4x_Interp8(pOut+BpL+BpL+BpL, c[5], c[8]);
262 #define PIXEL30_82 hq4x_Interp8(pOut+BpL+BpL+BpL, c[5], c[4]);
263 #define PIXEL31_0 *((int*)(pOut+BpL+BpL+BpL+BPP)) = c[5];
264 #define PIXEL31_10 hq4x_Interp1(pOut+BpL+BpL+BpL+BPP, c[5], c[7]);
265 #define PIXEL31_11 hq4x_Interp1(pOut+BpL+BpL+BpL+BPP, c[5], c[8]);
266 #define PIXEL31_13 hq4x_Interp1(pOut+BpL+BpL+BpL+BPP, c[8], c[5]);
267 #define PIXEL31_21 hq4x_Interp2(pOut+BpL+BpL+BpL+BPP, c[8], c[5], c[4]);
268 #define PIXEL31_32 hq4x_Interp3(pOut+BpL+BpL+BpL+BPP, c[5], c[4]);
269 #define PIXEL31_50 hq4x_Interp5(pOut+BpL+BpL+BpL+BPP, c[8], c[5]);
270 #define PIXEL31_60 hq4x_Interp6(pOut+BpL+BpL+BpL+BPP, c[5], c[8], c[4]);
271 #define PIXEL31_61 hq4x_Interp6(pOut+BpL+BpL+BpL+BPP, c[5], c[8], c[7]);
272 #define PIXEL31_81 hq4x_Interp8(pOut+BpL+BpL+BpL+BPP, c[5], c[8]);
273 #define PIXEL31_83 hq4x_Interp8(pOut+BpL+BpL+BpL+BPP, c[8], c[4]);
274 #define PIXEL32_0 *((int*)(pOut+BpL+BpL+BpL+BPP2)) = c[5];
275 #define PIXEL32_10 hq4x_Interp1(pOut+BpL+BpL+BpL+BPP2, c[5], c[9]);
276 #define PIXEL32_12 hq4x_Interp1(pOut+BpL+BpL+BpL+BPP2, c[5], c[8]);
277 #define PIXEL32_14 hq4x_Interp1(pOut+BpL+BpL+BpL+BPP2, c[8], c[5]);
278 #define PIXEL32_21 hq4x_Interp2(pOut+BpL+BpL+BpL+BPP2, c[8], c[5], c[6]);
279 #define PIXEL32_31 hq4x_Interp3(pOut+BpL+BpL+BpL+BPP2, c[5], c[6]);
280 #define PIXEL32_50 hq4x_Interp5(pOut+BpL+BpL+BpL+BPP2, c[8], c[5]);
281 #define PIXEL32_60 hq4x_Interp6(pOut+BpL+BpL+BpL+BPP2, c[5], c[8], c[6]);
282 #define PIXEL32_61 hq4x_Interp6(pOut+BpL+BpL+BpL+BPP2, c[5], c[8], c[9]);
283 #define PIXEL32_82 hq4x_Interp8(pOut+BpL+BpL+BpL+BPP2, c[5], c[8]);
284 #define PIXEL32_83 hq4x_Interp8(pOut+BpL+BpL+BpL+BPP2, c[8], c[6]);
285 #define PIXEL33_0 *((int*)(pOut+BpL+BpL+BpL+BPP3)) = c[5];
286 #define PIXEL33_11 hq4x_Interp1(pOut+BpL+BpL+BpL+BPP3, c[5], c[6]);
287 #define PIXEL33_12 hq4x_Interp1(pOut+BpL+BpL+BpL+BPP3, c[5], c[8]);
288 #define PIXEL33_20 hq4x_Interp2(pOut+BpL+BpL+BpL+BPP3, c[5], c[8], c[6]);
289 #define PIXEL33_50 hq4x_Interp5(pOut+BpL+BpL+BpL+BPP3, c[8], c[6]);
290 #define PIXEL33_80 hq4x_Interp8(pOut+BpL+BpL+BpL+BPP3, c[5], c[9]);
291 #define PIXEL33_81 hq4x_Interp8(pOut+BpL+BpL+BpL+BPP3, c[5], c[6]);
292 #define PIXEL33_82 hq4x_Interp8(pOut+BpL+BpL+BpL+BPP3, c[5], c[8]);
296 inline bool Diff_16(uint16 w1, uint16 w2)
298 YUV1 = RGB16toYUV(w1);
299 YUV2 = RGB16toYUV(w2);
300 return ( ( abs((YUV1 & Amask) - (YUV2 & Amask)) > trA ) ||
301 ( abs((YUV1 & Ymask) - (YUV2 & Ymask)) > trY ) ||
302 ( abs((YUV1 & Umask) - (YUV2 & Umask)) > trU ) ||
303 ( abs((YUV1 & Vmask) - (YUV2 & Vmask)) > trV ) );
305 inline bool Diff_32(uint32 w1, uint32 w2)
307 YUV1 = RGB32toYUV(w1);
308 YUV2 = RGB32toYUV(w2);
309 return ( ( abs((YUV1 & Amask) - (YUV2 & Amask)) > trA ) ||
310 ( abs((YUV1 & Ymask) - (YUV2 & Ymask)) > trY ) ||
311 ( abs((YUV1 & Umask) - (YUV2 & Umask)) > trU ) ||
312 ( abs((YUV1 & Vmask) - (YUV2 & Vmask)) > trV ) );
315 void hq4x_16( unsigned char * pIn, unsigned char * pOut, int Xres, int Yres, int SrcPPL, int BpL )
317 #define hq4x_Interp1 hq4x_Interp1_16
318 #define hq4x_Interp2 hq4x_Interp2_16
319 #define hq4x_Interp3 hq4x_Interp3_16
320 #define hq4x_Interp4 hq4x_Interp4_16
321 #define hq4x_Interp5 hq4x_Interp5_16
322 #define hq4x_Interp6 hq4x_Interp6_16
323 #define hq4x_Interp7 hq4x_Interp7_16
324 #define hq4x_Interp8 hq4x_Interp8_16
331 int prevline, nextline;
346 for (j=0; j<Yres; j++)
348 if (j>0) prevline = -SrcPPL*2; else prevline = 0;
349 if (j<Yres-1) nextline = SrcPPL*2; else nextline = 0;
351 for (i=0; i<Xres; i++)
353 w[2] = *((uint16*)(pIn + prevline));
354 w[5] = *((uint16*)pIn);
355 w[8] = *((uint16*)(pIn + nextline));
359 w[1] = *((uint16*)(pIn + prevline - 2));
360 w[4] = *((uint16*)(pIn - 2));
361 w[7] = *((uint16*)(pIn + nextline - 2));
372 w[3] = *((uint16*)(pIn + prevline + 2));
373 w[6] = *((uint16*)(pIn + 2));
374 w[9] = *((uint16*)(pIn + nextline + 2));
386 YUV1 = RGB16toYUV(w[5]);
394 YUV2 = RGB16toYUV(w[k]);
395 if ( ( abs((YUV1 & Amask) - (YUV2 & Amask)) > trA ) ||
396 ( abs((YUV1 & Ymask) - (YUV2 & Ymask)) > trY ) ||
397 ( abs((YUV1 & Umask) - (YUV2 & Umask)) > trU ) ||
398 ( abs((YUV1 & Vmask) - (YUV2 & Vmask)) > trV ) )
407 #include "TextureFilters_hq4x.h"
412 pIn += 2*(SrcPPL-Xres);
413 pOut+= 8*(SrcPPL-Xres);
433 void hq4x_32( unsigned char * pIn, unsigned char * pOut, int Xres, int Yres, int SrcPPL, int BpL )
435 #define hq4x_Interp1 hq4x_Interp1_32
436 #define hq4x_Interp2 hq4x_Interp2_32
437 #define hq4x_Interp3 hq4x_Interp3_32
438 #define hq4x_Interp4 hq4x_Interp4_32
439 #define hq4x_Interp5 hq4x_Interp5_32
440 #define hq4x_Interp6 hq4x_Interp6_32
441 #define hq4x_Interp7 hq4x_Interp7_32
442 #define hq4x_Interp8 hq4x_Interp8_32
449 int prevline, nextline;
464 for (j=0; j<Yres; j++)
466 if (j>0) prevline = -SrcPPL*4; else prevline = 0;
467 if (j<Yres-1) nextline = SrcPPL*4; else nextline = 0;
469 for (i=0; i<Xres; i++)
471 w[2] = *((uint32*)(pIn + prevline));
472 w[5] = *((uint32*)pIn);
473 w[8] = *((uint32*)(pIn + nextline));
477 w[1] = *((uint32*)(pIn + prevline - 4));
478 w[4] = *((uint32*)(pIn - 4));
479 w[7] = *((uint32*)(pIn + nextline - 4));
490 w[3] = *((uint32*)(pIn + prevline + 4));
491 w[6] = *((uint32*)(pIn + 4));
492 w[9] = *((uint32*)(pIn + nextline + 4));
504 YUV1 = RGB32toYUV(w[5]);
512 YUV2 = RGB32toYUV(w[k]);
513 if ( ( abs((YUV1 & Amask) - (YUV2 & Amask)) > trA ) ||
514 ( abs((YUV1 & Ymask) - (YUV2 & Ymask)) > trY ) ||
515 ( abs((YUV1 & Umask) - (YUV2 & Umask)) > trU ) ||
516 ( abs((YUV1 & Vmask) - (YUV2 & Vmask)) > trV ) )
525 #include "TextureFilters_hq4x.h"
531 pIn += 4*(SrcPPL-Xres);
532 pOut+= 16*(SrcPPL-Xres);
552 void hq4x_InitLUTs(void)
554 static bool done = false;
555 int i, j, k, r, g, b, Y, u, v;
568 Y = (r + g + b) >> 2;
569 u = 128 + ((r - b) >> 2);
570 v = 128 + ((-r + 2*g -b)>>3);
571 RGBtoYUV[ (i << 8) + (j << 4) + k ] = (Y<<16) + (u<<8) + v;