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 ***************************************************************************/
21 #include <X11/Xutil.h>
22 #include <X11/cursorfont.h>
30 BOOL bIsFirstFrame = TRUE;
31 BOOL bCheckMask = FALSE;
32 unsigned short sSetMask = 0;
33 unsigned long lSetMask = 0;
37 int iMaintainAspect = 0;
38 int iUseNoStretchBlt = 0;
42 PSXPoint_t ptCursorPoint[8];
43 unsigned short usCursorActive = 0;
44 unsigned long ulKeybits;
50 char szDebugText[512];
51 void InitMenu(void) {}
52 void CloseMenu(void) {}
54 //unsigned int LUT16to32[65536];
55 //unsigned int RGBtoYUV[65536];
59 #include <X11/extensions/Xv.h>
60 #include <X11/extensions/Xvlib.h>
61 #include <X11/extensions/XShm.h>
70 XShmSegmentInfo shminfo;
74 #define MWM_HINTS_DECORATIONS 2
81 extern XvImage *XvShmCreateImage(Display*, XvPortID, int, char*, int, int, XShmSegmentInfo*);
86 void hq2x_32( unsigned char * srcPtr, DWORD srcPitch, unsigned char * dstPtr, int width, int height);
87 void hq3x_32( unsigned char * srcPtr, DWORD srcPitch, unsigned char * dstPtr, int width, int height);
89 ////////////////////////////////////////////////////////////////////////
90 // generic 2xSaI helpers
91 ////////////////////////////////////////////////////////////////////////
93 void * pSaISmallBuff=NULL;
94 void * pSaIBigBuff=NULL;
96 #define GET_RESULT(A, B, C, D) ((A != C || A != D) - (B != C || B != D))
98 static __inline int GetResult1(DWORD A, DWORD B, DWORD C, DWORD D, DWORD E)
103 if (A == C) x+=1; else if (B == C) y+=1;
104 if (A == D) x+=1; else if (B == D) y+=1;
110 static __inline int GetResult2(DWORD A, DWORD B, DWORD C, DWORD D, DWORD E)
115 if (A == C) x+=1; else if (B == C) y+=1;
116 if (A == D) x+=1; else if (B == D) y+=1;
122 #define colorMask8 0x00FEFEFE
123 #define lowPixelMask8 0x00010101
124 #define qcolorMask8 0x00FCFCFC
125 #define qlowpixelMask8 0x00030303
127 #define INTERPOLATE8(A, B) ((((A & colorMask8) >> 1) + ((B & colorMask8) >> 1) + (A & B & lowPixelMask8)))
128 #define Q_INTERPOLATE8(A, B, C, D) (((((A & qcolorMask8) >> 2) + ((B & qcolorMask8) >> 2) + ((C & qcolorMask8) >> 2) + ((D & qcolorMask8) >> 2) \
129 + ((((A & qlowpixelMask8) + (B & qlowpixelMask8) + (C & qlowpixelMask8) + (D & qlowpixelMask8)) >> 2) & qlowpixelMask8))))
132 void Super2xSaI_ex8(unsigned char *srcPtr, DWORD srcPitch,
133 unsigned char *dstBitmap, int width, int height)
135 DWORD dstPitch = srcPitch<<1;
136 DWORD srcPitchHalf = srcPitch>>1;
137 int finWidth = srcPitch>>2;
141 int iXA,iXB,iXC,iYA,iYB,iYC,finish;
142 DWORD color4, color5, color6;
143 DWORD color1, color2, color3;
144 DWORD colorA0, colorA1, colorA2, colorA3,
145 colorB0, colorB1, colorB2, colorB3,
147 DWORD product1a, product1b,
148 product2a, product2b;
156 for (; height; height-=1)
158 bP = (DWORD *)srcPtr;
159 dP = (DWORD *)(dstBitmap + line*dstPitch);
160 for (finish = width; finish; finish -= 1 )
162 //--------------------------------------- B1 B2
166 if(finish==finWidth) iXA=0;
168 if(finish>4) {iXB=1;iXC=2;}
170 if(finish>3) {iXB=1;iXC=1;}
174 if(height>4) {iYB=finWidth;iYC=srcPitchHalf;}
176 if(height>3) {iYB=finWidth;iYC=finWidth;}
179 colorB0 = *(bP- iYA - iXA);
180 colorB1 = *(bP- iYA);
181 colorB2 = *(bP- iYA + iXB);
182 colorB3 = *(bP- iYA + iXC);
184 color4 = *(bP - iXA);
186 color6 = *(bP + iXB);
187 colorS2 = *(bP + iXC);
189 color1 = *(bP + iYB - iXA);
190 color2 = *(bP + iYB);
191 color3 = *(bP + iYB + iXB);
192 colorS1= *(bP + iYB + iXC);
194 colorA0 = *(bP + iYC - iXA);
195 colorA1 = *(bP + iYC);
196 colorA2 = *(bP + iYC + iXB);
197 colorA3 = *(bP + iYC + iXC);
199 if (color2 == color6 && color5 != color3)
201 product2b = product1b = color2;
204 if (color5 == color3 && color2 != color6)
206 product2b = product1b = color5;
209 if (color5 == color3 && color2 == color6)
213 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color1&0x00ffffff), (colorA1&0x00ffffff));
214 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color4&0x00ffffff), (colorB1&0x00ffffff));
215 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorA2&0x00ffffff), (colorS1&0x00ffffff));
216 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorB2&0x00ffffff), (colorS2&0x00ffffff));
219 product2b = product1b = color6;
222 product2b = product1b = color5;
225 product2b = product1b = INTERPOLATE8(color5, color6);
230 if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0)
231 product2b = Q_INTERPOLATE8 (color3, color3, color3, color2);
233 if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3)
234 product2b = Q_INTERPOLATE8 (color2, color2, color2, color3);
236 product2b = INTERPOLATE8 (color2, color3);
238 if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0)
239 product1b = Q_INTERPOLATE8 (color6, color6, color6, color5);
241 if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3)
242 product1b = Q_INTERPOLATE8 (color6, color5, color5, color5);
244 product1b = INTERPOLATE8 (color5, color6);
247 if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2)
248 product2a = INTERPOLATE8(color2, color5);
250 if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0)
251 product2a = INTERPOLATE8(color2, color5);
255 if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2)
256 product1a = INTERPOLATE8(color2, color5);
258 if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0)
259 product1a = INTERPOLATE8(color2, color5);
265 *(dP+(srcPitchHalf))=product2a;
266 *(dP+1+(srcPitchHalf))=product2b;
270 }//end of for ( finish= width etc..)
274 }; //endof: for (; height; height--)
278 ////////////////////////////////////////////////////////////////////////
280 void Std2xSaI_ex8(unsigned char *srcPtr, DWORD srcPitch,
281 unsigned char *dstBitmap, int width, int height)
283 DWORD dstPitch = srcPitch<<1;
284 DWORD srcPitchHalf = srcPitch>>1;
285 int finWidth = srcPitch>>2;
289 int iXA,iXB,iXC,iYA,iYB,iYC,finish;
294 DWORD colorA, colorB;
295 DWORD colorC, colorD,
296 colorE, colorF, colorG, colorH,
297 colorI, colorJ, colorK, colorL,
298 colorM, colorN, colorO, colorP;
299 DWORD product, product1, product2;
304 for (; height; height-=1)
306 bP = (DWORD *)srcPtr;
307 dP = (DWORD *)(dstBitmap + line*dstPitch);
308 for (finish = width; finish; finish -= 1 )
310 //---------------------------------------
311 // Map of the pixels: I|E F|J
315 if(finish==finWidth) iXA=0;
317 if(finish>4) {iXB=1;iXC=2;}
319 if(finish>3) {iXB=1;iXC=1;}
323 if(height>4) {iYB=finWidth;iYC=srcPitchHalf;}
325 if(height>3) {iYB=finWidth;iYC=finWidth;}
328 colorI = *(bP- iYA - iXA);
330 colorF = *(bP- iYA + iXB);
331 colorJ = *(bP- iYA + iXC);
333 colorG = *(bP - iXA);
335 colorB = *(bP + iXB);
336 colorK = *(bP + iXC);
338 colorH = *(bP + iYB - iXA);
339 colorC = *(bP + iYB);
340 colorD = *(bP + iYB + iXB);
341 colorL = *(bP + iYB + iXC);
343 colorM = *(bP + iYC - iXA);
344 colorN = *(bP + iYC);
345 colorO = *(bP + iYC + iXB);
346 colorP = *(bP + iYC + iXC);
349 if((colorA == colorD) && (colorB != colorC))
351 if(((colorA == colorE) && (colorB == colorL)) ||
352 ((colorA == colorC) && (colorA == colorF) &&
353 (colorB != colorE) && (colorB == colorJ)))
359 product = INTERPOLATE8(colorA, colorB);
362 if(((colorA == colorG) && (colorC == colorO)) ||
363 ((colorA == colorB) && (colorA == colorH) &&
364 (colorG != colorC) && (colorC == colorM)))
370 product1 = INTERPOLATE8(colorA, colorC);
375 if((colorB == colorC) && (colorA != colorD))
377 if(((colorB == colorF) && (colorA == colorH)) ||
378 ((colorB == colorE) && (colorB == colorD) &&
379 (colorA != colorF) && (colorA == colorI)))
385 product = INTERPOLATE8(colorA, colorB);
388 if(((colorC == colorH) && (colorA == colorF)) ||
389 ((colorC == colorG) && (colorC == colorD) &&
390 (colorA != colorH) && (colorA == colorI)))
396 product1=INTERPOLATE8(colorA, colorC);
401 if((colorA == colorD) && (colorB == colorC))
403 if (colorA == colorB)
412 product1 = INTERPOLATE8(colorA, colorC);
413 product = INTERPOLATE8(colorA, colorB);
415 r += GetResult1 (colorA&0x00FFFFFF, colorB&0x00FFFFFF, colorG&0x00FFFFFF, colorE&0x00FFFFFF, colorI&0x00FFFFFF);
416 r += GetResult2 (colorB&0x00FFFFFF, colorA&0x00FFFFFF, colorK&0x00FFFFFF, colorF&0x00FFFFFF, colorJ&0x00FFFFFF);
417 r += GetResult2 (colorB&0x00FFFFFF, colorA&0x00FFFFFF, colorH&0x00FFFFFF, colorN&0x00FFFFFF, colorM&0x00FFFFFF);
418 r += GetResult1 (colorA&0x00FFFFFF, colorB&0x00FFFFFF, colorL&0x00FFFFFF, colorO&0x00FFFFFF, colorP&0x00FFFFFF);
427 product2 = Q_INTERPOLATE8(colorA, colorB, colorC, colorD);
433 product2 = Q_INTERPOLATE8(colorA, colorB, colorC, colorD);
435 if ((colorA == colorC) && (colorA == colorF) &&
436 (colorB != colorE) && (colorB == colorJ))
441 if ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI))
447 product = INTERPOLATE8(colorA, colorB);
450 if ((colorA == colorB) && (colorA == colorH) &&
451 (colorG != colorC) && (colorC == colorM))
456 if ((colorC == colorG) && (colorC == colorD) &&
457 (colorA != colorH) && (colorA == colorI))
463 product1 = INTERPOLATE8(colorA, colorC);
467 //////////////////////////
471 *(dP+(srcPitchHalf))=product1;
472 *(dP+1+(srcPitchHalf))=product2;
476 }//end of for ( finish= width etc..)
480 }; //endof: for (; height; height--)
484 ////////////////////////////////////////////////////////////////////////
486 void SuperEagle_ex8(unsigned char *srcPtr, DWORD srcPitch,
487 unsigned char *dstBitmap, int width, int height)
489 DWORD dstPitch = srcPitch<<1;
490 DWORD srcPitchHalf = srcPitch>>1;
491 int finWidth = srcPitch>>2;
495 int iXA,iXB,iXC,iYA,iYB,iYC,finish;
496 DWORD color4, color5, color6;
497 DWORD color1, color2, color3;
498 DWORD colorA1, colorA2,
501 DWORD product1a, product1b,
502 product2a, product2b;
510 for (; height; height-=1)
512 bP = (DWORD *)srcPtr;
513 dP = (DWORD *)(dstBitmap + line*dstPitch);
514 for (finish = width; finish; finish -= 1 )
516 if(finish==finWidth) iXA=0;
518 if(finish>4) {iXB=1;iXC=2;}
520 if(finish>3) {iXB=1;iXC=1;}
524 if(height>4) {iYB=finWidth;iYC=srcPitchHalf;}
526 if(height>3) {iYB=finWidth;iYC=finWidth;}
529 colorB1 = *(bP- iYA);
530 colorB2 = *(bP- iYA + iXB);
532 color4 = *(bP - iXA);
534 color6 = *(bP + iXB);
535 colorS2 = *(bP + iXC);
537 color1 = *(bP + iYB - iXA);
538 color2 = *(bP + iYB);
539 color3 = *(bP + iYB + iXB);
540 colorS1= *(bP + iYB + iXC);
542 colorA1 = *(bP + iYC);
543 colorA2 = *(bP + iYC + iXB);
545 if(color2 == color6 && color5 != color3)
547 product1b = product2a = color2;
548 if((color1 == color2) ||
551 product1a = INTERPOLATE8(color2, color5);
552 product1a = INTERPOLATE8(color2, product1a);
556 product1a = INTERPOLATE8(color5, color6);
559 if((color6 == colorS2) ||
562 product2b = INTERPOLATE8(color2, color3);
563 product2b = INTERPOLATE8(color2, product2b);
567 product2b = INTERPOLATE8(color2, color3);
571 if (color5 == color3 && color2 != color6)
573 product2b = product1a = color5;
575 if ((colorB1 == color5) ||
578 product1b = INTERPOLATE8(color5, color6);
579 product1b = INTERPOLATE8(color5, product1b);
583 product1b = INTERPOLATE8(color5, color6);
586 if ((color3 == colorA2) ||
589 product2a = INTERPOLATE8(color5, color2);
590 product2a = INTERPOLATE8(color5, product2a);
594 product2a = INTERPOLATE8(color2, color3);
598 if (color5 == color3 && color2 == color6)
602 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color1&0x00ffffff), (colorA1&0x00ffffff));
603 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color4&0x00ffffff), (colorB1&0x00ffffff));
604 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorA2&0x00ffffff), (colorS1&0x00ffffff));
605 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorB2&0x00ffffff), (colorS2&0x00ffffff));
609 product1b = product2a = color2;
610 product1a = product2b = INTERPOLATE8(color5, color6);
615 product2b = product1a = color5;
616 product1b = product2a = INTERPOLATE8(color5, color6);
620 product2b = product1a = color5;
621 product1b = product2a = color2;
626 product2b = product1a = INTERPOLATE8(color2, color6);
627 product2b = Q_INTERPOLATE8(color3, color3, color3, product2b);
628 product1a = Q_INTERPOLATE8(color5, color5, color5, product1a);
630 product2a = product1b = INTERPOLATE8(color5, color3);
631 product2a = Q_INTERPOLATE8(color2, color2, color2, product2a);
632 product1b = Q_INTERPOLATE8(color6, color6, color6, product1b);
635 ////////////////////////////////
639 *(dP+(srcPitchHalf))=product2a;
640 *(dP+1+(srcPitchHalf))=product2b;
644 }//end of for ( finish= width etc..)
648 }; //endof: for (; height; height--)
652 /////////////////////////
654 //#include <assert.h>
656 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)
659 //assert(count >= 2);
662 if (src0[0] != src2[0] && src1[0] != src1[1]) {
663 dst0[0] = src1[0] == src0[0] ? src0[0] : src1[0];
664 dst0[1] = src1[1] == src0[0] ? src0[0] : src1[0];
665 dst1[0] = src1[0] == src2[0] ? src2[0] : src1[0];
666 dst1[1] = src1[1] == src2[0] ? src2[0] : src1[0];
682 if (src0[0] != src2[0] && src1[-1] != src1[1]) {
683 dst0[0] = src1[-1] == src0[0] ? src0[0] : src1[0];
684 dst0[1] = src1[1] == src0[0] ? src0[0] : src1[0];
685 dst1[0] = src1[-1] == src2[0] ? src2[0] : src1[0];
686 dst1[1] = src1[1] == src2[0] ? src2[0] : src1[0];
703 if (src0[0] != src2[0] && src1[-1] != src1[0]) {
704 dst0[0] = src1[-1] == src0[0] ? src0[0] : src1[0];
705 dst0[1] = src1[0] == src0[0] ? src0[0] : src1[0];
706 dst1[0] = src1[-1] == src2[0] ? src2[0] : src1[0];
707 dst1[1] = src1[0] == src2[0] ? src2[0] : src1[0];
716 void Scale2x_ex8(unsigned char *srcPtr, DWORD srcPitch,
717 unsigned char *dstPtr, int width, int height)
719 //const int srcpitch = srcPitch;
720 const int dstPitch = srcPitch<<1;
727 uint32_t *dst0 = (uint32_t *)dstPtr;
728 uint32_t *dst1 = dst0 + (dstPitch >> 2);
730 uint32_t *src0 = (uint32_t *)srcPtr;
731 uint32_t *src1 = src0 + (srcPitch >> 2);
732 uint32_t *src2 = src1 + (srcPitch >> 2);
733 scale2x_32_def_whole(dst0, dst1, src0, src0, src1, width);
737 dst0 += dstPitch >> 1;
738 dst1 += dstPitch >> 1;
739 scale2x_32_def_whole(dst0, dst1, src0, src0, src1, width);
742 src2 += srcPitch >> 2;
745 dst0 += dstPitch >> 1;
746 dst1 += dstPitch >> 1;
747 scale2x_32_def_whole(dst0, dst1, src0, src1, src1, width);
751 ////////////////////////////////////////////////////////////////////////
753 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)
755 //assert(count >= 2);
758 if (src0[0] != src2[0] && src1[0] != src1[1]) {
760 dst0[1] = (src1[0] == src0[0] && src1[0] != src0[1]) || (src1[1] == src0[0] && src1[0] != src0[0]) ? src0[0] : src1[0];
761 dst0[2] = src1[1] == src0[0] ? src1[1] : src1[0];
762 dst1[0] = (src1[0] == src0[0] && src1[0] != src2[0]) || (src1[0] == src2[0] && src1[0] != src0[0]) ? src1[0] : src1[0];
764 dst1[2] = (src1[1] == src0[0] && src1[0] != src2[1]) || (src1[1] == src2[0] && src1[0] != src0[1]) ? src1[1] : src1[0];
766 dst2[1] = (src1[0] == src2[0] && src1[0] != src2[1]) || (src1[1] == src2[0] && src1[0] != src2[0]) ? src2[0] : src1[0];
767 dst2[2] = src1[1] == src2[0] ? src1[1] : src1[0];
789 if (src0[0] != src2[0] && src1[-1] != src1[1]) {
790 dst0[0] = src1[-1] == src0[0] ? src1[-1] : src1[0];
791 dst0[1] = (src1[-1] == src0[0] && src1[0] != src0[1]) || (src1[1] == src0[0] && src1[0] != src0[-1]) ? src0[0] : src1[0];
792 dst0[2] = src1[1] == src0[0] ? src1[1] : src1[0];
793 dst1[0] = (src1[-1] == src0[0] && src1[0] != src2[-1]) || (src1[-1] == src2[0] && src1[0] != src0[-1]) ? src1[-1] : src1[0];
795 dst1[2] = (src1[1] == src0[0] && src1[0] != src2[1]) || (src1[1] == src2[0] && src1[0] != src0[1]) ? src1[1] : src1[0];
796 dst2[0] = src1[-1] == src2[0] ? src1[-1] : src1[0];
797 dst2[1] = (src1[-1] == src2[0] && src1[0] != src2[1]) || (src1[1] == src2[0] && src1[0] != src2[-1]) ? src2[0] : src1[0];
798 dst2[2] = src1[1] == src2[0] ? src1[1] : src1[0];
821 if (src0[0] != src2[0] && src1[-1] != src1[0]) {
822 dst0[0] = src1[-1] == src0[0] ? src1[-1] : src1[0];
823 dst0[1] = (src1[-1] == src0[0] && src1[0] != src0[0]) || (src1[0] == src0[0] && src1[0] != src0[-1]) ? src0[0] : src1[0];
825 dst1[0] = (src1[-1] == src0[0] && src1[0] != src2[-1]) || (src1[-1] == src2[0] && src1[0] != src0[-1]) ? src1[-1] : src1[0];
827 dst1[2] = (src1[0] == src0[0] && src1[0] != src2[0]) || (src1[0] == src2[0] && src1[0] != src0[0]) ? src1[0] : src1[0];
828 dst2[0] = src1[-1] == src2[0] ? src1[-1] : src1[0];
829 dst2[1] = (src1[-1] == src2[0] && src1[0] != src2[0]) || (src1[0] == src2[0] && src1[0] != src2[-1]) ? src2[0] : src1[0];
845 void Scale3x_ex8(unsigned char *srcPtr, DWORD srcPitch,
846 unsigned char *dstPtr, int width, int height)
850 int dstPitch = srcPitch*3;
851 int dstRowPixels = dstPitch>>2;
856 uint32_t *dst0 = (uint32_t *)dstPtr;
857 uint32_t *dst1 = dst0 + dstRowPixels;
858 uint32_t *dst2 = dst1 + dstRowPixels;
860 uint32_t *src0 = (uint32_t *)srcPtr;
861 uint32_t *src1 = src0 + (srcPitch >> 2);
862 uint32_t *src2 = src1 + (srcPitch >> 2);
863 scale3x_32_def_whole(dst0, dst1, dst2, src0, src0, src2, width);
867 dst0 += dstRowPixels*3;
868 dst1 += dstRowPixels*3;
869 dst2 += dstRowPixels*3;
871 scale3x_32_def_whole(dst0, dst1, dst2, src0, src1, src2, width);
874 src2 += srcPitch >> 2;
878 dst0 += dstRowPixels*3;
879 dst1 += dstRowPixels*3;
880 dst2 += dstRowPixels*3;
882 scale3x_32_def_whole(dst0, dst1, dst2, src0, src1, src1, width);
886 ////////////////////////////////////////////////////////////////////////
889 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
890 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
894 ////////////////////////////////////////////////////////////////////////
896 ////////////////////////////////////////////////////////////////////////
899 static Cursor cursor;
901 static XVisualInfo *myvisual;
903 static Colormap colormap;
906 static XImage * Ximage;
907 static XvImage * XCimage;
908 static XImage * XFimage;
909 static XImage * XPimage=0 ;
916 static Atom xv_intern_atom_if_exists( Display *display, char const * atom_name )
918 XvAttribute * attributes;
922 attributes = XvQueryPortAttributes( display, xv_port, &attrib_count );
923 if( attributes!=NULL )
925 for ( i = 0; i < attrib_count; ++i )
927 if ( strcmp(attributes[i].name, atom_name ) == 0 )
929 xv_atom = XInternAtom( display, atom_name, False );
930 break; // found what we want, break out
943 void DestroyDisplay(void)
947 XFreeColormap(display, colormap);
950 XFreeGC(display,hGC);
955 XDestroyImage(Ximage);
965 XDestroyImage(XFimage);
969 XShmDetach(display,&shminfo);
970 shmdt(shminfo.shmaddr);
971 shmctl(shminfo.shmid,IPC_RMID,NULL);
973 Atom atom_vsync = xv_intern_atom_if_exists(display, "XV_SYNC_TO_VBLANK");
974 if (atom_vsync != None) {
975 XvSetPortAttribute(display, xv_port, atom_vsync, xv_vsync);
978 XSync(display,False);
980 XCloseDisplay(display);
985 int root_window_id=0;
990 void CreateDisplay(void)
992 XSetWindowAttributes winattr;
998 MotifWmHints mwmhints;
1008 unsigned int p_num_adaptors=0, p_num_ports=0;
1011 XvImageFormatValues *fo;
1014 display = XOpenDisplay(NULL);
1018 fprintf (stderr,"Failed to open display!!!\n");
1023 myscreen=DefaultScreen(display);
1025 // desktop fullscreen switch
1026 if (!iWindowMode) fx = 1;
1028 screen=DefaultScreenOfDisplay(display);
1030 root_window_id=RootWindow(display,DefaultScreen(display));
1032 //Look for an Xvideo RGB port
1033 ret = XvQueryAdaptors(display, root_window_id, &p_num_adaptors, &ai);
1034 if (ret != Success) {
1035 if (ret == XvBadExtension)
1036 printf("XvBadExtension returned at XvQueryExtension.\n");
1038 if (ret == XvBadAlloc)
1039 printf("XvBadAlloc returned at XvQueryExtension.\n");
1041 printf("other error happaned at XvQueryAdaptors.\n");
1046 depth = DefaultDepth(display, myscreen);
1048 for (i = 0; i < p_num_adaptors; i++) {
1049 p_num_ports = ai[i].base_id + ai[i].num_ports;
1050 for (p = ai[i].base_id; p < p_num_ports; p++) {
1051 fo = XvListImageFormats(display, p, &formats);
1052 for (j = 0; j < formats; j++) {
1054 //hmm, should I bother check guid == 55595659-0000-0010-8000-00aa00389b71?
1055 //and check byte order? fo[j].byte_order == LSBFirst
1056 #ifdef __BIG_ENDIAN__
1057 if ( fo[j].type == XvYUV && fo[j].bits_per_pixel == 16 && fo[j].format == XvPacked && strncmp("YUYV", fo[j].component_order, 5) == 0 )
1059 if ( fo[j].type == XvYUV && fo[j].bits_per_pixel == 16 && fo[j].format == XvPacked && strncmp("UYVY", fo[j].component_order, 5) == 0 )
1065 if (fo[j].type == XvRGB && fo[j].bits_per_pixel == 32)
1069 xv_depth = fo[j].depth;
1070 printf("RGB mode found. id: %x, depth: %d\n", xv_id, xv_depth);
1072 if (xv_depth != depth) {
1073 printf("Warning: Depth does not match screen depth (%d)\n", depth);
1076 //break out of loops
1087 if (p_num_adaptors > 0)
1088 XvFreeAdaptorInfo(ai);
1089 if (xv_port == -1 && yuv_port == -1)
1091 printf("RGB & YUV not found. Quitting.\n");
1094 else if (xv_port == -1 && yuv_port != -1)
1097 printf("RGB not found. Using YUV.\n");
1101 else if (xv_depth && xv_depth != depth && yuv_port != -1)
1104 printf("Acceptable RGB mode not found. Using YUV.\n");
1109 Atom atom_vsync = xv_intern_atom_if_exists(display, "XV_SYNC_TO_VBLANK");
1110 if (atom_vsync != None) {
1111 XvGetPortAttribute(display, xv_port, atom_vsync, &xv_vsync);
1112 XvSetPortAttribute(display, xv_port, atom_vsync, 0);
1117 if(XMatchVisualInfo(display,myscreen, depth, TrueColor, &vi))
1122 fprintf(stderr,"Failed to obtain visual!\n");
1127 if(myvisual->red_mask==0x00007c00 &&
1128 myvisual->green_mask==0x000003e0 &&
1129 myvisual->blue_mask==0x0000001f)
1132 if(myvisual->red_mask==0x0000f800 &&
1133 myvisual->green_mask==0x000007e0 &&
1134 myvisual->blue_mask==0x0000001f)
1137 if(myvisual->red_mask==0x00ff0000 &&
1138 myvisual->green_mask==0x0000ff00 &&
1139 myvisual->blue_mask==0x000000ff)
1144 /* fprintf(stderr,"COLOR DEPTH NOT SUPPORTED!\n");
1145 fprintf(stderr,"r: %08lx\n",myvisual->red_mask);
1146 fprintf(stderr,"g: %08lx\n",myvisual->green_mask);
1147 fprintf(stderr,"b: %08lx\n",myvisual->blue_mask);
1152 // pffff... much work for a simple blank cursor... oh, well...
1153 if(iWindowMode) cursor=XCreateFontCursor(display,XC_trek);
1163 memset(&b,0,sizeof(XColor));
1164 memset(&w,0,sizeof(XColor));
1165 idata=(char *)malloc(8);
1168 p1=XCreatePixmap(display,RootWindow(display,myvisual->screen),8,8,1);
1169 p2=XCreatePixmap(display,RootWindow(display,myvisual->screen),8,8,1);
1171 img = XCreateImage(display,myvisual->visual,
1172 1,XYBitmap,0,idata,8,8,8,1);
1174 GCv.function = GXcopy;
1175 GCv.foreground = ~0;
1177 GCv.plane_mask = AllPlanes;
1178 GCc = XCreateGC(display,p1,
1179 (GCFunction|GCForeground|GCBackground|GCPlaneMask),&GCv);
1181 XPutImage(display, p1,GCc,img,0,0,0,0,8,8);
1182 XPutImage(display, p2,GCc,img,0,0,0,0,8,8);
1183 XFreeGC(display, GCc);
1185 cursor = XCreatePixmapCursor(display,p1,p2,&b,&w,0,0);
1187 XFreePixmap(display,p1);
1188 XFreePixmap(display,p2);
1189 XDestroyImage(img); // will free idata as well
1192 colormap=XCreateColormap(display,root_window_id,
1193 myvisual->visual,AllocNone);
1195 winattr.background_pixel=0;
1196 winattr.border_pixel=WhitePixelOfScreen(screen);
1197 winattr.bit_gravity=ForgetGravity;
1198 winattr.win_gravity=NorthWestGravity;
1199 winattr.backing_store=NotUseful;
1201 winattr.override_redirect=False;
1202 winattr.save_under=False;
1203 winattr.event_mask=0;
1204 winattr.do_not_propagate_mask=0;
1205 winattr.colormap=colormap;
1206 winattr.cursor=None;
1208 window=XCreateWindow(display,root_window_id,
1211 InputOutput,myvisual->visual,
1212 CWBorderPixel | CWBackPixel |
1213 CWEventMask | CWDontPropagate |
1214 CWColormap | CWCursor,
1219 fprintf(stderr,"Failed in XCreateWindow()!!!\n");
1224 delwindow = XInternAtom(display,"WM_DELETE_WINDOW",0);
1225 XSetWMProtocols(display, window, &delwindow, 1);
1227 hints.flags=USPosition|USSize;
1228 hints.base_width = iResX;
1229 hints.base_height = iResY;
1232 wm_hints.flags=InputHint;
1234 XSetWMHints(display,window,&wm_hints);
1235 XSetWMNormalHints(display,window,&hints);
1237 XStoreName(display,window,pCaptionText);
1238 else XStoreName(display,window,"P.E.Op.S SoftX PSX Gpu");
1240 XDefineCursor(display,window,cursor);
1242 // hack to get rid of window title bar
1245 mwmhints.flags=MWM_HINTS_DECORATIONS;
1246 mwmhints.decorations=0;
1247 mwmatom=XInternAtom(display,"_MOTIF_WM_HINTS",0);
1248 XChangeProperty(display,window,mwmatom,mwmatom,32,
1249 PropModeReplace,(unsigned char *)&mwmhints,4);
1253 XSelectInput(display,
1255 FocusChangeMask | ExposureMask |
1256 KeyPressMask | KeyReleaseMask
1259 XMapRaised(display,window);
1260 XClearWindow(display,window);
1261 XWindowEvent(display,window,ExposureMask,&event);
1263 if (fx) // fullscreen
1265 XResizeWindow(display,window,screen->width,screen->height);
1267 hints.min_width = hints.max_width = hints.base_width = screen->width;
1268 hints.min_height= hints.max_height = hints.base_height = screen->height;
1270 XSetWMNormalHints(display,window,&hints);
1272 // set the window layer for GNOME
1276 memset(&xev, 0, sizeof(xev));
1277 xev.xclient.type = ClientMessage;
1278 xev.xclient.serial = 0;
1279 xev.xclient.send_event = 1;
1280 xev.xclient.message_type = XInternAtom(display, "_NET_WM_STATE", 0);
1281 xev.xclient.window = window;
1282 xev.xclient.format = 32;
1283 xev.xclient.data.l[0] = 1;
1284 xev.xclient.data.l[1] = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", 0);
1285 xev.xclient.data.l[2] = 0;
1286 xev.xclient.data.l[3] = 0;
1287 xev.xclient.data.l[4] = 0;
1289 XSendEvent(display, root_window_id, 0,
1290 SubstructureRedirectMask | SubstructureNotifyMask, &xev);
1294 gcv.graphics_exposures = False;
1295 hGC = XCreateGC(display,window,
1296 GCGraphicsExposures, &gcv);
1299 fprintf(stderr,"No gfx context!!!\n");
1305 Xpixels = (char *)malloc(220*15*4);
1306 memset(Xpixels,255,220*15*4);
1307 XFimage = XCreateImage(display,myvisual->visual,
1314 Xpixels = (char *)malloc(8*8*4);
1315 memset(Xpixels,0,8*8*4);
1316 XCimage = XvCreateImage(display,xv_port,xv_id,
1317 (char *)Xpixels, 8, 8);
1321 Allocate max that could be needed:
1322 Big(est?) PSX res: 640x512
1324 2xsai func= 3xwidth,3xheight
1327 shminfo.shmid = shmget(IPC_PRIVATE, 640*512*4*3*3, IPC_CREAT | 0777);
1328 shminfo.shmaddr = shmat(shminfo.shmid, 0, 0);
1329 shminfo.readOnly = 0;
1331 if (!XShmAttach(display, &shminfo)) {
1332 printf("XShmAttach failed !\n");
1337 void (*p2XSaIFunc) (unsigned char *, DWORD, unsigned char *, int, int);
1338 unsigned char *pBackBuffer = 0;
1340 void BlitScreen32(unsigned char *surf, int32_t x, int32_t y)
1343 unsigned int startxy;
1346 unsigned short row, column;
1347 unsigned short dx = PreviousPSXDisplay.Range.x1;
1348 unsigned short dy = PreviousPSXDisplay.DisplayMode.y;
1350 int32_t lPitch = PSXDisplay.DisplayMode.x << 2;
1354 if (PreviousPSXDisplay.Range.y0) // centering needed?
1356 memset(surf, 0, (PreviousPSXDisplay.Range.y0 >> 1) * lPitch);
1358 dy -= PreviousPSXDisplay.Range.y0;
1359 surf += (PreviousPSXDisplay.Range.y0 >> 1) * lPitch;
1361 memset(surf + dy * lPitch,
1362 0, ((PreviousPSXDisplay.Range.y0 + 1) >> 1) * lPitch);
1365 if (PreviousPSXDisplay.Range.x0)
1367 for (column = 0; column < dy; column++)
1369 destpix = (uint32_t *)(surf + (column * lPitch));
1370 memset(destpix, 0, PreviousPSXDisplay.Range.x0 << 2);
1372 surf += PreviousPSXDisplay.Range.x0 << 2;
1375 if (PSXDisplay.RGB24)
1377 for (column = 0; column < dy; column++)
1379 startxy = ((1024) * (column + y)) + x;
1380 pD = (unsigned char *)&psxVuw[startxy];
1381 destpix = (uint32_t *)(surf + (column * lPitch));
1382 for (row = 0; row < dx; row++)
1384 lu = *((uint32_t *)pD);
1386 0xff000000 | (RED(lu) << 16) | (GREEN(lu) << 8) | (BLUE(lu));
1393 for (column = 0;column<dy;column++)
1395 startxy = (1024 * (column + y)) + x;
1396 destpix = (uint32_t *)(surf + (column * lPitch));
1397 for (row = 0; row < dx; row++)
1399 s = GETLE16(&psxVuw[startxy++]);
1401 (((s << 19) & 0xf80000) | ((s << 6) & 0xf800) | ((s >> 7) & 0xf8)) | 0xff000000;
1407 void BlitToYUV(unsigned char * surf,int32_t x,int32_t y)
1410 unsigned int startxy;
1411 uint32_t lu;unsigned short s;
1412 unsigned short row,column;
1413 unsigned short dx = PreviousPSXDisplay.Range.x1;
1414 unsigned short dy = PreviousPSXDisplay.DisplayMode.y;
1417 int32_t lPitch = PSXDisplay.DisplayMode.x << 2;
1420 if (PreviousPSXDisplay.Range.y0) // centering needed?
1422 for (column = 0; column < (PreviousPSXDisplay.Range.y0 >> 1); column++)
1424 destpix = (uint32_t *)(surf + column * lPitch);
1425 for (row = 0; row < dx; row++)
1427 destpix[row] = (4 << 24) | (128 << 16) | (4 << 8) | 128;
1431 dy -= PreviousPSXDisplay.Range.y0;
1432 surf += (PreviousPSXDisplay.Range.y0 >> 1) * lPitch;
1434 for (column = 0; column < (PreviousPSXDisplay.Range.y0 + 1) >> 1; column++)
1436 destpix = (uint32_t *)(surf + (dy + column) * lPitch);
1437 for (row = 0; row < dx; row++)
1439 destpix[row] = (4 << 24) | (128 << 16) | (4 << 8) | 128;
1444 if (PreviousPSXDisplay.Range.x0)
1446 for (column = 0; column < dy; column++)
1448 destpix = (uint32_t *)(surf + (column * lPitch));
1449 for (row = 0; row < PreviousPSXDisplay.Range.x0; row++)
1451 destpix[row] = (4 << 24) | (128 << 16) | (4 << 8) | 128;
1454 surf += PreviousPSXDisplay.Range.x0 << 2;
1457 if (PSXDisplay.RGB24)
1459 for (column = 0; column < dy; column++)
1461 startxy = (1024 * (column + y)) + x;
1462 pD = (unsigned char *)&psxVuw[startxy];
1463 destpix = (uint32_t *)(surf + (column * lPitch));
1464 for (row = 0; row < dx; row++)
1466 lu = *((uint32_t *)pD);
1472 Y = min(abs(R * 2104 + G * 4130 + B * 802 + 4096 + 131072) >> 13, 235);
1473 U = min(abs(R * -1214 + G * -2384 + B * 3598 + 4096 + 1048576) >> 13, 240);
1474 V = min(abs(R * 3598 + G * -3013 + B * -585 + 4096 + 1048576) >> 13, 240);
1476 #ifdef __BIG_ENDIAN__
1477 destpix[row] = Y << 24 | U << 16 | Y << 8 | V;
1479 destpix[row] = Y << 24 | V << 16 | Y << 8 | U;
1487 for (column = 0; column < dy; column++)
1489 startxy = (1024 * (column + y)) + x;
1490 destpix = (uint32_t *)(surf + (column * lPitch));
1491 for (row = 0; row < dx; row++)
1493 s = GETLE16(&psxVuw[startxy++]);
1499 Y = min(abs(R * 2104 + G * 4130 + B * 802 + 4096 + 131072) >> 13, 235);
1500 U = min(abs(R * -1214 + G * -2384 + B * 3598 + 4096 + 1048576) >> 13, 240);
1501 V = min(abs(R * 3598 + G * -3013 + B * -585 + 4096 + 1048576) >> 13, 240);
1503 #ifdef __BIG_ENDIAN__
1504 destpix[row] = Y << 24 | U << 16 | Y << 8 | V;
1506 destpix[row] = Y << 24 | V << 16 | Y << 8 | U;
1513 //dst will have half the pitch (32bit to 16bit)
1514 void RGB2YUV(uint32_t *s, int width, int height, uint32_t *d)
1517 int R,G,B, Y1,Y2,U,V;
1519 for (y=0; y<height; y++) {
1520 for(x=0; x<width>>1; x++) {
1521 R = (*s >> 16) & 0xff;
1522 G = (*s >> 8) & 0xff;
1526 Y1 = min(abs(R * 2104 + G * 4130 + B * 802 + 4096 + 131072) >> 13, 235);
1527 U = min(abs(R * -1214 + G * -2384 + B * 3598 + 4096 + 1048576) >> 13, 240);
1528 V = min(abs(R * 3598 + G * -3013 + B * -585 + 4096 + 1048576) >> 13, 240);
1530 R = (*s >> 16) & 0xff;
1531 G = (*s >> 8) & 0xff;
1535 Y2 = min(abs(R * 2104 + G * 4130 + B * 802 + 4096 + 131072) >> 13, 235);
1537 #ifdef __BIG_ENDIAN__
1538 *d = V | Y2 << 8 | U << 16 | Y1 << 24;
1540 *d = U | Y1 << 8 | V << 16 | Y2 << 24;
1549 //Note: dest x,y,w,h are both input and output variables
1550 inline void MaintainAspect(unsigned int *dx,unsigned int *dy,unsigned int *dw,unsigned int *dh)
1552 //Currently just 4/3 aspect ratio
1555 if (*dw * 3 > *dh * 4) {
1556 t = *dh * 4.0f / 3; //new width aspect
1557 *dx = (*dw - t) / 2; //centering
1561 *dy = (*dh - t) / 2;
1566 void DoBufferSwap(void)
1571 unsigned int dstx, dsty, srcy = 0;
1572 unsigned int _d, _w, _h; //don't care about _d
1574 finalw = PSXDisplay.DisplayMode.x;
1575 finalh = PSXDisplay.DisplayMode.y;
1577 if (finalw == 0 || finalh == 0)
1580 XSync(display,False);
1583 if (iUseNoStretchBlt==0 || finalw > 320 || finalh > 256) {
1584 BlitToYUV((unsigned char *)shminfo.shmaddr, PSXDisplay.DisplayPosition.x, PSXDisplay.DisplayPosition.y);
1587 BlitScreen32((unsigned char *)pBackBuffer, PSXDisplay.DisplayPosition.x, PSXDisplay.DisplayPosition.y);
1588 p2XSaIFunc(pBackBuffer, finalw<<2, (unsigned char *)pSaIBigBuff,finalw,finalh);
1589 RGB2YUV( (uint32_t*)pSaIBigBuff, finalw, finalh, (uint32_t*)shminfo.shmaddr);
1591 } else if(iUseNoStretchBlt==0 || finalw > 320 || finalh > 256) {
1592 BlitScreen32((unsigned char *)shminfo.shmaddr, PSXDisplay.DisplayPosition.x, PSXDisplay.DisplayPosition.y);
1594 BlitScreen32((unsigned char *)pBackBuffer, PSXDisplay.DisplayPosition.x, PSXDisplay.DisplayPosition.y);
1595 p2XSaIFunc(pBackBuffer, finalw<<2, (unsigned char *)shminfo.shmaddr,finalw,finalh);
1598 XGetGeometry(display, window, &_dw, (int *)&_d, (int *)&_d, &_w, &_h, &_d, &_d);
1600 xvi = XvShmCreateImage(display, yuv_port, yuv_id, 0, finalw, finalh, &shminfo);
1602 xvi = XvShmCreateImage(display, xv_port, xv_id, 0, finalw, finalh, &shminfo);
1604 xvi->data = shminfo.shmaddr;
1606 screen=DefaultScreenOfDisplay(display);
1607 //screennum = DefaultScreen(display);
1611 _h = screen->height;
1617 if (iMaintainAspect)
1618 MaintainAspect(&dstx, &dsty, &_w, &_h);
1620 if (ulKeybits&KEY_SHOWFPS) //to avoid flicker, don't paint overtop FPS bar
1622 srcy = 15 * finalh / _h;
1626 XvShmPutImage(display, xv_port, window, hGC, xvi,
1628 finalw,finalh, //src w,h
1629 dstx,dsty, //dst x,y
1634 if(ulKeybits&KEY_SHOWFPS) //DisplayText(); // paint menu text
1636 if(szDebugText[0] && ((time(NULL) - tStart) < 2))
1638 strcpy(szDispBuf,szDebugText);
1643 strcat(szDispBuf,szMenuBuf);
1646 //XPutImage(display,window,hGC, XFimage,
1647 // 0, 0, 0, 0, 220,15);
1649 xvi = XvCreateImage(display, xv_port, xv_id, XFimage->data, 220, 15);
1650 XvPutImage(display, xv_port, window, hGC, xvi,
1657 XDrawString(display,window,hGC,2,13,szDispBuf,strlen(szDispBuf));
1660 //if(XPimage) DisplayPic();
1666 void DoClearScreenBuffer(void) // CLEAR DX BUFFER
1669 unsigned int _d, _w, _h; //don't care about _d
1671 XGetGeometry(display, window, &_dw, (int *)&_d, (int *)&_d, &_w, &_h, &_d, &_d);
1673 XvPutImage(display, xv_port, window, hGC, XCimage,
1674 0, 0, 8, 8, 0, 0, _w, _h);
1675 //XSync(display,False);
1678 void DoClearFrontBuffer(void) // CLEAR DX BUFFER
1680 XPutImage(display,window,hGC, XCimage,
1681 0, 0, 0, 0, iResX, iResY);
1682 XSync(display,False);*/
1690 if(iUseNoStretchBlt>0)
1692 pBackBuffer=(unsigned char *)malloc(640*512*sizeof(uint32_t));
1693 memset(pBackBuffer,0,640*512*sizeof(uint32_t));
1695 pSaIBigBuff=malloc(640*512*4*3*3);
1696 memset(pSaIBigBuff,0,640*512*4*3*3);
1703 if(iUseNoStretchBlt==1)
1705 p2XSaIFunc=Std2xSaI_ex8;
1708 if(iUseNoStretchBlt==2)
1710 p2XSaIFunc=Super2xSaI_ex8;
1713 if(iUseNoStretchBlt==3)
1715 p2XSaIFunc=SuperEagle_ex8;
1718 if(iUseNoStretchBlt==4)
1720 p2XSaIFunc=Scale2x_ex8;
1722 if(iUseNoStretchBlt==5)
1724 p2XSaIFunc=Scale3x_ex8;
1726 if(iUseNoStretchBlt==6)
1730 if(iUseNoStretchBlt==7)
1740 bIsFirstFrame = FALSE; // done
1745 ulKeybits|=KEY_SHOWFPS;
1753 void Xcleanup() // X CLEANUP
1757 if(iUseNoStretchBlt>0)
1759 if(pBackBuffer) free(pBackBuffer);
1761 if(pSaIBigBuff) free(pSaIBigBuff);
1766 unsigned long ulInitDisplay(void)
1768 CreateDisplay(); // x stuff
1769 Xinitialize(); // init x
1770 return (unsigned long)display;
1773 void CloseDisplay(void)
1775 Xcleanup(); // cleanup dx
1779 void CreatePic(unsigned char * pMem)
1781 unsigned char * p=(unsigned char *)malloc(128*96*4);
1782 unsigned char * ps; int x,y;
1794 s|=((*(pMem+1))&0xfc)<<3;
1795 s|=((*(pMem+2))&0xf8)<<8;
1797 *((unsigned short *)(ps+y*256+x*2))=s;
1810 s|=((*(pMem+1))&0xfc)<<2;
1811 s|=((*(pMem+2))&0xf8)<<7;
1813 *((unsigned short *)(ps+y*256+x*2))=s;
1829 *((uint32_t *)(ps+y*512+x*4))=l;
1834 XPimage = XCreateImage(display,myvisual->visual,
1842 void DestroyPic(void)
1846 XPutImage(display,window,hGC, XCimage,
1847 0, 0, 0, 0, iResX, iResY);*/
1848 XDestroyImage(XPimage);
1853 void DisplayPic(void)
1855 XPutImage(display,window,hGC, XPimage,
1856 0, 0, iResX-128, 0,128,96);
1859 void ShowGpuPic(void)
1863 void ShowTextGpuPic(void)
1868 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)
1870 static unsigned char cache_vert_mask[640];
1871 unsigned char cache_horiz_mask = 0;
1877 if (src0 == src1) //processing first row
1878 memset(cache_vert_mask, 0, count);
1880 for(i=0;i<count;++i) {
1907 mask |= interp_32_diff(c[0], c[4]) << 0;
1908 mask |= cache_vert_mask[i];
1909 mask |= interp_32_diff(c[2], c[4]) << 2;
1910 mask |= cache_horiz_mask;
1911 cache_horiz_mask = interp_32_diff(c[5], c[4]) << 3;
1912 mask |= cache_horiz_mask << 1; // << 3 << 1 == << 4
1913 mask |= interp_32_diff(c[6], c[4]) << 5;
1914 cache_vert_mask[i] = interp_32_diff(c[7], c[4]) << 1;
1915 mask |= cache_vert_mask[i] << 5; // << 1 << 5 == << 6
1916 mask |= interp_32_diff(c[8], c[4]) << 7;
1932 void hq2x_32( unsigned char * srcPtr, DWORD srcPitch, unsigned char * dstPtr, int width, int height)
1934 const int dstPitch = srcPitch<<1;
1941 uint32_t *dst0 = (uint32_t *)dstPtr;
1942 uint32_t *dst1 = dst0 + (dstPitch >> 2);
1944 uint32_t *src0 = (uint32_t *)srcPtr;
1945 uint32_t *src1 = src0 + (srcPitch >> 2);
1946 uint32_t *src2 = src1 + (srcPitch >> 2);
1947 hq2x_32_def(dst0, dst1, src0, src0, src1, width);
1952 dst0 += dstPitch >> 1; //next 2 lines (dstPitch / 4 char per int * 2)
1953 dst1 += dstPitch >> 1;
1954 hq2x_32_def(dst0, dst1, src0, src1, src2, width);
1957 src2 += srcPitch >> 2;
1960 dst0 += dstPitch >> 1;
1961 dst1 += dstPitch >> 1;
1962 hq2x_32_def(dst0, dst1, src0, src1, src1, width);
1965 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)
1967 static unsigned char cache_vert_mask[640];
1968 unsigned char cache_horiz_mask = 0;
1974 if (src0 == src1) //processing first row
1975 memset(cache_vert_mask, 0, count);
1977 for(i=0;i<count;++i) {
2004 mask |= interp_32_diff(c[0], c[4]) << 0;
2005 mask |= cache_vert_mask[i];
2006 mask |= interp_32_diff(c[2], c[4]) << 2;
2007 mask |= cache_horiz_mask;
2008 cache_horiz_mask = interp_32_diff(c[5], c[4]) << 3;
2009 mask |= cache_horiz_mask << 1; // << 3 << 1 == << 4
2010 mask |= interp_32_diff(c[6], c[4]) << 5;
2011 cache_vert_mask[i] = interp_32_diff(c[7], c[4]) << 1;
2012 mask |= cache_vert_mask[i] << 5; // << 1 << 5 == << 6
2013 mask |= interp_32_diff(c[8], c[4]) << 7;
2028 void hq3x_32( unsigned char * srcPtr, DWORD srcPitch, unsigned char * dstPtr, int width, int height)
2032 int dstPitch = srcPitch*3;
2033 int dstRowPixels = dstPitch>>2;
2038 uint32_t *dst0 = (uint32_t *)dstPtr;
2039 uint32_t *dst1 = dst0 + dstRowPixels;
2040 uint32_t *dst2 = dst1 + dstRowPixels;
2042 uint32_t *src0 = (uint32_t *)srcPtr;
2043 uint32_t *src1 = src0 + (srcPitch >> 2);
2044 uint32_t *src2 = src1 + (srcPitch >> 2);
2045 hq3x_32_def(dst0, dst1, dst2, src0, src0, src2, width);
2049 dst0 += dstRowPixels * 3;
2050 dst1 += dstRowPixels * 3;
2051 dst2 += dstRowPixels * 3;
2053 hq3x_32_def(dst0, dst1, dst2, src0, src1, src2, width);
2056 src2 += srcPitch >> 2;
2059 dst0 += dstRowPixels * 3;
2060 dst1 += dstRowPixels * 3;
2061 dst2 += dstRowPixels * 3;
2063 hq3x_32_def(dst0, dst1, dst2, src0, src1, src1, width);