annotate src/filters/2xSaI.cpp @ 4:5f6f2134e8ce

apu appears to not be used
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:35:58 -0600
parents f9f4f1b99eed
children
rev   line source
rlm@1 1 #include "../common/System.h"
rlm@1 2
rlm@1 3 extern "C"
rlm@1 4 {
rlm@1 5 #ifdef MMX
rlm@1 6 void _2xSaILine(u8 *srcPtr, u8 *deltaPtr, u32 srcPitch,
rlm@1 7 u32 width, u8 *dstPtr, u32 dstPitch);
rlm@1 8 void _2xSaISuperEagleLine(u8 *srcPtr, u8 *deltaPtr,
rlm@1 9 u32 srcPitch, u32 width,
rlm@1 10 u8 *dstPtr, u32 dstPitch);
rlm@1 11 void _2xSaISuper2xSaILine(u8 *srcPtr, u8 *deltaPtr,
rlm@1 12 u32 srcPitch, u32 width,
rlm@1 13 u8 *dstPtr, u32 dstPitch);
rlm@1 14 void Init_2xSaIMMX(u32 BitFormat);
rlm@1 15 void BilinearMMX(u16 *A, u16 *B, u16 *C, u16 *D,
rlm@1 16 u16 *dx, u16 *dy, u8 *dP);
rlm@1 17 void BilinearMMXGrid0(u16 *A, u16 *B, u16 *C, u16 *D,
rlm@1 18 u16 *dx, u16 *dy, u8 *dP);
rlm@1 19 void BilinearMMXGrid1(u16 *A, u16 *B, u16 *C, u16 *D,
rlm@1 20 u16 *dx, u16 *dy, u8 *dP);
rlm@1 21 void EndMMX();
rlm@1 22
rlm@1 23 bool cpu_mmx = 1;
rlm@1 24 #endif
rlm@1 25 }
rlm@1 26 static u32 colorMask = 0xF7DEF7DE;
rlm@1 27 static u32 lowPixelMask = 0x08210821;
rlm@1 28 static u32 qcolorMask = 0xE79CE79C;
rlm@1 29 static u32 qlowpixelMask = 0x18631863;
rlm@1 30 static u32 redblueMask = 0xF81F;
rlm@1 31 static u32 greenMask = 0x7E0;
rlm@1 32
rlm@1 33 u32 qRGB_COLOR_MASK[2] = { 0xF7DEF7DE, 0xF7DEF7DE };
rlm@1 34
rlm@1 35 extern void hq2x_init(unsigned);
rlm@1 36
rlm@1 37 int Init_2xSaI(u32 BitFormat)
rlm@1 38 {
rlm@1 39 if (systemColorDepth == 16)
rlm@1 40 {
rlm@1 41 if (BitFormat == 565)
rlm@1 42 {
rlm@1 43 colorMask = 0xF7DEF7DE;
rlm@1 44 lowPixelMask = 0x08210821;
rlm@1 45 qcolorMask = 0xE79CE79C;
rlm@1 46 qlowpixelMask = 0x18631863;
rlm@1 47 redblueMask = 0xF81F;
rlm@1 48 greenMask = 0x7E0;
rlm@1 49 qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0xF7DEF7DE;
rlm@1 50 hq2x_init(16);
rlm@1 51 }
rlm@1 52 else if (BitFormat == 555)
rlm@1 53 {
rlm@1 54 colorMask = 0x7BDE7BDE;
rlm@1 55 lowPixelMask = 0x04210421;
rlm@1 56 qcolorMask = 0x739C739C;
rlm@1 57 qlowpixelMask = 0x0C630C63;
rlm@1 58 redblueMask = 0x7C1F;
rlm@1 59 greenMask = 0x3E0;
rlm@1 60 qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0x7BDE7BDE;
rlm@1 61 hq2x_init(15);
rlm@1 62 }
rlm@1 63 else
rlm@1 64 {
rlm@1 65 return 0;
rlm@1 66 }
rlm@1 67 }
rlm@1 68 else if (systemColorDepth == 32)
rlm@1 69 {
rlm@1 70 colorMask = 0xfefefe;
rlm@1 71 lowPixelMask = 0x010101;
rlm@1 72 qcolorMask = 0xfcfcfc;
rlm@1 73 qlowpixelMask = 0x030303;
rlm@1 74 qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0xfefefe;
rlm@1 75 hq2x_init(32);
rlm@1 76 }
rlm@1 77 else
rlm@1 78 return 0;
rlm@1 79
rlm@1 80 #ifdef MMX
rlm@1 81 Init_2xSaIMMX(BitFormat);
rlm@1 82 #endif
rlm@1 83
rlm@1 84 return 1;
rlm@1 85 }
rlm@1 86
rlm@1 87 static inline int GetResult1(u32 A, u32 B, u32 C, u32 D,
rlm@1 88 u32 /* E */)
rlm@1 89 {
rlm@1 90 int x = 0;
rlm@1 91 int y = 0;
rlm@1 92 int r = 0;
rlm@1 93
rlm@1 94 if (A == C)
rlm@1 95 x += 1;
rlm@1 96 else if (B == C)
rlm@1 97 y += 1;
rlm@1 98 if (A == D)
rlm@1 99 x += 1;
rlm@1 100 else if (B == D)
rlm@1 101 y += 1;
rlm@1 102 if (x <= 1)
rlm@1 103 r += 1;
rlm@1 104 if (y <= 1)
rlm@1 105 r -= 1;
rlm@1 106 return r;
rlm@1 107 }
rlm@1 108
rlm@1 109 static inline int GetResult2(u32 A, u32 B, u32 C, u32 D,
rlm@1 110 u32 /* E */)
rlm@1 111 {
rlm@1 112 int x = 0;
rlm@1 113 int y = 0;
rlm@1 114 int r = 0;
rlm@1 115
rlm@1 116 if (A == C)
rlm@1 117 x += 1;
rlm@1 118 else if (B == C)
rlm@1 119 y += 1;
rlm@1 120 if (A == D)
rlm@1 121 x += 1;
rlm@1 122 else if (B == D)
rlm@1 123 y += 1;
rlm@1 124 if (x <= 1)
rlm@1 125 r -= 1;
rlm@1 126 if (y <= 1)
rlm@1 127 r += 1;
rlm@1 128 return r;
rlm@1 129 }
rlm@1 130
rlm@1 131 static inline int GetResult(u32 A, u32 B, u32 C, u32 D)
rlm@1 132 {
rlm@1 133 int x = 0;
rlm@1 134 int y = 0;
rlm@1 135 int r = 0;
rlm@1 136
rlm@1 137 if (A == C)
rlm@1 138 x += 1;
rlm@1 139 else if (B == C)
rlm@1 140 y += 1;
rlm@1 141 if (A == D)
rlm@1 142 x += 1;
rlm@1 143 else if (B == D)
rlm@1 144 y += 1;
rlm@1 145 if (x <= 1)
rlm@1 146 r += 1;
rlm@1 147 if (y <= 1)
rlm@1 148 r -= 1;
rlm@1 149 return r;
rlm@1 150 }
rlm@1 151
rlm@1 152 static inline u32 INTERPOLATE(u32 A, u32 B)
rlm@1 153 {
rlm@1 154 if (A != B)
rlm@1 155 {
rlm@1 156 return (((A & colorMask) >> 1) + ((B & colorMask) >> 1) +
rlm@1 157 (A & B & lowPixelMask));
rlm@1 158 }
rlm@1 159 else
rlm@1 160 return A;
rlm@1 161 }
rlm@1 162
rlm@1 163 static inline u32 Q_INTERPOLATE(u32 A, u32 B, u32 C, u32 D)
rlm@1 164 {
rlm@1 165 register u32 x = ((A & qcolorMask) >> 2) +
rlm@1 166 ((B & qcolorMask) >> 2) +
rlm@1 167 ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2);
rlm@1 168 register u32 y = (A & qlowpixelMask) +
rlm@1 169 (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask);
rlm@1 170
rlm@1 171 y = (y >> 2) & qlowpixelMask;
rlm@1 172 return x + y;
rlm@1 173 }
rlm@1 174
rlm@1 175 static inline int GetResult1_32(u32 A, u32 B, u32 C, u32 D,
rlm@1 176 u32 /* E */)
rlm@1 177 {
rlm@1 178 int x = 0;
rlm@1 179 int y = 0;
rlm@1 180 int r = 0;
rlm@1 181
rlm@1 182 if (A == C)
rlm@1 183 x += 1;
rlm@1 184 else if (B == C)
rlm@1 185 y += 1;
rlm@1 186 if (A == D)
rlm@1 187 x += 1;
rlm@1 188 else if (B == D)
rlm@1 189 y += 1;
rlm@1 190 if (x <= 1)
rlm@1 191 r += 1;
rlm@1 192 if (y <= 1)
rlm@1 193 r -= 1;
rlm@1 194 return r;
rlm@1 195 }
rlm@1 196
rlm@1 197 static inline int GetResult2_32(u32 A, u32 B, u32 C, u32 D,
rlm@1 198 u32 /* E */)
rlm@1 199 {
rlm@1 200 int x = 0;
rlm@1 201 int y = 0;
rlm@1 202 int r = 0;
rlm@1 203
rlm@1 204 if (A == C)
rlm@1 205 x += 1;
rlm@1 206 else if (B == C)
rlm@1 207 y += 1;
rlm@1 208 if (A == D)
rlm@1 209 x += 1;
rlm@1 210 else if (B == D)
rlm@1 211 y += 1;
rlm@1 212 if (x <= 1)
rlm@1 213 r -= 1;
rlm@1 214 if (y <= 1)
rlm@1 215 r += 1;
rlm@1 216 return r;
rlm@1 217 }
rlm@1 218
rlm@1 219 #define BLUE_MASK565 0x001F001F
rlm@1 220 #define RED_MASK565 0xF800F800
rlm@1 221 #define GREEN_MASK565 0x07E007E0
rlm@1 222
rlm@1 223 #define BLUE_MASK555 0x001F001F
rlm@1 224 #define RED_MASK555 0x7C007C00
rlm@1 225 #define GREEN_MASK555 0x03E003E0
rlm@1 226
rlm@1 227 void Super2xSaI(u8 *srcPtr, u32 srcPitch,
rlm@1 228 u8 *deltaPtr, u8 *dstPtr, u32 dstPitch,
rlm@1 229 int width, int height)
rlm@1 230 {
rlm@1 231 u16 *bP;
rlm@1 232 u8 * dP;
rlm@1 233 u32 inc_bP;
rlm@1 234 u32 Nextline = srcPitch >> 1;
rlm@1 235 #ifdef MMX
rlm@1 236 if (cpu_mmx)
rlm@1 237 {
rlm@1 238 for (; height; height--)
rlm@1 239 {
rlm@1 240 _2xSaISuper2xSaILine(srcPtr, deltaPtr, srcPitch, width,
rlm@1 241 dstPtr, dstPitch);
rlm@1 242 srcPtr += srcPitch;
rlm@1 243 dstPtr += dstPitch * 2;
rlm@1 244 deltaPtr += srcPitch;
rlm@1 245 }
rlm@1 246 }
rlm@1 247 else
rlm@1 248 #endif
rlm@1 249 {
rlm@1 250 inc_bP = 1;
rlm@1 251
rlm@1 252 for (; height; height--)
rlm@1 253 {
rlm@1 254 bP = (u16 *) srcPtr;
rlm@1 255 dP = (u8 *) dstPtr;
rlm@1 256
rlm@1 257 for (u32 finish = width; finish; finish -= inc_bP)
rlm@1 258 {
rlm@1 259 u32 color4, color5, color6;
rlm@1 260 u32 color1, color2, color3;
rlm@1 261 u32 colorA0, colorA1, colorA2, colorA3,
rlm@1 262 colorB0, colorB1, colorB2, colorB3, colorS1, colorS2;
rlm@1 263 u32 product1a, product1b, product2a, product2b;
rlm@1 264
rlm@1 265 //--------------------------------------- B1 B2
rlm@1 266 // 4 5 6 S2
rlm@1 267 // 1 2 3 S1
rlm@1 268 // A1 A2
rlm@1 269
rlm@1 270 colorB0 = *(bP - Nextline - 1);
rlm@1 271 colorB1 = *(bP - Nextline);
rlm@1 272 colorB2 = *(bP - Nextline + 1);
rlm@1 273 colorB3 = *(bP - Nextline + 2);
rlm@1 274
rlm@1 275 color4 = *(bP - 1);
rlm@1 276 color5 = *(bP);
rlm@1 277 color6 = *(bP + 1);
rlm@1 278 colorS2 = *(bP + 2);
rlm@1 279
rlm@1 280 color1 = *(bP + Nextline - 1);
rlm@1 281 color2 = *(bP + Nextline);
rlm@1 282 color3 = *(bP + Nextline + 1);
rlm@1 283 colorS1 = *(bP + Nextline + 2);
rlm@1 284
rlm@1 285 colorA0 = *(bP + Nextline + Nextline - 1);
rlm@1 286 colorA1 = *(bP + Nextline + Nextline);
rlm@1 287 colorA2 = *(bP + Nextline + Nextline + 1);
rlm@1 288 colorA3 = *(bP + Nextline + Nextline + 2);
rlm@1 289
rlm@1 290 //--------------------------------------
rlm@1 291 if (color2 == color6 && color5 != color3)
rlm@1 292 {
rlm@1 293 product2b = product1b = color2;
rlm@1 294 }
rlm@1 295 else if (color5 == color3 && color2 != color6)
rlm@1 296 {
rlm@1 297 product2b = product1b = color5;
rlm@1 298 }
rlm@1 299 else if (color5 == color3 && color2 == color6)
rlm@1 300 {
rlm@1 301 register int r = 0;
rlm@1 302
rlm@1 303 r += GetResult(color6, color5, color1, colorA1);
rlm@1 304 r += GetResult(color6, color5, color4, colorB1);
rlm@1 305 r += GetResult(color6, color5, colorA2, colorS1);
rlm@1 306 r += GetResult(color6, color5, colorB2, colorS2);
rlm@1 307
rlm@1 308 if (r > 0)
rlm@1 309 product2b = product1b = color6;
rlm@1 310 else if (r < 0)
rlm@1 311 product2b = product1b = color5;
rlm@1 312 else
rlm@1 313 {
rlm@1 314 product2b = product1b = INTERPOLATE(color5, color6);
rlm@1 315 }
rlm@1 316 }
rlm@1 317 else
rlm@1 318 {
rlm@1 319 if (color6 == color3 && color3 == colorA1
rlm@1 320 && color2 != colorA2 && color3 != colorA0)
rlm@1 321 product2b =
rlm@1 322 Q_INTERPOLATE(color3, color3, color3, color2);
rlm@1 323 else if (color5 == color2 && color2 == colorA2
rlm@1 324 && colorA1 != color3 && color2 != colorA3)
rlm@1 325 product2b =
rlm@1 326 Q_INTERPOLATE(color2, color2, color2, color3);
rlm@1 327 else
rlm@1 328 product2b = INTERPOLATE(color2, color3);
rlm@1 329
rlm@1 330 if (color6 == color3 && color6 == colorB1
rlm@1 331 && color5 != colorB2 && color6 != colorB0)
rlm@1 332 product1b =
rlm@1 333 Q_INTERPOLATE(color6, color6, color6, color5);
rlm@1 334 else if (color5 == color2 && color5 == colorB2
rlm@1 335 && colorB1 != color6 && color5 != colorB3)
rlm@1 336 product1b =
rlm@1 337 Q_INTERPOLATE(color6, color5, color5, color5);
rlm@1 338 else
rlm@1 339 product1b = INTERPOLATE(color5, color6);
rlm@1 340 }
rlm@1 341
rlm@1 342 if (color5 == color3 && color2 != color6 && color4 == color5
rlm@1 343 && color5 != colorA2)
rlm@1 344 product2a = INTERPOLATE(color2, color5);
rlm@1 345 else
rlm@1 346 if (color5 == color1 && color6 == color5
rlm@1 347 && color4 != color2 && color5 != colorA0)
rlm@1 348 product2a = INTERPOLATE(color2, color5);
rlm@1 349 else
rlm@1 350 product2a = color2;
rlm@1 351
rlm@1 352 if (color2 == color6 && color5 != color3 && color1 == color2
rlm@1 353 && color2 != colorB2)
rlm@1 354 product1a = INTERPOLATE(color2, color5);
rlm@1 355 else
rlm@1 356 if (color4 == color2 && color3 == color2
rlm@1 357 && color1 != color5 && color2 != colorB0)
rlm@1 358 product1a = INTERPOLATE(color2, color5);
rlm@1 359 else
rlm@1 360 product1a = color5;
rlm@1 361
rlm@1 362 #ifdef WORDS_BIGENDIAN
rlm@1 363 product1a = (product1a << 16) | product1b;
rlm@1 364 product2a = (product2a << 16) | product2b;
rlm@1 365 #else
rlm@1 366 product1a = product1a | (product1b << 16);
rlm@1 367 product2a = product2a | (product2b << 16);
rlm@1 368 #endif
rlm@1 369
rlm@1 370 *((u32 *) dP) = product1a;
rlm@1 371 *((u32 *) (dP + dstPitch)) = product2a;
rlm@1 372
rlm@1 373 bP += inc_bP;
rlm@1 374 dP += sizeof(u32);
rlm@1 375 } // end of for ( finish= width etc..)
rlm@1 376
rlm@1 377 srcPtr += srcPitch;
rlm@1 378 dstPtr += dstPitch << 1;
rlm@1 379 deltaPtr += srcPitch;
rlm@1 380 } // endof: for (; height; height--)
rlm@1 381 }
rlm@1 382 }
rlm@1 383
rlm@1 384 void Super2xSaI32(u8 *srcPtr, u32 srcPitch,
rlm@1 385 u8 * /* deltaPtr */, u8 *dstPtr, u32 dstPitch,
rlm@1 386 int width, int height)
rlm@1 387 {
rlm@1 388 u32 *bP;
rlm@1 389 u32 *dP;
rlm@1 390 u32 inc_bP;
rlm@1 391 u32 Nextline = srcPitch >> 2;
rlm@1 392 inc_bP = 1;
rlm@1 393
rlm@1 394 for (; height; height--)
rlm@1 395 {
rlm@1 396 bP = (u32 *) srcPtr;
rlm@1 397 dP = (u32 *) dstPtr;
rlm@1 398
rlm@1 399 for (u32 finish = width; finish; finish -= inc_bP)
rlm@1 400 {
rlm@1 401 u32 color4, color5, color6;
rlm@1 402 u32 color1, color2, color3;
rlm@1 403 u32 colorA0, colorA1, colorA2, colorA3,
rlm@1 404 colorB0, colorB1, colorB2, colorB3, colorS1, colorS2;
rlm@1 405 u32 product1a, product1b, product2a, product2b;
rlm@1 406
rlm@1 407 //--------------------------------------- B1 B2
rlm@1 408 // 4 5 6 S2
rlm@1 409 // 1 2 3 S1
rlm@1 410 // A1 A2
rlm@1 411
rlm@1 412 colorB0 = *(bP - Nextline - 1);
rlm@1 413 colorB1 = *(bP - Nextline);
rlm@1 414 colorB2 = *(bP - Nextline + 1);
rlm@1 415 colorB3 = *(bP - Nextline + 2);
rlm@1 416
rlm@1 417 color4 = *(bP - 1);
rlm@1 418 color5 = *(bP);
rlm@1 419 color6 = *(bP + 1);
rlm@1 420 colorS2 = *(bP + 2);
rlm@1 421
rlm@1 422 color1 = *(bP + Nextline - 1);
rlm@1 423 color2 = *(bP + Nextline);
rlm@1 424 color3 = *(bP + Nextline + 1);
rlm@1 425 colorS1 = *(bP + Nextline + 2);
rlm@1 426
rlm@1 427 colorA0 = *(bP + Nextline + Nextline - 1);
rlm@1 428 colorA1 = *(bP + Nextline + Nextline);
rlm@1 429 colorA2 = *(bP + Nextline + Nextline + 1);
rlm@1 430 colorA3 = *(bP + Nextline + Nextline + 2);
rlm@1 431
rlm@1 432 //--------------------------------------
rlm@1 433 if (color2 == color6 && color5 != color3)
rlm@1 434 {
rlm@1 435 product2b = product1b = color2;
rlm@1 436 }
rlm@1 437 else if (color5 == color3 && color2 != color6)
rlm@1 438 {
rlm@1 439 product2b = product1b = color5;
rlm@1 440 }
rlm@1 441 else if (color5 == color3 && color2 == color6)
rlm@1 442 {
rlm@1 443 register int r = 0;
rlm@1 444
rlm@1 445 r += GetResult(color6, color5, color1, colorA1);
rlm@1 446 r += GetResult(color6, color5, color4, colorB1);
rlm@1 447 r += GetResult(color6, color5, colorA2, colorS1);
rlm@1 448 r += GetResult(color6, color5, colorB2, colorS2);
rlm@1 449
rlm@1 450 if (r > 0)
rlm@1 451 product2b = product1b = color6;
rlm@1 452 else if (r < 0)
rlm@1 453 product2b = product1b = color5;
rlm@1 454 else
rlm@1 455 {
rlm@1 456 product2b = product1b = INTERPOLATE(color5, color6);
rlm@1 457 }
rlm@1 458 }
rlm@1 459 else
rlm@1 460 {
rlm@1 461 if (color6 == color3 && color3 == colorA1
rlm@1 462 && color2 != colorA2 && color3 != colorA0)
rlm@1 463 product2b =
rlm@1 464 Q_INTERPOLATE(color3, color3, color3, color2);
rlm@1 465 else if (color5 == color2 && color2 == colorA2
rlm@1 466 && colorA1 != color3 && color2 != colorA3)
rlm@1 467 product2b =
rlm@1 468 Q_INTERPOLATE(color2, color2, color2, color3);
rlm@1 469 else
rlm@1 470 product2b = INTERPOLATE(color2, color3);
rlm@1 471
rlm@1 472 if (color6 == color3 && color6 == colorB1
rlm@1 473 && color5 != colorB2 && color6 != colorB0)
rlm@1 474 product1b =
rlm@1 475 Q_INTERPOLATE(color6, color6, color6, color5);
rlm@1 476 else if (color5 == color2 && color5 == colorB2
rlm@1 477 && colorB1 != color6 && color5 != colorB3)
rlm@1 478 product1b =
rlm@1 479 Q_INTERPOLATE(color6, color5, color5, color5);
rlm@1 480 else
rlm@1 481 product1b = INTERPOLATE(color5, color6);
rlm@1 482 }
rlm@1 483
rlm@1 484 if (color5 == color3 && color2 != color6 && color4 == color5
rlm@1 485 && color5 != colorA2)
rlm@1 486 product2a = INTERPOLATE(color2, color5);
rlm@1 487 else
rlm@1 488 if (color5 == color1 && color6 == color5
rlm@1 489 && color4 != color2 && color5 != colorA0)
rlm@1 490 product2a = INTERPOLATE(color2, color5);
rlm@1 491 else
rlm@1 492 product2a = color2;
rlm@1 493
rlm@1 494 if (color2 == color6 && color5 != color3 && color1 == color2
rlm@1 495 && color2 != colorB2)
rlm@1 496 product1a = INTERPOLATE(color2, color5);
rlm@1 497 else
rlm@1 498 if (color4 == color2 && color3 == color2
rlm@1 499 && color1 != color5 && color2 != colorB0)
rlm@1 500 product1a = INTERPOLATE(color2, color5);
rlm@1 501 else
rlm@1 502 product1a = color5;
rlm@1 503 *(dP) = product1a;
rlm@1 504 *(dP + 1) = product1b;
rlm@1 505 *(dP + (dstPitch >> 2)) = product2a;
rlm@1 506 *(dP + (dstPitch >> 2) + 1) = product2b;
rlm@1 507
rlm@1 508 bP += inc_bP;
rlm@1 509 dP += 2;
rlm@1 510 } // end of for ( finish= width etc..)
rlm@1 511
rlm@1 512 srcPtr += srcPitch;
rlm@1 513 dstPtr += dstPitch << 1;
rlm@1 514 // deltaPtr += srcPitch;
rlm@1 515 } // endof: for (; height; height--)
rlm@1 516 }
rlm@1 517
rlm@1 518 void SuperEagle(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
rlm@1 519 u8 *dstPtr, u32 dstPitch, int width, int height)
rlm@1 520 {
rlm@1 521 u8 * dP;
rlm@1 522 u16 *bP;
rlm@1 523 u16 *xP;
rlm@1 524 u32 inc_bP;
rlm@1 525
rlm@1 526 #ifdef MMX
rlm@1 527 if (cpu_mmx)
rlm@1 528 {
rlm@1 529 for (; height; height--)
rlm@1 530 {
rlm@1 531 _2xSaISuperEagleLine(srcPtr, deltaPtr, srcPitch, width,
rlm@1 532 dstPtr, dstPitch);
rlm@1 533 srcPtr += srcPitch;
rlm@1 534 dstPtr += dstPitch * 2;
rlm@1 535 deltaPtr += srcPitch;
rlm@1 536 }
rlm@1 537 }
rlm@1 538 else
rlm@1 539 #endif
rlm@1 540 {
rlm@1 541 inc_bP = 1;
rlm@1 542
rlm@1 543 u32 Nextline = srcPitch >> 1;
rlm@1 544
rlm@1 545 for (; height; height--)
rlm@1 546 {
rlm@1 547 bP = (u16 *) srcPtr;
rlm@1 548 xP = (u16 *) deltaPtr;
rlm@1 549 dP = dstPtr;
rlm@1 550 for (u32 finish = width; finish; finish -= inc_bP)
rlm@1 551 {
rlm@1 552 u32 color4, color5, color6;
rlm@1 553 u32 color1, color2, color3;
rlm@1 554 u32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2;
rlm@1 555 u32 product1a, product1b, product2a, product2b;
rlm@1 556
rlm@1 557 colorB1 = *(bP - Nextline);
rlm@1 558 colorB2 = *(bP - Nextline + 1);
rlm@1 559
rlm@1 560 color4 = *(bP - 1);
rlm@1 561 color5 = *(bP);
rlm@1 562 color6 = *(bP + 1);
rlm@1 563 colorS2 = *(bP + 2);
rlm@1 564
rlm@1 565 color1 = *(bP + Nextline - 1);
rlm@1 566 color2 = *(bP + Nextline);
rlm@1 567 color3 = *(bP + Nextline + 1);
rlm@1 568 colorS1 = *(bP + Nextline + 2);
rlm@1 569
rlm@1 570 colorA1 = *(bP + Nextline + Nextline);
rlm@1 571 colorA2 = *(bP + Nextline + Nextline + 1);
rlm@1 572
rlm@1 573 // --------------------------------------
rlm@1 574 if (color2 == color6 && color5 != color3)
rlm@1 575 {
rlm@1 576 product1b = product2a = color2;
rlm@1 577 if ((color1 == color2) || (color6 == colorB2))
rlm@1 578 {
rlm@1 579 product1a = INTERPOLATE(color2, color5);
rlm@1 580 product1a = INTERPOLATE(color2, product1a);
rlm@1 581 // product1a = color2;
rlm@1 582 }
rlm@1 583 else
rlm@1 584 {
rlm@1 585 product1a = INTERPOLATE(color5, color6);
rlm@1 586 }
rlm@1 587
rlm@1 588 if ((color6 == colorS2) || (color2 == colorA1))
rlm@1 589 {
rlm@1 590 product2b = INTERPOLATE(color2, color3);
rlm@1 591 product2b = INTERPOLATE(color2, product2b);
rlm@1 592 // product2b = color2;
rlm@1 593 }
rlm@1 594 else
rlm@1 595 {
rlm@1 596 product2b = INTERPOLATE(color2, color3);
rlm@1 597 }
rlm@1 598 }
rlm@1 599 else if (color5 == color3 && color2 != color6)
rlm@1 600 {
rlm@1 601 product2b = product1a = color5;
rlm@1 602
rlm@1 603 if ((colorB1 == color5) || (color3 == colorS1))
rlm@1 604 {
rlm@1 605 product1b = INTERPOLATE(color5, color6);
rlm@1 606 product1b = INTERPOLATE(color5, product1b);
rlm@1 607 // product1b = color5;
rlm@1 608 }
rlm@1 609 else
rlm@1 610 {
rlm@1 611 product1b = INTERPOLATE(color5, color6);
rlm@1 612 }
rlm@1 613
rlm@1 614 if ((color3 == colorA2) || (color4 == color5))
rlm@1 615 {
rlm@1 616 product2a = INTERPOLATE(color5, color2);
rlm@1 617 product2a = INTERPOLATE(color5, product2a);
rlm@1 618 // product2a = color5;
rlm@1 619 }
rlm@1 620 else
rlm@1 621 {
rlm@1 622 product2a = INTERPOLATE(color2, color3);
rlm@1 623 }
rlm@1 624 }
rlm@1 625 else if (color5 == color3 && color2 == color6)
rlm@1 626 {
rlm@1 627 register int r = 0;
rlm@1 628
rlm@1 629 r += GetResult(color6, color5, color1, colorA1);
rlm@1 630 r += GetResult(color6, color5, color4, colorB1);
rlm@1 631 r += GetResult(color6, color5, colorA2, colorS1);
rlm@1 632 r += GetResult(color6, color5, colorB2, colorS2);
rlm@1 633
rlm@1 634 if (r > 0)
rlm@1 635 {
rlm@1 636 product1b = product2a = color2;
rlm@1 637 product1a = product2b = INTERPOLATE(color5, color6);
rlm@1 638 }
rlm@1 639 else if (r < 0)
rlm@1 640 {
rlm@1 641 product2b = product1a = color5;
rlm@1 642 product1b = product2a = INTERPOLATE(color5, color6);
rlm@1 643 }
rlm@1 644 else
rlm@1 645 {
rlm@1 646 product2b = product1a = color5;
rlm@1 647 product1b = product2a = color2;
rlm@1 648 }
rlm@1 649 }
rlm@1 650 else
rlm@1 651 {
rlm@1 652 product2b = product1a = INTERPOLATE(color2, color6);
rlm@1 653 product2b =
rlm@1 654 Q_INTERPOLATE(color3, color3, color3, product2b);
rlm@1 655 product1a =
rlm@1 656 Q_INTERPOLATE(color5, color5, color5, product1a);
rlm@1 657
rlm@1 658 product2a = product1b = INTERPOLATE(color5, color3);
rlm@1 659 product2a =
rlm@1 660 Q_INTERPOLATE(color2, color2, color2, product2a);
rlm@1 661 product1b =
rlm@1 662 Q_INTERPOLATE(color6, color6, color6, product1b);
rlm@1 663
rlm@1 664 // product1a = color5;
rlm@1 665 // product1b = color6;
rlm@1 666 // product2a = color2;
rlm@1 667 // product2b = color3;
rlm@1 668 }
rlm@1 669 #ifdef WORDS_BIGENDIAN
rlm@1 670 product1a = (product1a << 16) | product1b;
rlm@1 671 product2a = (product2a << 16) | product2b;
rlm@1 672 #else
rlm@1 673 product1a = product1a | (product1b << 16);
rlm@1 674 product2a = product2a | (product2b << 16);
rlm@1 675 #endif
rlm@1 676
rlm@1 677 *((u32 *) dP) = product1a;
rlm@1 678 *((u32 *) (dP + dstPitch)) = product2a;
rlm@1 679 *xP = color5;
rlm@1 680
rlm@1 681 bP += inc_bP;
rlm@1 682 xP += inc_bP;
rlm@1 683 dP += sizeof(u32);
rlm@1 684 } // end of for ( finish= width etc..)
rlm@1 685
rlm@1 686 srcPtr += srcPitch;
rlm@1 687 dstPtr += dstPitch << 1;
rlm@1 688 deltaPtr += srcPitch;
rlm@1 689 } // endof: for (height; height; height--)
rlm@1 690 }
rlm@1 691 }
rlm@1 692
rlm@1 693 void SuperEagle32(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
rlm@1 694 u8 *dstPtr, u32 dstPitch, int width, int height)
rlm@1 695 {
rlm@1 696 u32 *dP;
rlm@1 697 u32 *bP;
rlm@1 698 u32 *xP;
rlm@1 699 u32 inc_bP;
rlm@1 700
rlm@1 701 inc_bP = 1;
rlm@1 702
rlm@1 703 u32 Nextline = srcPitch >> 2;
rlm@1 704
rlm@1 705 for (; height; height--)
rlm@1 706 {
rlm@1 707 bP = (u32 *) srcPtr;
rlm@1 708 xP = (u32 *) deltaPtr;
rlm@1 709 dP = (u32 *)dstPtr;
rlm@1 710 for (u32 finish = width; finish; finish -= inc_bP)
rlm@1 711 {
rlm@1 712 u32 color4, color5, color6;
rlm@1 713 u32 color1, color2, color3;
rlm@1 714 u32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2;
rlm@1 715 u32 product1a, product1b, product2a, product2b;
rlm@1 716
rlm@1 717 colorB1 = *(bP - Nextline);
rlm@1 718 colorB2 = *(bP - Nextline + 1);
rlm@1 719
rlm@1 720 color4 = *(bP - 1);
rlm@1 721 color5 = *(bP);
rlm@1 722 color6 = *(bP + 1);
rlm@1 723 colorS2 = *(bP + 2);
rlm@1 724
rlm@1 725 color1 = *(bP + Nextline - 1);
rlm@1 726 color2 = *(bP + Nextline);
rlm@1 727 color3 = *(bP + Nextline + 1);
rlm@1 728 colorS1 = *(bP + Nextline + 2);
rlm@1 729
rlm@1 730 colorA1 = *(bP + Nextline + Nextline);
rlm@1 731 colorA2 = *(bP + Nextline + Nextline + 1);
rlm@1 732
rlm@1 733 // --------------------------------------
rlm@1 734 if (color2 == color6 && color5 != color3)
rlm@1 735 {
rlm@1 736 product1b = product2a = color2;
rlm@1 737 if ((color1 == color2) || (color6 == colorB2))
rlm@1 738 {
rlm@1 739 product1a = INTERPOLATE(color2, color5);
rlm@1 740 product1a = INTERPOLATE(color2, product1a);
rlm@1 741 // product1a = color2;
rlm@1 742 }
rlm@1 743 else
rlm@1 744 {
rlm@1 745 product1a = INTERPOLATE(color5, color6);
rlm@1 746 }
rlm@1 747
rlm@1 748 if ((color6 == colorS2) || (color2 == colorA1))
rlm@1 749 {
rlm@1 750 product2b = INTERPOLATE(color2, color3);
rlm@1 751 product2b = INTERPOLATE(color2, product2b);
rlm@1 752 // product2b = color2;
rlm@1 753 }
rlm@1 754 else
rlm@1 755 {
rlm@1 756 product2b = INTERPOLATE(color2, color3);
rlm@1 757 }
rlm@1 758 }
rlm@1 759 else if (color5 == color3 && color2 != color6)
rlm@1 760 {
rlm@1 761 product2b = product1a = color5;
rlm@1 762
rlm@1 763 if ((colorB1 == color5) || (color3 == colorS1))
rlm@1 764 {
rlm@1 765 product1b = INTERPOLATE(color5, color6);
rlm@1 766 product1b = INTERPOLATE(color5, product1b);
rlm@1 767 // product1b = color5;
rlm@1 768 }
rlm@1 769 else
rlm@1 770 {
rlm@1 771 product1b = INTERPOLATE(color5, color6);
rlm@1 772 }
rlm@1 773
rlm@1 774 if ((color3 == colorA2) || (color4 == color5))
rlm@1 775 {
rlm@1 776 product2a = INTERPOLATE(color5, color2);
rlm@1 777 product2a = INTERPOLATE(color5, product2a);
rlm@1 778 // product2a = color5;
rlm@1 779 }
rlm@1 780 else
rlm@1 781 {
rlm@1 782 product2a = INTERPOLATE(color2, color3);
rlm@1 783 }
rlm@1 784 }
rlm@1 785 else if (color5 == color3 && color2 == color6)
rlm@1 786 {
rlm@1 787 register int r = 0;
rlm@1 788
rlm@1 789 r += GetResult(color6, color5, color1, colorA1);
rlm@1 790 r += GetResult(color6, color5, color4, colorB1);
rlm@1 791 r += GetResult(color6, color5, colorA2, colorS1);
rlm@1 792 r += GetResult(color6, color5, colorB2, colorS2);
rlm@1 793
rlm@1 794 if (r > 0)
rlm@1 795 {
rlm@1 796 product1b = product2a = color2;
rlm@1 797 product1a = product2b = INTERPOLATE(color5, color6);
rlm@1 798 }
rlm@1 799 else if (r < 0)
rlm@1 800 {
rlm@1 801 product2b = product1a = color5;
rlm@1 802 product1b = product2a = INTERPOLATE(color5, color6);
rlm@1 803 }
rlm@1 804 else
rlm@1 805 {
rlm@1 806 product2b = product1a = color5;
rlm@1 807 product1b = product2a = color2;
rlm@1 808 }
rlm@1 809 }
rlm@1 810 else
rlm@1 811 {
rlm@1 812 product2b = product1a = INTERPOLATE(color2, color6);
rlm@1 813 product2b =
rlm@1 814 Q_INTERPOLATE(color3, color3, color3, product2b);
rlm@1 815 product1a =
rlm@1 816 Q_INTERPOLATE(color5, color5, color5, product1a);
rlm@1 817
rlm@1 818 product2a = product1b = INTERPOLATE(color5, color3);
rlm@1 819 product2a =
rlm@1 820 Q_INTERPOLATE(color2, color2, color2, product2a);
rlm@1 821 product1b =
rlm@1 822 Q_INTERPOLATE(color6, color6, color6, product1b);
rlm@1 823
rlm@1 824 // product1a = color5;
rlm@1 825 // product1b = color6;
rlm@1 826 // product2a = color2;
rlm@1 827 // product2b = color3;
rlm@1 828 }
rlm@1 829 *(dP) = product1a;
rlm@1 830 *(dP + 1) = product1b;
rlm@1 831 *(dP + (dstPitch >> 2)) = product2a;
rlm@1 832 *(dP + (dstPitch >> 2) + 1) = product2b;
rlm@1 833 *xP = color5;
rlm@1 834
rlm@1 835 bP += inc_bP;
rlm@1 836 xP += inc_bP;
rlm@1 837 dP += 2;
rlm@1 838 } // end of for ( finish= width etc..)
rlm@1 839
rlm@1 840 srcPtr += srcPitch;
rlm@1 841 dstPtr += dstPitch << 1;
rlm@1 842 deltaPtr += srcPitch;
rlm@1 843 } // endof: for (height; height; height--)
rlm@1 844 }
rlm@1 845
rlm@1 846 void _2xSaI(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
rlm@1 847 u8 *dstPtr, u32 dstPitch, int width, int height)
rlm@1 848 {
rlm@1 849 u8 * dP;
rlm@1 850 u16 *bP;
rlm@1 851 u32 inc_bP;
rlm@1 852
rlm@1 853 #ifdef MMX
rlm@1 854 if (cpu_mmx)
rlm@1 855 {
rlm@1 856 for (; height; height -= 1)
rlm@1 857 {
rlm@1 858 _2xSaILine(srcPtr, deltaPtr, srcPitch, width, dstPtr, dstPitch);
rlm@1 859 srcPtr += srcPitch;
rlm@1 860 dstPtr += dstPitch * 2;
rlm@1 861 deltaPtr += srcPitch;
rlm@1 862 }
rlm@1 863 }
rlm@1 864 else
rlm@1 865 #endif
rlm@1 866 {
rlm@1 867 inc_bP = 1;
rlm@1 868
rlm@1 869 u32 Nextline = srcPitch >> 1;
rlm@1 870
rlm@1 871 for (; height; height--)
rlm@1 872 {
rlm@1 873 bP = (u16 *) srcPtr;
rlm@1 874 dP = dstPtr;
rlm@1 875
rlm@1 876 for (u32 finish = width; finish; finish -= inc_bP)
rlm@1 877 {
rlm@1 878 register u32 colorA, colorB;
rlm@1 879 u32 colorC, colorD,
rlm@1 880 colorE, colorF, colorG, colorH,
rlm@1 881 colorI, colorJ, colorK, colorL,
rlm@1 882
rlm@1 883 colorM, colorN, colorO, colorP;
rlm@1 884 u32 product, product1, product2;
rlm@1 885
rlm@1 886 //---------------------------------------
rlm@1 887 // Map of the pixels: I|E F|J
rlm@1 888 // G|A B|K
rlm@1 889 // H|C D|L
rlm@1 890 // M|N O|P
rlm@1 891 colorI = *(bP - Nextline - 1);
rlm@1 892 colorE = *(bP - Nextline);
rlm@1 893 colorF = *(bP - Nextline + 1);
rlm@1 894 colorJ = *(bP - Nextline + 2);
rlm@1 895
rlm@1 896 colorG = *(bP - 1);
rlm@1 897 colorA = *(bP);
rlm@1 898 colorB = *(bP + 1);
rlm@1 899 colorK = *(bP + 2);
rlm@1 900
rlm@1 901 colorH = *(bP + Nextline - 1);
rlm@1 902 colorC = *(bP + Nextline);
rlm@1 903 colorD = *(bP + Nextline + 1);
rlm@1 904 colorL = *(bP + Nextline + 2);
rlm@1 905
rlm@1 906 colorM = *(bP + Nextline + Nextline - 1);
rlm@1 907 colorN = *(bP + Nextline + Nextline);
rlm@1 908 colorO = *(bP + Nextline + Nextline + 1);
rlm@1 909 colorP = *(bP + Nextline + Nextline + 2);
rlm@1 910
rlm@1 911 if ((colorA == colorD) && (colorB != colorC))
rlm@1 912 {
rlm@1 913 if (((colorA == colorE) && (colorB == colorL)) ||
rlm@1 914 ((colorA == colorC) && (colorA == colorF)
rlm@1 915 && (colorB != colorE) && (colorB == colorJ)))
rlm@1 916 {
rlm@1 917 product = colorA;
rlm@1 918 }
rlm@1 919 else
rlm@1 920 {
rlm@1 921 product = INTERPOLATE(colorA, colorB);
rlm@1 922 }
rlm@1 923
rlm@1 924 if (((colorA == colorG) && (colorC == colorO)) ||
rlm@1 925 ((colorA == colorB) && (colorA == colorH)
rlm@1 926 && (colorG != colorC) && (colorC == colorM)))
rlm@1 927 {
rlm@1 928 product1 = colorA;
rlm@1 929 }
rlm@1 930 else
rlm@1 931 {
rlm@1 932 product1 = INTERPOLATE(colorA, colorC);
rlm@1 933 }
rlm@1 934 product2 = colorA;
rlm@1 935 }
rlm@1 936 else if ((colorB == colorC) && (colorA != colorD))
rlm@1 937 {
rlm@1 938 if (((colorB == colorF) && (colorA == colorH)) ||
rlm@1 939 ((colorB == colorE) && (colorB == colorD)
rlm@1 940 && (colorA != colorF) && (colorA == colorI)))
rlm@1 941 {
rlm@1 942 product = colorB;
rlm@1 943 }
rlm@1 944 else
rlm@1 945 {
rlm@1 946 product = INTERPOLATE(colorA, colorB);
rlm@1 947 }
rlm@1 948
rlm@1 949 if (((colorC == colorH) && (colorA == colorF)) ||
rlm@1 950 ((colorC == colorG) && (colorC == colorD)
rlm@1 951 && (colorA != colorH) && (colorA == colorI)))
rlm@1 952 {
rlm@1 953 product1 = colorC;
rlm@1 954 }
rlm@1 955 else
rlm@1 956 {
rlm@1 957 product1 = INTERPOLATE(colorA, colorC);
rlm@1 958 }
rlm@1 959 product2 = colorB;
rlm@1 960 }
rlm@1 961 else if ((colorA == colorD) && (colorB == colorC))
rlm@1 962 {
rlm@1 963 if (colorA == colorB)
rlm@1 964 {
rlm@1 965 product = colorA;
rlm@1 966 product1 = colorA;
rlm@1 967 product2 = colorA;
rlm@1 968 }
rlm@1 969 else
rlm@1 970 {
rlm@1 971 register int r = 0;
rlm@1 972
rlm@1 973 product1 = INTERPOLATE(colorA, colorC);
rlm@1 974 product = INTERPOLATE(colorA, colorB);
rlm@1 975
rlm@1 976 r +=
rlm@1 977 GetResult1(colorA, colorB, colorG, colorE,
rlm@1 978 colorI);
rlm@1 979 r +=
rlm@1 980 GetResult2(colorB, colorA, colorK, colorF,
rlm@1 981 colorJ);
rlm@1 982 r +=
rlm@1 983 GetResult2(colorB, colorA, colorH, colorN,
rlm@1 984 colorM);
rlm@1 985 r +=
rlm@1 986 GetResult1(colorA, colorB, colorL, colorO,
rlm@1 987 colorP);
rlm@1 988
rlm@1 989 if (r > 0)
rlm@1 990 product2 = colorA;
rlm@1 991 else if (r < 0)
rlm@1 992 product2 = colorB;
rlm@1 993 else
rlm@1 994 {
rlm@1 995 product2 =
rlm@1 996 Q_INTERPOLATE(colorA, colorB, colorC,
rlm@1 997 colorD);
rlm@1 998 }
rlm@1 999 }
rlm@1 1000 }
rlm@1 1001 else
rlm@1 1002 {
rlm@1 1003 product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD);
rlm@1 1004
rlm@1 1005 if ((colorA == colorC) && (colorA == colorF)
rlm@1 1006 && (colorB != colorE) && (colorB == colorJ))
rlm@1 1007 {
rlm@1 1008 product = colorA;
rlm@1 1009 }
rlm@1 1010 else if ((colorB == colorE) && (colorB == colorD)
rlm@1 1011 && (colorA != colorF) && (colorA == colorI))
rlm@1 1012 {
rlm@1 1013 product = colorB;
rlm@1 1014 }
rlm@1 1015 else
rlm@1 1016 {
rlm@1 1017 product = INTERPOLATE(colorA, colorB);
rlm@1 1018 }
rlm@1 1019
rlm@1 1020 if ((colorA == colorB) && (colorA == colorH)
rlm@1 1021 && (colorG != colorC) && (colorC == colorM))
rlm@1 1022 {
rlm@1 1023 product1 = colorA;
rlm@1 1024 }
rlm@1 1025 else if ((colorC == colorG) && (colorC == colorD)
rlm@1 1026 && (colorA != colorH) && (colorA == colorI))
rlm@1 1027 {
rlm@1 1028 product1 = colorC;
rlm@1 1029 }
rlm@1 1030 else
rlm@1 1031 {
rlm@1 1032 product1 = INTERPOLATE(colorA, colorC);
rlm@1 1033 }
rlm@1 1034 }
rlm@1 1035
rlm@1 1036 #ifdef WORDS_BIGENDIAN
rlm@1 1037 product = (colorA << 16) | product;
rlm@1 1038 product1 = (product1 << 16) | product2;
rlm@1 1039 #else
rlm@1 1040 product = colorA | (product << 16);
rlm@1 1041 product1 = product1 | (product2 << 16);
rlm@1 1042 #endif
rlm@1 1043 *((s32 *) dP) = product;
rlm@1 1044 *((u32 *) (dP + dstPitch)) = product1;
rlm@1 1045
rlm@1 1046 bP += inc_bP;
rlm@1 1047 dP += sizeof(u32);
rlm@1 1048 } // end of for ( finish= width etc..)
rlm@1 1049
rlm@1 1050 srcPtr += srcPitch;
rlm@1 1051 dstPtr += dstPitch << 1;
rlm@1 1052 deltaPtr += srcPitch;
rlm@1 1053 } // endof: for (height; height; height--)
rlm@1 1054 }
rlm@1 1055 }
rlm@1 1056
rlm@1 1057 void _2xSaI32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
rlm@1 1058 u8 *dstPtr, u32 dstPitch, int width, int height)
rlm@1 1059 {
rlm@1 1060 u32 *dP;
rlm@1 1061 u32 *bP;
rlm@1 1062 u32 inc_bP = 1;
rlm@1 1063
rlm@1 1064 u32 Nextline = srcPitch >> 2;
rlm@1 1065
rlm@1 1066 for (; height; height--)
rlm@1 1067 {
rlm@1 1068 bP = (u32 *) srcPtr;
rlm@1 1069 dP = (u32 *) dstPtr;
rlm@1 1070
rlm@1 1071 for (u32 finish = width; finish; finish -= inc_bP)
rlm@1 1072 {
rlm@1 1073 register u32 colorA, colorB;
rlm@1 1074 u32 colorC, colorD,
rlm@1 1075 colorE, colorF, colorG, colorH,
rlm@1 1076 colorI, colorJ, colorK, colorL,
rlm@1 1077
rlm@1 1078 colorM, colorN, colorO, colorP;
rlm@1 1079 u32 product, product1, product2;
rlm@1 1080
rlm@1 1081 //---------------------------------------
rlm@1 1082 // Map of the pixels: I|E F|J
rlm@1 1083 // G|A B|K
rlm@1 1084 // H|C D|L
rlm@1 1085 // M|N O|P
rlm@1 1086 colorI = *(bP - Nextline - 1);
rlm@1 1087 colorE = *(bP - Nextline);
rlm@1 1088 colorF = *(bP - Nextline + 1);
rlm@1 1089 colorJ = *(bP - Nextline + 2);
rlm@1 1090
rlm@1 1091 colorG = *(bP - 1);
rlm@1 1092 colorA = *(bP);
rlm@1 1093 colorB = *(bP + 1);
rlm@1 1094 colorK = *(bP + 2);
rlm@1 1095
rlm@1 1096 colorH = *(bP + Nextline - 1);
rlm@1 1097 colorC = *(bP + Nextline);
rlm@1 1098 colorD = *(bP + Nextline + 1);
rlm@1 1099 colorL = *(bP + Nextline + 2);
rlm@1 1100
rlm@1 1101 colorM = *(bP + Nextline + Nextline - 1);
rlm@1 1102 colorN = *(bP + Nextline + Nextline);
rlm@1 1103 colorO = *(bP + Nextline + Nextline + 1);
rlm@1 1104 colorP = *(bP + Nextline + Nextline + 2);
rlm@1 1105
rlm@1 1106 if ((colorA == colorD) && (colorB != colorC))
rlm@1 1107 {
rlm@1 1108 if (((colorA == colorE) && (colorB == colorL)) ||
rlm@1 1109 ((colorA == colorC) && (colorA == colorF)
rlm@1 1110 && (colorB != colorE) && (colorB == colorJ)))
rlm@1 1111 {
rlm@1 1112 product = colorA;
rlm@1 1113 }
rlm@1 1114 else
rlm@1 1115 {
rlm@1 1116 product = INTERPOLATE(colorA, colorB);
rlm@1 1117 }
rlm@1 1118
rlm@1 1119 if (((colorA == colorG) && (colorC == colorO)) ||
rlm@1 1120 ((colorA == colorB) && (colorA == colorH)
rlm@1 1121 && (colorG != colorC) && (colorC == colorM)))
rlm@1 1122 {
rlm@1 1123 product1 = colorA;
rlm@1 1124 }
rlm@1 1125 else
rlm@1 1126 {
rlm@1 1127 product1 = INTERPOLATE(colorA, colorC);
rlm@1 1128 }
rlm@1 1129 product2 = colorA;
rlm@1 1130 }
rlm@1 1131 else if ((colorB == colorC) && (colorA != colorD))
rlm@1 1132 {
rlm@1 1133 if (((colorB == colorF) && (colorA == colorH)) ||
rlm@1 1134 ((colorB == colorE) && (colorB == colorD)
rlm@1 1135 && (colorA != colorF) && (colorA == colorI)))
rlm@1 1136 {
rlm@1 1137 product = colorB;
rlm@1 1138 }
rlm@1 1139 else
rlm@1 1140 {
rlm@1 1141 product = INTERPOLATE(colorA, colorB);
rlm@1 1142 }
rlm@1 1143
rlm@1 1144 if (((colorC == colorH) && (colorA == colorF)) ||
rlm@1 1145 ((colorC == colorG) && (colorC == colorD)
rlm@1 1146 && (colorA != colorH) && (colorA == colorI)))
rlm@1 1147 {
rlm@1 1148 product1 = colorC;
rlm@1 1149 }
rlm@1 1150 else
rlm@1 1151 {
rlm@1 1152 product1 = INTERPOLATE(colorA, colorC);
rlm@1 1153 }
rlm@1 1154 product2 = colorB;
rlm@1 1155 }
rlm@1 1156 else if ((colorA == colorD) && (colorB == colorC))
rlm@1 1157 {
rlm@1 1158 if (colorA == colorB)
rlm@1 1159 {
rlm@1 1160 product = colorA;
rlm@1 1161 product1 = colorA;
rlm@1 1162 product2 = colorA;
rlm@1 1163 }
rlm@1 1164 else
rlm@1 1165 {
rlm@1 1166 register int r = 0;
rlm@1 1167
rlm@1 1168 product1 = INTERPOLATE(colorA, colorC);
rlm@1 1169 product = INTERPOLATE(colorA, colorB);
rlm@1 1170
rlm@1 1171 r +=
rlm@1 1172 GetResult1(colorA, colorB, colorG, colorE,
rlm@1 1173 colorI);
rlm@1 1174 r +=
rlm@1 1175 GetResult2(colorB, colorA, colorK, colorF,
rlm@1 1176 colorJ);
rlm@1 1177 r +=
rlm@1 1178 GetResult2(colorB, colorA, colorH, colorN,
rlm@1 1179 colorM);
rlm@1 1180 r +=
rlm@1 1181 GetResult1(colorA, colorB, colorL, colorO,
rlm@1 1182 colorP);
rlm@1 1183
rlm@1 1184 if (r > 0)
rlm@1 1185 product2 = colorA;
rlm@1 1186 else if (r < 0)
rlm@1 1187 product2 = colorB;
rlm@1 1188 else
rlm@1 1189 {
rlm@1 1190 product2 =
rlm@1 1191 Q_INTERPOLATE(colorA, colorB, colorC,
rlm@1 1192 colorD);
rlm@1 1193 }
rlm@1 1194 }
rlm@1 1195 }
rlm@1 1196 else
rlm@1 1197 {
rlm@1 1198 product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD);
rlm@1 1199
rlm@1 1200 if ((colorA == colorC) && (colorA == colorF)
rlm@1 1201 && (colorB != colorE) && (colorB == colorJ))
rlm@1 1202 {
rlm@1 1203 product = colorA;
rlm@1 1204 }
rlm@1 1205 else if ((colorB == colorE) && (colorB == colorD)
rlm@1 1206 && (colorA != colorF) && (colorA == colorI))
rlm@1 1207 {
rlm@1 1208 product = colorB;
rlm@1 1209 }
rlm@1 1210 else
rlm@1 1211 {
rlm@1 1212 product = INTERPOLATE(colorA, colorB);
rlm@1 1213 }
rlm@1 1214
rlm@1 1215 if ((colorA == colorB) && (colorA == colorH)
rlm@1 1216 && (colorG != colorC) && (colorC == colorM))
rlm@1 1217 {
rlm@1 1218 product1 = colorA;
rlm@1 1219 }
rlm@1 1220 else if ((colorC == colorG) && (colorC == colorD)
rlm@1 1221 && (colorA != colorH) && (colorA == colorI))
rlm@1 1222 {
rlm@1 1223 product1 = colorC;
rlm@1 1224 }
rlm@1 1225 else
rlm@1 1226 {
rlm@1 1227 product1 = INTERPOLATE(colorA, colorC);
rlm@1 1228 }
rlm@1 1229 }
rlm@1 1230 *(dP) = colorA;
rlm@1 1231 *(dP + 1) = product;
rlm@1 1232 *(dP + (dstPitch >> 2)) = product1;
rlm@1 1233 *(dP + (dstPitch >> 2) + 1) = product2;
rlm@1 1234
rlm@1 1235 bP += inc_bP;
rlm@1 1236 dP += 2;
rlm@1 1237 } // end of for ( finish= width etc..)
rlm@1 1238
rlm@1 1239 srcPtr += srcPitch;
rlm@1 1240 dstPtr += dstPitch << 1;
rlm@1 1241 // deltaPtr += srcPitch;
rlm@1 1242 } // endof: for (height; height; height--)
rlm@1 1243 }
rlm@1 1244
rlm@1 1245 static u32 Bilinear(u32 A, u32 B, u32 x)
rlm@1 1246 {
rlm@1 1247 unsigned long areaA, areaB;
rlm@1 1248 unsigned long result;
rlm@1 1249
rlm@1 1250 if (A == B)
rlm@1 1251 return A;
rlm@1 1252
rlm@1 1253 areaB = (x >> 11) & 0x1f; // reduce 16 bit fraction to 5 bits
rlm@1 1254 areaA = 0x20 - areaB;
rlm@1 1255
rlm@1 1256 A = (A & redblueMask) | ((A & greenMask) << 16);
rlm@1 1257 B = (B & redblueMask) | ((B & greenMask) << 16);
rlm@1 1258
rlm@1 1259 result = ((areaA * A) + (areaB * B)) >> 5;
rlm@1 1260
rlm@1 1261 return (result & redblueMask) | ((result >> 16) & greenMask);
rlm@1 1262 }
rlm@1 1263
rlm@1 1264 static u32 Bilinear4(u32 A, u32 B, u32 C, u32 D, u32 x,
rlm@1 1265 u32 y)
rlm@1 1266 {
rlm@1 1267 unsigned long areaA, areaB, areaC, areaD;
rlm@1 1268 unsigned long result, xy;
rlm@1 1269
rlm@1 1270 x = (x >> 11) & 0x1f;
rlm@1 1271 y = (y >> 11) & 0x1f;
rlm@1 1272 xy = (x * y) >> 5;
rlm@1 1273
rlm@1 1274 A = (A & redblueMask) | ((A & greenMask) << 16);
rlm@1 1275 B = (B & redblueMask) | ((B & greenMask) << 16);
rlm@1 1276 C = (C & redblueMask) | ((C & greenMask) << 16);
rlm@1 1277 D = (D & redblueMask) | ((D & greenMask) << 16);
rlm@1 1278
rlm@1 1279 areaA = 0x20 + xy - x - y;
rlm@1 1280 areaB = x - xy;
rlm@1 1281 areaC = y - xy;
rlm@1 1282 areaD = xy;
rlm@1 1283
rlm@1 1284 result = ((areaA * A) + (areaB * B) + (areaC * C) + (areaD * D)) >> 5;
rlm@1 1285
rlm@1 1286 return (result & redblueMask) | ((result >> 16) & greenMask);
rlm@1 1287 }
rlm@1 1288
rlm@1 1289 void Scale_2xSaI(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
rlm@1 1290 u8 *dstPtr, u32 dstPitch,
rlm@1 1291 u32 dstWidth, u32 dstHeight, int width, int height)
rlm@1 1292 {
rlm@1 1293 u8 * dP;
rlm@1 1294 u16 *bP;
rlm@1 1295
rlm@1 1296 u32 w;
rlm@1 1297 u32 h;
rlm@1 1298 u32 dw;
rlm@1 1299 u32 dh;
rlm@1 1300 u32 hfinish;
rlm@1 1301 u32 wfinish;
rlm@1 1302
rlm@1 1303 u32 Nextline = srcPitch >> 1;
rlm@1 1304
rlm@1 1305 wfinish = (width - 1) << 16; // convert to fixed point
rlm@1 1306 dw = wfinish / (dstWidth - 1);
rlm@1 1307 hfinish = (height - 1) << 16; // convert to fixed point
rlm@1 1308 dh = hfinish / (dstHeight - 1);
rlm@1 1309
rlm@1 1310 for (h = 0; h < hfinish; h += dh)
rlm@1 1311 {
rlm@1 1312 u32 y1, y2;
rlm@1 1313
rlm@1 1314 y1 = h & 0xffff; // fraction part of fixed point
rlm@1 1315 bP = (u16 *) (srcPtr + ((h >> 16) * srcPitch));
rlm@1 1316 dP = dstPtr;
rlm@1 1317 y2 = 0x10000 - y1;
rlm@1 1318
rlm@1 1319 w = 0;
rlm@1 1320
rlm@1 1321 for (; w < wfinish; )
rlm@1 1322 {
rlm@1 1323 u32 A, B, C, D;
rlm@1 1324 u32 E, F, G, H;
rlm@1 1325 u32 I, J, K, L;
rlm@1 1326 u32 x1, x2, a1, f1, f2;
rlm@1 1327 u32 position, product1;
rlm@1 1328
rlm@1 1329 position = w >> 16;
rlm@1 1330 A = bP[position]; // current pixel
rlm@1 1331 B = bP[position + 1]; // next pixel
rlm@1 1332 C = bP[position + Nextline];
rlm@1 1333 D = bP[position + Nextline + 1];
rlm@1 1334 E = bP[position - Nextline];
rlm@1 1335 F = bP[position - Nextline + 1];
rlm@1 1336 G = bP[position - 1];
rlm@1 1337 H = bP[position + Nextline - 1];
rlm@1 1338 I = bP[position + 2];
rlm@1 1339 J = bP[position + Nextline + 2];
rlm@1 1340 K = bP[position + Nextline + Nextline];
rlm@1 1341 L = bP[position + Nextline + Nextline + 1];
rlm@1 1342
rlm@1 1343 x1 = w & 0xffff; // fraction part of fixed point
rlm@1 1344 x2 = 0x10000 - x1;
rlm@1 1345
rlm@1 1346 /*0*/
rlm@1 1347 if (A == B && C == D && A == C)
rlm@1 1348 product1 = A;
rlm@1 1349 else /*1*/ if (A == D && B != C)
rlm@1 1350 {
rlm@1 1351 f1 = (x1 >> 1) + (0x10000 >> 2);
rlm@1 1352 f2 = (y1 >> 1) + (0x10000 >> 2);
rlm@1 1353 if (y1 <= f1 && A == J && A != E) // close to B
rlm@1 1354 {
rlm@1 1355 a1 = f1 - y1;
rlm@1 1356 product1 = Bilinear(A, B, a1);
rlm@1 1357 }
rlm@1 1358 else if (y1 >= f1 && A == G && A != L) // close to C
rlm@1 1359 {
rlm@1 1360 a1 = y1 - f1;
rlm@1 1361 product1 = Bilinear(A, C, a1);
rlm@1 1362 }
rlm@1 1363 else if (x1 >= f2 && A == E && A != J) // close to B
rlm@1 1364 {
rlm@1 1365 a1 = x1 - f2;
rlm@1 1366 product1 = Bilinear(A, B, a1);
rlm@1 1367 }
rlm@1 1368 else if (x1 <= f2 && A == L && A != G) // close to C
rlm@1 1369 {
rlm@1 1370 a1 = f2 - x1;
rlm@1 1371 product1 = Bilinear(A, C, a1);
rlm@1 1372 }
rlm@1 1373 else if (y1 >= x1) // close to C
rlm@1 1374 {
rlm@1 1375 a1 = y1 - x1;
rlm@1 1376 product1 = Bilinear(A, C, a1);
rlm@1 1377 }
rlm@1 1378 else if (y1 <= x1) // close to B
rlm@1 1379 {
rlm@1 1380 a1 = x1 - y1;
rlm@1 1381 product1 = Bilinear(A, B, a1);
rlm@1 1382 }
rlm@1 1383 }
rlm@1 1384 else
rlm@1 1385 /*2*/
rlm@1 1386 if (B == C && A != D)
rlm@1 1387 {
rlm@1 1388 f1 = (x1 >> 1) + (0x10000 >> 2);
rlm@1 1389 f2 = (y1 >> 1) + (0x10000 >> 2);
rlm@1 1390 if (y2 >= f1 && B == H && B != F) // close to A
rlm@1 1391 {
rlm@1 1392 a1 = y2 - f1;
rlm@1 1393 product1 = Bilinear(B, A, a1);
rlm@1 1394 }
rlm@1 1395 else if (y2 <= f1 && B == I && B != K) // close to D
rlm@1 1396 {
rlm@1 1397 a1 = f1 - y2;
rlm@1 1398 product1 = Bilinear(B, D, a1);
rlm@1 1399 }
rlm@1 1400 else if (x2 >= f2 && B == F && B != H) // close to A
rlm@1 1401 {
rlm@1 1402 a1 = x2 - f2;
rlm@1 1403 product1 = Bilinear(B, A, a1);
rlm@1 1404 }
rlm@1 1405 else if (x2 <= f2 && B == K && B != I) // close to D
rlm@1 1406 {
rlm@1 1407 a1 = f2 - x2;
rlm@1 1408 product1 = Bilinear(B, D, a1);
rlm@1 1409 }
rlm@1 1410 else if (y2 >= x1) // close to A
rlm@1 1411 {
rlm@1 1412 a1 = y2 - x1;
rlm@1 1413 product1 = Bilinear(B, A, a1);
rlm@1 1414 }
rlm@1 1415 else if (y2 <= x1) // close to D
rlm@1 1416 {
rlm@1 1417 a1 = x1 - y2;
rlm@1 1418 product1 = Bilinear(B, D, a1);
rlm@1 1419 }
rlm@1 1420 }
rlm@1 1421 /*3*/
rlm@1 1422 else
rlm@1 1423 {
rlm@1 1424 product1 = Bilinear4(A, B, C, D, x1, y1);
rlm@1 1425 }
rlm@1 1426
rlm@1 1427 //end First Pixel
rlm@1 1428 *(u32 *) dP = product1;
rlm@1 1429 dP += 2;
rlm@1 1430 w += dw;
rlm@1 1431 }
rlm@1 1432 dstPtr += dstPitch;
rlm@1 1433 }
rlm@1 1434 }