annotate src/filters/motionblur.cpp @ 598:0b4ff504157d

merge.
author Robert McIntyre <rlm@mit.edu>
date Sun, 02 Sep 2012 06:37:11 -0500
parents f9f4f1b99eed
children
rev   line source
rlm@1 1 #include "../Port.h"
rlm@1 2
rlm@1 3 extern u32 RGB_LOW_BITS_MASK;
rlm@1 4
rlm@1 5 void MotionBlur(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
rlm@1 6 u8 *dstPtr, u32 dstPitch, int width, int height)
rlm@1 7 {
rlm@1 8 u8 *nextLine, *finish;
rlm@1 9 u32 colorMask = ~(RGB_LOW_BITS_MASK | (RGB_LOW_BITS_MASK << 16));
rlm@1 10 u32 lowPixelMask = RGB_LOW_BITS_MASK;
rlm@1 11
rlm@1 12 nextLine = dstPtr + dstPitch;
rlm@1 13
rlm@1 14 do
rlm@1 15 {
rlm@1 16 u32 *bP = (u32 *) srcPtr;
rlm@1 17 u32 *xP = (u32 *) deltaPtr;
rlm@1 18 u32 *dP = (u32 *) dstPtr;
rlm@1 19 u32 *nL = (u32 *) nextLine;
rlm@1 20 u32 currentPixel;
rlm@1 21 u32 nextPixel;
rlm@1 22 u32 currentDelta;
rlm@1 23 u32 nextDelta;
rlm@1 24
rlm@1 25 finish = (u8 *) bP + ((width + 2) << 1);
rlm@1 26 nextPixel = *bP++;
rlm@1 27 nextDelta = *xP++;
rlm@1 28
rlm@1 29 do
rlm@1 30 {
rlm@1 31 currentPixel = nextPixel;
rlm@1 32 currentDelta = nextDelta;
rlm@1 33 nextPixel = *bP++;
rlm@1 34 nextDelta = *xP++;
rlm@1 35
rlm@1 36 if (currentPixel != currentDelta)
rlm@1 37 {
rlm@1 38 u32 colorA, product, colorB;
rlm@1 39
rlm@1 40 *(xP - 2) = currentPixel;
rlm@1 41 #ifdef WORDS_BIGENDIAN
rlm@1 42 colorA = currentPixel >> 16;
rlm@1 43 colorB = currentDelta >> 16;
rlm@1 44 #else
rlm@1 45 colorA = currentPixel & 0xffff;
rlm@1 46 colorB = currentDelta & 0xffff;
rlm@1 47 #endif
rlm@1 48
rlm@1 49 product = ((((colorA & colorMask) >> 1) +
rlm@1 50 ((colorB & colorMask) >> 1) +
rlm@1 51 (colorA & colorB & lowPixelMask)));
rlm@1 52
rlm@1 53 *(dP) = product | product << 16;
rlm@1 54 *(nL) = product | product << 16;
rlm@1 55
rlm@1 56 #ifdef WORDS_BIGENDIAN
rlm@1 57 colorA = (currentPixel & 0xffff);
rlm@1 58 colorB = (currentDelta & 0xffff);
rlm@1 59 #else
rlm@1 60 colorA = currentPixel >> 16;
rlm@1 61 colorB = currentDelta >> 16;
rlm@1 62 #endif
rlm@1 63 product = ((((colorA & colorMask) >> 1) +
rlm@1 64 ((colorB & colorMask) >> 1) +
rlm@1 65 (colorA & colorB & lowPixelMask)));
rlm@1 66
rlm@1 67 *(dP + 1) = product | product << 16;
rlm@1 68 *(nL + 1) = product | product << 16;
rlm@1 69 }
rlm@1 70 else
rlm@1 71 {
rlm@1 72 u32 colorA, product;
rlm@1 73
rlm@1 74 *(xP - 2) = currentPixel;
rlm@1 75 #ifdef WORDS_BIGENDIAN
rlm@1 76 colorA = currentPixel >> 16;
rlm@1 77 #else
rlm@1 78 colorA = currentPixel & 0xffff;
rlm@1 79 #endif
rlm@1 80
rlm@1 81 product = colorA;
rlm@1 82
rlm@1 83 *(dP) = product | product << 16;
rlm@1 84 *(nL) = product | product << 16;
rlm@1 85 #ifdef WORDS_BIGENDIAN
rlm@1 86 colorA = (currentPixel & 0xffff);
rlm@1 87 #else
rlm@1 88 colorA = currentPixel >> 16;
rlm@1 89 #endif
rlm@1 90 product = colorA;
rlm@1 91
rlm@1 92 *(dP + 1) = product | product << 16;
rlm@1 93 *(nL + 1) = product | product << 16;
rlm@1 94 }
rlm@1 95
rlm@1 96 dP += 2;
rlm@1 97 nL += 2;
rlm@1 98 }
rlm@1 99 while ((u8 *) bP < finish);
rlm@1 100
rlm@1 101 deltaPtr += srcPitch;
rlm@1 102 srcPtr += srcPitch;
rlm@1 103 dstPtr += dstPitch << 1;
rlm@1 104 nextLine += dstPitch << 1;
rlm@1 105 }
rlm@1 106 while (--height);
rlm@1 107 }
rlm@1 108
rlm@1 109 void MotionBlur32(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
rlm@1 110 u8 *dstPtr, u32 dstPitch, int width, int height)
rlm@1 111 {
rlm@1 112 u8 *nextLine, *finish;
rlm@1 113 u32 colorMask = ~RGB_LOW_BITS_MASK;
rlm@1 114 u32 lowPixelMask = RGB_LOW_BITS_MASK;
rlm@1 115
rlm@1 116 nextLine = dstPtr + dstPitch;
rlm@1 117
rlm@1 118 do
rlm@1 119 {
rlm@1 120 u32 *bP = (u32 *) srcPtr;
rlm@1 121 u32 *xP = (u32 *) deltaPtr;
rlm@1 122 u32 *dP = (u32 *) dstPtr;
rlm@1 123 u32 *nL = (u32 *) nextLine;
rlm@1 124 u32 currentPixel;
rlm@1 125 u32 nextPixel;
rlm@1 126 u32 currentDelta;
rlm@1 127 u32 nextDelta;
rlm@1 128
rlm@1 129 finish = (u8 *) bP + ((width + 1) << 2);
rlm@1 130 nextPixel = *bP++;
rlm@1 131 nextDelta = *xP++;
rlm@1 132
rlm@1 133 do
rlm@1 134 {
rlm@1 135 currentPixel = nextPixel;
rlm@1 136 currentDelta = nextDelta;
rlm@1 137 nextPixel = *bP++;
rlm@1 138 nextDelta = *xP++;
rlm@1 139
rlm@1 140 u32 colorA, product, colorB;
rlm@1 141
rlm@1 142 *(xP - 2) = currentPixel;
rlm@1 143 colorA = currentPixel;
rlm@1 144 colorB = currentDelta;
rlm@1 145
rlm@1 146 product = ((((colorA & colorMask) >> 1) +
rlm@1 147 ((colorB & colorMask) >> 1) +
rlm@1 148 (colorA & colorB & lowPixelMask)));
rlm@1 149
rlm@1 150 *(dP) = product;
rlm@1 151 *(dP + 1) = product;
rlm@1 152 *(nL) = product;
rlm@1 153 *(nL + 1) = product;
rlm@1 154
rlm@1 155 *(xP - 1) = nextPixel;
rlm@1 156
rlm@1 157 colorA = nextPixel;
rlm@1 158 colorB = nextDelta;
rlm@1 159
rlm@1 160 product = ((((colorA & colorMask) >> 1) +
rlm@1 161 ((colorB & colorMask) >> 1) +
rlm@1 162 (colorA & colorB & lowPixelMask)));
rlm@1 163
rlm@1 164 *(dP + 2) = product;
rlm@1 165 *(dP + 3) = product;
rlm@1 166 *(nL + 2) = product;
rlm@1 167 *(nL + 3) = product;
rlm@1 168
rlm@1 169 nextPixel = *bP++;
rlm@1 170 nextDelta = *xP++;
rlm@1 171
rlm@1 172 dP += 4;
rlm@1 173 nL += 4;
rlm@1 174 }
rlm@1 175 while ((u8 *) bP < finish);
rlm@1 176
rlm@1 177 deltaPtr += srcPitch;
rlm@1 178 srcPtr += srcPitch;
rlm@1 179 dstPtr += dstPitch << 1;
rlm@1 180 nextLine += dstPitch << 1;
rlm@1 181 }
rlm@1 182 while (--height);
rlm@1 183 }