Mercurial > vba-clojure
view src/filters/2xSaI.cpp @ 493:783a09c84a28
can now display a single color :)
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 07 Jun 2012 23:03:05 -0500 |
parents | f9f4f1b99eed |
children |
line wrap: on
line source
1 #include "../common/System.h"3 extern "C"4 {5 #ifdef MMX6 void _2xSaILine(u8 *srcPtr, u8 *deltaPtr, u32 srcPitch,7 u32 width, u8 *dstPtr, u32 dstPitch);8 void _2xSaISuperEagleLine(u8 *srcPtr, u8 *deltaPtr,9 u32 srcPitch, u32 width,10 u8 *dstPtr, u32 dstPitch);11 void _2xSaISuper2xSaILine(u8 *srcPtr, u8 *deltaPtr,12 u32 srcPitch, u32 width,13 u8 *dstPtr, u32 dstPitch);14 void Init_2xSaIMMX(u32 BitFormat);15 void BilinearMMX(u16 *A, u16 *B, u16 *C, u16 *D,16 u16 *dx, u16 *dy, u8 *dP);17 void BilinearMMXGrid0(u16 *A, u16 *B, u16 *C, u16 *D,18 u16 *dx, u16 *dy, u8 *dP);19 void BilinearMMXGrid1(u16 *A, u16 *B, u16 *C, u16 *D,20 u16 *dx, u16 *dy, u8 *dP);21 void EndMMX();23 bool cpu_mmx = 1;24 #endif25 }26 static u32 colorMask = 0xF7DEF7DE;27 static u32 lowPixelMask = 0x08210821;28 static u32 qcolorMask = 0xE79CE79C;29 static u32 qlowpixelMask = 0x18631863;30 static u32 redblueMask = 0xF81F;31 static u32 greenMask = 0x7E0;33 u32 qRGB_COLOR_MASK[2] = { 0xF7DEF7DE, 0xF7DEF7DE };35 extern void hq2x_init(unsigned);37 int Init_2xSaI(u32 BitFormat)38 {39 if (systemColorDepth == 16)40 {41 if (BitFormat == 565)42 {43 colorMask = 0xF7DEF7DE;44 lowPixelMask = 0x08210821;45 qcolorMask = 0xE79CE79C;46 qlowpixelMask = 0x18631863;47 redblueMask = 0xF81F;48 greenMask = 0x7E0;49 qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0xF7DEF7DE;50 hq2x_init(16);51 }52 else if (BitFormat == 555)53 {54 colorMask = 0x7BDE7BDE;55 lowPixelMask = 0x04210421;56 qcolorMask = 0x739C739C;57 qlowpixelMask = 0x0C630C63;58 redblueMask = 0x7C1F;59 greenMask = 0x3E0;60 qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0x7BDE7BDE;61 hq2x_init(15);62 }63 else64 {65 return 0;66 }67 }68 else if (systemColorDepth == 32)69 {70 colorMask = 0xfefefe;71 lowPixelMask = 0x010101;72 qcolorMask = 0xfcfcfc;73 qlowpixelMask = 0x030303;74 qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0xfefefe;75 hq2x_init(32);76 }77 else78 return 0;80 #ifdef MMX81 Init_2xSaIMMX(BitFormat);82 #endif84 return 1;85 }87 static inline int GetResult1(u32 A, u32 B, u32 C, u32 D,88 u32 /* E */)89 {90 int x = 0;91 int y = 0;92 int r = 0;94 if (A == C)95 x += 1;96 else if (B == C)97 y += 1;98 if (A == D)99 x += 1;100 else if (B == D)101 y += 1;102 if (x <= 1)103 r += 1;104 if (y <= 1)105 r -= 1;106 return r;107 }109 static inline int GetResult2(u32 A, u32 B, u32 C, u32 D,110 u32 /* E */)111 {112 int x = 0;113 int y = 0;114 int r = 0;116 if (A == C)117 x += 1;118 else if (B == C)119 y += 1;120 if (A == D)121 x += 1;122 else if (B == D)123 y += 1;124 if (x <= 1)125 r -= 1;126 if (y <= 1)127 r += 1;128 return r;129 }131 static inline int GetResult(u32 A, u32 B, u32 C, u32 D)132 {133 int x = 0;134 int y = 0;135 int r = 0;137 if (A == C)138 x += 1;139 else if (B == C)140 y += 1;141 if (A == D)142 x += 1;143 else if (B == D)144 y += 1;145 if (x <= 1)146 r += 1;147 if (y <= 1)148 r -= 1;149 return r;150 }152 static inline u32 INTERPOLATE(u32 A, u32 B)153 {154 if (A != B)155 {156 return (((A & colorMask) >> 1) + ((B & colorMask) >> 1) +157 (A & B & lowPixelMask));158 }159 else160 return A;161 }163 static inline u32 Q_INTERPOLATE(u32 A, u32 B, u32 C, u32 D)164 {165 register u32 x = ((A & qcolorMask) >> 2) +166 ((B & qcolorMask) >> 2) +167 ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2);168 register u32 y = (A & qlowpixelMask) +169 (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask);171 y = (y >> 2) & qlowpixelMask;172 return x + y;173 }175 static inline int GetResult1_32(u32 A, u32 B, u32 C, u32 D,176 u32 /* E */)177 {178 int x = 0;179 int y = 0;180 int r = 0;182 if (A == C)183 x += 1;184 else if (B == C)185 y += 1;186 if (A == D)187 x += 1;188 else if (B == D)189 y += 1;190 if (x <= 1)191 r += 1;192 if (y <= 1)193 r -= 1;194 return r;195 }197 static inline int GetResult2_32(u32 A, u32 B, u32 C, u32 D,198 u32 /* E */)199 {200 int x = 0;201 int y = 0;202 int r = 0;204 if (A == C)205 x += 1;206 else if (B == C)207 y += 1;208 if (A == D)209 x += 1;210 else if (B == D)211 y += 1;212 if (x <= 1)213 r -= 1;214 if (y <= 1)215 r += 1;216 return r;217 }219 #define BLUE_MASK565 0x001F001F220 #define RED_MASK565 0xF800F800221 #define GREEN_MASK565 0x07E007E0223 #define BLUE_MASK555 0x001F001F224 #define RED_MASK555 0x7C007C00225 #define GREEN_MASK555 0x03E003E0227 void Super2xSaI(u8 *srcPtr, u32 srcPitch,228 u8 *deltaPtr, u8 *dstPtr, u32 dstPitch,229 int width, int height)230 {231 u16 *bP;232 u8 * dP;233 u32 inc_bP;234 u32 Nextline = srcPitch >> 1;235 #ifdef MMX236 if (cpu_mmx)237 {238 for (; height; height--)239 {240 _2xSaISuper2xSaILine(srcPtr, deltaPtr, srcPitch, width,241 dstPtr, dstPitch);242 srcPtr += srcPitch;243 dstPtr += dstPitch * 2;244 deltaPtr += srcPitch;245 }246 }247 else248 #endif249 {250 inc_bP = 1;252 for (; height; height--)253 {254 bP = (u16 *) srcPtr;255 dP = (u8 *) dstPtr;257 for (u32 finish = width; finish; finish -= inc_bP)258 {259 u32 color4, color5, color6;260 u32 color1, color2, color3;261 u32 colorA0, colorA1, colorA2, colorA3,262 colorB0, colorB1, colorB2, colorB3, colorS1, colorS2;263 u32 product1a, product1b, product2a, product2b;265 //--------------------------------------- B1 B2266 // 4 5 6 S2267 // 1 2 3 S1268 // A1 A2270 colorB0 = *(bP - Nextline - 1);271 colorB1 = *(bP - Nextline);272 colorB2 = *(bP - Nextline + 1);273 colorB3 = *(bP - Nextline + 2);275 color4 = *(bP - 1);276 color5 = *(bP);277 color6 = *(bP + 1);278 colorS2 = *(bP + 2);280 color1 = *(bP + Nextline - 1);281 color2 = *(bP + Nextline);282 color3 = *(bP + Nextline + 1);283 colorS1 = *(bP + Nextline + 2);285 colorA0 = *(bP + Nextline + Nextline - 1);286 colorA1 = *(bP + Nextline + Nextline);287 colorA2 = *(bP + Nextline + Nextline + 1);288 colorA3 = *(bP + Nextline + Nextline + 2);290 //--------------------------------------291 if (color2 == color6 && color5 != color3)292 {293 product2b = product1b = color2;294 }295 else if (color5 == color3 && color2 != color6)296 {297 product2b = product1b = color5;298 }299 else if (color5 == color3 && color2 == color6)300 {301 register int r = 0;303 r += GetResult(color6, color5, color1, colorA1);304 r += GetResult(color6, color5, color4, colorB1);305 r += GetResult(color6, color5, colorA2, colorS1);306 r += GetResult(color6, color5, colorB2, colorS2);308 if (r > 0)309 product2b = product1b = color6;310 else if (r < 0)311 product2b = product1b = color5;312 else313 {314 product2b = product1b = INTERPOLATE(color5, color6);315 }316 }317 else318 {319 if (color6 == color3 && color3 == colorA1320 && color2 != colorA2 && color3 != colorA0)321 product2b =322 Q_INTERPOLATE(color3, color3, color3, color2);323 else if (color5 == color2 && color2 == colorA2324 && colorA1 != color3 && color2 != colorA3)325 product2b =326 Q_INTERPOLATE(color2, color2, color2, color3);327 else328 product2b = INTERPOLATE(color2, color3);330 if (color6 == color3 && color6 == colorB1331 && color5 != colorB2 && color6 != colorB0)332 product1b =333 Q_INTERPOLATE(color6, color6, color6, color5);334 else if (color5 == color2 && color5 == colorB2335 && colorB1 != color6 && color5 != colorB3)336 product1b =337 Q_INTERPOLATE(color6, color5, color5, color5);338 else339 product1b = INTERPOLATE(color5, color6);340 }342 if (color5 == color3 && color2 != color6 && color4 == color5343 && color5 != colorA2)344 product2a = INTERPOLATE(color2, color5);345 else346 if (color5 == color1 && color6 == color5347 && color4 != color2 && color5 != colorA0)348 product2a = INTERPOLATE(color2, color5);349 else350 product2a = color2;352 if (color2 == color6 && color5 != color3 && color1 == color2353 && color2 != colorB2)354 product1a = INTERPOLATE(color2, color5);355 else356 if (color4 == color2 && color3 == color2357 && color1 != color5 && color2 != colorB0)358 product1a = INTERPOLATE(color2, color5);359 else360 product1a = color5;362 #ifdef WORDS_BIGENDIAN363 product1a = (product1a << 16) | product1b;364 product2a = (product2a << 16) | product2b;365 #else366 product1a = product1a | (product1b << 16);367 product2a = product2a | (product2b << 16);368 #endif370 *((u32 *) dP) = product1a;371 *((u32 *) (dP + dstPitch)) = product2a;373 bP += inc_bP;374 dP += sizeof(u32);375 } // end of for ( finish= width etc..)377 srcPtr += srcPitch;378 dstPtr += dstPitch << 1;379 deltaPtr += srcPitch;380 } // endof: for (; height; height--)381 }382 }384 void Super2xSaI32(u8 *srcPtr, u32 srcPitch,385 u8 * /* deltaPtr */, u8 *dstPtr, u32 dstPitch,386 int width, int height)387 {388 u32 *bP;389 u32 *dP;390 u32 inc_bP;391 u32 Nextline = srcPitch >> 2;392 inc_bP = 1;394 for (; height; height--)395 {396 bP = (u32 *) srcPtr;397 dP = (u32 *) dstPtr;399 for (u32 finish = width; finish; finish -= inc_bP)400 {401 u32 color4, color5, color6;402 u32 color1, color2, color3;403 u32 colorA0, colorA1, colorA2, colorA3,404 colorB0, colorB1, colorB2, colorB3, colorS1, colorS2;405 u32 product1a, product1b, product2a, product2b;407 //--------------------------------------- B1 B2408 // 4 5 6 S2409 // 1 2 3 S1410 // A1 A2412 colorB0 = *(bP - Nextline - 1);413 colorB1 = *(bP - Nextline);414 colorB2 = *(bP - Nextline + 1);415 colorB3 = *(bP - Nextline + 2);417 color4 = *(bP - 1);418 color5 = *(bP);419 color6 = *(bP + 1);420 colorS2 = *(bP + 2);422 color1 = *(bP + Nextline - 1);423 color2 = *(bP + Nextline);424 color3 = *(bP + Nextline + 1);425 colorS1 = *(bP + Nextline + 2);427 colorA0 = *(bP + Nextline + Nextline - 1);428 colorA1 = *(bP + Nextline + Nextline);429 colorA2 = *(bP + Nextline + Nextline + 1);430 colorA3 = *(bP + Nextline + Nextline + 2);432 //--------------------------------------433 if (color2 == color6 && color5 != color3)434 {435 product2b = product1b = color2;436 }437 else if (color5 == color3 && color2 != color6)438 {439 product2b = product1b = color5;440 }441 else if (color5 == color3 && color2 == color6)442 {443 register int r = 0;445 r += GetResult(color6, color5, color1, colorA1);446 r += GetResult(color6, color5, color4, colorB1);447 r += GetResult(color6, color5, colorA2, colorS1);448 r += GetResult(color6, color5, colorB2, colorS2);450 if (r > 0)451 product2b = product1b = color6;452 else if (r < 0)453 product2b = product1b = color5;454 else455 {456 product2b = product1b = INTERPOLATE(color5, color6);457 }458 }459 else460 {461 if (color6 == color3 && color3 == colorA1462 && color2 != colorA2 && color3 != colorA0)463 product2b =464 Q_INTERPOLATE(color3, color3, color3, color2);465 else if (color5 == color2 && color2 == colorA2466 && colorA1 != color3 && color2 != colorA3)467 product2b =468 Q_INTERPOLATE(color2, color2, color2, color3);469 else470 product2b = INTERPOLATE(color2, color3);472 if (color6 == color3 && color6 == colorB1473 && color5 != colorB2 && color6 != colorB0)474 product1b =475 Q_INTERPOLATE(color6, color6, color6, color5);476 else if (color5 == color2 && color5 == colorB2477 && colorB1 != color6 && color5 != colorB3)478 product1b =479 Q_INTERPOLATE(color6, color5, color5, color5);480 else481 product1b = INTERPOLATE(color5, color6);482 }484 if (color5 == color3 && color2 != color6 && color4 == color5485 && color5 != colorA2)486 product2a = INTERPOLATE(color2, color5);487 else488 if (color5 == color1 && color6 == color5489 && color4 != color2 && color5 != colorA0)490 product2a = INTERPOLATE(color2, color5);491 else492 product2a = color2;494 if (color2 == color6 && color5 != color3 && color1 == color2495 && color2 != colorB2)496 product1a = INTERPOLATE(color2, color5);497 else498 if (color4 == color2 && color3 == color2499 && color1 != color5 && color2 != colorB0)500 product1a = INTERPOLATE(color2, color5);501 else502 product1a = color5;503 *(dP) = product1a;504 *(dP + 1) = product1b;505 *(dP + (dstPitch >> 2)) = product2a;506 *(dP + (dstPitch >> 2) + 1) = product2b;508 bP += inc_bP;509 dP += 2;510 } // end of for ( finish= width etc..)512 srcPtr += srcPitch;513 dstPtr += dstPitch << 1;514 // deltaPtr += srcPitch;515 } // endof: for (; height; height--)516 }518 void SuperEagle(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,519 u8 *dstPtr, u32 dstPitch, int width, int height)520 {521 u8 * dP;522 u16 *bP;523 u16 *xP;524 u32 inc_bP;526 #ifdef MMX527 if (cpu_mmx)528 {529 for (; height; height--)530 {531 _2xSaISuperEagleLine(srcPtr, deltaPtr, srcPitch, width,532 dstPtr, dstPitch);533 srcPtr += srcPitch;534 dstPtr += dstPitch * 2;535 deltaPtr += srcPitch;536 }537 }538 else539 #endif540 {541 inc_bP = 1;543 u32 Nextline = srcPitch >> 1;545 for (; height; height--)546 {547 bP = (u16 *) srcPtr;548 xP = (u16 *) deltaPtr;549 dP = dstPtr;550 for (u32 finish = width; finish; finish -= inc_bP)551 {552 u32 color4, color5, color6;553 u32 color1, color2, color3;554 u32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2;555 u32 product1a, product1b, product2a, product2b;557 colorB1 = *(bP - Nextline);558 colorB2 = *(bP - Nextline + 1);560 color4 = *(bP - 1);561 color5 = *(bP);562 color6 = *(bP + 1);563 colorS2 = *(bP + 2);565 color1 = *(bP + Nextline - 1);566 color2 = *(bP + Nextline);567 color3 = *(bP + Nextline + 1);568 colorS1 = *(bP + Nextline + 2);570 colorA1 = *(bP + Nextline + Nextline);571 colorA2 = *(bP + Nextline + Nextline + 1);573 // --------------------------------------574 if (color2 == color6 && color5 != color3)575 {576 product1b = product2a = color2;577 if ((color1 == color2) || (color6 == colorB2))578 {579 product1a = INTERPOLATE(color2, color5);580 product1a = INTERPOLATE(color2, product1a);581 // product1a = color2;582 }583 else584 {585 product1a = INTERPOLATE(color5, color6);586 }588 if ((color6 == colorS2) || (color2 == colorA1))589 {590 product2b = INTERPOLATE(color2, color3);591 product2b = INTERPOLATE(color2, product2b);592 // product2b = color2;593 }594 else595 {596 product2b = INTERPOLATE(color2, color3);597 }598 }599 else if (color5 == color3 && color2 != color6)600 {601 product2b = product1a = color5;603 if ((colorB1 == color5) || (color3 == colorS1))604 {605 product1b = INTERPOLATE(color5, color6);606 product1b = INTERPOLATE(color5, product1b);607 // product1b = color5;608 }609 else610 {611 product1b = INTERPOLATE(color5, color6);612 }614 if ((color3 == colorA2) || (color4 == color5))615 {616 product2a = INTERPOLATE(color5, color2);617 product2a = INTERPOLATE(color5, product2a);618 // product2a = color5;619 }620 else621 {622 product2a = INTERPOLATE(color2, color3);623 }624 }625 else if (color5 == color3 && color2 == color6)626 {627 register int r = 0;629 r += GetResult(color6, color5, color1, colorA1);630 r += GetResult(color6, color5, color4, colorB1);631 r += GetResult(color6, color5, colorA2, colorS1);632 r += GetResult(color6, color5, colorB2, colorS2);634 if (r > 0)635 {636 product1b = product2a = color2;637 product1a = product2b = INTERPOLATE(color5, color6);638 }639 else if (r < 0)640 {641 product2b = product1a = color5;642 product1b = product2a = INTERPOLATE(color5, color6);643 }644 else645 {646 product2b = product1a = color5;647 product1b = product2a = color2;648 }649 }650 else651 {652 product2b = product1a = INTERPOLATE(color2, color6);653 product2b =654 Q_INTERPOLATE(color3, color3, color3, product2b);655 product1a =656 Q_INTERPOLATE(color5, color5, color5, product1a);658 product2a = product1b = INTERPOLATE(color5, color3);659 product2a =660 Q_INTERPOLATE(color2, color2, color2, product2a);661 product1b =662 Q_INTERPOLATE(color6, color6, color6, product1b);664 // product1a = color5;665 // product1b = color6;666 // product2a = color2;667 // product2b = color3;668 }669 #ifdef WORDS_BIGENDIAN670 product1a = (product1a << 16) | product1b;671 product2a = (product2a << 16) | product2b;672 #else673 product1a = product1a | (product1b << 16);674 product2a = product2a | (product2b << 16);675 #endif677 *((u32 *) dP) = product1a;678 *((u32 *) (dP + dstPitch)) = product2a;679 *xP = color5;681 bP += inc_bP;682 xP += inc_bP;683 dP += sizeof(u32);684 } // end of for ( finish= width etc..)686 srcPtr += srcPitch;687 dstPtr += dstPitch << 1;688 deltaPtr += srcPitch;689 } // endof: for (height; height; height--)690 }691 }693 void SuperEagle32(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,694 u8 *dstPtr, u32 dstPitch, int width, int height)695 {696 u32 *dP;697 u32 *bP;698 u32 *xP;699 u32 inc_bP;701 inc_bP = 1;703 u32 Nextline = srcPitch >> 2;705 for (; height; height--)706 {707 bP = (u32 *) srcPtr;708 xP = (u32 *) deltaPtr;709 dP = (u32 *)dstPtr;710 for (u32 finish = width; finish; finish -= inc_bP)711 {712 u32 color4, color5, color6;713 u32 color1, color2, color3;714 u32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2;715 u32 product1a, product1b, product2a, product2b;717 colorB1 = *(bP - Nextline);718 colorB2 = *(bP - Nextline + 1);720 color4 = *(bP - 1);721 color5 = *(bP);722 color6 = *(bP + 1);723 colorS2 = *(bP + 2);725 color1 = *(bP + Nextline - 1);726 color2 = *(bP + Nextline);727 color3 = *(bP + Nextline + 1);728 colorS1 = *(bP + Nextline + 2);730 colorA1 = *(bP + Nextline + Nextline);731 colorA2 = *(bP + Nextline + Nextline + 1);733 // --------------------------------------734 if (color2 == color6 && color5 != color3)735 {736 product1b = product2a = color2;737 if ((color1 == color2) || (color6 == colorB2))738 {739 product1a = INTERPOLATE(color2, color5);740 product1a = INTERPOLATE(color2, product1a);741 // product1a = color2;742 }743 else744 {745 product1a = INTERPOLATE(color5, color6);746 }748 if ((color6 == colorS2) || (color2 == colorA1))749 {750 product2b = INTERPOLATE(color2, color3);751 product2b = INTERPOLATE(color2, product2b);752 // product2b = color2;753 }754 else755 {756 product2b = INTERPOLATE(color2, color3);757 }758 }759 else if (color5 == color3 && color2 != color6)760 {761 product2b = product1a = color5;763 if ((colorB1 == color5) || (color3 == colorS1))764 {765 product1b = INTERPOLATE(color5, color6);766 product1b = INTERPOLATE(color5, product1b);767 // product1b = color5;768 }769 else770 {771 product1b = INTERPOLATE(color5, color6);772 }774 if ((color3 == colorA2) || (color4 == color5))775 {776 product2a = INTERPOLATE(color5, color2);777 product2a = INTERPOLATE(color5, product2a);778 // product2a = color5;779 }780 else781 {782 product2a = INTERPOLATE(color2, color3);783 }784 }785 else if (color5 == color3 && color2 == color6)786 {787 register int r = 0;789 r += GetResult(color6, color5, color1, colorA1);790 r += GetResult(color6, color5, color4, colorB1);791 r += GetResult(color6, color5, colorA2, colorS1);792 r += GetResult(color6, color5, colorB2, colorS2);794 if (r > 0)795 {796 product1b = product2a = color2;797 product1a = product2b = INTERPOLATE(color5, color6);798 }799 else if (r < 0)800 {801 product2b = product1a = color5;802 product1b = product2a = INTERPOLATE(color5, color6);803 }804 else805 {806 product2b = product1a = color5;807 product1b = product2a = color2;808 }809 }810 else811 {812 product2b = product1a = INTERPOLATE(color2, color6);813 product2b =814 Q_INTERPOLATE(color3, color3, color3, product2b);815 product1a =816 Q_INTERPOLATE(color5, color5, color5, product1a);818 product2a = product1b = INTERPOLATE(color5, color3);819 product2a =820 Q_INTERPOLATE(color2, color2, color2, product2a);821 product1b =822 Q_INTERPOLATE(color6, color6, color6, product1b);824 // product1a = color5;825 // product1b = color6;826 // product2a = color2;827 // product2b = color3;828 }829 *(dP) = product1a;830 *(dP + 1) = product1b;831 *(dP + (dstPitch >> 2)) = product2a;832 *(dP + (dstPitch >> 2) + 1) = product2b;833 *xP = color5;835 bP += inc_bP;836 xP += inc_bP;837 dP += 2;838 } // end of for ( finish= width etc..)840 srcPtr += srcPitch;841 dstPtr += dstPitch << 1;842 deltaPtr += srcPitch;843 } // endof: for (height; height; height--)844 }846 void _2xSaI(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,847 u8 *dstPtr, u32 dstPitch, int width, int height)848 {849 u8 * dP;850 u16 *bP;851 u32 inc_bP;853 #ifdef MMX854 if (cpu_mmx)855 {856 for (; height; height -= 1)857 {858 _2xSaILine(srcPtr, deltaPtr, srcPitch, width, dstPtr, dstPitch);859 srcPtr += srcPitch;860 dstPtr += dstPitch * 2;861 deltaPtr += srcPitch;862 }863 }864 else865 #endif866 {867 inc_bP = 1;869 u32 Nextline = srcPitch >> 1;871 for (; height; height--)872 {873 bP = (u16 *) srcPtr;874 dP = dstPtr;876 for (u32 finish = width; finish; finish -= inc_bP)877 {878 register u32 colorA, colorB;879 u32 colorC, colorD,880 colorE, colorF, colorG, colorH,881 colorI, colorJ, colorK, colorL,883 colorM, colorN, colorO, colorP;884 u32 product, product1, product2;886 //---------------------------------------887 // Map of the pixels: I|E F|J888 // G|A B|K889 // H|C D|L890 // M|N O|P891 colorI = *(bP - Nextline - 1);892 colorE = *(bP - Nextline);893 colorF = *(bP - Nextline + 1);894 colorJ = *(bP - Nextline + 2);896 colorG = *(bP - 1);897 colorA = *(bP);898 colorB = *(bP + 1);899 colorK = *(bP + 2);901 colorH = *(bP + Nextline - 1);902 colorC = *(bP + Nextline);903 colorD = *(bP + Nextline + 1);904 colorL = *(bP + Nextline + 2);906 colorM = *(bP + Nextline + Nextline - 1);907 colorN = *(bP + Nextline + Nextline);908 colorO = *(bP + Nextline + Nextline + 1);909 colorP = *(bP + Nextline + Nextline + 2);911 if ((colorA == colorD) && (colorB != colorC))912 {913 if (((colorA == colorE) && (colorB == colorL)) ||914 ((colorA == colorC) && (colorA == colorF)915 && (colorB != colorE) && (colorB == colorJ)))916 {917 product = colorA;918 }919 else920 {921 product = INTERPOLATE(colorA, colorB);922 }924 if (((colorA == colorG) && (colorC == colorO)) ||925 ((colorA == colorB) && (colorA == colorH)926 && (colorG != colorC) && (colorC == colorM)))927 {928 product1 = colorA;929 }930 else931 {932 product1 = INTERPOLATE(colorA, colorC);933 }934 product2 = colorA;935 }936 else if ((colorB == colorC) && (colorA != colorD))937 {938 if (((colorB == colorF) && (colorA == colorH)) ||939 ((colorB == colorE) && (colorB == colorD)940 && (colorA != colorF) && (colorA == colorI)))941 {942 product = colorB;943 }944 else945 {946 product = INTERPOLATE(colorA, colorB);947 }949 if (((colorC == colorH) && (colorA == colorF)) ||950 ((colorC == colorG) && (colorC == colorD)951 && (colorA != colorH) && (colorA == colorI)))952 {953 product1 = colorC;954 }955 else956 {957 product1 = INTERPOLATE(colorA, colorC);958 }959 product2 = colorB;960 }961 else if ((colorA == colorD) && (colorB == colorC))962 {963 if (colorA == colorB)964 {965 product = colorA;966 product1 = colorA;967 product2 = colorA;968 }969 else970 {971 register int r = 0;973 product1 = INTERPOLATE(colorA, colorC);974 product = INTERPOLATE(colorA, colorB);976 r +=977 GetResult1(colorA, colorB, colorG, colorE,978 colorI);979 r +=980 GetResult2(colorB, colorA, colorK, colorF,981 colorJ);982 r +=983 GetResult2(colorB, colorA, colorH, colorN,984 colorM);985 r +=986 GetResult1(colorA, colorB, colorL, colorO,987 colorP);989 if (r > 0)990 product2 = colorA;991 else if (r < 0)992 product2 = colorB;993 else994 {995 product2 =996 Q_INTERPOLATE(colorA, colorB, colorC,997 colorD);998 }999 }1000 }1001 else1002 {1003 product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD);1005 if ((colorA == colorC) && (colorA == colorF)1006 && (colorB != colorE) && (colorB == colorJ))1007 {1008 product = colorA;1009 }1010 else if ((colorB == colorE) && (colorB == colorD)1011 && (colorA != colorF) && (colorA == colorI))1012 {1013 product = colorB;1014 }1015 else1016 {1017 product = INTERPOLATE(colorA, colorB);1018 }1020 if ((colorA == colorB) && (colorA == colorH)1021 && (colorG != colorC) && (colorC == colorM))1022 {1023 product1 = colorA;1024 }1025 else if ((colorC == colorG) && (colorC == colorD)1026 && (colorA != colorH) && (colorA == colorI))1027 {1028 product1 = colorC;1029 }1030 else1031 {1032 product1 = INTERPOLATE(colorA, colorC);1033 }1034 }1036 #ifdef WORDS_BIGENDIAN1037 product = (colorA << 16) | product;1038 product1 = (product1 << 16) | product2;1039 #else1040 product = colorA | (product << 16);1041 product1 = product1 | (product2 << 16);1042 #endif1043 *((s32 *) dP) = product;1044 *((u32 *) (dP + dstPitch)) = product1;1046 bP += inc_bP;1047 dP += sizeof(u32);1048 } // end of for ( finish= width etc..)1050 srcPtr += srcPitch;1051 dstPtr += dstPitch << 1;1052 deltaPtr += srcPitch;1053 } // endof: for (height; height; height--)1054 }1055 }1057 void _2xSaI32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,1058 u8 *dstPtr, u32 dstPitch, int width, int height)1059 {1060 u32 *dP;1061 u32 *bP;1062 u32 inc_bP = 1;1064 u32 Nextline = srcPitch >> 2;1066 for (; height; height--)1067 {1068 bP = (u32 *) srcPtr;1069 dP = (u32 *) dstPtr;1071 for (u32 finish = width; finish; finish -= inc_bP)1072 {1073 register u32 colorA, colorB;1074 u32 colorC, colorD,1075 colorE, colorF, colorG, colorH,1076 colorI, colorJ, colorK, colorL,1078 colorM, colorN, colorO, colorP;1079 u32 product, product1, product2;1081 //---------------------------------------1082 // Map of the pixels: I|E F|J1083 // G|A B|K1084 // H|C D|L1085 // M|N O|P1086 colorI = *(bP - Nextline - 1);1087 colorE = *(bP - Nextline);1088 colorF = *(bP - Nextline + 1);1089 colorJ = *(bP - Nextline + 2);1091 colorG = *(bP - 1);1092 colorA = *(bP);1093 colorB = *(bP + 1);1094 colorK = *(bP + 2);1096 colorH = *(bP + Nextline - 1);1097 colorC = *(bP + Nextline);1098 colorD = *(bP + Nextline + 1);1099 colorL = *(bP + Nextline + 2);1101 colorM = *(bP + Nextline + Nextline - 1);1102 colorN = *(bP + Nextline + Nextline);1103 colorO = *(bP + Nextline + Nextline + 1);1104 colorP = *(bP + Nextline + Nextline + 2);1106 if ((colorA == colorD) && (colorB != colorC))1107 {1108 if (((colorA == colorE) && (colorB == colorL)) ||1109 ((colorA == colorC) && (colorA == colorF)1110 && (colorB != colorE) && (colorB == colorJ)))1111 {1112 product = colorA;1113 }1114 else1115 {1116 product = INTERPOLATE(colorA, colorB);1117 }1119 if (((colorA == colorG) && (colorC == colorO)) ||1120 ((colorA == colorB) && (colorA == colorH)1121 && (colorG != colorC) && (colorC == colorM)))1122 {1123 product1 = colorA;1124 }1125 else1126 {1127 product1 = INTERPOLATE(colorA, colorC);1128 }1129 product2 = colorA;1130 }1131 else if ((colorB == colorC) && (colorA != colorD))1132 {1133 if (((colorB == colorF) && (colorA == colorH)) ||1134 ((colorB == colorE) && (colorB == colorD)1135 && (colorA != colorF) && (colorA == colorI)))1136 {1137 product = colorB;1138 }1139 else1140 {1141 product = INTERPOLATE(colorA, colorB);1142 }1144 if (((colorC == colorH) && (colorA == colorF)) ||1145 ((colorC == colorG) && (colorC == colorD)1146 && (colorA != colorH) && (colorA == colorI)))1147 {1148 product1 = colorC;1149 }1150 else1151 {1152 product1 = INTERPOLATE(colorA, colorC);1153 }1154 product2 = colorB;1155 }1156 else if ((colorA == colorD) && (colorB == colorC))1157 {1158 if (colorA == colorB)1159 {1160 product = colorA;1161 product1 = colorA;1162 product2 = colorA;1163 }1164 else1165 {1166 register int r = 0;1168 product1 = INTERPOLATE(colorA, colorC);1169 product = INTERPOLATE(colorA, colorB);1171 r +=1172 GetResult1(colorA, colorB, colorG, colorE,1173 colorI);1174 r +=1175 GetResult2(colorB, colorA, colorK, colorF,1176 colorJ);1177 r +=1178 GetResult2(colorB, colorA, colorH, colorN,1179 colorM);1180 r +=1181 GetResult1(colorA, colorB, colorL, colorO,1182 colorP);1184 if (r > 0)1185 product2 = colorA;1186 else if (r < 0)1187 product2 = colorB;1188 else1189 {1190 product2 =1191 Q_INTERPOLATE(colorA, colorB, colorC,1192 colorD);1193 }1194 }1195 }1196 else1197 {1198 product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD);1200 if ((colorA == colorC) && (colorA == colorF)1201 && (colorB != colorE) && (colorB == colorJ))1202 {1203 product = colorA;1204 }1205 else if ((colorB == colorE) && (colorB == colorD)1206 && (colorA != colorF) && (colorA == colorI))1207 {1208 product = colorB;1209 }1210 else1211 {1212 product = INTERPOLATE(colorA, colorB);1213 }1215 if ((colorA == colorB) && (colorA == colorH)1216 && (colorG != colorC) && (colorC == colorM))1217 {1218 product1 = colorA;1219 }1220 else if ((colorC == colorG) && (colorC == colorD)1221 && (colorA != colorH) && (colorA == colorI))1222 {1223 product1 = colorC;1224 }1225 else1226 {1227 product1 = INTERPOLATE(colorA, colorC);1228 }1229 }1230 *(dP) = colorA;1231 *(dP + 1) = product;1232 *(dP + (dstPitch >> 2)) = product1;1233 *(dP + (dstPitch >> 2) + 1) = product2;1235 bP += inc_bP;1236 dP += 2;1237 } // end of for ( finish= width etc..)1239 srcPtr += srcPitch;1240 dstPtr += dstPitch << 1;1241 // deltaPtr += srcPitch;1242 } // endof: for (height; height; height--)1243 }1245 static u32 Bilinear(u32 A, u32 B, u32 x)1246 {1247 unsigned long areaA, areaB;1248 unsigned long result;1250 if (A == B)1251 return A;1253 areaB = (x >> 11) & 0x1f; // reduce 16 bit fraction to 5 bits1254 areaA = 0x20 - areaB;1256 A = (A & redblueMask) | ((A & greenMask) << 16);1257 B = (B & redblueMask) | ((B & greenMask) << 16);1259 result = ((areaA * A) + (areaB * B)) >> 5;1261 return (result & redblueMask) | ((result >> 16) & greenMask);1262 }1264 static u32 Bilinear4(u32 A, u32 B, u32 C, u32 D, u32 x,1265 u32 y)1266 {1267 unsigned long areaA, areaB, areaC, areaD;1268 unsigned long result, xy;1270 x = (x >> 11) & 0x1f;1271 y = (y >> 11) & 0x1f;1272 xy = (x * y) >> 5;1274 A = (A & redblueMask) | ((A & greenMask) << 16);1275 B = (B & redblueMask) | ((B & greenMask) << 16);1276 C = (C & redblueMask) | ((C & greenMask) << 16);1277 D = (D & redblueMask) | ((D & greenMask) << 16);1279 areaA = 0x20 + xy - x - y;1280 areaB = x - xy;1281 areaC = y - xy;1282 areaD = xy;1284 result = ((areaA * A) + (areaB * B) + (areaC * C) + (areaD * D)) >> 5;1286 return (result & redblueMask) | ((result >> 16) & greenMask);1287 }1289 void Scale_2xSaI(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,1290 u8 *dstPtr, u32 dstPitch,1291 u32 dstWidth, u32 dstHeight, int width, int height)1292 {1293 u8 * dP;1294 u16 *bP;1296 u32 w;1297 u32 h;1298 u32 dw;1299 u32 dh;1300 u32 hfinish;1301 u32 wfinish;1303 u32 Nextline = srcPitch >> 1;1305 wfinish = (width - 1) << 16; // convert to fixed point1306 dw = wfinish / (dstWidth - 1);1307 hfinish = (height - 1) << 16; // convert to fixed point1308 dh = hfinish / (dstHeight - 1);1310 for (h = 0; h < hfinish; h += dh)1311 {1312 u32 y1, y2;1314 y1 = h & 0xffff; // fraction part of fixed point1315 bP = (u16 *) (srcPtr + ((h >> 16) * srcPitch));1316 dP = dstPtr;1317 y2 = 0x10000 - y1;1319 w = 0;1321 for (; w < wfinish; )1322 {1323 u32 A, B, C, D;1324 u32 E, F, G, H;1325 u32 I, J, K, L;1326 u32 x1, x2, a1, f1, f2;1327 u32 position, product1;1329 position = w >> 16;1330 A = bP[position]; // current pixel1331 B = bP[position + 1]; // next pixel1332 C = bP[position + Nextline];1333 D = bP[position + Nextline + 1];1334 E = bP[position - Nextline];1335 F = bP[position - Nextline + 1];1336 G = bP[position - 1];1337 H = bP[position + Nextline - 1];1338 I = bP[position + 2];1339 J = bP[position + Nextline + 2];1340 K = bP[position + Nextline + Nextline];1341 L = bP[position + Nextline + Nextline + 1];1343 x1 = w & 0xffff; // fraction part of fixed point1344 x2 = 0x10000 - x1;1346 /*0*/1347 if (A == B && C == D && A == C)1348 product1 = A;1349 else /*1*/ if (A == D && B != C)1350 {1351 f1 = (x1 >> 1) + (0x10000 >> 2);1352 f2 = (y1 >> 1) + (0x10000 >> 2);1353 if (y1 <= f1 && A == J && A != E) // close to B1354 {1355 a1 = f1 - y1;1356 product1 = Bilinear(A, B, a1);1357 }1358 else if (y1 >= f1 && A == G && A != L) // close to C1359 {1360 a1 = y1 - f1;1361 product1 = Bilinear(A, C, a1);1362 }1363 else if (x1 >= f2 && A == E && A != J) // close to B1364 {1365 a1 = x1 - f2;1366 product1 = Bilinear(A, B, a1);1367 }1368 else if (x1 <= f2 && A == L && A != G) // close to C1369 {1370 a1 = f2 - x1;1371 product1 = Bilinear(A, C, a1);1372 }1373 else if (y1 >= x1) // close to C1374 {1375 a1 = y1 - x1;1376 product1 = Bilinear(A, C, a1);1377 }1378 else if (y1 <= x1) // close to B1379 {1380 a1 = x1 - y1;1381 product1 = Bilinear(A, B, a1);1382 }1383 }1384 else1385 /*2*/1386 if (B == C && A != D)1387 {1388 f1 = (x1 >> 1) + (0x10000 >> 2);1389 f2 = (y1 >> 1) + (0x10000 >> 2);1390 if (y2 >= f1 && B == H && B != F) // close to A1391 {1392 a1 = y2 - f1;1393 product1 = Bilinear(B, A, a1);1394 }1395 else if (y2 <= f1 && B == I && B != K) // close to D1396 {1397 a1 = f1 - y2;1398 product1 = Bilinear(B, D, a1);1399 }1400 else if (x2 >= f2 && B == F && B != H) // close to A1401 {1402 a1 = x2 - f2;1403 product1 = Bilinear(B, A, a1);1404 }1405 else if (x2 <= f2 && B == K && B != I) // close to D1406 {1407 a1 = f2 - x2;1408 product1 = Bilinear(B, D, a1);1409 }1410 else if (y2 >= x1) // close to A1411 {1412 a1 = y2 - x1;1413 product1 = Bilinear(B, A, a1);1414 }1415 else if (y2 <= x1) // close to D1416 {1417 a1 = x1 - y2;1418 product1 = Bilinear(B, D, a1);1419 }1420 }1421 /*3*/1422 else1423 {1424 product1 = Bilinear4(A, B, C, D, x1, y1);1425 }1427 //end First Pixel1428 *(u32 *) dP = product1;1429 dP += 2;1430 w += dw;1431 }1432 dstPtr += dstPitch;1433 }1434 }