Mercurial > vba-clojure
diff src/filters/motionblur.cpp @ 27:b970226568d2
brought in filters package
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 04 Mar 2012 20:32:31 -0600 |
parents | f9f4f1b99eed |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/filters/motionblur.cpp Sun Mar 04 20:32:31 2012 -0600 1.3 @@ -0,0 +1,183 @@ 1.4 +#include "../Port.h" 1.5 + 1.6 +extern u32 RGB_LOW_BITS_MASK; 1.7 + 1.8 +void MotionBlur(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, 1.9 + u8 *dstPtr, u32 dstPitch, int width, int height) 1.10 +{ 1.11 + u8 *nextLine, *finish; 1.12 + u32 colorMask = ~(RGB_LOW_BITS_MASK | (RGB_LOW_BITS_MASK << 16)); 1.13 + u32 lowPixelMask = RGB_LOW_BITS_MASK; 1.14 + 1.15 + nextLine = dstPtr + dstPitch; 1.16 + 1.17 + do 1.18 + { 1.19 + u32 *bP = (u32 *) srcPtr; 1.20 + u32 *xP = (u32 *) deltaPtr; 1.21 + u32 *dP = (u32 *) dstPtr; 1.22 + u32 *nL = (u32 *) nextLine; 1.23 + u32 currentPixel; 1.24 + u32 nextPixel; 1.25 + u32 currentDelta; 1.26 + u32 nextDelta; 1.27 + 1.28 + finish = (u8 *) bP + ((width + 2) << 1); 1.29 + nextPixel = *bP++; 1.30 + nextDelta = *xP++; 1.31 + 1.32 + do 1.33 + { 1.34 + currentPixel = nextPixel; 1.35 + currentDelta = nextDelta; 1.36 + nextPixel = *bP++; 1.37 + nextDelta = *xP++; 1.38 + 1.39 + if (currentPixel != currentDelta) 1.40 + { 1.41 + u32 colorA, product, colorB; 1.42 + 1.43 + *(xP - 2) = currentPixel; 1.44 +#ifdef WORDS_BIGENDIAN 1.45 + colorA = currentPixel >> 16; 1.46 + colorB = currentDelta >> 16; 1.47 +#else 1.48 + colorA = currentPixel & 0xffff; 1.49 + colorB = currentDelta & 0xffff; 1.50 +#endif 1.51 + 1.52 + product = ((((colorA & colorMask) >> 1) + 1.53 + ((colorB & colorMask) >> 1) + 1.54 + (colorA & colorB & lowPixelMask))); 1.55 + 1.56 + *(dP) = product | product << 16; 1.57 + *(nL) = product | product << 16; 1.58 + 1.59 +#ifdef WORDS_BIGENDIAN 1.60 + colorA = (currentPixel & 0xffff); 1.61 + colorB = (currentDelta & 0xffff); 1.62 +#else 1.63 + colorA = currentPixel >> 16; 1.64 + colorB = currentDelta >> 16; 1.65 +#endif 1.66 + product = ((((colorA & colorMask) >> 1) + 1.67 + ((colorB & colorMask) >> 1) + 1.68 + (colorA & colorB & lowPixelMask))); 1.69 + 1.70 + *(dP + 1) = product | product << 16; 1.71 + *(nL + 1) = product | product << 16; 1.72 + } 1.73 + else 1.74 + { 1.75 + u32 colorA, product; 1.76 + 1.77 + *(xP - 2) = currentPixel; 1.78 +#ifdef WORDS_BIGENDIAN 1.79 + colorA = currentPixel >> 16; 1.80 +#else 1.81 + colorA = currentPixel & 0xffff; 1.82 +#endif 1.83 + 1.84 + product = colorA; 1.85 + 1.86 + *(dP) = product | product << 16; 1.87 + *(nL) = product | product << 16; 1.88 +#ifdef WORDS_BIGENDIAN 1.89 + colorA = (currentPixel & 0xffff); 1.90 +#else 1.91 + colorA = currentPixel >> 16; 1.92 +#endif 1.93 + product = colorA; 1.94 + 1.95 + *(dP + 1) = product | product << 16; 1.96 + *(nL + 1) = product | product << 16; 1.97 + } 1.98 + 1.99 + dP += 2; 1.100 + nL += 2; 1.101 + } 1.102 + while ((u8 *) bP < finish); 1.103 + 1.104 + deltaPtr += srcPitch; 1.105 + srcPtr += srcPitch; 1.106 + dstPtr += dstPitch << 1; 1.107 + nextLine += dstPitch << 1; 1.108 + } 1.109 + while (--height); 1.110 +} 1.111 + 1.112 +void MotionBlur32(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, 1.113 + u8 *dstPtr, u32 dstPitch, int width, int height) 1.114 +{ 1.115 + u8 *nextLine, *finish; 1.116 + u32 colorMask = ~RGB_LOW_BITS_MASK; 1.117 + u32 lowPixelMask = RGB_LOW_BITS_MASK; 1.118 + 1.119 + nextLine = dstPtr + dstPitch; 1.120 + 1.121 + do 1.122 + { 1.123 + u32 *bP = (u32 *) srcPtr; 1.124 + u32 *xP = (u32 *) deltaPtr; 1.125 + u32 *dP = (u32 *) dstPtr; 1.126 + u32 *nL = (u32 *) nextLine; 1.127 + u32 currentPixel; 1.128 + u32 nextPixel; 1.129 + u32 currentDelta; 1.130 + u32 nextDelta; 1.131 + 1.132 + finish = (u8 *) bP + ((width + 1) << 2); 1.133 + nextPixel = *bP++; 1.134 + nextDelta = *xP++; 1.135 + 1.136 + do 1.137 + { 1.138 + currentPixel = nextPixel; 1.139 + currentDelta = nextDelta; 1.140 + nextPixel = *bP++; 1.141 + nextDelta = *xP++; 1.142 + 1.143 + u32 colorA, product, colorB; 1.144 + 1.145 + *(xP - 2) = currentPixel; 1.146 + colorA = currentPixel; 1.147 + colorB = currentDelta; 1.148 + 1.149 + product = ((((colorA & colorMask) >> 1) + 1.150 + ((colorB & colorMask) >> 1) + 1.151 + (colorA & colorB & lowPixelMask))); 1.152 + 1.153 + *(dP) = product; 1.154 + *(dP + 1) = product; 1.155 + *(nL) = product; 1.156 + *(nL + 1) = product; 1.157 + 1.158 + *(xP - 1) = nextPixel; 1.159 + 1.160 + colorA = nextPixel; 1.161 + colorB = nextDelta; 1.162 + 1.163 + product = ((((colorA & colorMask) >> 1) + 1.164 + ((colorB & colorMask) >> 1) + 1.165 + (colorA & colorB & lowPixelMask))); 1.166 + 1.167 + *(dP + 2) = product; 1.168 + *(dP + 3) = product; 1.169 + *(nL + 2) = product; 1.170 + *(nL + 3) = product; 1.171 + 1.172 + nextPixel = *bP++; 1.173 + nextDelta = *xP++; 1.174 + 1.175 + dP += 4; 1.176 + nL += 4; 1.177 + } 1.178 + while ((u8 *) bP < finish); 1.179 + 1.180 + deltaPtr += srcPitch; 1.181 + srcPtr += srcPitch; 1.182 + dstPtr += dstPitch << 1; 1.183 + nextLine += dstPitch << 1; 1.184 + } 1.185 + while (--height); 1.186 +}