Mercurial > vba-linux
comparison src/filters/pixel.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 #include "../Port.h" | |
2 | |
3 extern u32 RGB_LOW_BITS_MASK; | |
4 | |
5 void Pixelate2x16(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, | |
6 u8 *dstPtr, u32 dstPitch, int width, int height) | |
7 { | |
8 u8 *nextLine, *finish; | |
9 u32 colorMask = ~(RGB_LOW_BITS_MASK | (RGB_LOW_BITS_MASK << 16)); | |
10 colorMask = (colorMask >> 2) & (colorMask >> 1); | |
11 | |
12 nextLine = dstPtr + dstPitch; | |
13 | |
14 do | |
15 { | |
16 u32 *bP = (u32 *) srcPtr; | |
17 u32 *xP = (u32 *) deltaPtr; | |
18 u32 *dP = (u32 *) dstPtr; | |
19 u32 *nL = (u32 *) nextLine; | |
20 u32 currentPixel; | |
21 u32 nextPixel; | |
22 u32 currentDelta; | |
23 u32 nextDelta; | |
24 | |
25 finish = (u8 *) bP + ((width+2) << 1); | |
26 nextPixel = *bP++; | |
27 nextDelta = *xP++; | |
28 | |
29 do | |
30 { | |
31 currentPixel = nextPixel; | |
32 currentDelta = nextDelta; | |
33 nextPixel = *bP++; | |
34 nextDelta = *xP++; | |
35 | |
36 if ((nextPixel != nextDelta) || (currentPixel != currentDelta)) | |
37 { | |
38 u32 colorA, colorB, product; | |
39 | |
40 *(xP - 2) = currentPixel; | |
41 #ifdef WORDS_BIGENDIAN | |
42 colorA = currentPixel >> 16; | |
43 colorB = currentPixel & 0xffff; | |
44 #else | |
45 colorA = currentPixel & 0xffff; | |
46 colorB = currentPixel >> 16; | |
47 #endif | |
48 product = (colorA >> 2) & colorMask; | |
49 | |
50 #ifdef WORDS_BIGENDIAN | |
51 *(nL) = (product << 16) | (product); | |
52 *(dP) = (colorA << 16) | product; | |
53 #else | |
54 *(nL) = product | (product << 16); | |
55 *(dP) = colorA | (product << 16); | |
56 #endif | |
57 | |
58 #ifdef WORDS_BIGENDIAN | |
59 colorA = nextPixel >> 16; | |
60 #else | |
61 colorA = nextPixel & 0xffff; | |
62 #endif | |
63 product = (colorB >> 2) & colorMask; | |
64 #ifdef WORDS_BIGENDIAN | |
65 *(nL + 1) = (product << 16) | (product); | |
66 *(dP + 1) = (colorB << 16) | (product); | |
67 #else | |
68 *(nL + 1) = (product) | (product << 16); | |
69 *(dP + 1) = (colorB) | (product << 16); | |
70 #endif | |
71 } | |
72 | |
73 dP += 2; | |
74 nL += 2; | |
75 } | |
76 while ((u8 *) bP < finish); | |
77 | |
78 deltaPtr += srcPitch; | |
79 srcPtr += srcPitch; | |
80 dstPtr += dstPitch << 1; | |
81 nextLine += dstPitch << 1; | |
82 } | |
83 while (--height); | |
84 } | |
85 | |
86 void Pixelate2x32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */, | |
87 u8 *dstPtr, u32 dstPitch, int width, int height) | |
88 { | |
89 u8 *nextLine, *finish; | |
90 u32 colorMask = ((u32)~RGB_LOW_BITS_MASK >> 2) & ((u32)~RGB_LOW_BITS_MASK >> 1); | |
91 | |
92 nextLine = dstPtr + dstPitch; | |
93 | |
94 do | |
95 { | |
96 u32 *bP = (u32 *) srcPtr; | |
97 // u32 *xP = (u32 *) deltaPtr; | |
98 u32 *dP = (u32 *) dstPtr; | |
99 u32 *nL = (u32 *) nextLine; | |
100 u32 currentPixel; | |
101 u32 nextPixel; | |
102 | |
103 finish = (u8 *) bP + ((width+1) << 2); | |
104 nextPixel = *bP++; | |
105 | |
106 do | |
107 { | |
108 u32 product; | |
109 | |
110 currentPixel = nextPixel; | |
111 nextPixel = *bP++; | |
112 product = (currentPixel >> 2) & colorMask; | |
113 *(nL) = product; | |
114 *(nL+1) = product; | |
115 *(dP) = currentPixel; | |
116 *(dP+1) = product; | |
117 | |
118 currentPixel = nextPixel; | |
119 nextPixel = *bP++; | |
120 product = (currentPixel >> 2) & colorMask; | |
121 *(nL + 2) = product; | |
122 *(nL + 3) = product; | |
123 *(dP + 2) = currentPixel; | |
124 *(dP + 3) = product; | |
125 | |
126 dP += 4; | |
127 nL += 4; | |
128 } | |
129 while ((u8 *) bP < finish); | |
130 | |
131 srcPtr += srcPitch; | |
132 dstPtr += dstPitch << 1; | |
133 nextLine += dstPitch << 1; | |
134 } | |
135 while (--height); | |
136 } | |
137 | |
138 // generic Pixelate Nx magnification filter | |
139 template <int magnification, typename ColorType> | |
140 void PixelateNx(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */, | |
141 u8 *dstPtr, u32 dstPitch, int width, int height) | |
142 { | |
143 ColorType colorMask = ((ColorType)~RGB_LOW_BITS_MASK >> 2) & ((ColorType)~RGB_LOW_BITS_MASK >> 1); | |
144 | |
145 srcPitch = srcPitch / sizeof(ColorType) - width; | |
146 u32 dstNextP = dstPitch / sizeof(ColorType); | |
147 u32 dstNextL = (dstNextP - width) * magnification; // skip to the next magnificated 'line' | |
148 dstNextP -= magnification; | |
149 | |
150 u32 offset = (dstPitch + sizeof(ColorType)) * magnification - dstPitch; | |
151 | |
152 ColorType *src = (ColorType *)srcPtr; | |
153 ColorType *dst = (ColorType *)dstPtr; | |
154 | |
155 do // per src line | |
156 { | |
157 u8 *finishP = (u8 *)dst + offset; | |
158 for (int x = 0; x < width; ++x) // per pixel in line | |
159 { | |
160 ColorType col = *src; | |
161 ColorType *dst2 = dst; | |
162 u8 *finishM = (u8 *)(dst + magnification); | |
163 | |
164 ColorType product = (col >> 2) & colorMask; | |
165 do | |
166 { | |
167 *dst2 = product; | |
168 } while ((u8 *)++dst2 < finishM); | |
169 dst2 += dstNextP; | |
170 finishM += dstPitch; | |
171 do // dst magnificated pixel | |
172 { | |
173 *dst2++ = product; | |
174 do | |
175 { | |
176 *dst2 = col; | |
177 } while ((u8 *)++dst2 < finishM); | |
178 dst2 += dstNextP; | |
179 finishM += dstPitch; | |
180 } while ((u8 *)dst2 < finishP); | |
181 | |
182 ++src; | |
183 dst += magnification; | |
184 finishP += magnification * sizeof(ColorType); | |
185 } | |
186 src += srcPitch; | |
187 dst += dstNextL; | |
188 } while (--height); | |
189 } | |
190 | |
191 typedef void (*PixelateNxFP)(u8*, u32, u8*, u8*, u32, int, int); | |
192 | |
193 PixelateNxFP Pixelate3x16 = PixelateNx<3, u16>; | |
194 PixelateNxFP Pixelate3x32 = PixelateNx<3, u32>; | |
195 PixelateNxFP Pixelate4x16 = PixelateNx<4, u16>; | |
196 PixelateNxFP Pixelate4x32 = PixelateNx<4, u32>; |