Mercurial > vba-linux
diff src/filters/2xSaI.cpp @ 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/2xSaI.cpp Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,1434 @@ 1.4 +#include "../common/System.h" 1.5 + 1.6 +extern "C" 1.7 +{ 1.8 +#ifdef MMX 1.9 + void _2xSaILine(u8 *srcPtr, u8 *deltaPtr, u32 srcPitch, 1.10 + u32 width, u8 *dstPtr, u32 dstPitch); 1.11 + void _2xSaISuperEagleLine(u8 *srcPtr, u8 *deltaPtr, 1.12 + u32 srcPitch, u32 width, 1.13 + u8 *dstPtr, u32 dstPitch); 1.14 + void _2xSaISuper2xSaILine(u8 *srcPtr, u8 *deltaPtr, 1.15 + u32 srcPitch, u32 width, 1.16 + u8 *dstPtr, u32 dstPitch); 1.17 + void Init_2xSaIMMX(u32 BitFormat); 1.18 + void BilinearMMX(u16 *A, u16 *B, u16 *C, u16 *D, 1.19 + u16 *dx, u16 *dy, u8 *dP); 1.20 + void BilinearMMXGrid0(u16 *A, u16 *B, u16 *C, u16 *D, 1.21 + u16 *dx, u16 *dy, u8 *dP); 1.22 + void BilinearMMXGrid1(u16 *A, u16 *B, u16 *C, u16 *D, 1.23 + u16 *dx, u16 *dy, u8 *dP); 1.24 + void EndMMX(); 1.25 + 1.26 + bool cpu_mmx = 1; 1.27 +#endif 1.28 +} 1.29 +static u32 colorMask = 0xF7DEF7DE; 1.30 +static u32 lowPixelMask = 0x08210821; 1.31 +static u32 qcolorMask = 0xE79CE79C; 1.32 +static u32 qlowpixelMask = 0x18631863; 1.33 +static u32 redblueMask = 0xF81F; 1.34 +static u32 greenMask = 0x7E0; 1.35 + 1.36 +u32 qRGB_COLOR_MASK[2] = { 0xF7DEF7DE, 0xF7DEF7DE }; 1.37 + 1.38 +extern void hq2x_init(unsigned); 1.39 + 1.40 +int Init_2xSaI(u32 BitFormat) 1.41 +{ 1.42 + if (systemColorDepth == 16) 1.43 + { 1.44 + if (BitFormat == 565) 1.45 + { 1.46 + colorMask = 0xF7DEF7DE; 1.47 + lowPixelMask = 0x08210821; 1.48 + qcolorMask = 0xE79CE79C; 1.49 + qlowpixelMask = 0x18631863; 1.50 + redblueMask = 0xF81F; 1.51 + greenMask = 0x7E0; 1.52 + qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0xF7DEF7DE; 1.53 + hq2x_init(16); 1.54 + } 1.55 + else if (BitFormat == 555) 1.56 + { 1.57 + colorMask = 0x7BDE7BDE; 1.58 + lowPixelMask = 0x04210421; 1.59 + qcolorMask = 0x739C739C; 1.60 + qlowpixelMask = 0x0C630C63; 1.61 + redblueMask = 0x7C1F; 1.62 + greenMask = 0x3E0; 1.63 + qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0x7BDE7BDE; 1.64 + hq2x_init(15); 1.65 + } 1.66 + else 1.67 + { 1.68 + return 0; 1.69 + } 1.70 + } 1.71 + else if (systemColorDepth == 32) 1.72 + { 1.73 + colorMask = 0xfefefe; 1.74 + lowPixelMask = 0x010101; 1.75 + qcolorMask = 0xfcfcfc; 1.76 + qlowpixelMask = 0x030303; 1.77 + qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0xfefefe; 1.78 + hq2x_init(32); 1.79 + } 1.80 + else 1.81 + return 0; 1.82 + 1.83 +#ifdef MMX 1.84 + Init_2xSaIMMX(BitFormat); 1.85 +#endif 1.86 + 1.87 + return 1; 1.88 +} 1.89 + 1.90 +static inline int GetResult1(u32 A, u32 B, u32 C, u32 D, 1.91 + u32 /* E */) 1.92 +{ 1.93 + int x = 0; 1.94 + int y = 0; 1.95 + int r = 0; 1.96 + 1.97 + if (A == C) 1.98 + x += 1; 1.99 + else if (B == C) 1.100 + y += 1; 1.101 + if (A == D) 1.102 + x += 1; 1.103 + else if (B == D) 1.104 + y += 1; 1.105 + if (x <= 1) 1.106 + r += 1; 1.107 + if (y <= 1) 1.108 + r -= 1; 1.109 + return r; 1.110 +} 1.111 + 1.112 +static inline int GetResult2(u32 A, u32 B, u32 C, u32 D, 1.113 + u32 /* E */) 1.114 +{ 1.115 + int x = 0; 1.116 + int y = 0; 1.117 + int r = 0; 1.118 + 1.119 + if (A == C) 1.120 + x += 1; 1.121 + else if (B == C) 1.122 + y += 1; 1.123 + if (A == D) 1.124 + x += 1; 1.125 + else if (B == D) 1.126 + y += 1; 1.127 + if (x <= 1) 1.128 + r -= 1; 1.129 + if (y <= 1) 1.130 + r += 1; 1.131 + return r; 1.132 +} 1.133 + 1.134 +static inline int GetResult(u32 A, u32 B, u32 C, u32 D) 1.135 +{ 1.136 + int x = 0; 1.137 + int y = 0; 1.138 + int r = 0; 1.139 + 1.140 + if (A == C) 1.141 + x += 1; 1.142 + else if (B == C) 1.143 + y += 1; 1.144 + if (A == D) 1.145 + x += 1; 1.146 + else if (B == D) 1.147 + y += 1; 1.148 + if (x <= 1) 1.149 + r += 1; 1.150 + if (y <= 1) 1.151 + r -= 1; 1.152 + return r; 1.153 +} 1.154 + 1.155 +static inline u32 INTERPOLATE(u32 A, u32 B) 1.156 +{ 1.157 + if (A != B) 1.158 + { 1.159 + return (((A & colorMask) >> 1) + ((B & colorMask) >> 1) + 1.160 + (A & B & lowPixelMask)); 1.161 + } 1.162 + else 1.163 + return A; 1.164 +} 1.165 + 1.166 +static inline u32 Q_INTERPOLATE(u32 A, u32 B, u32 C, u32 D) 1.167 +{ 1.168 + register u32 x = ((A & qcolorMask) >> 2) + 1.169 + ((B & qcolorMask) >> 2) + 1.170 + ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2); 1.171 + register u32 y = (A & qlowpixelMask) + 1.172 + (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask); 1.173 + 1.174 + y = (y >> 2) & qlowpixelMask; 1.175 + return x + y; 1.176 +} 1.177 + 1.178 +static inline int GetResult1_32(u32 A, u32 B, u32 C, u32 D, 1.179 + u32 /* E */) 1.180 +{ 1.181 + int x = 0; 1.182 + int y = 0; 1.183 + int r = 0; 1.184 + 1.185 + if (A == C) 1.186 + x += 1; 1.187 + else if (B == C) 1.188 + y += 1; 1.189 + if (A == D) 1.190 + x += 1; 1.191 + else if (B == D) 1.192 + y += 1; 1.193 + if (x <= 1) 1.194 + r += 1; 1.195 + if (y <= 1) 1.196 + r -= 1; 1.197 + return r; 1.198 +} 1.199 + 1.200 +static inline int GetResult2_32(u32 A, u32 B, u32 C, u32 D, 1.201 + u32 /* E */) 1.202 +{ 1.203 + int x = 0; 1.204 + int y = 0; 1.205 + int r = 0; 1.206 + 1.207 + if (A == C) 1.208 + x += 1; 1.209 + else if (B == C) 1.210 + y += 1; 1.211 + if (A == D) 1.212 + x += 1; 1.213 + else if (B == D) 1.214 + y += 1; 1.215 + if (x <= 1) 1.216 + r -= 1; 1.217 + if (y <= 1) 1.218 + r += 1; 1.219 + return r; 1.220 +} 1.221 + 1.222 +#define BLUE_MASK565 0x001F001F 1.223 +#define RED_MASK565 0xF800F800 1.224 +#define GREEN_MASK565 0x07E007E0 1.225 + 1.226 +#define BLUE_MASK555 0x001F001F 1.227 +#define RED_MASK555 0x7C007C00 1.228 +#define GREEN_MASK555 0x03E003E0 1.229 + 1.230 +void Super2xSaI(u8 *srcPtr, u32 srcPitch, 1.231 + u8 *deltaPtr, u8 *dstPtr, u32 dstPitch, 1.232 + int width, int height) 1.233 +{ 1.234 + u16 *bP; 1.235 + u8 * dP; 1.236 + u32 inc_bP; 1.237 + u32 Nextline = srcPitch >> 1; 1.238 +#ifdef MMX 1.239 + if (cpu_mmx) 1.240 + { 1.241 + for (; height; height--) 1.242 + { 1.243 + _2xSaISuper2xSaILine(srcPtr, deltaPtr, srcPitch, width, 1.244 + dstPtr, dstPitch); 1.245 + srcPtr += srcPitch; 1.246 + dstPtr += dstPitch * 2; 1.247 + deltaPtr += srcPitch; 1.248 + } 1.249 + } 1.250 + else 1.251 +#endif 1.252 + { 1.253 + inc_bP = 1; 1.254 + 1.255 + for (; height; height--) 1.256 + { 1.257 + bP = (u16 *) srcPtr; 1.258 + dP = (u8 *) dstPtr; 1.259 + 1.260 + for (u32 finish = width; finish; finish -= inc_bP) 1.261 + { 1.262 + u32 color4, color5, color6; 1.263 + u32 color1, color2, color3; 1.264 + u32 colorA0, colorA1, colorA2, colorA3, 1.265 + colorB0, colorB1, colorB2, colorB3, colorS1, colorS2; 1.266 + u32 product1a, product1b, product2a, product2b; 1.267 + 1.268 + //--------------------------------------- B1 B2 1.269 + // 4 5 6 S2 1.270 + // 1 2 3 S1 1.271 + // A1 A2 1.272 + 1.273 + colorB0 = *(bP - Nextline - 1); 1.274 + colorB1 = *(bP - Nextline); 1.275 + colorB2 = *(bP - Nextline + 1); 1.276 + colorB3 = *(bP - Nextline + 2); 1.277 + 1.278 + color4 = *(bP - 1); 1.279 + color5 = *(bP); 1.280 + color6 = *(bP + 1); 1.281 + colorS2 = *(bP + 2); 1.282 + 1.283 + color1 = *(bP + Nextline - 1); 1.284 + color2 = *(bP + Nextline); 1.285 + color3 = *(bP + Nextline + 1); 1.286 + colorS1 = *(bP + Nextline + 2); 1.287 + 1.288 + colorA0 = *(bP + Nextline + Nextline - 1); 1.289 + colorA1 = *(bP + Nextline + Nextline); 1.290 + colorA2 = *(bP + Nextline + Nextline + 1); 1.291 + colorA3 = *(bP + Nextline + Nextline + 2); 1.292 + 1.293 + //-------------------------------------- 1.294 + if (color2 == color6 && color5 != color3) 1.295 + { 1.296 + product2b = product1b = color2; 1.297 + } 1.298 + else if (color5 == color3 && color2 != color6) 1.299 + { 1.300 + product2b = product1b = color5; 1.301 + } 1.302 + else if (color5 == color3 && color2 == color6) 1.303 + { 1.304 + register int r = 0; 1.305 + 1.306 + r += GetResult(color6, color5, color1, colorA1); 1.307 + r += GetResult(color6, color5, color4, colorB1); 1.308 + r += GetResult(color6, color5, colorA2, colorS1); 1.309 + r += GetResult(color6, color5, colorB2, colorS2); 1.310 + 1.311 + if (r > 0) 1.312 + product2b = product1b = color6; 1.313 + else if (r < 0) 1.314 + product2b = product1b = color5; 1.315 + else 1.316 + { 1.317 + product2b = product1b = INTERPOLATE(color5, color6); 1.318 + } 1.319 + } 1.320 + else 1.321 + { 1.322 + if (color6 == color3 && color3 == colorA1 1.323 + && color2 != colorA2 && color3 != colorA0) 1.324 + product2b = 1.325 + Q_INTERPOLATE(color3, color3, color3, color2); 1.326 + else if (color5 == color2 && color2 == colorA2 1.327 + && colorA1 != color3 && color2 != colorA3) 1.328 + product2b = 1.329 + Q_INTERPOLATE(color2, color2, color2, color3); 1.330 + else 1.331 + product2b = INTERPOLATE(color2, color3); 1.332 + 1.333 + if (color6 == color3 && color6 == colorB1 1.334 + && color5 != colorB2 && color6 != colorB0) 1.335 + product1b = 1.336 + Q_INTERPOLATE(color6, color6, color6, color5); 1.337 + else if (color5 == color2 && color5 == colorB2 1.338 + && colorB1 != color6 && color5 != colorB3) 1.339 + product1b = 1.340 + Q_INTERPOLATE(color6, color5, color5, color5); 1.341 + else 1.342 + product1b = INTERPOLATE(color5, color6); 1.343 + } 1.344 + 1.345 + if (color5 == color3 && color2 != color6 && color4 == color5 1.346 + && color5 != colorA2) 1.347 + product2a = INTERPOLATE(color2, color5); 1.348 + else 1.349 + if (color5 == color1 && color6 == color5 1.350 + && color4 != color2 && color5 != colorA0) 1.351 + product2a = INTERPOLATE(color2, color5); 1.352 + else 1.353 + product2a = color2; 1.354 + 1.355 + if (color2 == color6 && color5 != color3 && color1 == color2 1.356 + && color2 != colorB2) 1.357 + product1a = INTERPOLATE(color2, color5); 1.358 + else 1.359 + if (color4 == color2 && color3 == color2 1.360 + && color1 != color5 && color2 != colorB0) 1.361 + product1a = INTERPOLATE(color2, color5); 1.362 + else 1.363 + product1a = color5; 1.364 + 1.365 +#ifdef WORDS_BIGENDIAN 1.366 + product1a = (product1a << 16) | product1b; 1.367 + product2a = (product2a << 16) | product2b; 1.368 +#else 1.369 + product1a = product1a | (product1b << 16); 1.370 + product2a = product2a | (product2b << 16); 1.371 +#endif 1.372 + 1.373 + *((u32 *) dP) = product1a; 1.374 + *((u32 *) (dP + dstPitch)) = product2a; 1.375 + 1.376 + bP += inc_bP; 1.377 + dP += sizeof(u32); 1.378 + } // end of for ( finish= width etc..) 1.379 + 1.380 + srcPtr += srcPitch; 1.381 + dstPtr += dstPitch << 1; 1.382 + deltaPtr += srcPitch; 1.383 + } // endof: for (; height; height--) 1.384 + } 1.385 +} 1.386 + 1.387 +void Super2xSaI32(u8 *srcPtr, u32 srcPitch, 1.388 + u8 * /* deltaPtr */, u8 *dstPtr, u32 dstPitch, 1.389 + int width, int height) 1.390 +{ 1.391 + u32 *bP; 1.392 + u32 *dP; 1.393 + u32 inc_bP; 1.394 + u32 Nextline = srcPitch >> 2; 1.395 + inc_bP = 1; 1.396 + 1.397 + for (; height; height--) 1.398 + { 1.399 + bP = (u32 *) srcPtr; 1.400 + dP = (u32 *) dstPtr; 1.401 + 1.402 + for (u32 finish = width; finish; finish -= inc_bP) 1.403 + { 1.404 + u32 color4, color5, color6; 1.405 + u32 color1, color2, color3; 1.406 + u32 colorA0, colorA1, colorA2, colorA3, 1.407 + colorB0, colorB1, colorB2, colorB3, colorS1, colorS2; 1.408 + u32 product1a, product1b, product2a, product2b; 1.409 + 1.410 + //--------------------------------------- B1 B2 1.411 + // 4 5 6 S2 1.412 + // 1 2 3 S1 1.413 + // A1 A2 1.414 + 1.415 + colorB0 = *(bP - Nextline - 1); 1.416 + colorB1 = *(bP - Nextline); 1.417 + colorB2 = *(bP - Nextline + 1); 1.418 + colorB3 = *(bP - Nextline + 2); 1.419 + 1.420 + color4 = *(bP - 1); 1.421 + color5 = *(bP); 1.422 + color6 = *(bP + 1); 1.423 + colorS2 = *(bP + 2); 1.424 + 1.425 + color1 = *(bP + Nextline - 1); 1.426 + color2 = *(bP + Nextline); 1.427 + color3 = *(bP + Nextline + 1); 1.428 + colorS1 = *(bP + Nextline + 2); 1.429 + 1.430 + colorA0 = *(bP + Nextline + Nextline - 1); 1.431 + colorA1 = *(bP + Nextline + Nextline); 1.432 + colorA2 = *(bP + Nextline + Nextline + 1); 1.433 + colorA3 = *(bP + Nextline + Nextline + 2); 1.434 + 1.435 + //-------------------------------------- 1.436 + if (color2 == color6 && color5 != color3) 1.437 + { 1.438 + product2b = product1b = color2; 1.439 + } 1.440 + else if (color5 == color3 && color2 != color6) 1.441 + { 1.442 + product2b = product1b = color5; 1.443 + } 1.444 + else if (color5 == color3 && color2 == color6) 1.445 + { 1.446 + register int r = 0; 1.447 + 1.448 + r += GetResult(color6, color5, color1, colorA1); 1.449 + r += GetResult(color6, color5, color4, colorB1); 1.450 + r += GetResult(color6, color5, colorA2, colorS1); 1.451 + r += GetResult(color6, color5, colorB2, colorS2); 1.452 + 1.453 + if (r > 0) 1.454 + product2b = product1b = color6; 1.455 + else if (r < 0) 1.456 + product2b = product1b = color5; 1.457 + else 1.458 + { 1.459 + product2b = product1b = INTERPOLATE(color5, color6); 1.460 + } 1.461 + } 1.462 + else 1.463 + { 1.464 + if (color6 == color3 && color3 == colorA1 1.465 + && color2 != colorA2 && color3 != colorA0) 1.466 + product2b = 1.467 + Q_INTERPOLATE(color3, color3, color3, color2); 1.468 + else if (color5 == color2 && color2 == colorA2 1.469 + && colorA1 != color3 && color2 != colorA3) 1.470 + product2b = 1.471 + Q_INTERPOLATE(color2, color2, color2, color3); 1.472 + else 1.473 + product2b = INTERPOLATE(color2, color3); 1.474 + 1.475 + if (color6 == color3 && color6 == colorB1 1.476 + && color5 != colorB2 && color6 != colorB0) 1.477 + product1b = 1.478 + Q_INTERPOLATE(color6, color6, color6, color5); 1.479 + else if (color5 == color2 && color5 == colorB2 1.480 + && colorB1 != color6 && color5 != colorB3) 1.481 + product1b = 1.482 + Q_INTERPOLATE(color6, color5, color5, color5); 1.483 + else 1.484 + product1b = INTERPOLATE(color5, color6); 1.485 + } 1.486 + 1.487 + if (color5 == color3 && color2 != color6 && color4 == color5 1.488 + && color5 != colorA2) 1.489 + product2a = INTERPOLATE(color2, color5); 1.490 + else 1.491 + if (color5 == color1 && color6 == color5 1.492 + && color4 != color2 && color5 != colorA0) 1.493 + product2a = INTERPOLATE(color2, color5); 1.494 + else 1.495 + product2a = color2; 1.496 + 1.497 + if (color2 == color6 && color5 != color3 && color1 == color2 1.498 + && color2 != colorB2) 1.499 + product1a = INTERPOLATE(color2, color5); 1.500 + else 1.501 + if (color4 == color2 && color3 == color2 1.502 + && color1 != color5 && color2 != colorB0) 1.503 + product1a = INTERPOLATE(color2, color5); 1.504 + else 1.505 + product1a = color5; 1.506 + *(dP) = product1a; 1.507 + *(dP + 1) = product1b; 1.508 + *(dP + (dstPitch >> 2)) = product2a; 1.509 + *(dP + (dstPitch >> 2) + 1) = product2b; 1.510 + 1.511 + bP += inc_bP; 1.512 + dP += 2; 1.513 + } // end of for ( finish= width etc..) 1.514 + 1.515 + srcPtr += srcPitch; 1.516 + dstPtr += dstPitch << 1; 1.517 + // deltaPtr += srcPitch; 1.518 + } // endof: for (; height; height--) 1.519 +} 1.520 + 1.521 +void SuperEagle(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, 1.522 + u8 *dstPtr, u32 dstPitch, int width, int height) 1.523 +{ 1.524 + u8 * dP; 1.525 + u16 *bP; 1.526 + u16 *xP; 1.527 + u32 inc_bP; 1.528 + 1.529 +#ifdef MMX 1.530 + if (cpu_mmx) 1.531 + { 1.532 + for (; height; height--) 1.533 + { 1.534 + _2xSaISuperEagleLine(srcPtr, deltaPtr, srcPitch, width, 1.535 + dstPtr, dstPitch); 1.536 + srcPtr += srcPitch; 1.537 + dstPtr += dstPitch * 2; 1.538 + deltaPtr += srcPitch; 1.539 + } 1.540 + } 1.541 + else 1.542 +#endif 1.543 + { 1.544 + inc_bP = 1; 1.545 + 1.546 + u32 Nextline = srcPitch >> 1; 1.547 + 1.548 + for (; height; height--) 1.549 + { 1.550 + bP = (u16 *) srcPtr; 1.551 + xP = (u16 *) deltaPtr; 1.552 + dP = dstPtr; 1.553 + for (u32 finish = width; finish; finish -= inc_bP) 1.554 + { 1.555 + u32 color4, color5, color6; 1.556 + u32 color1, color2, color3; 1.557 + u32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2; 1.558 + u32 product1a, product1b, product2a, product2b; 1.559 + 1.560 + colorB1 = *(bP - Nextline); 1.561 + colorB2 = *(bP - Nextline + 1); 1.562 + 1.563 + color4 = *(bP - 1); 1.564 + color5 = *(bP); 1.565 + color6 = *(bP + 1); 1.566 + colorS2 = *(bP + 2); 1.567 + 1.568 + color1 = *(bP + Nextline - 1); 1.569 + color2 = *(bP + Nextline); 1.570 + color3 = *(bP + Nextline + 1); 1.571 + colorS1 = *(bP + Nextline + 2); 1.572 + 1.573 + colorA1 = *(bP + Nextline + Nextline); 1.574 + colorA2 = *(bP + Nextline + Nextline + 1); 1.575 + 1.576 + // -------------------------------------- 1.577 + if (color2 == color6 && color5 != color3) 1.578 + { 1.579 + product1b = product2a = color2; 1.580 + if ((color1 == color2) || (color6 == colorB2)) 1.581 + { 1.582 + product1a = INTERPOLATE(color2, color5); 1.583 + product1a = INTERPOLATE(color2, product1a); 1.584 + // product1a = color2; 1.585 + } 1.586 + else 1.587 + { 1.588 + product1a = INTERPOLATE(color5, color6); 1.589 + } 1.590 + 1.591 + if ((color6 == colorS2) || (color2 == colorA1)) 1.592 + { 1.593 + product2b = INTERPOLATE(color2, color3); 1.594 + product2b = INTERPOLATE(color2, product2b); 1.595 + // product2b = color2; 1.596 + } 1.597 + else 1.598 + { 1.599 + product2b = INTERPOLATE(color2, color3); 1.600 + } 1.601 + } 1.602 + else if (color5 == color3 && color2 != color6) 1.603 + { 1.604 + product2b = product1a = color5; 1.605 + 1.606 + if ((colorB1 == color5) || (color3 == colorS1)) 1.607 + { 1.608 + product1b = INTERPOLATE(color5, color6); 1.609 + product1b = INTERPOLATE(color5, product1b); 1.610 + // product1b = color5; 1.611 + } 1.612 + else 1.613 + { 1.614 + product1b = INTERPOLATE(color5, color6); 1.615 + } 1.616 + 1.617 + if ((color3 == colorA2) || (color4 == color5)) 1.618 + { 1.619 + product2a = INTERPOLATE(color5, color2); 1.620 + product2a = INTERPOLATE(color5, product2a); 1.621 + // product2a = color5; 1.622 + } 1.623 + else 1.624 + { 1.625 + product2a = INTERPOLATE(color2, color3); 1.626 + } 1.627 + } 1.628 + else if (color5 == color3 && color2 == color6) 1.629 + { 1.630 + register int r = 0; 1.631 + 1.632 + r += GetResult(color6, color5, color1, colorA1); 1.633 + r += GetResult(color6, color5, color4, colorB1); 1.634 + r += GetResult(color6, color5, colorA2, colorS1); 1.635 + r += GetResult(color6, color5, colorB2, colorS2); 1.636 + 1.637 + if (r > 0) 1.638 + { 1.639 + product1b = product2a = color2; 1.640 + product1a = product2b = INTERPOLATE(color5, color6); 1.641 + } 1.642 + else if (r < 0) 1.643 + { 1.644 + product2b = product1a = color5; 1.645 + product1b = product2a = INTERPOLATE(color5, color6); 1.646 + } 1.647 + else 1.648 + { 1.649 + product2b = product1a = color5; 1.650 + product1b = product2a = color2; 1.651 + } 1.652 + } 1.653 + else 1.654 + { 1.655 + product2b = product1a = INTERPOLATE(color2, color6); 1.656 + product2b = 1.657 + Q_INTERPOLATE(color3, color3, color3, product2b); 1.658 + product1a = 1.659 + Q_INTERPOLATE(color5, color5, color5, product1a); 1.660 + 1.661 + product2a = product1b = INTERPOLATE(color5, color3); 1.662 + product2a = 1.663 + Q_INTERPOLATE(color2, color2, color2, product2a); 1.664 + product1b = 1.665 + Q_INTERPOLATE(color6, color6, color6, product1b); 1.666 + 1.667 + // product1a = color5; 1.668 + // product1b = color6; 1.669 + // product2a = color2; 1.670 + // product2b = color3; 1.671 + } 1.672 +#ifdef WORDS_BIGENDIAN 1.673 + product1a = (product1a << 16) | product1b; 1.674 + product2a = (product2a << 16) | product2b; 1.675 +#else 1.676 + product1a = product1a | (product1b << 16); 1.677 + product2a = product2a | (product2b << 16); 1.678 +#endif 1.679 + 1.680 + *((u32 *) dP) = product1a; 1.681 + *((u32 *) (dP + dstPitch)) = product2a; 1.682 + *xP = color5; 1.683 + 1.684 + bP += inc_bP; 1.685 + xP += inc_bP; 1.686 + dP += sizeof(u32); 1.687 + } // end of for ( finish= width etc..) 1.688 + 1.689 + srcPtr += srcPitch; 1.690 + dstPtr += dstPitch << 1; 1.691 + deltaPtr += srcPitch; 1.692 + } // endof: for (height; height; height--) 1.693 + } 1.694 +} 1.695 + 1.696 +void SuperEagle32(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, 1.697 + u8 *dstPtr, u32 dstPitch, int width, int height) 1.698 +{ 1.699 + u32 *dP; 1.700 + u32 *bP; 1.701 + u32 *xP; 1.702 + u32 inc_bP; 1.703 + 1.704 + inc_bP = 1; 1.705 + 1.706 + u32 Nextline = srcPitch >> 2; 1.707 + 1.708 + for (; height; height--) 1.709 + { 1.710 + bP = (u32 *) srcPtr; 1.711 + xP = (u32 *) deltaPtr; 1.712 + dP = (u32 *)dstPtr; 1.713 + for (u32 finish = width; finish; finish -= inc_bP) 1.714 + { 1.715 + u32 color4, color5, color6; 1.716 + u32 color1, color2, color3; 1.717 + u32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2; 1.718 + u32 product1a, product1b, product2a, product2b; 1.719 + 1.720 + colorB1 = *(bP - Nextline); 1.721 + colorB2 = *(bP - Nextline + 1); 1.722 + 1.723 + color4 = *(bP - 1); 1.724 + color5 = *(bP); 1.725 + color6 = *(bP + 1); 1.726 + colorS2 = *(bP + 2); 1.727 + 1.728 + color1 = *(bP + Nextline - 1); 1.729 + color2 = *(bP + Nextline); 1.730 + color3 = *(bP + Nextline + 1); 1.731 + colorS1 = *(bP + Nextline + 2); 1.732 + 1.733 + colorA1 = *(bP + Nextline + Nextline); 1.734 + colorA2 = *(bP + Nextline + Nextline + 1); 1.735 + 1.736 + // -------------------------------------- 1.737 + if (color2 == color6 && color5 != color3) 1.738 + { 1.739 + product1b = product2a = color2; 1.740 + if ((color1 == color2) || (color6 == colorB2)) 1.741 + { 1.742 + product1a = INTERPOLATE(color2, color5); 1.743 + product1a = INTERPOLATE(color2, product1a); 1.744 + // product1a = color2; 1.745 + } 1.746 + else 1.747 + { 1.748 + product1a = INTERPOLATE(color5, color6); 1.749 + } 1.750 + 1.751 + if ((color6 == colorS2) || (color2 == colorA1)) 1.752 + { 1.753 + product2b = INTERPOLATE(color2, color3); 1.754 + product2b = INTERPOLATE(color2, product2b); 1.755 + // product2b = color2; 1.756 + } 1.757 + else 1.758 + { 1.759 + product2b = INTERPOLATE(color2, color3); 1.760 + } 1.761 + } 1.762 + else if (color5 == color3 && color2 != color6) 1.763 + { 1.764 + product2b = product1a = color5; 1.765 + 1.766 + if ((colorB1 == color5) || (color3 == colorS1)) 1.767 + { 1.768 + product1b = INTERPOLATE(color5, color6); 1.769 + product1b = INTERPOLATE(color5, product1b); 1.770 + // product1b = color5; 1.771 + } 1.772 + else 1.773 + { 1.774 + product1b = INTERPOLATE(color5, color6); 1.775 + } 1.776 + 1.777 + if ((color3 == colorA2) || (color4 == color5)) 1.778 + { 1.779 + product2a = INTERPOLATE(color5, color2); 1.780 + product2a = INTERPOLATE(color5, product2a); 1.781 + // product2a = color5; 1.782 + } 1.783 + else 1.784 + { 1.785 + product2a = INTERPOLATE(color2, color3); 1.786 + } 1.787 + } 1.788 + else if (color5 == color3 && color2 == color6) 1.789 + { 1.790 + register int r = 0; 1.791 + 1.792 + r += GetResult(color6, color5, color1, colorA1); 1.793 + r += GetResult(color6, color5, color4, colorB1); 1.794 + r += GetResult(color6, color5, colorA2, colorS1); 1.795 + r += GetResult(color6, color5, colorB2, colorS2); 1.796 + 1.797 + if (r > 0) 1.798 + { 1.799 + product1b = product2a = color2; 1.800 + product1a = product2b = INTERPOLATE(color5, color6); 1.801 + } 1.802 + else if (r < 0) 1.803 + { 1.804 + product2b = product1a = color5; 1.805 + product1b = product2a = INTERPOLATE(color5, color6); 1.806 + } 1.807 + else 1.808 + { 1.809 + product2b = product1a = color5; 1.810 + product1b = product2a = color2; 1.811 + } 1.812 + } 1.813 + else 1.814 + { 1.815 + product2b = product1a = INTERPOLATE(color2, color6); 1.816 + product2b = 1.817 + Q_INTERPOLATE(color3, color3, color3, product2b); 1.818 + product1a = 1.819 + Q_INTERPOLATE(color5, color5, color5, product1a); 1.820 + 1.821 + product2a = product1b = INTERPOLATE(color5, color3); 1.822 + product2a = 1.823 + Q_INTERPOLATE(color2, color2, color2, product2a); 1.824 + product1b = 1.825 + Q_INTERPOLATE(color6, color6, color6, product1b); 1.826 + 1.827 + // product1a = color5; 1.828 + // product1b = color6; 1.829 + // product2a = color2; 1.830 + // product2b = color3; 1.831 + } 1.832 + *(dP) = product1a; 1.833 + *(dP + 1) = product1b; 1.834 + *(dP + (dstPitch >> 2)) = product2a; 1.835 + *(dP + (dstPitch >> 2) + 1) = product2b; 1.836 + *xP = color5; 1.837 + 1.838 + bP += inc_bP; 1.839 + xP += inc_bP; 1.840 + dP += 2; 1.841 + } // end of for ( finish= width etc..) 1.842 + 1.843 + srcPtr += srcPitch; 1.844 + dstPtr += dstPitch << 1; 1.845 + deltaPtr += srcPitch; 1.846 + } // endof: for (height; height; height--) 1.847 +} 1.848 + 1.849 +void _2xSaI(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, 1.850 + u8 *dstPtr, u32 dstPitch, int width, int height) 1.851 +{ 1.852 + u8 * dP; 1.853 + u16 *bP; 1.854 + u32 inc_bP; 1.855 + 1.856 +#ifdef MMX 1.857 + if (cpu_mmx) 1.858 + { 1.859 + for (; height; height -= 1) 1.860 + { 1.861 + _2xSaILine(srcPtr, deltaPtr, srcPitch, width, dstPtr, dstPitch); 1.862 + srcPtr += srcPitch; 1.863 + dstPtr += dstPitch * 2; 1.864 + deltaPtr += srcPitch; 1.865 + } 1.866 + } 1.867 + else 1.868 +#endif 1.869 + { 1.870 + inc_bP = 1; 1.871 + 1.872 + u32 Nextline = srcPitch >> 1; 1.873 + 1.874 + for (; height; height--) 1.875 + { 1.876 + bP = (u16 *) srcPtr; 1.877 + dP = dstPtr; 1.878 + 1.879 + for (u32 finish = width; finish; finish -= inc_bP) 1.880 + { 1.881 + register u32 colorA, colorB; 1.882 + u32 colorC, colorD, 1.883 + colorE, colorF, colorG, colorH, 1.884 + colorI, colorJ, colorK, colorL, 1.885 + 1.886 + colorM, colorN, colorO, colorP; 1.887 + u32 product, product1, product2; 1.888 + 1.889 + //--------------------------------------- 1.890 + // Map of the pixels: I|E F|J 1.891 + // G|A B|K 1.892 + // H|C D|L 1.893 + // M|N O|P 1.894 + colorI = *(bP - Nextline - 1); 1.895 + colorE = *(bP - Nextline); 1.896 + colorF = *(bP - Nextline + 1); 1.897 + colorJ = *(bP - Nextline + 2); 1.898 + 1.899 + colorG = *(bP - 1); 1.900 + colorA = *(bP); 1.901 + colorB = *(bP + 1); 1.902 + colorK = *(bP + 2); 1.903 + 1.904 + colorH = *(bP + Nextline - 1); 1.905 + colorC = *(bP + Nextline); 1.906 + colorD = *(bP + Nextline + 1); 1.907 + colorL = *(bP + Nextline + 2); 1.908 + 1.909 + colorM = *(bP + Nextline + Nextline - 1); 1.910 + colorN = *(bP + Nextline + Nextline); 1.911 + colorO = *(bP + Nextline + Nextline + 1); 1.912 + colorP = *(bP + Nextline + Nextline + 2); 1.913 + 1.914 + if ((colorA == colorD) && (colorB != colorC)) 1.915 + { 1.916 + if (((colorA == colorE) && (colorB == colorL)) || 1.917 + ((colorA == colorC) && (colorA == colorF) 1.918 + && (colorB != colorE) && (colorB == colorJ))) 1.919 + { 1.920 + product = colorA; 1.921 + } 1.922 + else 1.923 + { 1.924 + product = INTERPOLATE(colorA, colorB); 1.925 + } 1.926 + 1.927 + if (((colorA == colorG) && (colorC == colorO)) || 1.928 + ((colorA == colorB) && (colorA == colorH) 1.929 + && (colorG != colorC) && (colorC == colorM))) 1.930 + { 1.931 + product1 = colorA; 1.932 + } 1.933 + else 1.934 + { 1.935 + product1 = INTERPOLATE(colorA, colorC); 1.936 + } 1.937 + product2 = colorA; 1.938 + } 1.939 + else if ((colorB == colorC) && (colorA != colorD)) 1.940 + { 1.941 + if (((colorB == colorF) && (colorA == colorH)) || 1.942 + ((colorB == colorE) && (colorB == colorD) 1.943 + && (colorA != colorF) && (colorA == colorI))) 1.944 + { 1.945 + product = colorB; 1.946 + } 1.947 + else 1.948 + { 1.949 + product = INTERPOLATE(colorA, colorB); 1.950 + } 1.951 + 1.952 + if (((colorC == colorH) && (colorA == colorF)) || 1.953 + ((colorC == colorG) && (colorC == colorD) 1.954 + && (colorA != colorH) && (colorA == colorI))) 1.955 + { 1.956 + product1 = colorC; 1.957 + } 1.958 + else 1.959 + { 1.960 + product1 = INTERPOLATE(colorA, colorC); 1.961 + } 1.962 + product2 = colorB; 1.963 + } 1.964 + else if ((colorA == colorD) && (colorB == colorC)) 1.965 + { 1.966 + if (colorA == colorB) 1.967 + { 1.968 + product = colorA; 1.969 + product1 = colorA; 1.970 + product2 = colorA; 1.971 + } 1.972 + else 1.973 + { 1.974 + register int r = 0; 1.975 + 1.976 + product1 = INTERPOLATE(colorA, colorC); 1.977 + product = INTERPOLATE(colorA, colorB); 1.978 + 1.979 + r += 1.980 + GetResult1(colorA, colorB, colorG, colorE, 1.981 + colorI); 1.982 + r += 1.983 + GetResult2(colorB, colorA, colorK, colorF, 1.984 + colorJ); 1.985 + r += 1.986 + GetResult2(colorB, colorA, colorH, colorN, 1.987 + colorM); 1.988 + r += 1.989 + GetResult1(colorA, colorB, colorL, colorO, 1.990 + colorP); 1.991 + 1.992 + if (r > 0) 1.993 + product2 = colorA; 1.994 + else if (r < 0) 1.995 + product2 = colorB; 1.996 + else 1.997 + { 1.998 + product2 = 1.999 + Q_INTERPOLATE(colorA, colorB, colorC, 1.1000 + colorD); 1.1001 + } 1.1002 + } 1.1003 + } 1.1004 + else 1.1005 + { 1.1006 + product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD); 1.1007 + 1.1008 + if ((colorA == colorC) && (colorA == colorF) 1.1009 + && (colorB != colorE) && (colorB == colorJ)) 1.1010 + { 1.1011 + product = colorA; 1.1012 + } 1.1013 + else if ((colorB == colorE) && (colorB == colorD) 1.1014 + && (colorA != colorF) && (colorA == colorI)) 1.1015 + { 1.1016 + product = colorB; 1.1017 + } 1.1018 + else 1.1019 + { 1.1020 + product = INTERPOLATE(colorA, colorB); 1.1021 + } 1.1022 + 1.1023 + if ((colorA == colorB) && (colorA == colorH) 1.1024 + && (colorG != colorC) && (colorC == colorM)) 1.1025 + { 1.1026 + product1 = colorA; 1.1027 + } 1.1028 + else if ((colorC == colorG) && (colorC == colorD) 1.1029 + && (colorA != colorH) && (colorA == colorI)) 1.1030 + { 1.1031 + product1 = colorC; 1.1032 + } 1.1033 + else 1.1034 + { 1.1035 + product1 = INTERPOLATE(colorA, colorC); 1.1036 + } 1.1037 + } 1.1038 + 1.1039 +#ifdef WORDS_BIGENDIAN 1.1040 + product = (colorA << 16) | product; 1.1041 + product1 = (product1 << 16) | product2; 1.1042 +#else 1.1043 + product = colorA | (product << 16); 1.1044 + product1 = product1 | (product2 << 16); 1.1045 +#endif 1.1046 + *((s32 *) dP) = product; 1.1047 + *((u32 *) (dP + dstPitch)) = product1; 1.1048 + 1.1049 + bP += inc_bP; 1.1050 + dP += sizeof(u32); 1.1051 + } // end of for ( finish= width etc..) 1.1052 + 1.1053 + srcPtr += srcPitch; 1.1054 + dstPtr += dstPitch << 1; 1.1055 + deltaPtr += srcPitch; 1.1056 + } // endof: for (height; height; height--) 1.1057 + } 1.1058 +} 1.1059 + 1.1060 +void _2xSaI32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */, 1.1061 + u8 *dstPtr, u32 dstPitch, int width, int height) 1.1062 +{ 1.1063 + u32 *dP; 1.1064 + u32 *bP; 1.1065 + u32 inc_bP = 1; 1.1066 + 1.1067 + u32 Nextline = srcPitch >> 2; 1.1068 + 1.1069 + for (; height; height--) 1.1070 + { 1.1071 + bP = (u32 *) srcPtr; 1.1072 + dP = (u32 *) dstPtr; 1.1073 + 1.1074 + for (u32 finish = width; finish; finish -= inc_bP) 1.1075 + { 1.1076 + register u32 colorA, colorB; 1.1077 + u32 colorC, colorD, 1.1078 + colorE, colorF, colorG, colorH, 1.1079 + colorI, colorJ, colorK, colorL, 1.1080 + 1.1081 + colorM, colorN, colorO, colorP; 1.1082 + u32 product, product1, product2; 1.1083 + 1.1084 + //--------------------------------------- 1.1085 + // Map of the pixels: I|E F|J 1.1086 + // G|A B|K 1.1087 + // H|C D|L 1.1088 + // M|N O|P 1.1089 + colorI = *(bP - Nextline - 1); 1.1090 + colorE = *(bP - Nextline); 1.1091 + colorF = *(bP - Nextline + 1); 1.1092 + colorJ = *(bP - Nextline + 2); 1.1093 + 1.1094 + colorG = *(bP - 1); 1.1095 + colorA = *(bP); 1.1096 + colorB = *(bP + 1); 1.1097 + colorK = *(bP + 2); 1.1098 + 1.1099 + colorH = *(bP + Nextline - 1); 1.1100 + colorC = *(bP + Nextline); 1.1101 + colorD = *(bP + Nextline + 1); 1.1102 + colorL = *(bP + Nextline + 2); 1.1103 + 1.1104 + colorM = *(bP + Nextline + Nextline - 1); 1.1105 + colorN = *(bP + Nextline + Nextline); 1.1106 + colorO = *(bP + Nextline + Nextline + 1); 1.1107 + colorP = *(bP + Nextline + Nextline + 2); 1.1108 + 1.1109 + if ((colorA == colorD) && (colorB != colorC)) 1.1110 + { 1.1111 + if (((colorA == colorE) && (colorB == colorL)) || 1.1112 + ((colorA == colorC) && (colorA == colorF) 1.1113 + && (colorB != colorE) && (colorB == colorJ))) 1.1114 + { 1.1115 + product = colorA; 1.1116 + } 1.1117 + else 1.1118 + { 1.1119 + product = INTERPOLATE(colorA, colorB); 1.1120 + } 1.1121 + 1.1122 + if (((colorA == colorG) && (colorC == colorO)) || 1.1123 + ((colorA == colorB) && (colorA == colorH) 1.1124 + && (colorG != colorC) && (colorC == colorM))) 1.1125 + { 1.1126 + product1 = colorA; 1.1127 + } 1.1128 + else 1.1129 + { 1.1130 + product1 = INTERPOLATE(colorA, colorC); 1.1131 + } 1.1132 + product2 = colorA; 1.1133 + } 1.1134 + else if ((colorB == colorC) && (colorA != colorD)) 1.1135 + { 1.1136 + if (((colorB == colorF) && (colorA == colorH)) || 1.1137 + ((colorB == colorE) && (colorB == colorD) 1.1138 + && (colorA != colorF) && (colorA == colorI))) 1.1139 + { 1.1140 + product = colorB; 1.1141 + } 1.1142 + else 1.1143 + { 1.1144 + product = INTERPOLATE(colorA, colorB); 1.1145 + } 1.1146 + 1.1147 + if (((colorC == colorH) && (colorA == colorF)) || 1.1148 + ((colorC == colorG) && (colorC == colorD) 1.1149 + && (colorA != colorH) && (colorA == colorI))) 1.1150 + { 1.1151 + product1 = colorC; 1.1152 + } 1.1153 + else 1.1154 + { 1.1155 + product1 = INTERPOLATE(colorA, colorC); 1.1156 + } 1.1157 + product2 = colorB; 1.1158 + } 1.1159 + else if ((colorA == colorD) && (colorB == colorC)) 1.1160 + { 1.1161 + if (colorA == colorB) 1.1162 + { 1.1163 + product = colorA; 1.1164 + product1 = colorA; 1.1165 + product2 = colorA; 1.1166 + } 1.1167 + else 1.1168 + { 1.1169 + register int r = 0; 1.1170 + 1.1171 + product1 = INTERPOLATE(colorA, colorC); 1.1172 + product = INTERPOLATE(colorA, colorB); 1.1173 + 1.1174 + r += 1.1175 + GetResult1(colorA, colorB, colorG, colorE, 1.1176 + colorI); 1.1177 + r += 1.1178 + GetResult2(colorB, colorA, colorK, colorF, 1.1179 + colorJ); 1.1180 + r += 1.1181 + GetResult2(colorB, colorA, colorH, colorN, 1.1182 + colorM); 1.1183 + r += 1.1184 + GetResult1(colorA, colorB, colorL, colorO, 1.1185 + colorP); 1.1186 + 1.1187 + if (r > 0) 1.1188 + product2 = colorA; 1.1189 + else if (r < 0) 1.1190 + product2 = colorB; 1.1191 + else 1.1192 + { 1.1193 + product2 = 1.1194 + Q_INTERPOLATE(colorA, colorB, colorC, 1.1195 + colorD); 1.1196 + } 1.1197 + } 1.1198 + } 1.1199 + else 1.1200 + { 1.1201 + product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD); 1.1202 + 1.1203 + if ((colorA == colorC) && (colorA == colorF) 1.1204 + && (colorB != colorE) && (colorB == colorJ)) 1.1205 + { 1.1206 + product = colorA; 1.1207 + } 1.1208 + else if ((colorB == colorE) && (colorB == colorD) 1.1209 + && (colorA != colorF) && (colorA == colorI)) 1.1210 + { 1.1211 + product = colorB; 1.1212 + } 1.1213 + else 1.1214 + { 1.1215 + product = INTERPOLATE(colorA, colorB); 1.1216 + } 1.1217 + 1.1218 + if ((colorA == colorB) && (colorA == colorH) 1.1219 + && (colorG != colorC) && (colorC == colorM)) 1.1220 + { 1.1221 + product1 = colorA; 1.1222 + } 1.1223 + else if ((colorC == colorG) && (colorC == colorD) 1.1224 + && (colorA != colorH) && (colorA == colorI)) 1.1225 + { 1.1226 + product1 = colorC; 1.1227 + } 1.1228 + else 1.1229 + { 1.1230 + product1 = INTERPOLATE(colorA, colorC); 1.1231 + } 1.1232 + } 1.1233 + *(dP) = colorA; 1.1234 + *(dP + 1) = product; 1.1235 + *(dP + (dstPitch >> 2)) = product1; 1.1236 + *(dP + (dstPitch >> 2) + 1) = product2; 1.1237 + 1.1238 + bP += inc_bP; 1.1239 + dP += 2; 1.1240 + } // end of for ( finish= width etc..) 1.1241 + 1.1242 + srcPtr += srcPitch; 1.1243 + dstPtr += dstPitch << 1; 1.1244 + // deltaPtr += srcPitch; 1.1245 + } // endof: for (height; height; height--) 1.1246 +} 1.1247 + 1.1248 +static u32 Bilinear(u32 A, u32 B, u32 x) 1.1249 +{ 1.1250 + unsigned long areaA, areaB; 1.1251 + unsigned long result; 1.1252 + 1.1253 + if (A == B) 1.1254 + return A; 1.1255 + 1.1256 + areaB = (x >> 11) & 0x1f; // reduce 16 bit fraction to 5 bits 1.1257 + areaA = 0x20 - areaB; 1.1258 + 1.1259 + A = (A & redblueMask) | ((A & greenMask) << 16); 1.1260 + B = (B & redblueMask) | ((B & greenMask) << 16); 1.1261 + 1.1262 + result = ((areaA * A) + (areaB * B)) >> 5; 1.1263 + 1.1264 + return (result & redblueMask) | ((result >> 16) & greenMask); 1.1265 +} 1.1266 + 1.1267 +static u32 Bilinear4(u32 A, u32 B, u32 C, u32 D, u32 x, 1.1268 + u32 y) 1.1269 +{ 1.1270 + unsigned long areaA, areaB, areaC, areaD; 1.1271 + unsigned long result, xy; 1.1272 + 1.1273 + x = (x >> 11) & 0x1f; 1.1274 + y = (y >> 11) & 0x1f; 1.1275 + xy = (x * y) >> 5; 1.1276 + 1.1277 + A = (A & redblueMask) | ((A & greenMask) << 16); 1.1278 + B = (B & redblueMask) | ((B & greenMask) << 16); 1.1279 + C = (C & redblueMask) | ((C & greenMask) << 16); 1.1280 + D = (D & redblueMask) | ((D & greenMask) << 16); 1.1281 + 1.1282 + areaA = 0x20 + xy - x - y; 1.1283 + areaB = x - xy; 1.1284 + areaC = y - xy; 1.1285 + areaD = xy; 1.1286 + 1.1287 + result = ((areaA * A) + (areaB * B) + (areaC * C) + (areaD * D)) >> 5; 1.1288 + 1.1289 + return (result & redblueMask) | ((result >> 16) & greenMask); 1.1290 +} 1.1291 + 1.1292 +void Scale_2xSaI(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */, 1.1293 + u8 *dstPtr, u32 dstPitch, 1.1294 + u32 dstWidth, u32 dstHeight, int width, int height) 1.1295 +{ 1.1296 + u8 * dP; 1.1297 + u16 *bP; 1.1298 + 1.1299 + u32 w; 1.1300 + u32 h; 1.1301 + u32 dw; 1.1302 + u32 dh; 1.1303 + u32 hfinish; 1.1304 + u32 wfinish; 1.1305 + 1.1306 + u32 Nextline = srcPitch >> 1; 1.1307 + 1.1308 + wfinish = (width - 1) << 16; // convert to fixed point 1.1309 + dw = wfinish / (dstWidth - 1); 1.1310 + hfinish = (height - 1) << 16; // convert to fixed point 1.1311 + dh = hfinish / (dstHeight - 1); 1.1312 + 1.1313 + for (h = 0; h < hfinish; h += dh) 1.1314 + { 1.1315 + u32 y1, y2; 1.1316 + 1.1317 + y1 = h & 0xffff; // fraction part of fixed point 1.1318 + bP = (u16 *) (srcPtr + ((h >> 16) * srcPitch)); 1.1319 + dP = dstPtr; 1.1320 + y2 = 0x10000 - y1; 1.1321 + 1.1322 + w = 0; 1.1323 + 1.1324 + for (; w < wfinish; ) 1.1325 + { 1.1326 + u32 A, B, C, D; 1.1327 + u32 E, F, G, H; 1.1328 + u32 I, J, K, L; 1.1329 + u32 x1, x2, a1, f1, f2; 1.1330 + u32 position, product1; 1.1331 + 1.1332 + position = w >> 16; 1.1333 + A = bP[position]; // current pixel 1.1334 + B = bP[position + 1]; // next pixel 1.1335 + C = bP[position + Nextline]; 1.1336 + D = bP[position + Nextline + 1]; 1.1337 + E = bP[position - Nextline]; 1.1338 + F = bP[position - Nextline + 1]; 1.1339 + G = bP[position - 1]; 1.1340 + H = bP[position + Nextline - 1]; 1.1341 + I = bP[position + 2]; 1.1342 + J = bP[position + Nextline + 2]; 1.1343 + K = bP[position + Nextline + Nextline]; 1.1344 + L = bP[position + Nextline + Nextline + 1]; 1.1345 + 1.1346 + x1 = w & 0xffff; // fraction part of fixed point 1.1347 + x2 = 0x10000 - x1; 1.1348 + 1.1349 + /*0*/ 1.1350 + if (A == B && C == D && A == C) 1.1351 + product1 = A; 1.1352 + else /*1*/ if (A == D && B != C) 1.1353 + { 1.1354 + f1 = (x1 >> 1) + (0x10000 >> 2); 1.1355 + f2 = (y1 >> 1) + (0x10000 >> 2); 1.1356 + if (y1 <= f1 && A == J && A != E) // close to B 1.1357 + { 1.1358 + a1 = f1 - y1; 1.1359 + product1 = Bilinear(A, B, a1); 1.1360 + } 1.1361 + else if (y1 >= f1 && A == G && A != L) // close to C 1.1362 + { 1.1363 + a1 = y1 - f1; 1.1364 + product1 = Bilinear(A, C, a1); 1.1365 + } 1.1366 + else if (x1 >= f2 && A == E && A != J) // close to B 1.1367 + { 1.1368 + a1 = x1 - f2; 1.1369 + product1 = Bilinear(A, B, a1); 1.1370 + } 1.1371 + else if (x1 <= f2 && A == L && A != G) // close to C 1.1372 + { 1.1373 + a1 = f2 - x1; 1.1374 + product1 = Bilinear(A, C, a1); 1.1375 + } 1.1376 + else if (y1 >= x1) // close to C 1.1377 + { 1.1378 + a1 = y1 - x1; 1.1379 + product1 = Bilinear(A, C, a1); 1.1380 + } 1.1381 + else if (y1 <= x1) // close to B 1.1382 + { 1.1383 + a1 = x1 - y1; 1.1384 + product1 = Bilinear(A, B, a1); 1.1385 + } 1.1386 + } 1.1387 + else 1.1388 + /*2*/ 1.1389 + if (B == C && A != D) 1.1390 + { 1.1391 + f1 = (x1 >> 1) + (0x10000 >> 2); 1.1392 + f2 = (y1 >> 1) + (0x10000 >> 2); 1.1393 + if (y2 >= f1 && B == H && B != F) // close to A 1.1394 + { 1.1395 + a1 = y2 - f1; 1.1396 + product1 = Bilinear(B, A, a1); 1.1397 + } 1.1398 + else if (y2 <= f1 && B == I && B != K) // close to D 1.1399 + { 1.1400 + a1 = f1 - y2; 1.1401 + product1 = Bilinear(B, D, a1); 1.1402 + } 1.1403 + else if (x2 >= f2 && B == F && B != H) // close to A 1.1404 + { 1.1405 + a1 = x2 - f2; 1.1406 + product1 = Bilinear(B, A, a1); 1.1407 + } 1.1408 + else if (x2 <= f2 && B == K && B != I) // close to D 1.1409 + { 1.1410 + a1 = f2 - x2; 1.1411 + product1 = Bilinear(B, D, a1); 1.1412 + } 1.1413 + else if (y2 >= x1) // close to A 1.1414 + { 1.1415 + a1 = y2 - x1; 1.1416 + product1 = Bilinear(B, A, a1); 1.1417 + } 1.1418 + else if (y2 <= x1) // close to D 1.1419 + { 1.1420 + a1 = x1 - y2; 1.1421 + product1 = Bilinear(B, D, a1); 1.1422 + } 1.1423 + } 1.1424 + /*3*/ 1.1425 + else 1.1426 + { 1.1427 + product1 = Bilinear4(A, B, C, D, x1, y1); 1.1428 + } 1.1429 + 1.1430 + //end First Pixel 1.1431 + *(u32 *) dP = product1; 1.1432 + dP += 2; 1.1433 + w += dw; 1.1434 + } 1.1435 + dstPtr += dstPitch; 1.1436 + } 1.1437 +}