remote.c: remove autotoolized conditional includes
[rofl0r-VisualBoyAdvance.git] / src / 2xSaI.c
blob5a9a38ef03ed46e32e909b50ac44db7076eb04bf
1 #include "System.h"
2 #include "Port.h"
4 extern int RGB_LOW_BITS_MASK;
6 #ifdef MMX
7 void _2xSaILine (u8 *srcPtr, u8 *deltaPtr, u32 srcPitch,
8 u32 width, u8 *dstPtr, u32 dstPitch);
9 void _2xSaISuperEagleLine (u8 *srcPtr, u8 *deltaPtr,
10 u32 srcPitch, u32 width,
11 u8 *dstPtr, u32 dstPitch);
12 void _2xSaISuper2xSaILine (u8 *srcPtr, u8 *deltaPtr,
13 u32 srcPitch, u32 width,
14 u8 *dstPtr, u32 dstPitch);
15 void Init_2xSaIMMX (u32 BitFormat);
16 void BilinearMMX (u16 * A, u16 * B, u16 * C, u16 * D,
17 u16 * dx, u16 * dy, u8 *dP);
18 void BilinearMMXGrid0 (u16 * A, u16 * B, u16 * C, u16 * D,
19 u16 * dx, u16 * dy, u8 *dP);
20 void BilinearMMXGrid1 (u16 * A, u16 * B, u16 * C, u16 * D,
21 u16 * dx, u16 * dy, u8 *dP);
22 void EndMMX ();
24 bool cpu_mmx = 1;
25 #endif
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)
39 if(systemColorDepth == 16) {
40 if (BitFormat == 565) {
41 colorMask = 0xF7DEF7DE;
42 lowPixelMask = 0x08210821;
43 qcolorMask = 0xE79CE79C;
44 qlowpixelMask = 0x18631863;
45 redblueMask = 0xF81F;
46 greenMask = 0x7E0;
47 qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0xF7DEF7DE;
48 hq2x_init(16);
49 RGB_LOW_BITS_MASK = 0x0821;
50 } else if (BitFormat == 555) {
51 colorMask = 0x7BDE7BDE;
52 lowPixelMask = 0x04210421;
53 qcolorMask = 0x739C739C;
54 qlowpixelMask = 0x0C630C63;
55 redblueMask = 0x7C1F;
56 greenMask = 0x3E0;
57 qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0x7BDE7BDE;
58 hq2x_init(15);
59 RGB_LOW_BITS_MASK = 0x0421;
60 } else {
61 return 0;
63 } else if(systemColorDepth == 32) {
64 colorMask = 0xfefefe;
65 lowPixelMask = 0x010101;
66 qcolorMask = 0xfcfcfc;
67 qlowpixelMask = 0x030303;
68 qRGB_COLOR_MASK[0] = qRGB_COLOR_MASK[1] = 0xfefefe;
69 hq2x_init(32);
70 RGB_LOW_BITS_MASK = 0x010101;
71 } else
72 return 0;
74 #ifdef MMX
75 Init_2xSaIMMX (BitFormat);
76 #endif
78 return 1;
81 static inline int GetResult1 (u32 A, u32 B, u32 C, u32 D,
82 u32 unused)
84 int x = 0;
85 int y = 0;
86 int r = 0;
88 if (A == C)
89 x += 1;
90 else if (B == C)
91 y += 1;
92 if (A == D)
93 x += 1;
94 else if (B == D)
95 y += 1;
96 if (x <= 1)
97 r += 1;
98 if (y <= 1)
99 r -= 1;
100 return r;
103 static inline int GetResult2 (u32 A, u32 B, u32 C, u32 D,
104 u32 unused)
106 int x = 0;
107 int y = 0;
108 int r = 0;
110 if (A == C)
111 x += 1;
112 else if (B == C)
113 y += 1;
114 if (A == D)
115 x += 1;
116 else if (B == D)
117 y += 1;
118 if (x <= 1)
119 r -= 1;
120 if (y <= 1)
121 r += 1;
122 return r;
125 static inline int GetResult (u32 A, u32 B, u32 C, u32 D)
127 int x = 0;
128 int y = 0;
129 int r = 0;
131 if (A == C)
132 x += 1;
133 else if (B == C)
134 y += 1;
135 if (A == D)
136 x += 1;
137 else if (B == D)
138 y += 1;
139 if (x <= 1)
140 r += 1;
141 if (y <= 1)
142 r -= 1;
143 return r;
146 static inline u32 INTERPOLATE (u32 A, u32 B)
148 if (A != B) {
149 return (((A & colorMask) >> 1) + ((B & colorMask) >> 1) +
150 (A & B & lowPixelMask));
151 } else
152 return A;
155 static inline u32 Q_INTERPOLATE (u32 A, u32 B, u32 C, u32 D)
157 register u32 x = ((A & qcolorMask) >> 2) +
158 ((B & qcolorMask) >> 2) +
159 ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2);
160 register u32 y = (A & qlowpixelMask) +
161 (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask);
163 y = (y >> 2) & qlowpixelMask;
164 return x + y;
167 static inline int GetResult1_32 (u32 A, u32 B, u32 C, u32 D,
168 u32 unused /* E */)
170 int x = 0;
171 int y = 0;
172 int r = 0;
174 if (A == C)
175 x += 1;
176 else if (B == C)
177 y += 1;
178 if (A == D)
179 x += 1;
180 else if (B == D)
181 y += 1;
182 if (x <= 1)
183 r += 1;
184 if (y <= 1)
185 r -= 1;
186 return r;
189 static inline int GetResult2_32 (u32 A, u32 B, u32 C, u32 D,
190 u32 unused/* E */)
192 int x = 0;
193 int y = 0;
194 int r = 0;
196 if (A == C)
197 x += 1;
198 else if (B == C)
199 y += 1;
200 if (A == D)
201 x += 1;
202 else if (B == D)
203 y += 1;
204 if (x <= 1)
205 r -= 1;
206 if (y <= 1)
207 r += 1;
208 return r;
211 #define BLUE_MASK565 0x001F001F
212 #define RED_MASK565 0xF800F800
213 #define GREEN_MASK565 0x07E007E0
215 #define BLUE_MASK555 0x001F001F
216 #define RED_MASK555 0x7C007C00
217 #define GREEN_MASK555 0x03E003E0
219 void Super2xSaI (u8 *srcPtr, u32 srcPitch,
220 u8 *deltaPtr, u8 *dstPtr, u32 dstPitch,
221 int width, int height)
223 u16 *bP;
224 u8 *dP;
225 u32 inc_bP;
226 u32 Nextline = srcPitch >> 1;
227 #ifdef MMX
228 if (cpu_mmx) {
229 for (; height; height--) {
230 _2xSaISuper2xSaILine (srcPtr, deltaPtr, srcPitch, width,
231 dstPtr, dstPitch);
232 srcPtr += srcPitch;
233 dstPtr += dstPitch * 2;
234 deltaPtr += srcPitch;
236 } else
237 #endif
239 inc_bP = 1;
241 for (; height; height--) {
242 bP = (u16 *) srcPtr;
243 dP = (u8 *) dstPtr;
245 for (u32 finish = width; finish; finish -= inc_bP) {
246 u32 color4, color5, color6;
247 u32 color1, color2, color3;
248 u32 colorA0, colorA1, colorA2, colorA3,
249 colorB0, colorB1, colorB2, colorB3, colorS1, colorS2;
250 u32 product1a, product1b, product2a, product2b;
252 //--------------------------------------- B1 B2
253 // 4 5 6 S2
254 // 1 2 3 S1
255 // A1 A2
257 colorB0 = *(bP - Nextline - 1);
258 colorB1 = *(bP - Nextline);
259 colorB2 = *(bP - Nextline + 1);
260 colorB3 = *(bP - Nextline + 2);
262 color4 = *(bP - 1);
263 color5 = *(bP);
264 color6 = *(bP + 1);
265 colorS2 = *(bP + 2);
267 color1 = *(bP + Nextline - 1);
268 color2 = *(bP + Nextline);
269 color3 = *(bP + Nextline + 1);
270 colorS1 = *(bP + Nextline + 2);
272 colorA0 = *(bP + Nextline + Nextline - 1);
273 colorA1 = *(bP + Nextline + Nextline);
274 colorA2 = *(bP + Nextline + Nextline + 1);
275 colorA3 = *(bP + Nextline + Nextline + 2);
277 //--------------------------------------
278 if (color2 == color6 && color5 != color3) {
279 product2b = product1b = color2;
280 } else if (color5 == color3 && color2 != color6) {
281 product2b = product1b = color5;
282 } else if (color5 == color3 && color2 == color6) {
283 register int r = 0;
285 r += GetResult (color6, color5, color1, colorA1);
286 r += GetResult (color6, color5, color4, colorB1);
287 r += GetResult (color6, color5, colorA2, colorS1);
288 r += GetResult (color6, color5, colorB2, colorS2);
290 if (r > 0)
291 product2b = product1b = color6;
292 else if (r < 0)
293 product2b = product1b = color5;
294 else {
295 product2b = product1b = INTERPOLATE (color5, color6);
297 } else {
298 if (color6 == color3 && color3 == colorA1
299 && color2 != colorA2 && color3 != colorA0)
300 product2b =
301 Q_INTERPOLATE (color3, color3, color3, color2);
302 else if (color5 == color2 && color2 == colorA2
303 && colorA1 != color3 && color2 != colorA3)
304 product2b =
305 Q_INTERPOLATE (color2, color2, color2, color3);
306 else
307 product2b = INTERPOLATE (color2, color3);
309 if (color6 == color3 && color6 == colorB1
310 && color5 != colorB2 && color6 != colorB0)
311 product1b =
312 Q_INTERPOLATE (color6, color6, color6, color5);
313 else if (color5 == color2 && color5 == colorB2
314 && colorB1 != color6 && color5 != colorB3)
315 product1b =
316 Q_INTERPOLATE (color6, color5, color5, color5);
317 else
318 product1b = INTERPOLATE (color5, color6);
321 if (color5 == color3 && color2 != color6 && color4 == color5
322 && color5 != colorA2)
323 product2a = INTERPOLATE (color2, color5);
324 else
325 if (color5 == color1 && color6 == color5
326 && color4 != color2 && color5 != colorA0)
327 product2a = INTERPOLATE (color2, color5);
328 else
329 product2a = color2;
331 if (color2 == color6 && color5 != color3 && color1 == color2
332 && color2 != colorB2)
333 product1a = INTERPOLATE (color2, color5);
334 else
335 if (color4 == color2 && color3 == color2
336 && color1 != color5 && color2 != colorB0)
337 product1a = INTERPOLATE (color2, color5);
338 else
339 product1a = color5;
341 #ifdef WORDS_BIGENDIAN
342 product1a = (product1a << 16) | product1b;
343 product2a = (product2a << 16) | product2b;
344 #else
345 product1a = product1a | (product1b << 16);
346 product2a = product2a | (product2b << 16);
347 #endif
349 *((u32 *) dP) = product1a;
350 *((u32 *) (dP + dstPitch)) = product2a;
352 bP += inc_bP;
353 dP += sizeof (u32);
354 } // end of for ( finish= width etc..)
356 srcPtr += srcPitch;
357 dstPtr += dstPitch << 1;
358 deltaPtr += srcPitch;
359 } // endof: for (; height; height--)
363 void Super2xSaI32 (u8 *srcPtr, u32 srcPitch,
364 u8 * unused /* deltaPtr */, u8 *dstPtr, u32 dstPitch,
365 int width, int height)
367 u32 *bP;
368 u32 *dP;
369 u32 inc_bP;
370 u32 Nextline = srcPitch >> 2;
371 inc_bP = 1;
373 for (; height; height--) {
374 bP = (u32 *) srcPtr;
375 dP = (u32 *) dstPtr;
377 for (u32 finish = width; finish; finish -= inc_bP) {
378 u32 color4, color5, color6;
379 u32 color1, color2, color3;
380 u32 colorA0, colorA1, colorA2, colorA3,
381 colorB0, colorB1, colorB2, colorB3, colorS1, colorS2;
382 u32 product1a, product1b, product2a, product2b;
384 //--------------------------------------- B1 B2
385 // 4 5 6 S2
386 // 1 2 3 S1
387 // A1 A2
389 colorB0 = *(bP - Nextline - 1);
390 colorB1 = *(bP - Nextline);
391 colorB2 = *(bP - Nextline + 1);
392 colorB3 = *(bP - Nextline + 2);
394 color4 = *(bP - 1);
395 color5 = *(bP);
396 color6 = *(bP + 1);
397 colorS2 = *(bP + 2);
399 color1 = *(bP + Nextline - 1);
400 color2 = *(bP + Nextline);
401 color3 = *(bP + Nextline + 1);
402 colorS1 = *(bP + Nextline + 2);
404 colorA0 = *(bP + Nextline + Nextline - 1);
405 colorA1 = *(bP + Nextline + Nextline);
406 colorA2 = *(bP + Nextline + Nextline + 1);
407 colorA3 = *(bP + Nextline + Nextline + 2);
409 //--------------------------------------
410 if (color2 == color6 && color5 != color3) {
411 product2b = product1b = color2;
412 } else if (color5 == color3 && color2 != color6) {
413 product2b = product1b = color5;
414 } else if (color5 == color3 && color2 == color6) {
415 register int r = 0;
417 r += GetResult (color6, color5, color1, colorA1);
418 r += GetResult (color6, color5, color4, colorB1);
419 r += GetResult (color6, color5, colorA2, colorS1);
420 r += GetResult (color6, color5, colorB2, colorS2);
422 if (r > 0)
423 product2b = product1b = color6;
424 else if (r < 0)
425 product2b = product1b = color5;
426 else {
427 product2b = product1b = INTERPOLATE (color5, color6);
429 } else {
430 if (color6 == color3 && color3 == colorA1
431 && color2 != colorA2 && color3 != colorA0)
432 product2b =
433 Q_INTERPOLATE (color3, color3, color3, color2);
434 else if (color5 == color2 && color2 == colorA2
435 && colorA1 != color3 && color2 != colorA3)
436 product2b =
437 Q_INTERPOLATE (color2, color2, color2, color3);
438 else
439 product2b = INTERPOLATE (color2, color3);
441 if (color6 == color3 && color6 == colorB1
442 && color5 != colorB2 && color6 != colorB0)
443 product1b =
444 Q_INTERPOLATE (color6, color6, color6, color5);
445 else if (color5 == color2 && color5 == colorB2
446 && colorB1 != color6 && color5 != colorB3)
447 product1b =
448 Q_INTERPOLATE (color6, color5, color5, color5);
449 else
450 product1b = INTERPOLATE (color5, color6);
453 if (color5 == color3 && color2 != color6 && color4 == color5
454 && color5 != colorA2)
455 product2a = INTERPOLATE (color2, color5);
456 else
457 if (color5 == color1 && color6 == color5
458 && color4 != color2 && color5 != colorA0)
459 product2a = INTERPOLATE (color2, color5);
460 else
461 product2a = color2;
463 if (color2 == color6 && color5 != color3 && color1 == color2
464 && color2 != colorB2)
465 product1a = INTERPOLATE (color2, color5);
466 else
467 if (color4 == color2 && color3 == color2
468 && color1 != color5 && color2 != colorB0)
469 product1a = INTERPOLATE (color2, color5);
470 else
471 product1a = color5;
472 *(dP) = product1a;
473 *(dP+1) = product1b;
474 *(dP + (dstPitch >> 2)) = product2a;
475 *(dP + (dstPitch >> 2) + 1) = product2b;
477 bP += inc_bP;
478 dP += 2;
479 } // end of for ( finish= width etc..)
481 srcPtr += srcPitch;
482 dstPtr += dstPitch << 1;
483 // deltaPtr += srcPitch;
484 } // endof: for (; height; height--)
487 void SuperEagle (u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
488 u8 *dstPtr, u32 dstPitch, int width, int height)
490 u8 *dP;
491 u16 *bP;
492 u16 *xP;
493 u32 inc_bP;
495 #ifdef MMX
496 if (cpu_mmx) {
497 for (; height; height--) {
498 _2xSaISuperEagleLine (srcPtr, deltaPtr, srcPitch, width,
499 dstPtr, dstPitch);
500 srcPtr += srcPitch;
501 dstPtr += dstPitch * 2;
502 deltaPtr += srcPitch;
504 } else
505 #endif
507 inc_bP = 1;
509 u32 Nextline = srcPitch >> 1;
511 for (; height; height--) {
512 bP = (u16 *) srcPtr;
513 xP = (u16 *) deltaPtr;
514 dP = dstPtr;
515 for (u32 finish = width; finish; finish -= inc_bP) {
516 u32 color4, color5, color6;
517 u32 color1, color2, color3;
518 u32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2;
519 u32 product1a, product1b, product2a, product2b;
521 colorB1 = *(bP - Nextline);
522 colorB2 = *(bP - Nextline + 1);
524 color4 = *(bP - 1);
525 color5 = *(bP);
526 color6 = *(bP + 1);
527 colorS2 = *(bP + 2);
529 color1 = *(bP + Nextline - 1);
530 color2 = *(bP + Nextline);
531 color3 = *(bP + Nextline + 1);
532 colorS1 = *(bP + Nextline + 2);
534 colorA1 = *(bP + Nextline + Nextline);
535 colorA2 = *(bP + Nextline + Nextline + 1);
537 // --------------------------------------
538 if (color2 == color6 && color5 != color3) {
539 product1b = product2a = color2;
540 if ((color1 == color2) || (color6 == colorB2)) {
541 product1a = INTERPOLATE (color2, color5);
542 product1a = INTERPOLATE (color2, product1a);
543 // product1a = color2;
544 } else {
545 product1a = INTERPOLATE (color5, color6);
548 if ((color6 == colorS2) || (color2 == colorA1)) {
549 product2b = INTERPOLATE (color2, color3);
550 product2b = INTERPOLATE (color2, product2b);
551 // product2b = color2;
552 } else {
553 product2b = INTERPOLATE (color2, color3);
555 } else if (color5 == color3 && color2 != color6) {
556 product2b = product1a = color5;
558 if ((colorB1 == color5) || (color3 == colorS1)) {
559 product1b = INTERPOLATE (color5, color6);
560 product1b = INTERPOLATE (color5, product1b);
561 // product1b = color5;
562 } else {
563 product1b = INTERPOLATE (color5, color6);
566 if ((color3 == colorA2) || (color4 == color5)) {
567 product2a = INTERPOLATE (color5, color2);
568 product2a = INTERPOLATE (color5, product2a);
569 // product2a = color5;
570 } else {
571 product2a = INTERPOLATE (color2, color3);
574 } else if (color5 == color3 && color2 == color6) {
575 register int r = 0;
577 r += GetResult (color6, color5, color1, colorA1);
578 r += GetResult (color6, color5, color4, colorB1);
579 r += GetResult (color6, color5, colorA2, colorS1);
580 r += GetResult (color6, color5, colorB2, colorS2);
582 if (r > 0) {
583 product1b = product2a = color2;
584 product1a = product2b = INTERPOLATE (color5, color6);
585 } else if (r < 0) {
586 product2b = product1a = color5;
587 product1b = product2a = INTERPOLATE (color5, color6);
588 } else {
589 product2b = product1a = color5;
590 product1b = product2a = color2;
592 } else {
593 product2b = product1a = INTERPOLATE (color2, color6);
594 product2b =
595 Q_INTERPOLATE (color3, color3, color3, product2b);
596 product1a =
597 Q_INTERPOLATE (color5, color5, color5, product1a);
599 product2a = product1b = INTERPOLATE (color5, color3);
600 product2a =
601 Q_INTERPOLATE (color2, color2, color2, product2a);
602 product1b =
603 Q_INTERPOLATE (color6, color6, color6, product1b);
605 // product1a = color5;
606 // product1b = color6;
607 // product2a = color2;
608 // product2b = color3;
610 #ifdef WORDS_BIGENDIAN
611 product1a = (product1a << 16) | product1b;
612 product2a = (product2a << 16) | product2b;
613 #else
614 product1a = product1a | (product1b << 16);
615 product2a = product2a | (product2b << 16);
616 #endif
618 *((u32 *) dP) = product1a;
619 *((u32 *) (dP + dstPitch)) = product2a;
620 *xP = color5;
622 bP += inc_bP;
623 xP += inc_bP;
624 dP += sizeof (u32);
625 } // end of for ( finish= width etc..)
627 srcPtr += srcPitch;
628 dstPtr += dstPitch << 1;
629 deltaPtr += srcPitch;
630 } // endof: for (height; height; height--)
634 void SuperEagle32 (u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
635 u8 *dstPtr, u32 dstPitch, int width, int height)
637 u32 *dP;
638 u32 *bP;
639 u32 *xP;
640 u32 inc_bP;
642 inc_bP = 1;
644 u32 Nextline = srcPitch >> 2;
646 for (; height; height--) {
647 bP = (u32 *) srcPtr;
648 xP = (u32 *) deltaPtr;
649 dP = (u32 *)dstPtr;
650 for (u32 finish = width; finish; finish -= inc_bP) {
651 u32 color4, color5, color6;
652 u32 color1, color2, color3;
653 u32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2;
654 u32 product1a, product1b, product2a, product2b;
656 colorB1 = *(bP - Nextline);
657 colorB2 = *(bP - Nextline + 1);
659 color4 = *(bP - 1);
660 color5 = *(bP);
661 color6 = *(bP + 1);
662 colorS2 = *(bP + 2);
664 color1 = *(bP + Nextline - 1);
665 color2 = *(bP + Nextline);
666 color3 = *(bP + Nextline + 1);
667 colorS1 = *(bP + Nextline + 2);
669 colorA1 = *(bP + Nextline + Nextline);
670 colorA2 = *(bP + Nextline + Nextline + 1);
672 // --------------------------------------
673 if (color2 == color6 && color5 != color3) {
674 product1b = product2a = color2;
675 if ((color1 == color2) || (color6 == colorB2)) {
676 product1a = INTERPOLATE (color2, color5);
677 product1a = INTERPOLATE (color2, product1a);
678 // product1a = color2;
679 } else {
680 product1a = INTERPOLATE (color5, color6);
683 if ((color6 == colorS2) || (color2 == colorA1)) {
684 product2b = INTERPOLATE (color2, color3);
685 product2b = INTERPOLATE (color2, product2b);
686 // product2b = color2;
687 } else {
688 product2b = INTERPOLATE (color2, color3);
690 } else if (color5 == color3 && color2 != color6) {
691 product2b = product1a = color5;
693 if ((colorB1 == color5) || (color3 == colorS1)) {
694 product1b = INTERPOLATE (color5, color6);
695 product1b = INTERPOLATE (color5, product1b);
696 // product1b = color5;
697 } else {
698 product1b = INTERPOLATE (color5, color6);
701 if ((color3 == colorA2) || (color4 == color5)) {
702 product2a = INTERPOLATE (color5, color2);
703 product2a = INTERPOLATE (color5, product2a);
704 // product2a = color5;
705 } else {
706 product2a = INTERPOLATE (color2, color3);
709 } else if (color5 == color3 && color2 == color6) {
710 register int r = 0;
712 r += GetResult (color6, color5, color1, colorA1);
713 r += GetResult (color6, color5, color4, colorB1);
714 r += GetResult (color6, color5, colorA2, colorS1);
715 r += GetResult (color6, color5, colorB2, colorS2);
717 if (r > 0) {
718 product1b = product2a = color2;
719 product1a = product2b = INTERPOLATE (color5, color6);
720 } else if (r < 0) {
721 product2b = product1a = color5;
722 product1b = product2a = INTERPOLATE (color5, color6);
723 } else {
724 product2b = product1a = color5;
725 product1b = product2a = color2;
727 } else {
728 product2b = product1a = INTERPOLATE (color2, color6);
729 product2b =
730 Q_INTERPOLATE (color3, color3, color3, product2b);
731 product1a =
732 Q_INTERPOLATE (color5, color5, color5, product1a);
734 product2a = product1b = INTERPOLATE (color5, color3);
735 product2a =
736 Q_INTERPOLATE (color2, color2, color2, product2a);
737 product1b =
738 Q_INTERPOLATE (color6, color6, color6, product1b);
740 // product1a = color5;
741 // product1b = color6;
742 // product2a = color2;
743 // product2b = color3;
745 *(dP) = product1a;
746 *(dP+1) = product1b;
747 *(dP + (dstPitch >> 2)) = product2a;
748 *(dP + (dstPitch >> 2) +1) = product2b;
749 *xP = color5;
751 bP += inc_bP;
752 xP += inc_bP;
753 dP += 2;
754 } // end of for ( finish= width etc..)
756 srcPtr += srcPitch;
757 dstPtr += dstPitch << 1;
758 deltaPtr += srcPitch;
759 } // endof: for (height; height; height--)
762 void _2xSaI (u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
763 u8 *dstPtr, u32 dstPitch, int width, int height)
765 u8 *dP;
766 u16 *bP;
767 u32 inc_bP;
769 #ifdef MMX
770 if (cpu_mmx) {
771 for (; height; height -= 1) {
772 _2xSaILine (srcPtr, deltaPtr, srcPitch, width, dstPtr, dstPitch);
773 srcPtr += srcPitch;
774 dstPtr += dstPitch * 2;
775 deltaPtr += srcPitch;
777 } else
778 #endif
780 inc_bP = 1;
782 u32 Nextline = srcPitch >> 1;
784 for (; height; height--) {
785 bP = (u16 *) srcPtr;
786 dP = dstPtr;
788 for (u32 finish = width; finish; finish -= inc_bP) {
790 register u32 colorA, colorB;
791 u32 colorC, colorD,
792 colorE, colorF, colorG, colorH,
793 colorI, colorJ, colorK, colorL,
795 colorM, colorN, colorO, colorP;
796 u32 product, product1, product2;
798 //---------------------------------------
799 // Map of the pixels: I|E F|J
800 // G|A B|K
801 // H|C D|L
802 // M|N O|P
803 colorI = *(bP - Nextline - 1);
804 colorE = *(bP - Nextline);
805 colorF = *(bP - Nextline + 1);
806 colorJ = *(bP - Nextline + 2);
808 colorG = *(bP - 1);
809 colorA = *(bP);
810 colorB = *(bP + 1);
811 colorK = *(bP + 2);
813 colorH = *(bP + Nextline - 1);
814 colorC = *(bP + Nextline);
815 colorD = *(bP + Nextline + 1);
816 colorL = *(bP + Nextline + 2);
818 colorM = *(bP + Nextline + Nextline - 1);
819 colorN = *(bP + Nextline + Nextline);
820 colorO = *(bP + Nextline + Nextline + 1);
821 colorP = *(bP + Nextline + Nextline + 2);
823 if ((colorA == colorD) && (colorB != colorC)) {
824 if (((colorA == colorE) && (colorB == colorL)) ||
825 ((colorA == colorC) && (colorA == colorF)
826 && (colorB != colorE) && (colorB == colorJ))) {
827 product = colorA;
828 } else {
829 product = INTERPOLATE (colorA, colorB);
832 if (((colorA == colorG) && (colorC == colorO)) ||
833 ((colorA == colorB) && (colorA == colorH)
834 && (colorG != colorC) && (colorC == colorM))) {
835 product1 = colorA;
836 } else {
837 product1 = INTERPOLATE (colorA, colorC);
839 product2 = colorA;
840 } else if ((colorB == colorC) && (colorA != colorD)) {
841 if (((colorB == colorF) && (colorA == colorH)) ||
842 ((colorB == colorE) && (colorB == colorD)
843 && (colorA != colorF) && (colorA == colorI))) {
844 product = colorB;
845 } else {
846 product = INTERPOLATE (colorA, colorB);
849 if (((colorC == colorH) && (colorA == colorF)) ||
850 ((colorC == colorG) && (colorC == colorD)
851 && (colorA != colorH) && (colorA == colorI))) {
852 product1 = colorC;
853 } else {
854 product1 = INTERPOLATE (colorA, colorC);
856 product2 = colorB;
857 } else if ((colorA == colorD) && (colorB == colorC)) {
858 if (colorA == colorB) {
859 product = colorA;
860 product1 = colorA;
861 product2 = colorA;
862 } else {
863 register int r = 0;
865 product1 = INTERPOLATE (colorA, colorC);
866 product = INTERPOLATE (colorA, colorB);
868 r +=
869 GetResult1 (colorA, colorB, colorG, colorE,
870 colorI);
871 r +=
872 GetResult2 (colorB, colorA, colorK, colorF,
873 colorJ);
874 r +=
875 GetResult2 (colorB, colorA, colorH, colorN,
876 colorM);
877 r +=
878 GetResult1 (colorA, colorB, colorL, colorO,
879 colorP);
881 if (r > 0)
882 product2 = colorA;
883 else if (r < 0)
884 product2 = colorB;
885 else {
886 product2 =
887 Q_INTERPOLATE (colorA, colorB, colorC,
888 colorD);
891 } else {
892 product2 = Q_INTERPOLATE (colorA, colorB, colorC, colorD);
894 if ((colorA == colorC) && (colorA == colorF)
895 && (colorB != colorE) && (colorB == colorJ)) {
896 product = colorA;
897 } else if ((colorB == colorE) && (colorB == colorD)
898 && (colorA != colorF) && (colorA == colorI)) {
899 product = colorB;
900 } else {
901 product = INTERPOLATE (colorA, colorB);
904 if ((colorA == colorB) && (colorA == colorH)
905 && (colorG != colorC) && (colorC == colorM)) {
906 product1 = colorA;
907 } else if ((colorC == colorG) && (colorC == colorD)
908 && (colorA != colorH) && (colorA == colorI)) {
909 product1 = colorC;
910 } else {
911 product1 = INTERPOLATE (colorA, colorC);
915 #ifdef WORDS_BIGENDIAN
916 product = (colorA << 16) | product ;
917 product1 = (product1 << 16) | product2 ;
918 #else
919 product = colorA | (product << 16);
920 product1 = product1 | (product2 << 16);
921 #endif
922 *((s32 *) dP) = product;
923 *((u32 *) (dP + dstPitch)) = product1;
925 bP += inc_bP;
926 dP += sizeof (u32);
927 } // end of for ( finish= width etc..)
929 srcPtr += srcPitch;
930 dstPtr += dstPitch << 1;
931 deltaPtr += srcPitch;
932 } // endof: for (height; height; height--)
936 void _2xSaI32 (u8 *srcPtr, u32 srcPitch, u8 * unused/* deltaPtr */,
937 u8 *dstPtr, u32 dstPitch, int width, int height)
939 u32 *dP;
940 u32 *bP;
941 u32 inc_bP = 1;
943 u32 Nextline = srcPitch >> 2;
945 for (; height; height--) {
946 bP = (u32 *) srcPtr;
947 dP = (u32 *) dstPtr;
949 for (u32 finish = width; finish; finish -= inc_bP) {
950 register u32 colorA, colorB;
951 u32 colorC, colorD,
952 colorE, colorF, colorG, colorH,
953 colorI, colorJ, colorK, colorL,
955 colorM, colorN, colorO, colorP;
956 u32 product, product1, product2;
958 //---------------------------------------
959 // Map of the pixels: I|E F|J
960 // G|A B|K
961 // H|C D|L
962 // M|N O|P
963 colorI = *(bP - Nextline - 1);
964 colorE = *(bP - Nextline);
965 colorF = *(bP - Nextline + 1);
966 colorJ = *(bP - Nextline + 2);
968 colorG = *(bP - 1);
969 colorA = *(bP);
970 colorB = *(bP + 1);
971 colorK = *(bP + 2);
973 colorH = *(bP + Nextline - 1);
974 colorC = *(bP + Nextline);
975 colorD = *(bP + Nextline + 1);
976 colorL = *(bP + Nextline + 2);
978 colorM = *(bP + Nextline + Nextline - 1);
979 colorN = *(bP + Nextline + Nextline);
980 colorO = *(bP + Nextline + Nextline + 1);
981 colorP = *(bP + Nextline + Nextline + 2);
983 if ((colorA == colorD) && (colorB != colorC)) {
984 if (((colorA == colorE) && (colorB == colorL)) ||
985 ((colorA == colorC) && (colorA == colorF)
986 && (colorB != colorE) && (colorB == colorJ))) {
987 product = colorA;
988 } else {
989 product = INTERPOLATE (colorA, colorB);
992 if (((colorA == colorG) && (colorC == colorO)) ||
993 ((colorA == colorB) && (colorA == colorH)
994 && (colorG != colorC) && (colorC == colorM))) {
995 product1 = colorA;
996 } else {
997 product1 = INTERPOLATE (colorA, colorC);
999 product2 = colorA;
1000 } else if ((colorB == colorC) && (colorA != colorD)) {
1001 if (((colorB == colorF) && (colorA == colorH)) ||
1002 ((colorB == colorE) && (colorB == colorD)
1003 && (colorA != colorF) && (colorA == colorI))) {
1004 product = colorB;
1005 } else {
1006 product = INTERPOLATE (colorA, colorB);
1009 if (((colorC == colorH) && (colorA == colorF)) ||
1010 ((colorC == colorG) && (colorC == colorD)
1011 && (colorA != colorH) && (colorA == colorI))) {
1012 product1 = colorC;
1013 } else {
1014 product1 = INTERPOLATE (colorA, colorC);
1016 product2 = colorB;
1017 } else if ((colorA == colorD) && (colorB == colorC)) {
1018 if (colorA == colorB) {
1019 product = colorA;
1020 product1 = colorA;
1021 product2 = colorA;
1022 } else {
1023 register int r = 0;
1025 product1 = INTERPOLATE (colorA, colorC);
1026 product = INTERPOLATE (colorA, colorB);
1028 r +=
1029 GetResult1 (colorA, colorB, colorG, colorE,
1030 colorI);
1031 r +=
1032 GetResult2 (colorB, colorA, colorK, colorF,
1033 colorJ);
1034 r +=
1035 GetResult2 (colorB, colorA, colorH, colorN,
1036 colorM);
1037 r +=
1038 GetResult1 (colorA, colorB, colorL, colorO,
1039 colorP);
1041 if (r > 0)
1042 product2 = colorA;
1043 else if (r < 0)
1044 product2 = colorB;
1045 else {
1046 product2 =
1047 Q_INTERPOLATE (colorA, colorB, colorC,
1048 colorD);
1051 } else {
1052 product2 = Q_INTERPOLATE (colorA, colorB, colorC, colorD);
1054 if ((colorA == colorC) && (colorA == colorF)
1055 && (colorB != colorE) && (colorB == colorJ)) {
1056 product = colorA;
1057 } else if ((colorB == colorE) && (colorB == colorD)
1058 && (colorA != colorF) && (colorA == colorI)) {
1059 product = colorB;
1060 } else {
1061 product = INTERPOLATE (colorA, colorB);
1064 if ((colorA == colorB) && (colorA == colorH)
1065 && (colorG != colorC) && (colorC == colorM)) {
1066 product1 = colorA;
1067 } else if ((colorC == colorG) && (colorC == colorD)
1068 && (colorA != colorH) && (colorA == colorI)) {
1069 product1 = colorC;
1070 } else {
1071 product1 = INTERPOLATE (colorA, colorC);
1074 *(dP) = colorA;
1075 *(dP + 1) = product;
1076 *(dP + (dstPitch >> 2)) = product1;
1077 *(dP + (dstPitch >> 2) + 1) = product2;
1079 bP += inc_bP;
1080 dP += 2;
1081 } // end of for ( finish= width etc..)
1083 srcPtr += srcPitch;
1084 dstPtr += dstPitch << 1;
1085 // deltaPtr += srcPitch;
1086 } // endof: for (height; height; height--)
1089 static u32 Bilinear (u32 A, u32 B, u32 x)
1091 unsigned long areaA, areaB;
1092 unsigned long result;
1094 if (A == B)
1095 return A;
1097 areaB = (x >> 11) & 0x1f; // reduce 16 bit fraction to 5 bits
1098 areaA = 0x20 - areaB;
1100 A = (A & redblueMask) | ((A & greenMask) << 16);
1101 B = (B & redblueMask) | ((B & greenMask) << 16);
1103 result = ((areaA * A) + (areaB * B)) >> 5;
1105 return (result & redblueMask) | ((result >> 16) & greenMask);
1108 static u32 Bilinear4 (u32 A, u32 B, u32 C, u32 D, u32 x,
1109 u32 y)
1111 unsigned long areaA, areaB, areaC, areaD;
1112 unsigned long result, xy;
1114 x = (x >> 11) & 0x1f;
1115 y = (y >> 11) & 0x1f;
1116 xy = (x * y) >> 5;
1118 A = (A & redblueMask) | ((A & greenMask) << 16);
1119 B = (B & redblueMask) | ((B & greenMask) << 16);
1120 C = (C & redblueMask) | ((C & greenMask) << 16);
1121 D = (D & redblueMask) | ((D & greenMask) << 16);
1123 areaA = 0x20 + xy - x - y;
1124 areaB = x - xy;
1125 areaC = y - xy;
1126 areaD = xy;
1128 result = ((areaA * A) + (areaB * B) + (areaC * C) + (areaD * D)) >> 5;
1130 return (result & redblueMask) | ((result >> 16) & greenMask);
1133 void Scale_2xSaI (u8 *srcPtr, u32 srcPitch, u8 * unused /* deltaPtr */,
1134 u8 *dstPtr, u32 dstPitch,
1135 u32 dstWidth, u32 dstHeight, int width, int height)
1137 u8 *dP;
1138 u16 *bP;
1140 u32 w;
1141 u32 h;
1142 u32 dw;
1143 u32 dh;
1144 u32 hfinish;
1145 u32 wfinish;
1147 u32 Nextline = srcPitch >> 1;
1149 wfinish = (width - 1) << 16; // convert to fixed point
1150 dw = wfinish / (dstWidth - 1);
1151 hfinish = (height - 1) << 16; // convert to fixed point
1152 dh = hfinish / (dstHeight - 1);
1154 for (h = 0; h < hfinish; h += dh) {
1155 u32 y1, y2;
1157 y1 = h & 0xffff; // fraction part of fixed point
1158 bP = (u16 *) (srcPtr + ((h >> 16) * srcPitch));
1159 dP = dstPtr;
1160 y2 = 0x10000 - y1;
1162 w = 0;
1164 for (; w < wfinish;) {
1165 u32 A, B, C, D;
1166 u32 E, F, G, H;
1167 u32 I, J, K, L;
1168 u32 x1, x2, a1, f1, f2;
1169 u32 position, product1;
1171 position = w >> 16;
1172 A = bP[position]; // current pixel
1173 B = bP[position + 1]; // next pixel
1174 C = bP[position + Nextline];
1175 D = bP[position + Nextline + 1];
1176 E = bP[position - Nextline];
1177 F = bP[position - Nextline + 1];
1178 G = bP[position - 1];
1179 H = bP[position + Nextline - 1];
1180 I = bP[position + 2];
1181 J = bP[position + Nextline + 2];
1182 K = bP[position + Nextline + Nextline];
1183 L = bP[position + Nextline + Nextline + 1];
1185 x1 = w & 0xffff; // fraction part of fixed point
1186 x2 = 0x10000 - x1;
1188 /*0*/
1189 if (A == B && C == D && A == C)
1190 product1 = A;
1191 else /*1*/ if (A == D && B != C) {
1192 f1 = (x1 >> 1) + (0x10000 >> 2);
1193 f2 = (y1 >> 1) + (0x10000 >> 2);
1194 if (y1 <= f1 && A == J && A != E) // close to B
1196 a1 = f1 - y1;
1197 product1 = Bilinear (A, B, a1);
1198 } else if (y1 >= f1 && A == G && A != L) // close to C
1200 a1 = y1 - f1;
1201 product1 = Bilinear (A, C, a1);
1203 else if (x1 >= f2 && A == E && A != J) // close to B
1205 a1 = x1 - f2;
1206 product1 = Bilinear (A, B, a1);
1208 else if (x1 <= f2 && A == L && A != G) // close to C
1210 a1 = f2 - x1;
1211 product1 = Bilinear (A, C, a1);
1213 else if (y1 >= x1) // close to C
1215 a1 = y1 - x1;
1216 product1 = Bilinear (A, C, a1);
1218 else if (y1 <= x1) // close to B
1220 a1 = x1 - y1;
1221 product1 = Bilinear (A, B, a1);
1224 else
1225 /*2*/
1226 if (B == C && A != D)
1228 f1 = (x1 >> 1) + (0x10000 >> 2);
1229 f2 = (y1 >> 1) + (0x10000 >> 2);
1230 if (y2 >= f1 && B == H && B != F) // close to A
1232 a1 = y2 - f1;
1233 product1 = Bilinear (B, A, a1);
1235 else if (y2 <= f1 && B == I && B != K) // close to D
1237 a1 = f1 - y2;
1238 product1 = Bilinear (B, D, a1);
1240 else if (x2 >= f2 && B == F && B != H) // close to A
1242 a1 = x2 - f2;
1243 product1 = Bilinear (B, A, a1);
1245 else if (x2 <= f2 && B == K && B != I) // close to D
1247 a1 = f2 - x2;
1248 product1 = Bilinear (B, D, a1);
1250 else if (y2 >= x1) // close to A
1252 a1 = y2 - x1;
1253 product1 = Bilinear (B, A, a1);
1255 else if (y2 <= x1) // close to D
1257 a1 = x1 - y2;
1258 product1 = Bilinear (B, D, a1);
1261 /*3*/
1262 else
1264 product1 = Bilinear4 (A, B, C, D, x1, y1);
1267 //end First Pixel
1268 *(u32 *) dP = product1;
1269 dP += 2;
1270 w += dw;
1272 dstPtr += dstPitch;