inline uint16 avg(const uint16 col1,const uint16 col2) { //res = col1/2 + col2/2 uint16 r1,r2; uint16 g1,g2,b1,b2; r1 = (col1 & 0xF800)>>11; r2 = (col2 & 0xF800)>>11; g1 = (col1 & 0x07E0)>>5; g2 = (col2 & 0x07E0)>>5; b1 = (col1 & 0x1F); b2 = (col2 & 0x1F); return (((r1+r2)>>1)<<11) + (((g1+g2)>>1)<<5)+ ( (b1+b2)>>1) ; } inline uint16 GetScale2xVal(const uint16 col,const uint16 near1,const uint16 near2,const uint16 far1,const uint16 far2) { if ( (near1==near2) && (near1!=far1) && (near1 != far2)) return near1; //this is the original scale2x code (http://scale2x.sourceforge.net) else if ((near1==near2) && (near1==far1) && (near1==far2) && (near1 !=col)) return avg(col,near1); // remove dither patterns else if ((col != near1) && (col !=near2) && (col!= far1) && (col!=far2)) return avg(col,avg(near1,near2)); //if col is different from all neighbours ==> blur it else return col; } void AdvMame2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height) { unsigned int nextlineSrc = srcPitch / sizeof(uint16); const uint16 *p = (const uint16 *)srcPtr; unsigned int nextlineDst = dstPitch / sizeof(uint16); uint16 *q = (uint16 *)dstPtr; uint16 A, B, C; uint16 D, E, F; uint16 G, H, I; while (height--) { B = *(p - 1 - nextlineSrc); E = *(p - 1); H = *(p - 1 + nextlineSrc); C = *(p - nextlineSrc); F = *(p); I = *(p + nextlineSrc); for (int i = 0; i < width; ++i) { p++; A = B; B = C; C = *(p - nextlineSrc); D = E; E = F; F = *(p); G = H; H = I; I = *(p + nextlineSrc); *(q) = GetScale2xVal(E,D,B,F,H); *(q + 1) = GetScale2xVal(E,B,F,D,H); *(q + nextlineDst) = GetScale2xVal(E,D,H,B,F); *(q + nextlineDst + 1) = GetScale2xVal(E,H,F,D,B); q += 2; } p += nextlineSrc - width; q += (nextlineDst - width) << 1; } }