Mercurial > vba-linux
comparison src/filters/motionblur.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 MotionBlur(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 u32 lowPixelMask = RGB_LOW_BITS_MASK; | |
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 (currentPixel != currentDelta) | |
37 { | |
38 u32 colorA, product, colorB; | |
39 | |
40 *(xP - 2) = currentPixel; | |
41 #ifdef WORDS_BIGENDIAN | |
42 colorA = currentPixel >> 16; | |
43 colorB = currentDelta >> 16; | |
44 #else | |
45 colorA = currentPixel & 0xffff; | |
46 colorB = currentDelta & 0xffff; | |
47 #endif | |
48 | |
49 product = ((((colorA & colorMask) >> 1) + | |
50 ((colorB & colorMask) >> 1) + | |
51 (colorA & colorB & lowPixelMask))); | |
52 | |
53 *(dP) = product | product << 16; | |
54 *(nL) = product | product << 16; | |
55 | |
56 #ifdef WORDS_BIGENDIAN | |
57 colorA = (currentPixel & 0xffff); | |
58 colorB = (currentDelta & 0xffff); | |
59 #else | |
60 colorA = currentPixel >> 16; | |
61 colorB = currentDelta >> 16; | |
62 #endif | |
63 product = ((((colorA & colorMask) >> 1) + | |
64 ((colorB & colorMask) >> 1) + | |
65 (colorA & colorB & lowPixelMask))); | |
66 | |
67 *(dP + 1) = product | product << 16; | |
68 *(nL + 1) = product | product << 16; | |
69 } | |
70 else | |
71 { | |
72 u32 colorA, product; | |
73 | |
74 *(xP - 2) = currentPixel; | |
75 #ifdef WORDS_BIGENDIAN | |
76 colorA = currentPixel >> 16; | |
77 #else | |
78 colorA = currentPixel & 0xffff; | |
79 #endif | |
80 | |
81 product = colorA; | |
82 | |
83 *(dP) = product | product << 16; | |
84 *(nL) = product | product << 16; | |
85 #ifdef WORDS_BIGENDIAN | |
86 colorA = (currentPixel & 0xffff); | |
87 #else | |
88 colorA = currentPixel >> 16; | |
89 #endif | |
90 product = colorA; | |
91 | |
92 *(dP + 1) = product | product << 16; | |
93 *(nL + 1) = product | product << 16; | |
94 } | |
95 | |
96 dP += 2; | |
97 nL += 2; | |
98 } | |
99 while ((u8 *) bP < finish); | |
100 | |
101 deltaPtr += srcPitch; | |
102 srcPtr += srcPitch; | |
103 dstPtr += dstPitch << 1; | |
104 nextLine += dstPitch << 1; | |
105 } | |
106 while (--height); | |
107 } | |
108 | |
109 void MotionBlur32(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, | |
110 u8 *dstPtr, u32 dstPitch, int width, int height) | |
111 { | |
112 u8 *nextLine, *finish; | |
113 u32 colorMask = ~RGB_LOW_BITS_MASK; | |
114 u32 lowPixelMask = RGB_LOW_BITS_MASK; | |
115 | |
116 nextLine = dstPtr + dstPitch; | |
117 | |
118 do | |
119 { | |
120 u32 *bP = (u32 *) srcPtr; | |
121 u32 *xP = (u32 *) deltaPtr; | |
122 u32 *dP = (u32 *) dstPtr; | |
123 u32 *nL = (u32 *) nextLine; | |
124 u32 currentPixel; | |
125 u32 nextPixel; | |
126 u32 currentDelta; | |
127 u32 nextDelta; | |
128 | |
129 finish = (u8 *) bP + ((width + 1) << 2); | |
130 nextPixel = *bP++; | |
131 nextDelta = *xP++; | |
132 | |
133 do | |
134 { | |
135 currentPixel = nextPixel; | |
136 currentDelta = nextDelta; | |
137 nextPixel = *bP++; | |
138 nextDelta = *xP++; | |
139 | |
140 u32 colorA, product, colorB; | |
141 | |
142 *(xP - 2) = currentPixel; | |
143 colorA = currentPixel; | |
144 colorB = currentDelta; | |
145 | |
146 product = ((((colorA & colorMask) >> 1) + | |
147 ((colorB & colorMask) >> 1) + | |
148 (colorA & colorB & lowPixelMask))); | |
149 | |
150 *(dP) = product; | |
151 *(dP + 1) = product; | |
152 *(nL) = product; | |
153 *(nL + 1) = product; | |
154 | |
155 *(xP - 1) = nextPixel; | |
156 | |
157 colorA = nextPixel; | |
158 colorB = nextDelta; | |
159 | |
160 product = ((((colorA & colorMask) >> 1) + | |
161 ((colorB & colorMask) >> 1) + | |
162 (colorA & colorB & lowPixelMask))); | |
163 | |
164 *(dP + 2) = product; | |
165 *(dP + 3) = product; | |
166 *(nL + 2) = product; | |
167 *(nL + 3) = product; | |
168 | |
169 nextPixel = *bP++; | |
170 nextDelta = *xP++; | |
171 | |
172 dP += 4; | |
173 nL += 4; | |
174 } | |
175 while ((u8 *) bP < finish); | |
176 | |
177 deltaPtr += srcPitch; | |
178 srcPtr += srcPitch; | |
179 dstPtr += dstPitch << 1; | |
180 nextLine += dstPitch << 1; | |
181 } | |
182 while (--height); | |
183 } |