1 // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
2 // Copyright (C) 1999-2003 Forgotten
3 // Copyright (C) 2004 Forgotten and the VBA development team
4
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2, or(at your option)
8 // any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 /*
20 * Code adapted To OpenBOR by SX
21 * motionblur.c - Trying to scale 2x and applying blur.
22 *
23 * Updated: 5/05/08 - SX
24 *
25 */
26
27 #include "borendian.h"
28 #include "gfxtypes.h"
29
MotionBlur(u8 * srcPtr,u32 srcPitch,u8 * deltaPtr,u8 * dstPtr,u32 dstPitch,int width,int height)30 void MotionBlur(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, u8 *dstPtr, u32 dstPitch, int width, int height)
31 {
32 u8 *nextLine, *finish;
33 u32 colorMask = ~(RGB_LOW_BITS_MASK | (RGB_LOW_BITS_MASK << 16));
34 u32 lowPixelMask = RGB_LOW_BITS_MASK;
35
36 nextLine = dstPtr + dstPitch;
37
38 do
39 {
40 u32 *bP = (u32 *) srcPtr;
41 u32 *xP = (u32 *) deltaPtr;
42 u32 *dP = (u32 *) dstPtr;
43 u32 *nL = (u32 *) nextLine;
44 u32 currentPixel;
45 u32 nextPixel;
46 u32 currentDelta;
47 u32 nextDelta;
48
49 finish = (u8 *) bP + ((width+2) << 1);
50 nextPixel = *bP++;
51 nextDelta = *xP++;
52
53 do
54 {
55 currentPixel = nextPixel;
56 currentDelta = nextDelta;
57 nextPixel = *bP++;
58 nextDelta = *xP++;
59
60 if(currentPixel != currentDelta)
61 {
62 u32 colorA, product, colorB;
63
64 *(xP - 2) = currentPixel;
65
66 #ifdef BOR_BIG_ENDIAN
67 colorA = currentPixel >> 16;
68 colorB = currentDelta >> 16;
69 #else
70 colorA = currentPixel & 0xffff;
71 colorB = currentDelta & 0xffff;
72 #endif
73
74 product = ((((colorA & colorMask) >> 1) + ((colorB & colorMask) >> 1) + (colorA & colorB & lowPixelMask)));
75
76 *(dP) = product | product << 16;
77 *(nL) = product | product << 16;
78
79 #ifdef BOR_BIG_ENDIAN
80 colorA = (currentPixel & 0xffff);
81 colorB = (currentDelta & 0xffff);
82 #else
83 colorA = currentPixel >> 16;
84 colorB = currentDelta >> 16;
85 #endif
86 product = ((((colorA & colorMask) >> 1) + ((colorB & colorMask) >> 1) + (colorA & colorB & lowPixelMask)));
87
88 *(dP + 1) = product | product << 16;
89 *(nL + 1) = product | product << 16;
90 }
91 else
92 {
93 u32 colorA, product;
94
95 *(xP - 2) = currentPixel;
96
97 #ifdef BOR_BIG_ENDIAN
98 colorA = currentPixel >> 16;
99 #else
100 colorA = currentPixel & 0xffff;
101 #endif
102
103 product = colorA;
104
105 *(dP) = product | product << 16;
106 *(nL) = product | product << 16;
107
108 #ifdef BOR_BIG_ENDIAN
109 colorA = (currentPixel & 0xffff);
110 #else
111 colorA = currentPixel >> 16;
112 #endif
113 product = colorA;
114
115 *(dP + 1) = product | product << 16;
116 *(nL + 1) = product | product << 16;
117 }
118
119 dP += 2;
120 nL += 2;
121 }
122 while ((u8 *) bP < finish);
123
124 deltaPtr += srcPitch;
125 srcPtr += srcPitch;
126 dstPtr += dstPitch << 1;
127 nextLine += dstPitch << 1;
128 }
129 while (--height);
130 }
131
MotionBlur32(u8 * srcPtr,u32 srcPitch,u8 * deltaPtr,u8 * dstPtr,u32 dstPitch,int width,int height)132 void MotionBlur32(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, u8 *dstPtr, u32 dstPitch, int width, int height)
133 {
134 u8 *nextLine, *finish;
135 u32 colorMask = ~RGB_LOW_BITS_MASK;
136 u32 lowPixelMask = RGB_LOW_BITS_MASK;
137
138 nextLine = dstPtr + dstPitch;
139
140 do
141 {
142 u32 *bP = (u32 *) srcPtr;
143 u32 *xP = (u32 *) deltaPtr;
144 u32 *dP = (u32 *) dstPtr;
145 u32 *nL = (u32 *) nextLine;
146 u32 currentPixel;
147 u32 nextPixel;
148 u32 currentDelta;
149 u32 nextDelta;
150
151 finish = (u8 *) bP + ((width+1) << 2);
152 nextPixel = *bP++;
153 nextDelta = *xP++;
154
155 do
156 {
157 u32 colorA, product, colorB;
158
159 currentPixel = nextPixel;
160 currentDelta = nextDelta;
161 nextPixel = *bP++;
162 nextDelta = *xP++;
163
164 *(xP - 2) = currentPixel;
165 colorA = currentPixel;
166 colorB = currentDelta;
167
168 product = ((((colorA & colorMask) >> 1) + ((colorB & colorMask) >> 1) + (colorA & colorB & lowPixelMask)));
169
170 *(dP) = product;
171 *(dP+1) = product;
172 *(nL) = product;
173 *(nL+1) = product;
174
175 *(xP - 1) = nextPixel;
176
177 colorA = nextPixel;
178 colorB = nextDelta;
179
180 product = ((((colorA & colorMask) >> 1) + ((colorB & colorMask) >> 1) + (colorA & colorB & lowPixelMask)));
181
182 *(dP + 2) = product;
183 *(dP + 3) = product;
184 *(nL + 2) = product;
185 *(nL + 3) = product;
186
187 nextPixel = *bP++;
188 nextDelta = *xP++;
189
190 dP += 4;
191 nL += 4;
192 }
193 while ((u8 *) bP < finish);
194
195 deltaPtr += srcPitch;
196 srcPtr += srcPitch;
197 dstPtr += dstPitch << 1;
198 nextLine += dstPitch << 1;
199 }
200 while (--height);
201 }
202