1 /***************************************************************************
4 begin : Sun Oct 28 2001
5 copyright : (C) 2001 by Pete Bernert
6 email : BlackDove@addcom.de
7 ***************************************************************************/
8 /***************************************************************************
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. See also the license.txt file for *
14 * additional informations. *
16 ***************************************************************************/
20 #include "externals.h"
32 BOOL bIsFirstFrame = TRUE;
33 BOOL bCheckMask = FALSE;
34 unsigned short sSetMask = 0;
35 unsigned long lSetMask = 0;
39 int iMaintainAspect = 0;
40 int iUseNoStretchBlt = 0;
44 PSXPoint_t ptCursorPoint[8];
45 unsigned short usCursorActive = 0;
47 //unsigned int LUT16to32[65536];
48 //unsigned int RGBtoYUV[65536];
52 #include <X11/extensions/Xv.h>
53 #include <X11/extensions/Xvlib.h>
54 #include <X11/extensions/XShm.h>
63 XShmSegmentInfo shminfo;
66 extern XvImage *XvShmCreateImage(Display*, XvPortID, int, char*, int, int, XShmSegmentInfo*);
71 void hq2x_32( unsigned char * srcPtr, DWORD srcPitch, unsigned char * dstPtr, int width, int height);
72 void hq3x_32( unsigned char * srcPtr, DWORD srcPitch, unsigned char * dstPtr, int width, int height);
74 ////////////////////////////////////////////////////////////////////////
75 // generic 2xSaI helpers
76 ////////////////////////////////////////////////////////////////////////
78 void * pSaISmallBuff=NULL;
79 void * pSaIBigBuff=NULL;
81 #define GET_RESULT(A, B, C, D) ((A != C || A != D) - (B != C || B != D))
83 static __inline int GetResult1(DWORD A, DWORD B, DWORD C, DWORD D, DWORD E)
88 if (A == C) x+=1; else if (B == C) y+=1;
89 if (A == D) x+=1; else if (B == D) y+=1;
95 static __inline int GetResult2(DWORD A, DWORD B, DWORD C, DWORD D, DWORD E)
100 if (A == C) x+=1; else if (B == C) y+=1;
101 if (A == D) x+=1; else if (B == D) y+=1;
107 #define colorMask8 0x00FEFEFE
108 #define lowPixelMask8 0x00010101
109 #define qcolorMask8 0x00FCFCFC
110 #define qlowpixelMask8 0x00030303
112 #define INTERPOLATE8(A, B) ((((A & colorMask8) >> 1) + ((B & colorMask8) >> 1) + (A & B & lowPixelMask8)))
113 #define Q_INTERPOLATE8(A, B, C, D) (((((A & qcolorMask8) >> 2) + ((B & qcolorMask8) >> 2) + ((C & qcolorMask8) >> 2) + ((D & qcolorMask8) >> 2) \
114 + ((((A & qlowpixelMask8) + (B & qlowpixelMask8) + (C & qlowpixelMask8) + (D & qlowpixelMask8)) >> 2) & qlowpixelMask8))))
117 void Super2xSaI_ex8(unsigned char *srcPtr, DWORD srcPitch,
118 unsigned char *dstBitmap, int width, int height)
120 DWORD dstPitch = srcPitch<<1;
121 DWORD srcPitchHalf = srcPitch>>1;
122 int finWidth = srcPitch>>2;
126 int iXA,iXB,iXC,iYA,iYB,iYC,finish;
127 DWORD color4, color5, color6;
128 DWORD color1, color2, color3;
129 DWORD colorA0, colorA1, colorA2, colorA3,
130 colorB0, colorB1, colorB2, colorB3,
132 DWORD product1a, product1b,
133 product2a, product2b;
141 for (; height; height-=1)
143 bP = (DWORD *)srcPtr;
144 dP = (DWORD *)(dstBitmap + line*dstPitch);
145 for (finish = width; finish; finish -= 1 )
147 //--------------------------------------- B1 B2
151 if(finish==finWidth) iXA=0;
153 if(finish>4) {iXB=1;iXC=2;}
155 if(finish>3) {iXB=1;iXC=1;}
159 if(height>4) {iYB=finWidth;iYC=srcPitchHalf;}
161 if(height>3) {iYB=finWidth;iYC=finWidth;}
164 colorB0 = *(bP- iYA - iXA);
165 colorB1 = *(bP- iYA);
166 colorB2 = *(bP- iYA + iXB);
167 colorB3 = *(bP- iYA + iXC);
169 color4 = *(bP - iXA);
171 color6 = *(bP + iXB);
172 colorS2 = *(bP + iXC);
174 color1 = *(bP + iYB - iXA);
175 color2 = *(bP + iYB);
176 color3 = *(bP + iYB + iXB);
177 colorS1= *(bP + iYB + iXC);
179 colorA0 = *(bP + iYC - iXA);
180 colorA1 = *(bP + iYC);
181 colorA2 = *(bP + iYC + iXB);
182 colorA3 = *(bP + iYC + iXC);
184 if (color2 == color6 && color5 != color3)
186 product2b = product1b = color2;
189 if (color5 == color3 && color2 != color6)
191 product2b = product1b = color5;
194 if (color5 == color3 && color2 == color6)
198 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color1&0x00ffffff), (colorA1&0x00ffffff));
199 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color4&0x00ffffff), (colorB1&0x00ffffff));
200 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorA2&0x00ffffff), (colorS1&0x00ffffff));
201 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorB2&0x00ffffff), (colorS2&0x00ffffff));
204 product2b = product1b = color6;
207 product2b = product1b = color5;
210 product2b = product1b = INTERPOLATE8(color5, color6);
215 if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0)
216 product2b = Q_INTERPOLATE8 (color3, color3, color3, color2);
218 if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3)
219 product2b = Q_INTERPOLATE8 (color2, color2, color2, color3);
221 product2b = INTERPOLATE8 (color2, color3);
223 if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0)
224 product1b = Q_INTERPOLATE8 (color6, color6, color6, color5);
226 if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3)
227 product1b = Q_INTERPOLATE8 (color6, color5, color5, color5);
229 product1b = INTERPOLATE8 (color5, color6);
232 if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2)
233 product2a = INTERPOLATE8(color2, color5);
235 if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0)
236 product2a = INTERPOLATE8(color2, color5);
240 if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2)
241 product1a = INTERPOLATE8(color2, color5);
243 if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0)
244 product1a = INTERPOLATE8(color2, color5);
250 *(dP+(srcPitchHalf))=product2a;
251 *(dP+1+(srcPitchHalf))=product2b;
255 }//end of for ( finish= width etc..)
259 }; //endof: for (; height; height--)
263 ////////////////////////////////////////////////////////////////////////
265 void Std2xSaI_ex8(unsigned char *srcPtr, DWORD srcPitch,
266 unsigned char *dstBitmap, int width, int height)
268 DWORD dstPitch = srcPitch<<1;
269 DWORD srcPitchHalf = srcPitch>>1;
270 int finWidth = srcPitch>>2;
274 int iXA,iXB,iXC,iYA,iYB,iYC,finish;
279 DWORD colorA, colorB;
280 DWORD colorC, colorD,
281 colorE, colorF, colorG, colorH,
282 colorI, colorJ, colorK, colorL,
283 colorM, colorN, colorO, colorP;
284 DWORD product, product1, product2;
289 for (; height; height-=1)
291 bP = (DWORD *)srcPtr;
292 dP = (DWORD *)(dstBitmap + line*dstPitch);
293 for (finish = width; finish; finish -= 1 )
295 //---------------------------------------
296 // Map of the pixels: I|E F|J
300 if(finish==finWidth) iXA=0;
302 if(finish>4) {iXB=1;iXC=2;}
304 if(finish>3) {iXB=1;iXC=1;}
308 if(height>4) {iYB=finWidth;iYC=srcPitchHalf;}
310 if(height>3) {iYB=finWidth;iYC=finWidth;}
313 colorI = *(bP- iYA - iXA);
315 colorF = *(bP- iYA + iXB);
316 colorJ = *(bP- iYA + iXC);
318 colorG = *(bP - iXA);
320 colorB = *(bP + iXB);
321 colorK = *(bP + iXC);
323 colorH = *(bP + iYB - iXA);
324 colorC = *(bP + iYB);
325 colorD = *(bP + iYB + iXB);
326 colorL = *(bP + iYB + iXC);
328 colorM = *(bP + iYC - iXA);
329 colorN = *(bP + iYC);
330 colorO = *(bP + iYC + iXB);
331 colorP = *(bP + iYC + iXC);
334 if((colorA == colorD) && (colorB != colorC))
336 if(((colorA == colorE) && (colorB == colorL)) ||
337 ((colorA == colorC) && (colorA == colorF) &&
338 (colorB != colorE) && (colorB == colorJ)))
344 product = INTERPOLATE8(colorA, colorB);
347 if(((colorA == colorG) && (colorC == colorO)) ||
348 ((colorA == colorB) && (colorA == colorH) &&
349 (colorG != colorC) && (colorC == colorM)))
355 product1 = INTERPOLATE8(colorA, colorC);
360 if((colorB == colorC) && (colorA != colorD))
362 if(((colorB == colorF) && (colorA == colorH)) ||
363 ((colorB == colorE) && (colorB == colorD) &&
364 (colorA != colorF) && (colorA == colorI)))
370 product = INTERPOLATE8(colorA, colorB);
373 if(((colorC == colorH) && (colorA == colorF)) ||
374 ((colorC == colorG) && (colorC == colorD) &&
375 (colorA != colorH) && (colorA == colorI)))
381 product1=INTERPOLATE8(colorA, colorC);
386 if((colorA == colorD) && (colorB == colorC))
388 if (colorA == colorB)
397 product1 = INTERPOLATE8(colorA, colorC);
398 product = INTERPOLATE8(colorA, colorB);
400 r += GetResult1 (colorA&0x00FFFFFF, colorB&0x00FFFFFF, colorG&0x00FFFFFF, colorE&0x00FFFFFF, colorI&0x00FFFFFF);
401 r += GetResult2 (colorB&0x00FFFFFF, colorA&0x00FFFFFF, colorK&0x00FFFFFF, colorF&0x00FFFFFF, colorJ&0x00FFFFFF);
402 r += GetResult2 (colorB&0x00FFFFFF, colorA&0x00FFFFFF, colorH&0x00FFFFFF, colorN&0x00FFFFFF, colorM&0x00FFFFFF);
403 r += GetResult1 (colorA&0x00FFFFFF, colorB&0x00FFFFFF, colorL&0x00FFFFFF, colorO&0x00FFFFFF, colorP&0x00FFFFFF);
412 product2 = Q_INTERPOLATE8(colorA, colorB, colorC, colorD);
418 product2 = Q_INTERPOLATE8(colorA, colorB, colorC, colorD);
420 if ((colorA == colorC) && (colorA == colorF) &&
421 (colorB != colorE) && (colorB == colorJ))
426 if ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI))
432 product = INTERPOLATE8(colorA, colorB);
435 if ((colorA == colorB) && (colorA == colorH) &&
436 (colorG != colorC) && (colorC == colorM))
441 if ((colorC == colorG) && (colorC == colorD) &&
442 (colorA != colorH) && (colorA == colorI))
448 product1 = INTERPOLATE8(colorA, colorC);
452 //////////////////////////
456 *(dP+(srcPitchHalf))=product1;
457 *(dP+1+(srcPitchHalf))=product2;
461 }//end of for ( finish= width etc..)
465 }; //endof: for (; height; height--)
469 ////////////////////////////////////////////////////////////////////////
471 void SuperEagle_ex8(unsigned char *srcPtr, DWORD srcPitch,
472 unsigned char *dstBitmap, int width, int height)
474 DWORD dstPitch = srcPitch<<1;
475 DWORD srcPitchHalf = srcPitch>>1;
476 int finWidth = srcPitch>>2;
480 int iXA,iXB,iXC,iYA,iYB,iYC,finish;
481 DWORD color4, color5, color6;
482 DWORD color1, color2, color3;
483 DWORD colorA1, colorA2,
486 DWORD product1a, product1b,
487 product2a, product2b;
495 for (; height; height-=1)
497 bP = (DWORD *)srcPtr;
498 dP = (DWORD *)(dstBitmap + line*dstPitch);
499 for (finish = width; finish; finish -= 1 )
501 if(finish==finWidth) iXA=0;
503 if(finish>4) {iXB=1;iXC=2;}
505 if(finish>3) {iXB=1;iXC=1;}
509 if(height>4) {iYB=finWidth;iYC=srcPitchHalf;}
511 if(height>3) {iYB=finWidth;iYC=finWidth;}
514 colorB1 = *(bP- iYA);
515 colorB2 = *(bP- iYA + iXB);
517 color4 = *(bP - iXA);
519 color6 = *(bP + iXB);
520 colorS2 = *(bP + iXC);
522 color1 = *(bP + iYB - iXA);
523 color2 = *(bP + iYB);
524 color3 = *(bP + iYB + iXB);
525 colorS1= *(bP + iYB + iXC);
527 colorA1 = *(bP + iYC);
528 colorA2 = *(bP + iYC + iXB);
530 if(color2 == color6 && color5 != color3)
532 product1b = product2a = color2;
533 if((color1 == color2) ||
536 product1a = INTERPOLATE8(color2, color5);
537 product1a = INTERPOLATE8(color2, product1a);
541 product1a = INTERPOLATE8(color5, color6);
544 if((color6 == colorS2) ||
547 product2b = INTERPOLATE8(color2, color3);
548 product2b = INTERPOLATE8(color2, product2b);
552 product2b = INTERPOLATE8(color2, color3);
556 if (color5 == color3 && color2 != color6)
558 product2b = product1a = color5;
560 if ((colorB1 == color5) ||
563 product1b = INTERPOLATE8(color5, color6);
564 product1b = INTERPOLATE8(color5, product1b);
568 product1b = INTERPOLATE8(color5, color6);
571 if ((color3 == colorA2) ||
574 product2a = INTERPOLATE8(color5, color2);
575 product2a = INTERPOLATE8(color5, product2a);
579 product2a = INTERPOLATE8(color2, color3);
583 if (color5 == color3 && color2 == color6)
587 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color1&0x00ffffff), (colorA1&0x00ffffff));
588 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color4&0x00ffffff), (colorB1&0x00ffffff));
589 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorA2&0x00ffffff), (colorS1&0x00ffffff));
590 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorB2&0x00ffffff), (colorS2&0x00ffffff));
594 product1b = product2a = color2;
595 product1a = product2b = INTERPOLATE8(color5, color6);
600 product2b = product1a = color5;
601 product1b = product2a = INTERPOLATE8(color5, color6);
605 product2b = product1a = color5;
606 product1b = product2a = color2;
611 product2b = product1a = INTERPOLATE8(color2, color6);
612 product2b = Q_INTERPOLATE8(color3, color3, color3, product2b);
613 product1a = Q_INTERPOLATE8(color5, color5, color5, product1a);
615 product2a = product1b = INTERPOLATE8(color5, color3);
616 product2a = Q_INTERPOLATE8(color2, color2, color2, product2a);
617 product1b = Q_INTERPOLATE8(color6, color6, color6, product1b);
620 ////////////////////////////////
624 *(dP+(srcPitchHalf))=product2a;
625 *(dP+1+(srcPitchHalf))=product2b;
629 }//end of for ( finish= width etc..)
633 }; //endof: for (; height; height--)
637 /////////////////////////
639 //#include <assert.h>
641 static __inline void scale2x_32_def_whole(uint32_t* dst0, uint32_t* dst1, const uint32_t* src0, const uint32_t* src1, const uint32_t* src2, unsigned count)
644 //assert(count >= 2);
647 if (src0[0] != src2[0] && src1[0] != src1[1]) {
648 dst0[0] = src1[0] == src0[0] ? src0[0] : src1[0];
649 dst0[1] = src1[1] == src0[0] ? src0[0] : src1[0];
650 dst1[0] = src1[0] == src2[0] ? src2[0] : src1[0];
651 dst1[1] = src1[1] == src2[0] ? src2[0] : src1[0];
667 if (src0[0] != src2[0] && src1[-1] != src1[1]) {
668 dst0[0] = src1[-1] == src0[0] ? src0[0] : src1[0];
669 dst0[1] = src1[1] == src0[0] ? src0[0] : src1[0];
670 dst1[0] = src1[-1] == src2[0] ? src2[0] : src1[0];
671 dst1[1] = src1[1] == src2[0] ? src2[0] : src1[0];
688 if (src0[0] != src2[0] && src1[-1] != src1[0]) {
689 dst0[0] = src1[-1] == src0[0] ? src0[0] : src1[0];
690 dst0[1] = src1[0] == src0[0] ? src0[0] : src1[0];
691 dst1[0] = src1[-1] == src2[0] ? src2[0] : src1[0];
692 dst1[1] = src1[0] == src2[0] ? src2[0] : src1[0];
701 void Scale2x_ex8(unsigned char *srcPtr, DWORD srcPitch,
702 unsigned char *dstPtr, int width, int height)
704 //const int srcpitch = srcPitch;
705 const int dstPitch = srcPitch<<1;
712 uint32_t *dst0 = (uint32_t *)dstPtr;
713 uint32_t *dst1 = dst0 + (dstPitch >> 2);
715 uint32_t *src0 = (uint32_t *)srcPtr;
716 uint32_t *src1 = src0 + (srcPitch >> 2);
717 uint32_t *src2 = src1 + (srcPitch >> 2);
718 scale2x_32_def_whole(dst0, dst1, src0, src0, src1, width);
722 dst0 += dstPitch >> 1;
723 dst1 += dstPitch >> 1;
724 scale2x_32_def_whole(dst0, dst1, src0, src0, src1, width);
727 src2 += srcPitch >> 2;
730 dst0 += dstPitch >> 1;
731 dst1 += dstPitch >> 1;
732 scale2x_32_def_whole(dst0, dst1, src0, src1, src1, width);
736 ////////////////////////////////////////////////////////////////////////
738 static __inline void scale3x_32_def_whole(uint32_t* dst0, uint32_t* dst1, uint32_t* dst2, const uint32_t* src0, const uint32_t* src1, const uint32_t* src2, unsigned count)
740 //assert(count >= 2);
743 if (src0[0] != src2[0] && src1[0] != src1[1]) {
745 dst0[1] = (src1[0] == src0[0] && src1[0] != src0[1]) || (src1[1] == src0[0] && src1[0] != src0[0]) ? src0[0] : src1[0];
746 dst0[2] = src1[1] == src0[0] ? src1[1] : src1[0];
747 dst1[0] = (src1[0] == src0[0] && src1[0] != src2[0]) || (src1[0] == src2[0] && src1[0] != src0[0]) ? src1[0] : src1[0];
749 dst1[2] = (src1[1] == src0[0] && src1[0] != src2[1]) || (src1[1] == src2[0] && src1[0] != src0[1]) ? src1[1] : src1[0];
751 dst2[1] = (src1[0] == src2[0] && src1[0] != src2[1]) || (src1[1] == src2[0] && src1[0] != src2[0]) ? src2[0] : src1[0];
752 dst2[2] = src1[1] == src2[0] ? src1[1] : src1[0];
774 if (src0[0] != src2[0] && src1[-1] != src1[1]) {
775 dst0[0] = src1[-1] == src0[0] ? src1[-1] : src1[0];
776 dst0[1] = (src1[-1] == src0[0] && src1[0] != src0[1]) || (src1[1] == src0[0] && src1[0] != src0[-1]) ? src0[0] : src1[0];
777 dst0[2] = src1[1] == src0[0] ? src1[1] : src1[0];
778 dst1[0] = (src1[-1] == src0[0] && src1[0] != src2[-1]) || (src1[-1] == src2[0] && src1[0] != src0[-1]) ? src1[-1] : src1[0];
780 dst1[2] = (src1[1] == src0[0] && src1[0] != src2[1]) || (src1[1] == src2[0] && src1[0] != src0[1]) ? src1[1] : src1[0];
781 dst2[0] = src1[-1] == src2[0] ? src1[-1] : src1[0];
782 dst2[1] = (src1[-1] == src2[0] && src1[0] != src2[1]) || (src1[1] == src2[0] && src1[0] != src2[-1]) ? src2[0] : src1[0];
783 dst2[2] = src1[1] == src2[0] ? src1[1] : src1[0];
806 if (src0[0] != src2[0] && src1[-1] != src1[0]) {
807 dst0[0] = src1[-1] == src0[0] ? src1[-1] : src1[0];
808 dst0[1] = (src1[-1] == src0[0] && src1[0] != src0[0]) || (src1[0] == src0[0] && src1[0] != src0[-1]) ? src0[0] : src1[0];
810 dst1[0] = (src1[-1] == src0[0] && src1[0] != src2[-1]) || (src1[-1] == src2[0] && src1[0] != src0[-1]) ? src1[-1] : src1[0];
812 dst1[2] = (src1[0] == src0[0] && src1[0] != src2[0]) || (src1[0] == src2[0] && src1[0] != src0[0]) ? src1[0] : src1[0];
813 dst2[0] = src1[-1] == src2[0] ? src1[-1] : src1[0];
814 dst2[1] = (src1[-1] == src2[0] && src1[0] != src2[0]) || (src1[0] == src2[0] && src1[0] != src2[-1]) ? src2[0] : src1[0];
830 void Scale3x_ex8(unsigned char *srcPtr, DWORD srcPitch,
831 unsigned char *dstPtr, int width, int height)
835 int dstPitch = srcPitch*3;
836 int dstRowPixels = dstPitch>>2;
841 uint32_t *dst0 = (uint32_t *)dstPtr;
842 uint32_t *dst1 = dst0 + dstRowPixels;
843 uint32_t *dst2 = dst1 + dstRowPixels;
845 uint32_t *src0 = (uint32_t *)srcPtr;
846 uint32_t *src1 = src0 + (srcPitch >> 2);
847 uint32_t *src2 = src1 + (srcPitch >> 2);
848 scale3x_32_def_whole(dst0, dst1, dst2, src0, src0, src2, width);
852 dst0 += dstRowPixels*3;
853 dst1 += dstRowPixels*3;
854 dst2 += dstRowPixels*3;
856 scale3x_32_def_whole(dst0, dst1, dst2, src0, src1, src2, width);
859 src2 += srcPitch >> 2;
863 dst0 += dstRowPixels*3;
864 dst1 += dstRowPixels*3;
865 dst2 += dstRowPixels*3;
867 scale3x_32_def_whole(dst0, dst1, dst2, src0, src1, src1, width);
871 ////////////////////////////////////////////////////////////////////////
874 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
875 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
879 ////////////////////////////////////////////////////////////////////////
881 ////////////////////////////////////////////////////////////////////////
884 static Cursor cursor;
886 static XVisualInfo *myvisual;
888 static Colormap colormap;
891 static XImage * Ximage;
892 static XvImage * XCimage;
893 static XImage * XFimage;
894 static XImage * XPimage=0 ;
901 static Atom xv_intern_atom_if_exists( Display *display, char const * atom_name )
903 XvAttribute * attributes;
907 attributes = XvQueryPortAttributes( display, xv_port, &attrib_count );
908 if( attributes!=NULL )
910 for ( i = 0; i < attrib_count; ++i )
912 if ( strcmp(attributes[i].name, atom_name ) == 0 )
914 xv_atom = XInternAtom( display, atom_name, False );
915 break; // found what we want, break out
928 void DestroyDisplay(void)
932 XFreeColormap(display, colormap);
935 XFreeGC(display,hGC);
940 XDestroyImage(Ximage);
950 XDestroyImage(XFimage);
954 XShmDetach(display,&shminfo);
955 shmdt(shminfo.shmaddr);
956 shmctl(shminfo.shmid,IPC_RMID,NULL);
958 Atom atom_vsync = xv_intern_atom_if_exists(display, "XV_SYNC_TO_VBLANK");
959 if (atom_vsync != None) {
960 XvSetPortAttribute(display, xv_port, atom_vsync, xv_vsync);
963 XSync(display,False);
965 XCloseDisplay(display);
970 int root_window_id=0;
975 void CreateDisplay(void)
977 XSetWindowAttributes winattr;
983 MotifWmHints mwmhints;
993 unsigned int p_num_adaptors=0, p_num_ports=0;
996 XvImageFormatValues *fo;
999 display = XOpenDisplay(NULL);
1003 fprintf (stderr,"Failed to open display!!!\n");
1008 myscreen=DefaultScreen(display);
1010 // desktop fullscreen switch
1011 if (!iWindowMode) fx = 1;
1013 screen=DefaultScreenOfDisplay(display);
1015 root_window_id=RootWindow(display,DefaultScreen(display));
1017 //Look for an Xvideo RGB port
1018 ret = XvQueryAdaptors(display, root_window_id, &p_num_adaptors, &ai);
1019 if (ret != Success) {
1020 if (ret == XvBadExtension)
1021 printf("XvBadExtension returned at XvQueryExtension.\n");
1023 if (ret == XvBadAlloc)
1024 printf("XvBadAlloc returned at XvQueryExtension.\n");
1026 printf("other error happaned at XvQueryAdaptors.\n");
1031 depth = DefaultDepth(display, myscreen);
1033 for (i = 0; i < p_num_adaptors; i++) {
1034 p_num_ports = ai[i].base_id + ai[i].num_ports;
1035 for (p = ai[i].base_id; p < p_num_ports; p++) {
1036 fo = XvListImageFormats(display, p, &formats);
1037 for (j = 0; j < formats; j++) {
1039 //hmm, should I bother check guid == 55595659-0000-0010-8000-00aa00389b71?
1040 //and check byte order? fo[j].byte_order == LSBFirst
1041 #ifdef __BIG_ENDIAN__
1042 if ( fo[j].type == XvYUV && fo[j].bits_per_pixel == 16 && fo[j].format == XvPacked && strncmp("YUYV", fo[j].component_order, 5) == 0 )
1044 if ( fo[j].type == XvYUV && fo[j].bits_per_pixel == 16 && fo[j].format == XvPacked && strncmp("UYVY", fo[j].component_order, 5) == 0 )
1050 if (fo[j].type == XvRGB && fo[j].bits_per_pixel == 32)
1054 xv_depth = fo[j].depth;
1055 printf("RGB mode found. id: %x, depth: %d\n", xv_id, xv_depth);
1057 if (xv_depth != depth) {
1058 printf("Warning: Depth does not match screen depth (%d)\n", depth);
1061 //break out of loops
1072 if (p_num_adaptors > 0)
1073 XvFreeAdaptorInfo(ai);
1074 if (xv_port == -1 && yuv_port == -1)
1076 printf("RGB & YUV not found. Quitting.\n");
1079 else if (xv_port == -1 && yuv_port != -1)
1082 printf("RGB not found. Using YUV.\n");
1086 else if (xv_depth && xv_depth != depth && yuv_port != -1)
1089 printf("Acceptable RGB mode not found. Using YUV.\n");
1094 Atom atom_vsync = xv_intern_atom_if_exists(display, "XV_SYNC_TO_VBLANK");
1095 if (atom_vsync != None) {
1096 XvGetPortAttribute(display, xv_port, atom_vsync, &xv_vsync);
1097 XvSetPortAttribute(display, xv_port, atom_vsync, 0);
1102 if(XMatchVisualInfo(display,myscreen, depth, TrueColor, &vi))
1107 fprintf(stderr,"Failed to obtain visual!\n");
1112 if(myvisual->red_mask==0x00007c00 &&
1113 myvisual->green_mask==0x000003e0 &&
1114 myvisual->blue_mask==0x0000001f)
1117 if(myvisual->red_mask==0x0000f800 &&
1118 myvisual->green_mask==0x000007e0 &&
1119 myvisual->blue_mask==0x0000001f)
1122 if(myvisual->red_mask==0x00ff0000 &&
1123 myvisual->green_mask==0x0000ff00 &&
1124 myvisual->blue_mask==0x000000ff)
1129 /* fprintf(stderr,"COLOR DEPTH NOT SUPPORTED!\n");
1130 fprintf(stderr,"r: %08lx\n",myvisual->red_mask);
1131 fprintf(stderr,"g: %08lx\n",myvisual->green_mask);
1132 fprintf(stderr,"b: %08lx\n",myvisual->blue_mask);
1137 // pffff... much work for a simple blank cursor... oh, well...
1138 if(iWindowMode) cursor=XCreateFontCursor(display,XC_trek);
1148 memset(&b,0,sizeof(XColor));
1149 memset(&w,0,sizeof(XColor));
1150 idata=(char *)malloc(8);
1153 p1=XCreatePixmap(display,RootWindow(display,myvisual->screen),8,8,1);
1154 p2=XCreatePixmap(display,RootWindow(display,myvisual->screen),8,8,1);
1156 img = XCreateImage(display,myvisual->visual,
1157 1,XYBitmap,0,idata,8,8,8,1);
1159 GCv.function = GXcopy;
1160 GCv.foreground = ~0;
1162 GCv.plane_mask = AllPlanes;
1163 GCc = XCreateGC(display,p1,
1164 (GCFunction|GCForeground|GCBackground|GCPlaneMask),&GCv);
1166 XPutImage(display, p1,GCc,img,0,0,0,0,8,8);
1167 XPutImage(display, p2,GCc,img,0,0,0,0,8,8);
1168 XFreeGC(display, GCc);
1170 cursor = XCreatePixmapCursor(display,p1,p2,&b,&w,0,0);
1172 XFreePixmap(display,p1);
1173 XFreePixmap(display,p2);
1174 XDestroyImage(img); // will free idata as well
1177 colormap=XCreateColormap(display,root_window_id,
1178 myvisual->visual,AllocNone);
1180 winattr.background_pixel=0;
1181 winattr.border_pixel=WhitePixelOfScreen(screen);
1182 winattr.bit_gravity=ForgetGravity;
1183 winattr.win_gravity=NorthWestGravity;
1184 winattr.backing_store=NotUseful;
1186 winattr.override_redirect=False;
1187 winattr.save_under=False;
1188 winattr.event_mask=0;
1189 winattr.do_not_propagate_mask=0;
1190 winattr.colormap=colormap;
1191 winattr.cursor=None;
1193 window=XCreateWindow(display,root_window_id,
1196 InputOutput,myvisual->visual,
1197 CWBorderPixel | CWBackPixel |
1198 CWEventMask | CWDontPropagate |
1199 CWColormap | CWCursor,
1204 fprintf(stderr,"Failed in XCreateWindow()!!!\n");
1209 delwindow = XInternAtom(display,"WM_DELETE_WINDOW",0);
1210 XSetWMProtocols(display, window, &delwindow, 1);
1212 hints.flags=USPosition|USSize;
1213 hints.base_width = iResX;
1214 hints.base_height = iResY;
1217 wm_hints.flags=InputHint;
1219 XSetWMHints(display,window,&wm_hints);
1220 XSetWMNormalHints(display,window,&hints);
1222 XStoreName(display,window,pCaptionText);
1223 else XStoreName(display,window,"P.E.Op.S SoftX PSX Gpu");
1225 XDefineCursor(display,window,cursor);
1227 // hack to get rid of window title bar
1230 mwmhints.flags=MWM_HINTS_DECORATIONS;
1231 mwmhints.decorations=0;
1232 mwmatom=XInternAtom(display,"_MOTIF_WM_HINTS",0);
1233 XChangeProperty(display,window,mwmatom,mwmatom,32,
1234 PropModeReplace,(unsigned char *)&mwmhints,4);
1238 XSelectInput(display,
1240 FocusChangeMask | ExposureMask |
1241 KeyPressMask | KeyReleaseMask
1244 XMapRaised(display,window);
1245 XClearWindow(display,window);
1246 XWindowEvent(display,window,ExposureMask,&event);
1248 if (fx) // fullscreen
1250 XResizeWindow(display,window,screen->width,screen->height);
1252 hints.min_width = hints.max_width = hints.base_width = screen->width;
1253 hints.min_height= hints.max_height = hints.base_height = screen->height;
1255 XSetWMNormalHints(display,window,&hints);
1257 // set the window layer for GNOME
1261 memset(&xev, 0, sizeof(xev));
1262 xev.xclient.type = ClientMessage;
1263 xev.xclient.serial = 0;
1264 xev.xclient.send_event = 1;
1265 xev.xclient.message_type = XInternAtom(display, "_NET_WM_STATE", 0);
1266 xev.xclient.window = window;
1267 xev.xclient.format = 32;
1268 xev.xclient.data.l[0] = 1;
1269 xev.xclient.data.l[1] = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", 0);
1270 xev.xclient.data.l[2] = 0;
1271 xev.xclient.data.l[3] = 0;
1272 xev.xclient.data.l[4] = 0;
1274 XSendEvent(display, root_window_id, 0,
1275 SubstructureRedirectMask | SubstructureNotifyMask, &xev);
1279 gcv.graphics_exposures = False;
1280 hGC = XCreateGC(display,window,
1281 GCGraphicsExposures, &gcv);
1284 fprintf(stderr,"No gfx context!!!\n");
1290 Xpixels = (char *)malloc(220*15*4);
1291 memset(Xpixels,255,220*15*4);
1292 XFimage = XCreateImage(display,myvisual->visual,
1299 Xpixels = (char *)malloc(8*8*4);
1300 memset(Xpixels,0,8*8*4);
1301 XCimage = XvCreateImage(display,xv_port,xv_id,
1302 (char *)Xpixels, 8, 8);
1306 Allocate max that could be needed:
1307 Big(est?) PSX res: 640x512
1309 2xsai func= 3xwidth,3xheight
1312 shminfo.shmid = shmget(IPC_PRIVATE, 640*512*4*3*3, IPC_CREAT | 0777);
1313 shminfo.shmaddr = shmat(shminfo.shmid, 0, 0);
1314 shminfo.readOnly = 0;
1316 if (!XShmAttach(display, &shminfo)) {
1317 printf("XShmAttach failed !\n");
1322 void (*p2XSaIFunc) (unsigned char *, DWORD, unsigned char *, int, int);
1323 unsigned char *pBackBuffer = 0;
1325 void BlitScreen32(unsigned char *surf, int32_t x, int32_t y)
1328 unsigned int startxy;
1331 unsigned short row, column;
1332 unsigned short dx = PreviousPSXDisplay.Range.x1;
1333 unsigned short dy = PreviousPSXDisplay.DisplayMode.y;
1335 int32_t lPitch = PSXDisplay.DisplayMode.x << 2;
1339 if (PreviousPSXDisplay.Range.y0) // centering needed?
1341 memset(surf, 0, (PreviousPSXDisplay.Range.y0 >> 1) * lPitch);
1343 dy -= PreviousPSXDisplay.Range.y0;
1344 surf += (PreviousPSXDisplay.Range.y0 >> 1) * lPitch;
1346 memset(surf + dy * lPitch,
1347 0, ((PreviousPSXDisplay.Range.y0 + 1) >> 1) * lPitch);
1350 if (PreviousPSXDisplay.Range.x0)
1352 for (column = 0; column < dy; column++)
1354 destpix = (uint32_t *)(surf + (column * lPitch));
1355 memset(destpix, 0, PreviousPSXDisplay.Range.x0 << 2);
1357 surf += PreviousPSXDisplay.Range.x0 << 2;
1360 if (PSXDisplay.RGB24)
1362 for (column = 0; column < dy; column++)
1364 startxy = ((1024) * (column + y)) + x;
1365 pD = (unsigned char *)&psxVuw[startxy];
1366 destpix = (uint32_t *)(surf + (column * lPitch));
1367 for (row = 0; row < dx; row++)
1369 lu = *((uint32_t *)pD);
1371 0xff000000 | (RED(lu) << 16) | (GREEN(lu) << 8) | (BLUE(lu));
1378 for (column = 0;column<dy;column++)
1380 startxy = (1024 * (column + y)) + x;
1381 destpix = (uint32_t *)(surf + (column * lPitch));
1382 for (row = 0; row < dx; row++)
1384 s = GETLE16(&psxVuw[startxy++]);
1386 (((s << 19) & 0xf80000) | ((s << 6) & 0xf800) | ((s >> 7) & 0xf8)) | 0xff000000;
1392 void BlitToYUV(unsigned char * surf,int32_t x,int32_t y)
1395 unsigned int startxy;
1396 uint32_t lu;unsigned short s;
1397 unsigned short row,column;
1398 unsigned short dx = PreviousPSXDisplay.Range.x1;
1399 unsigned short dy = PreviousPSXDisplay.DisplayMode.y;
1402 int32_t lPitch = PSXDisplay.DisplayMode.x << 2;
1405 if (PreviousPSXDisplay.Range.y0) // centering needed?
1407 for (column = 0; column < (PreviousPSXDisplay.Range.y0 >> 1); column++)
1409 destpix = (uint32_t *)(surf + column * lPitch);
1410 for (row = 0; row < dx; row++)
1412 destpix[row] = (4 << 24) | (128 << 16) | (4 << 8) | 128;
1416 dy -= PreviousPSXDisplay.Range.y0;
1417 surf += (PreviousPSXDisplay.Range.y0 >> 1) * lPitch;
1419 for (column = 0; column < (PreviousPSXDisplay.Range.y0 + 1) >> 1; column++)
1421 destpix = (uint32_t *)(surf + (dy + column) * lPitch);
1422 for (row = 0; row < dx; row++)
1424 destpix[row] = (4 << 24) | (128 << 16) | (4 << 8) | 128;
1429 if (PreviousPSXDisplay.Range.x0)
1431 for (column = 0; column < dy; column++)
1433 destpix = (uint32_t *)(surf + (column * lPitch));
1434 for (row = 0; row < PreviousPSXDisplay.Range.x0; row++)
1436 destpix[row] = (4 << 24) | (128 << 16) | (4 << 8) | 128;
1439 surf += PreviousPSXDisplay.Range.x0 << 2;
1442 if (PSXDisplay.RGB24)
1444 for (column = 0; column < dy; column++)
1446 startxy = (1024 * (column + y)) + x;
1447 pD = (unsigned char *)&psxVuw[startxy];
1448 destpix = (uint32_t *)(surf + (column * lPitch));
1449 for (row = 0; row < dx; row++)
1451 lu = *((uint32_t *)pD);
1457 Y = min(abs(R * 2104 + G * 4130 + B * 802 + 4096 + 131072) >> 13, 235);
1458 U = min(abs(R * -1214 + G * -2384 + B * 3598 + 4096 + 1048576) >> 13, 240);
1459 V = min(abs(R * 3598 + G * -3013 + B * -585 + 4096 + 1048576) >> 13, 240);
1461 #ifdef __BIG_ENDIAN__
1462 destpix[row] = Y << 24 | U << 16 | Y << 8 | V;
1464 destpix[row] = Y << 24 | V << 16 | Y << 8 | U;
1472 for (column = 0; column < dy; column++)
1474 startxy = (1024 * (column + y)) + x;
1475 destpix = (uint32_t *)(surf + (column * lPitch));
1476 for (row = 0; row < dx; row++)
1478 s = GETLE16(&psxVuw[startxy++]);
1484 Y = min(abs(R * 2104 + G * 4130 + B * 802 + 4096 + 131072) >> 13, 235);
1485 U = min(abs(R * -1214 + G * -2384 + B * 3598 + 4096 + 1048576) >> 13, 240);
1486 V = min(abs(R * 3598 + G * -3013 + B * -585 + 4096 + 1048576) >> 13, 240);
1488 #ifdef __BIG_ENDIAN__
1489 destpix[row] = Y << 24 | U << 16 | Y << 8 | V;
1491 destpix[row] = Y << 24 | V << 16 | Y << 8 | U;
1498 //dst will have half the pitch (32bit to 16bit)
1499 void RGB2YUV(uint32_t *s, int width, int height, uint32_t *d)
1502 int R,G,B, Y1,Y2,U,V;
1504 for (y=0; y<height; y++) {
1505 for(x=0; x<width>>1; x++) {
1506 R = (*s >> 16) & 0xff;
1507 G = (*s >> 8) & 0xff;
1511 Y1 = min(abs(R * 2104 + G * 4130 + B * 802 + 4096 + 131072) >> 13, 235);
1512 U = min(abs(R * -1214 + G * -2384 + B * 3598 + 4096 + 1048576) >> 13, 240);
1513 V = min(abs(R * 3598 + G * -3013 + B * -585 + 4096 + 1048576) >> 13, 240);
1515 R = (*s >> 16) & 0xff;
1516 G = (*s >> 8) & 0xff;
1520 Y2 = min(abs(R * 2104 + G * 4130 + B * 802 + 4096 + 131072) >> 13, 235);
1522 #ifdef __BIG_ENDIAN__
1523 *d = V | Y2 << 8 | U << 16 | Y1 << 24;
1525 *d = U | Y1 << 8 | V << 16 | Y2 << 24;
1532 extern time_t tStart;
1534 //Note: dest x,y,w,h are both input and output variables
1535 inline void MaintainAspect(unsigned int *dx,unsigned int *dy,unsigned int *dw,unsigned int *dh)
1537 //Currently just 4/3 aspect ratio
1540 if (*dw * 3 > *dh * 4) {
1541 t = *dh * 4.0f / 3; //new width aspect
1542 *dx = (*dw - t) / 2; //centering
1546 *dy = (*dh - t) / 2;
1551 void DoBufferSwap(void)
1556 unsigned int dstx, dsty, srcy = 0;
1557 unsigned int _d, _w, _h; //don't care about _d
1559 finalw = PSXDisplay.DisplayMode.x;
1560 finalh = PSXDisplay.DisplayMode.y;
1562 if (finalw == 0 || finalh == 0)
1565 XSync(display,False);
1568 if (iUseNoStretchBlt==0 || finalw > 320 || finalh > 256) {
1569 BlitToYUV((unsigned char *)shminfo.shmaddr, PSXDisplay.DisplayPosition.x, PSXDisplay.DisplayPosition.y);
1572 BlitScreen32((unsigned char *)pBackBuffer, PSXDisplay.DisplayPosition.x, PSXDisplay.DisplayPosition.y);
1573 p2XSaIFunc(pBackBuffer, finalw<<2, (unsigned char *)pSaIBigBuff,finalw,finalh);
1574 RGB2YUV( (uint32_t*)pSaIBigBuff, finalw, finalh, (uint32_t*)shminfo.shmaddr);
1576 } else if(iUseNoStretchBlt==0 || finalw > 320 || finalh > 256) {
1577 BlitScreen32((unsigned char *)shminfo.shmaddr, PSXDisplay.DisplayPosition.x, PSXDisplay.DisplayPosition.y);
1579 BlitScreen32((unsigned char *)pBackBuffer, PSXDisplay.DisplayPosition.x, PSXDisplay.DisplayPosition.y);
1580 p2XSaIFunc(pBackBuffer, finalw<<2, (unsigned char *)shminfo.shmaddr,finalw,finalh);
1583 XGetGeometry(display, window, &_dw, (int *)&_d, (int *)&_d, &_w, &_h, &_d, &_d);
1585 xvi = XvShmCreateImage(display, yuv_port, yuv_id, 0, finalw, finalh, &shminfo);
1587 xvi = XvShmCreateImage(display, xv_port, xv_id, 0, finalw, finalh, &shminfo);
1589 xvi->data = shminfo.shmaddr;
1591 screen=DefaultScreenOfDisplay(display);
1592 //screennum = DefaultScreen(display);
1596 _h = screen->height;
1602 if (iMaintainAspect)
1603 MaintainAspect(&dstx, &dsty, &_w, &_h);
1605 if (ulKeybits&KEY_SHOWFPS) //to avoid flicker, don't paint overtop FPS bar
1607 srcy = 15 * finalh / _h;
1611 XvShmPutImage(display, xv_port, window, hGC, xvi,
1613 finalw,finalh, //src w,h
1614 dstx,dsty, //dst x,y
1619 if(ulKeybits&KEY_SHOWFPS) //DisplayText(); // paint menu text
1621 if(szDebugText[0] && ((time(NULL) - tStart) < 2))
1623 strcpy(szDispBuf,szDebugText);
1628 strcat(szDispBuf,szMenuBuf);
1631 //XPutImage(display,window,hGC, XFimage,
1632 // 0, 0, 0, 0, 220,15);
1634 xvi = XvCreateImage(display, xv_port, xv_id, XFimage->data, 220, 15);
1635 XvPutImage(display, xv_port, window, hGC, xvi,
1642 XDrawString(display,window,hGC,2,13,szDispBuf,strlen(szDispBuf));
1645 //if(XPimage) DisplayPic();
1651 void DoClearScreenBuffer(void) // CLEAR DX BUFFER
1654 unsigned int _d, _w, _h; //don't care about _d
1656 XGetGeometry(display, window, &_dw, (int *)&_d, (int *)&_d, &_w, &_h, &_d, &_d);
1658 XvPutImage(display, xv_port, window, hGC, XCimage,
1659 0, 0, 8, 8, 0, 0, _w, _h);
1660 //XSync(display,False);
1663 void DoClearFrontBuffer(void) // CLEAR DX BUFFER
1665 XPutImage(display,window,hGC, XCimage,
1666 0, 0, 0, 0, iResX, iResY);
1667 XSync(display,False);*/
1675 if(iUseNoStretchBlt>0)
1677 pBackBuffer=(unsigned char *)malloc(640*512*sizeof(uint32_t));
1678 memset(pBackBuffer,0,640*512*sizeof(uint32_t));
1680 pSaIBigBuff=malloc(640*512*4*3*3);
1681 memset(pSaIBigBuff,0,640*512*4*3*3);
1687 if(iUseNoStretchBlt==1)
1689 p2XSaIFunc=Std2xSaI_ex8;
1692 if(iUseNoStretchBlt==2)
1694 p2XSaIFunc=Super2xSaI_ex8;
1697 if(iUseNoStretchBlt==3)
1699 p2XSaIFunc=SuperEagle_ex8;
1702 if(iUseNoStretchBlt==4)
1704 p2XSaIFunc=Scale2x_ex8;
1706 if(iUseNoStretchBlt==5)
1708 p2XSaIFunc=Scale3x_ex8;
1710 if(iUseNoStretchBlt==6)
1714 if(iUseNoStretchBlt==7)
1723 bIsFirstFrame = FALSE; // done
1728 ulKeybits|=KEY_SHOWFPS;
1736 void Xcleanup() // X CLEANUP
1740 if(iUseNoStretchBlt>0)
1742 if(pBackBuffer) free(pBackBuffer);
1744 if(pSaIBigBuff) free(pSaIBigBuff);
1749 unsigned long ulInitDisplay(void)
1751 CreateDisplay(); // x stuff
1752 Xinitialize(); // init x
1753 return (unsigned long)display;
1756 void CloseDisplay(void)
1758 Xcleanup(); // cleanup dx
1762 void CreatePic(unsigned char * pMem)
1764 unsigned char * p=(unsigned char *)malloc(128*96*4);
1765 unsigned char * ps; int x,y;
1777 s|=((*(pMem+1))&0xfc)<<3;
1778 s|=((*(pMem+2))&0xf8)<<8;
1780 *((unsigned short *)(ps+y*256+x*2))=s;
1793 s|=((*(pMem+1))&0xfc)<<2;
1794 s|=((*(pMem+2))&0xf8)<<7;
1796 *((unsigned short *)(ps+y*256+x*2))=s;
1812 *((uint32_t *)(ps+y*512+x*4))=l;
1817 XPimage = XCreateImage(display,myvisual->visual,
1825 void DestroyPic(void)
1829 XPutImage(display,window,hGC, XCimage,
1830 0, 0, 0, 0, iResX, iResY);*/
1831 XDestroyImage(XPimage);
1836 void DisplayPic(void)
1838 XPutImage(display,window,hGC, XPimage,
1839 0, 0, iResX-128, 0,128,96);
1842 void ShowGpuPic(void)
1846 void ShowTextGpuPic(void)
1850 static void hq2x_32_def(uint32_t * dst0, uint32_t * dst1, const uint32_t * src0, const uint32_t * src1, const uint32_t * src2, unsigned count)
1852 static unsigned char cache_vert_mask[640];
1853 unsigned char cache_horiz_mask = 0;
1859 if (src0 == src1) //processing first row
1860 memset(cache_vert_mask, 0, count);
1862 for(i=0;i<count;++i) {
1889 mask |= interp_32_diff(c[0], c[4]) << 0;
1890 mask |= cache_vert_mask[i];
1891 mask |= interp_32_diff(c[2], c[4]) << 2;
1892 mask |= cache_horiz_mask;
1893 cache_horiz_mask = interp_32_diff(c[5], c[4]) << 3;
1894 mask |= cache_horiz_mask << 1; // << 3 << 1 == << 4
1895 mask |= interp_32_diff(c[6], c[4]) << 5;
1896 cache_vert_mask[i] = interp_32_diff(c[7], c[4]) << 1;
1897 mask |= cache_vert_mask[i] << 5; // << 1 << 5 == << 6
1898 mask |= interp_32_diff(c[8], c[4]) << 7;
1914 void hq2x_32( unsigned char * srcPtr, DWORD srcPitch, unsigned char * dstPtr, int width, int height)
1916 const int dstPitch = srcPitch<<1;
1923 uint32_t *dst0 = (uint32_t *)dstPtr;
1924 uint32_t *dst1 = dst0 + (dstPitch >> 2);
1926 uint32_t *src0 = (uint32_t *)srcPtr;
1927 uint32_t *src1 = src0 + (srcPitch >> 2);
1928 uint32_t *src2 = src1 + (srcPitch >> 2);
1929 hq2x_32_def(dst0, dst1, src0, src0, src1, width);
1934 dst0 += dstPitch >> 1; //next 2 lines (dstPitch / 4 char per int * 2)
1935 dst1 += dstPitch >> 1;
1936 hq2x_32_def(dst0, dst1, src0, src1, src2, width);
1939 src2 += srcPitch >> 2;
1942 dst0 += dstPitch >> 1;
1943 dst1 += dstPitch >> 1;
1944 hq2x_32_def(dst0, dst1, src0, src1, src1, width);
1947 static void hq3x_32_def(uint32_t* dst0, uint32_t* dst1, uint32_t* dst2, const uint32_t* src0, const uint32_t* src1, const uint32_t* src2, unsigned count)
1949 static unsigned char cache_vert_mask[640];
1950 unsigned char cache_horiz_mask = 0;
1956 if (src0 == src1) //processing first row
1957 memset(cache_vert_mask, 0, count);
1959 for(i=0;i<count;++i) {
1986 mask |= interp_32_diff(c[0], c[4]) << 0;
1987 mask |= cache_vert_mask[i];
1988 mask |= interp_32_diff(c[2], c[4]) << 2;
1989 mask |= cache_horiz_mask;
1990 cache_horiz_mask = interp_32_diff(c[5], c[4]) << 3;
1991 mask |= cache_horiz_mask << 1; // << 3 << 1 == << 4
1992 mask |= interp_32_diff(c[6], c[4]) << 5;
1993 cache_vert_mask[i] = interp_32_diff(c[7], c[4]) << 1;
1994 mask |= cache_vert_mask[i] << 5; // << 1 << 5 == << 6
1995 mask |= interp_32_diff(c[8], c[4]) << 7;
2010 void hq3x_32( unsigned char * srcPtr, DWORD srcPitch, unsigned char * dstPtr, int width, int height)
2014 int dstPitch = srcPitch*3;
2015 int dstRowPixels = dstPitch>>2;
2020 uint32_t *dst0 = (uint32_t *)dstPtr;
2021 uint32_t *dst1 = dst0 + dstRowPixels;
2022 uint32_t *dst2 = dst1 + dstRowPixels;
2024 uint32_t *src0 = (uint32_t *)srcPtr;
2025 uint32_t *src1 = src0 + (srcPitch >> 2);
2026 uint32_t *src2 = src1 + (srcPitch >> 2);
2027 hq3x_32_def(dst0, dst1, dst2, src0, src0, src2, width);
2031 dst0 += dstRowPixels * 3;
2032 dst1 += dstRowPixels * 3;
2033 dst2 += dstRowPixels * 3;
2035 hq3x_32_def(dst0, dst1, dst2, src0, src1, src2, width);
2038 src2 += srcPitch >> 2;
2041 dst0 += dstRowPixels * 3;
2042 dst1 += dstRowPixels * 3;
2043 dst2 += dstRowPixels * 3;
2045 hq3x_32_def(dst0, dst1, dst2, src0, src1, src1, width);