Mercurial > vba-linux
diff src/filters/interp.h @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/filters/interp.h Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,351 @@ 1.4 +/* 1.5 + * This file is part of the Advance project. 1.6 + * 1.7 + * Copyright (C) 2003 Andrea Mazzoleni 1.8 + * 1.9 + * This program is free software; you can redistribute it and/or modify 1.10 + * it under the terms of the GNU General Public License as published by 1.11 + * the Free Software Foundation; either version 2 of the License, or 1.12 + * (at your option) any later version. 1.13 + * 1.14 + * This program is distributed in the hope that it will be useful, 1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.17 + * GNU General Public License for more details. 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License 1.20 + * along with this program; if not, write to the Free Software 1.21 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 1.22 + * 1.23 + * In addition, as a special exception, Andrea Mazzoleni 1.24 + * gives permission to link the code of this program with 1.25 + * the MAME library (or with modified versions of MAME that use the 1.26 + * same license as MAME), and distribute linked combinations including 1.27 + * the two. You must obey the GNU General Public License in all 1.28 + * respects for all of the code used other than MAME. If you modify 1.29 + * this file, you may extend this exception to your version of the 1.30 + * file, but you are not obligated to do so. If you do not wish to 1.31 + * do so, delete this exception statement from your version. 1.32 + */ 1.33 + 1.34 +#ifndef __INTERP_H 1.35 +#define __INTERP_H 1.36 + 1.37 +/***************************************************************************/ 1.38 +/* Basic types */ 1.39 + 1.40 +/***************************************************************************/ 1.41 +/* interpolation */ 1.42 + 1.43 +extern unsigned interp_mask[2]; 1.44 +extern unsigned interp_bits_per_pixel; 1.45 + 1.46 +#define INTERP_16_MASK_1(v) (v & interp_mask[0]) 1.47 +#define INTERP_16_MASK_2(v) (v & interp_mask[1]) 1.48 + 1.49 +static inline u16 interp_16_521(u16 p1, u16 p2, u16 p3) 1.50 +{ 1.51 + return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*5 + INTERP_16_MASK_1(p2)*2 + INTERP_16_MASK_1(p3)*1) / 8) 1.52 + | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*5 + INTERP_16_MASK_2(p2)*2 + INTERP_16_MASK_2(p3)*1) / 8); 1.53 +} 1.54 + 1.55 +static inline u16 interp_16_332(u16 p1, u16 p2, u16 p3) 1.56 +{ 1.57 + return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*3 + INTERP_16_MASK_1(p2)*3 + INTERP_16_MASK_1(p3)*2) / 8) 1.58 + | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*3 + INTERP_16_MASK_2(p2)*3 + INTERP_16_MASK_2(p3)*2) / 8); 1.59 +} 1.60 + 1.61 +static inline u16 interp_16_611(u16 p1, u16 p2, u16 p3) 1.62 +{ 1.63 + return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*6 + INTERP_16_MASK_1(p2) + INTERP_16_MASK_1(p3)) / 8) 1.64 + | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*6 + INTERP_16_MASK_2(p2) + INTERP_16_MASK_2(p3)) / 8); 1.65 +} 1.66 + 1.67 +static inline u16 interp_16_71(u16 p1, u16 p2) 1.68 +{ 1.69 + return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*7 + INTERP_16_MASK_1(p2)) / 8) 1.70 + | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*7 + INTERP_16_MASK_2(p2)) / 8); 1.71 +} 1.72 + 1.73 +static inline u16 interp_16_211(u16 p1, u16 p2, u16 p3) 1.74 +{ 1.75 + return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*2 + INTERP_16_MASK_1(p2) + INTERP_16_MASK_1(p3)) / 4) 1.76 + | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*2 + INTERP_16_MASK_2(p2) + INTERP_16_MASK_2(p3)) / 4); 1.77 +} 1.78 + 1.79 +static inline u16 interp_16_772(u16 p1, u16 p2, u16 p3) 1.80 +{ 1.81 + return INTERP_16_MASK_1(((INTERP_16_MASK_1(p1) + INTERP_16_MASK_1(p2))*7 + INTERP_16_MASK_1(p3)*2) / 16) 1.82 + | INTERP_16_MASK_2(((INTERP_16_MASK_2(p1) + INTERP_16_MASK_2(p2))*7 + INTERP_16_MASK_2(p3)*2) / 16); 1.83 +} 1.84 + 1.85 +static inline u16 interp_16_11(u16 p1, u16 p2) 1.86 +{ 1.87 + return INTERP_16_MASK_1((INTERP_16_MASK_1(p1) + INTERP_16_MASK_1(p2)) / 2) 1.88 + | INTERP_16_MASK_2((INTERP_16_MASK_2(p1) + INTERP_16_MASK_2(p2)) / 2); 1.89 +} 1.90 + 1.91 +static inline u16 interp_16_31(u16 p1, u16 p2) 1.92 +{ 1.93 + return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*3 + INTERP_16_MASK_1(p2)) / 4) 1.94 + | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*3 + INTERP_16_MASK_2(p2)) / 4); 1.95 +} 1.96 + 1.97 +static inline u16 interp_16_1411(u16 p1, u16 p2, u16 p3) 1.98 +{ 1.99 + return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*14 + INTERP_16_MASK_1(p2) + INTERP_16_MASK_1(p3)) / 16) 1.100 + | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*14 + INTERP_16_MASK_2(p2) + INTERP_16_MASK_2(p3)) / 16); 1.101 +} 1.102 + 1.103 +static inline u16 interp_16_431(u16 p1, u16 p2, u16 p3) 1.104 +{ 1.105 + return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*4 + INTERP_16_MASK_1(p2)*3 + INTERP_16_MASK_1(p3)) / 8) 1.106 + | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*4 + INTERP_16_MASK_2(p2)*3 + INTERP_16_MASK_2(p3)) / 8); 1.107 +} 1.108 + 1.109 +static inline u16 interp_16_53(u16 p1, u16 p2) 1.110 +{ 1.111 + return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*5 + INTERP_16_MASK_1(p2)*3) / 8) 1.112 + | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*5 + INTERP_16_MASK_2(p2)*3) / 8); 1.113 +} 1.114 + 1.115 +static inline u16 interp_16_151(u16 p1, u16 p2) 1.116 +{ 1.117 + return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*15 + INTERP_16_MASK_1(p2)) / 16) 1.118 + | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*15 + INTERP_16_MASK_2(p2)) / 16); 1.119 +} 1.120 + 1.121 +static inline u16 interp_16_97(u16 p1, u16 p2) 1.122 +{ 1.123 + return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*9 + INTERP_16_MASK_1(p2)*7) / 16) 1.124 + | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*9 + INTERP_16_MASK_2(p2)*7) / 16); 1.125 +} 1.126 + 1.127 +#define INTERP_32_MASK_1(v) (v & 0xFF00FF) 1.128 +#define INTERP_32_MASK_2(v) (v & 0x00FF00) 1.129 + 1.130 +static inline u32 interp_32_521(u32 p1, u32 p2, u32 p3) 1.131 +{ 1.132 + return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*5 + INTERP_32_MASK_1(p2)*2 + INTERP_32_MASK_1(p3)*1) / 8) 1.133 + | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*5 + INTERP_32_MASK_2(p2)*2 + INTERP_32_MASK_2(p3)*1) / 8); 1.134 +} 1.135 + 1.136 +static inline u32 interp_32_332(u32 p1, u32 p2, u32 p3) 1.137 +{ 1.138 + return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*3 + INTERP_32_MASK_1(p2)*3 + INTERP_32_MASK_1(p3)*2) / 8) 1.139 + | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*3 + INTERP_32_MASK_2(p2)*3 + INTERP_32_MASK_2(p3)*2) / 8); 1.140 +} 1.141 + 1.142 +static inline u32 interp_32_211(u32 p1, u32 p2, u32 p3) 1.143 +{ 1.144 + return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*2 + INTERP_32_MASK_1(p2) + INTERP_32_MASK_1(p3)) / 4) 1.145 + | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*2 + INTERP_32_MASK_2(p2) + INTERP_32_MASK_2(p3)) / 4); 1.146 +} 1.147 + 1.148 +static inline u32 interp_32_611(u32 p1, u32 p2, u32 p3) 1.149 +{ 1.150 + return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*6 + INTERP_32_MASK_1(p2) + INTERP_32_MASK_1(p3)) / 8) 1.151 + | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*6 + INTERP_32_MASK_2(p2) + INTERP_32_MASK_2(p3)) / 8); 1.152 +} 1.153 + 1.154 +static inline u32 interp_32_71(u32 p1, u32 p2) 1.155 +{ 1.156 + return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*7 + INTERP_32_MASK_1(p2)) / 8) 1.157 + | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*7 + INTERP_32_MASK_2(p2)) / 8); 1.158 +} 1.159 + 1.160 +static inline u32 interp_32_772(u32 p1, u32 p2, u32 p3) 1.161 +{ 1.162 + return INTERP_32_MASK_1(((INTERP_32_MASK_1(p1) + INTERP_32_MASK_1(p2))*7 + INTERP_32_MASK_1(p3)*2) / 16) 1.163 + | INTERP_32_MASK_2(((INTERP_32_MASK_2(p1) + INTERP_32_MASK_2(p2))*7 + INTERP_32_MASK_2(p3)*2) / 16); 1.164 +} 1.165 + 1.166 +static inline u32 interp_32_11(u32 p1, u32 p2) 1.167 +{ 1.168 + return INTERP_32_MASK_1((INTERP_32_MASK_1(p1) + INTERP_32_MASK_1(p2)) / 2) 1.169 + | INTERP_32_MASK_2((INTERP_32_MASK_2(p1) + INTERP_32_MASK_2(p2)) / 2); 1.170 +} 1.171 + 1.172 +static inline u32 interp_32_31(u32 p1, u32 p2) 1.173 +{ 1.174 + return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*3 + INTERP_32_MASK_1(p2)) / 4) 1.175 + | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*3 + INTERP_32_MASK_2(p2)) / 4); 1.176 +} 1.177 + 1.178 +static inline u32 interp_32_1411(u32 p1, u32 p2, u32 p3) 1.179 +{ 1.180 + return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*14 + INTERP_32_MASK_1(p2) + INTERP_32_MASK_1(p3)) / 16) 1.181 + | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*14 + INTERP_32_MASK_2(p2) + INTERP_32_MASK_2(p3)) / 16); 1.182 +} 1.183 + 1.184 +static inline u32 interp_32_431(u32 p1, u32 p2, u32 p3) 1.185 +{ 1.186 + return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*4 + INTERP_32_MASK_1(p2)*3 + INTERP_32_MASK_1(p3)) / 8) 1.187 + | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*4 + INTERP_32_MASK_2(p2)*3 + INTERP_32_MASK_2(p3)) / 8); 1.188 +} 1.189 + 1.190 +static inline u32 interp_32_53(u32 p1, u32 p2) 1.191 +{ 1.192 + return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*5 + INTERP_32_MASK_1(p2)*3) / 8) 1.193 + | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*5 + INTERP_32_MASK_2(p2)*3) / 8); 1.194 +} 1.195 + 1.196 +static inline u32 interp_32_151(u32 p1, u32 p2) 1.197 +{ 1.198 + return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*15 + INTERP_32_MASK_1(p2)) / 16) 1.199 + | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*15 + INTERP_32_MASK_2(p2)) / 16); 1.200 +} 1.201 + 1.202 +static inline u32 interp_32_97(u32 p1, u32 p2) 1.203 +{ 1.204 + return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*9 + INTERP_32_MASK_1(p2)*7) / 16) 1.205 + | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*9 + INTERP_32_MASK_2(p2)*7) / 16); 1.206 +} 1.207 + 1.208 +/***************************************************************************/ 1.209 +/* diff */ 1.210 + 1.211 +#define INTERP_Y_LIMIT (0x30*4) 1.212 +#define INTERP_U_LIMIT (0x07*4) 1.213 +#define INTERP_V_LIMIT (0x06*8) 1.214 + 1.215 +static int interp_16_diff(u16 p1, u16 p2) 1.216 +{ 1.217 + int r, g, b; 1.218 + int y, u, v; 1.219 + 1.220 + if (p1 == p2) 1.221 + return 0; 1.222 + 1.223 + if (interp_bits_per_pixel == 16) { 1.224 + b = (int)((p1 & 0x1F) - (p2 & 0x1F)) << 3; 1.225 + g = (int)((p1 & 0x7E0) - (p2 & 0x7E0)) >> 3; 1.226 + r = (int)((p1 & 0xF800) - (p2 & 0xF800)) >> 8; 1.227 + } else { 1.228 + b = (int)((p1 & 0x1F) - (p2 & 0x1F)) << 3; 1.229 + g = (int)((p1 & 0x3E0) - (p2 & 0x3E0)) >> 2; 1.230 + r = (int)((p1 & 0x7C00) - (p2 & 0x7C00)) >> 7; 1.231 + } 1.232 + 1.233 + y = r + g + b; 1.234 + u = r - b; 1.235 + v = -r + 2*g - b; 1.236 + 1.237 + if (y < -INTERP_Y_LIMIT || y > INTERP_Y_LIMIT) 1.238 + return 1; 1.239 + 1.240 + if (u < -INTERP_U_LIMIT || u > INTERP_U_LIMIT) 1.241 + return 1; 1.242 + 1.243 + if (v < -INTERP_V_LIMIT || v > INTERP_V_LIMIT) 1.244 + return 1; 1.245 + 1.246 +return 0; 1.247 +} 1.248 + 1.249 +static int interp_32_diff(u32 p1, u32 p2) 1.250 +{ 1.251 + int r, g, b; 1.252 + int y, u, v; 1.253 + 1.254 + if ((p1 & 0xF8F8F8) == (p2 & 0xF8F8F8)) 1.255 + return 0; 1.256 + 1.257 + b = (int)((p1 & 0xFF) - (p2 & 0xFF)); 1.258 + g = (int)((p1 & 0xFF00) - (p2 & 0xFF00)) >> 8; 1.259 + r = (int)((p1 & 0xFF0000) - (p2 & 0xFF0000)) >> 16; 1.260 + 1.261 + y = r + g + b; 1.262 + u = r - b; 1.263 + v = -r + 2*g - b; 1.264 + 1.265 + if (y < -INTERP_Y_LIMIT || y > INTERP_Y_LIMIT) 1.266 + return 1; 1.267 + 1.268 + if (u < -INTERP_U_LIMIT || u > INTERP_U_LIMIT) 1.269 + return 1; 1.270 + 1.271 + if (v < -INTERP_V_LIMIT || v > INTERP_V_LIMIT) 1.272 + return 1; 1.273 + 1.274 + return 0; 1.275 +} 1.276 + 1.277 + 1.278 +#define INTERP_LIMIT2 (96000) 1.279 +#define ABS(x) ((x) < 0 ? -(x) : (x)) 1.280 +#define MAX(x,y) ((x) > (y) ? (x) : (y)) 1.281 +#define MIN(x,y) ((x) < (y) ? (x) : (y)) 1.282 + 1.283 +static int interp_16_diff2(u16 p1, u16 p2) 1.284 +{ 1.285 + int r, g, b; 1.286 + int y, u, v; 1.287 + 1.288 + if ((p1 & 0xF79E) == (p2 & 0xF79E)) 1.289 + return 0; 1.290 + 1.291 + if (interp_bits_per_pixel == 16) { 1.292 + b = (int)((p1 & 0x1F) - (p2 & 0x1F)) << 3; 1.293 + g = (int)((p1 & 0x7E0) - (p2 & 0x7E0)) >> 3; 1.294 + r = (int)((p1 & 0xF800) - (p2 & 0xF800)) >> 8; 1.295 + } else { 1.296 + b = (int)((p1 & 0x1F) - (p2 & 0x1F)) << 3; 1.297 + g = (int)((p1 & 0x3E0) - (p2 & 0x3E0)) >> 2; 1.298 + r = (int)((p1 & 0x7C00) - (p2 & 0x7C00)) >> 7; 1.299 + } 1.300 + 1.301 +// yb = 30*r + 58*g + 12*b; 1.302 + y = 33*r + 36*g + 31*b; 1.303 + u = -14*r - 29*g + 44*b; 1.304 + v = 62*r - 51*g - 10*b; 1.305 + 1.306 + if (11*ABS(y) + 8*ABS(u) + 6*ABS(v) > INTERP_LIMIT2) 1.307 + return 1; 1.308 + return 0; 1.309 +} 1.310 + 1.311 +static int interp_32_diff2(u32 p1, u32 p2) 1.312 +{ 1.313 + int r, g, b; 1.314 + int y, u, v; 1.315 + 1.316 + if ((p1 & 0xF0F0F0) == (p2 & 0xF0F0F0)) 1.317 + return 0; 1.318 + 1.319 + b = (int)((p1 & 0xF8) - (p2 & 0xF8)); 1.320 + g = (int)((p1 & 0xF800) - (p2 & 0xF800)) >> 8; 1.321 + r = (int)((p1 & 0xF80000) - (p2 & 0xF80000)) >> 16; 1.322 + 1.323 +// y = 30*r + 58*g + 12*b; 1.324 + y = 33*r + 36*g + 31*b; 1.325 + u = -14*r - 29*g + 44*b; 1.326 + v = 62*r - 51*g - 10*b; 1.327 + 1.328 + if (11*ABS(y) + 8*ABS(u) + 6*ABS(v) > INTERP_LIMIT2) 1.329 + return 1; 1.330 + 1.331 + return 0; 1.332 +} 1.333 + 1.334 +static void interp_set(unsigned bits_per_pixel) 1.335 +{ 1.336 + interp_bits_per_pixel = bits_per_pixel; 1.337 + 1.338 + switch (bits_per_pixel) { 1.339 + case 15 : 1.340 + interp_mask[0] = 0x7C1F; 1.341 + interp_mask[1] = 0x03E0; 1.342 + break; 1.343 + case 16 : 1.344 + interp_mask[0] = 0xF81F; 1.345 + interp_mask[1] = 0x07E0; 1.346 + break; 1.347 + case 32 : 1.348 + interp_mask[0] = 0xFF00FF; 1.349 + interp_mask[1] = 0x00FF00; 1.350 + break; 1.351 + } 1.352 +} 1.353 + 1.354 +#endif