Ticket #8278: scaler.cpp.txt

File scaler.cpp.txt, 1.8 KB (added by SF/*anonymous, 21 years ago)

The code snipet containing the modified scaler

Line 
1inline uint16 avg(const uint16 col1,const uint16 col2)
2{
3 //res = col1/2 + col2/2
4 uint16 r1,r2;
5 uint16 g1,g2,b1,b2;
6 r1 = (col1 & 0xF800)>>11;
7 r2 = (col2 & 0xF800)>>11;
8
9 g1 = (col1 & 0x07E0)>>5;
10 g2 = (col2 & 0x07E0)>>5;
11
12 b1 = (col1 & 0x1F);
13 b2 = (col2 & 0x1F);
14 return (((r1+r2)>>1)<<11) + (((g1+g2)>>1)<<5)+ ( (b1+b2)>>1) ;
15}
16
17inline uint16 GetScale2xVal(const uint16 col,const uint16 near1,const uint16 near2,const uint16 far1,const uint16 far2)
18{
19 if ( (near1==near2) && (near1!=far1) && (near1 != far2))
20 return near1; //this is the original scale2x code (http://scale2x.sourceforge.net)
21 else if ((near1==near2) && (near1==far1) && (near1==far2) && (near1 !=col))
22 return avg(col,near1); // remove dither patterns
23 else if ((col != near1) && (col !=near2) && (col!= far1) && (col!=far2))
24 return avg(col,avg(near1,near2)); //if col is different from all neighbours ==> blur it
25 else return col;
26}
27void AdvMame2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
28 int width, int height) {
29 unsigned int nextlineSrc = srcPitch / sizeof(uint16);
30 const uint16 *p = (const uint16 *)srcPtr;
31
32 unsigned int nextlineDst = dstPitch / sizeof(uint16);
33 uint16 *q = (uint16 *)dstPtr;
34
35 uint16 A, B, C;
36 uint16 D, E, F;
37 uint16 G, H, I;
38
39 while (height--) {
40 B = *(p - 1 - nextlineSrc);
41 E = *(p - 1);
42 H = *(p - 1 + nextlineSrc);
43 C = *(p - nextlineSrc);
44 F = *(p);
45 I = *(p + nextlineSrc);
46 for (int i = 0; i < width; ++i) {
47 p++;
48 A = B; B = C; C = *(p - nextlineSrc);
49 D = E; E = F; F = *(p);
50 G = H; H = I; I = *(p + nextlineSrc);
51
52 *(q) = GetScale2xVal(E,D,B,F,H);
53 *(q + 1) = GetScale2xVal(E,B,F,D,H);
54 *(q + nextlineDst) = GetScale2xVal(E,D,H,B,F);
55 *(q + nextlineDst + 1) = GetScale2xVal(E,H,F,D,B);
56 q += 2;
57 }
58 p += nextlineSrc - width;
59 q += (nextlineDst - width) << 1;
60 }
61}