Mercurial > vba-clojure
view src/filters/motionblur.cpp @ 520:fe2b9a1fe919
reduced colors in pinkie pie mark to exactly 4.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 23 Jun 2012 17:22:32 -0500 |
parents | f9f4f1b99eed |
children |
line wrap: on
line source
1 #include "../Port.h"3 extern u32 RGB_LOW_BITS_MASK;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;12 nextLine = dstPtr + dstPitch;14 do15 {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;25 finish = (u8 *) bP + ((width + 2) << 1);26 nextPixel = *bP++;27 nextDelta = *xP++;29 do30 {31 currentPixel = nextPixel;32 currentDelta = nextDelta;33 nextPixel = *bP++;34 nextDelta = *xP++;36 if (currentPixel != currentDelta)37 {38 u32 colorA, product, colorB;40 *(xP - 2) = currentPixel;41 #ifdef WORDS_BIGENDIAN42 colorA = currentPixel >> 16;43 colorB = currentDelta >> 16;44 #else45 colorA = currentPixel & 0xffff;46 colorB = currentDelta & 0xffff;47 #endif49 product = ((((colorA & colorMask) >> 1) +50 ((colorB & colorMask) >> 1) +51 (colorA & colorB & lowPixelMask)));53 *(dP) = product | product << 16;54 *(nL) = product | product << 16;56 #ifdef WORDS_BIGENDIAN57 colorA = (currentPixel & 0xffff);58 colorB = (currentDelta & 0xffff);59 #else60 colorA = currentPixel >> 16;61 colorB = currentDelta >> 16;62 #endif63 product = ((((colorA & colorMask) >> 1) +64 ((colorB & colorMask) >> 1) +65 (colorA & colorB & lowPixelMask)));67 *(dP + 1) = product | product << 16;68 *(nL + 1) = product | product << 16;69 }70 else71 {72 u32 colorA, product;74 *(xP - 2) = currentPixel;75 #ifdef WORDS_BIGENDIAN76 colorA = currentPixel >> 16;77 #else78 colorA = currentPixel & 0xffff;79 #endif81 product = colorA;83 *(dP) = product | product << 16;84 *(nL) = product | product << 16;85 #ifdef WORDS_BIGENDIAN86 colorA = (currentPixel & 0xffff);87 #else88 colorA = currentPixel >> 16;89 #endif90 product = colorA;92 *(dP + 1) = product | product << 16;93 *(nL + 1) = product | product << 16;94 }96 dP += 2;97 nL += 2;98 }99 while ((u8 *) bP < finish);101 deltaPtr += srcPitch;102 srcPtr += srcPitch;103 dstPtr += dstPitch << 1;104 nextLine += dstPitch << 1;105 }106 while (--height);107 }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;116 nextLine = dstPtr + dstPitch;118 do119 {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;129 finish = (u8 *) bP + ((width + 1) << 2);130 nextPixel = *bP++;131 nextDelta = *xP++;133 do134 {135 currentPixel = nextPixel;136 currentDelta = nextDelta;137 nextPixel = *bP++;138 nextDelta = *xP++;140 u32 colorA, product, colorB;142 *(xP - 2) = currentPixel;143 colorA = currentPixel;144 colorB = currentDelta;146 product = ((((colorA & colorMask) >> 1) +147 ((colorB & colorMask) >> 1) +148 (colorA & colorB & lowPixelMask)));150 *(dP) = product;151 *(dP + 1) = product;152 *(nL) = product;153 *(nL + 1) = product;155 *(xP - 1) = nextPixel;157 colorA = nextPixel;158 colorB = nextDelta;160 product = ((((colorA & colorMask) >> 1) +161 ((colorB & colorMask) >> 1) +162 (colorA & colorB & lowPixelMask)));164 *(dP + 2) = product;165 *(dP + 3) = product;166 *(nL + 2) = product;167 *(nL + 3) = product;169 nextPixel = *bP++;170 nextDelta = *xP++;172 dP += 4;173 nL += 4;174 }175 while ((u8 *) bP < finish);177 deltaPtr += srcPitch;178 srcPtr += srcPitch;179 dstPtr += dstPitch << 1;180 nextLine += dstPitch << 1;181 }182 while (--height);183 }