Debian Codegraph @

plugins/actor/oinksie/gfx-blur.c

raw
1 /* Libvisual-plugins - Standard plugins for libvisual
2 *
3 * Copyright (C) 2002, 2003, 2004, 2005, 2006 Dennis Smit <[email protected]>
4 *
5 * Authors: Dennis Smit <[email protected]>
6 *
7 * $Id: gfx-blur.c,v 1.12 2006/02/05 18:47:26 synap Exp $
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include "common.h"
25 #include "gfx-blur.h"
26
27 #include "gfx-misc.h"
28 #include "screen.h"
29
30 void _oink_gfx_blur_fade (OinksiePrivate *priv, uint8_t *buf, int fade)
31 {
32 int i;
33 uint8_t valuetab[256];
34
35 if (visual_cpu_get_mmx ()) {
36 #if defined(VISUAL_ARCH_X86) || defined(VISUAL_ARCH_X86_64)
37 int fadeflag = fade | fade << 8 | fade << 16 | fade << 24;
38
39 /* Prepare substraction register */
40 __asm __volatile
41 ("\n\t movd %[fade], %%mm3"
42 "\n\t movd %[fade], %%mm4"
43 "\n\t psllq $32, %%mm3"
44 "\n\t por %%mm4, %%mm3"
45 :: [fade] "m" (fadeflag));
46
47
48 for (i = 0; i < priv->screen_size; i += 8) {
49 __asm __volatile
50 ("\n\t movq %[buf], %%mm0"
51 "\n\t psubsb %%mm3, %%mm0"
52 "\n\t movq %%mm0, %[buf]"
53 :: [buf] "m" (*buf));
54 }
55
56 __asm __volatile
57 ("\n\t emms");
58 #endif
59 } else {
60 for (i = 0; i < 256; i++)
61 valuetab[i] = (i - fade) > 0 ? i - fade : 0;
62
63 for (i = 0; i < priv->screen_size; i++) {
64 *buf = valuetab[*buf];
65 buf++;
66 }
67 }
68 }
69
70 /* FIXME also make mmx versions for these, let's rock this babe! */
71 void _oink_gfx_blur_simple (OinksiePrivate *priv, uint8_t *buf)
72 {
73 int i;
74
75 for (i = 0; i < (priv->screen_size - priv->screen_width - 1); i++)
76 {
77 buf[i] = (buf[i + 1] + buf[i + 2] + buf[i + priv->screen_width]
78 + buf[i + 1 + (priv->screen_width)]) >> 2;
79 }
80
81 for (i = (priv->screen_size - priv->screen_width - 1); i < priv->screen_size - 2; i++)
82 {
83 buf[i] = (buf[i + 1] + buf[i + 2]) >> 1;
84 }
85 }
86
87 void _oink_gfx_blur_middle (OinksiePrivate *priv, uint8_t *buf)
88 {
89 int i;
90 int scrsh = priv->screen_size / 2;
91
92 if (visual_cpu_get_mmx ()) {
93 #if defined(VISUAL_ARCH_X86) || defined(VISUAL_ARCH_X86_64)
94 __asm __volatile
95 ("\n\t pxor %%mm6, %%mm6"
96 ::);
97
98 for (i = 0; i < scrsh; i += 4) {
99 __asm __volatile
100 ("\n\t movd %[buf], %%mm0"
101 "\n\t movd %[add1], %%mm1"
102 "\n\t punpcklbw %%mm6, %%mm0"
103 "\n\t movd %[add2], %%mm2"
104 "\n\t punpcklbw %%mm6, %%mm1"
105 "\n\t movd %[add3], %%mm3"
106 "\n\t punpcklbw %%mm6, %%mm2"
107 "\n\t paddw %%mm1, %%mm0"
108 "\n\t punpcklbw %%mm6, %%mm3"
109 "\n\t paddw %%mm2, %%mm0"
110 "\n\t paddw %%mm3, %%mm0"
111 "\n\t psrlw $2, %%mm0"
112 "\n\t packuswb %%mm6, %%mm0"
113 "\n\t movd %%mm0, %[buf]"
114 :: [buf] "m" (*(buf + i))
115 , [add1] "m" (*(buf + i + priv->screen_width))
116 , [add2] "m" (*(buf + i + priv->screen_width + 1))
117 , [add3] "m" (*(buf + i + priv->screen_width - 1)));
118 }
119
120 for (i = priv->screen_size - 1; i > scrsh; i -= 4) {
121 __asm __volatile
122 ("\n\t movd %[buf], %%mm0"
123 "\n\t movd %[add1], %%mm1"
124 "\n\t punpcklbw %%mm6, %%mm0"
125 "\n\t movd %[add2], %%mm2"
126 "\n\t punpcklbw %%mm6, %%mm1"
127 "\n\t movd %[add3], %%mm3"
128 "\n\t punpcklbw %%mm6, %%mm2"
129 "\n\t paddw %%mm1, %%mm0"
130 "\n\t punpcklbw %%mm6, %%mm3"
131 "\n\t paddw %%mm2, %%mm0"
132 "\n\t paddw %%mm3, %%mm0"
133 "\n\t psrlw $2, %%mm0"
134 "\n\t packuswb %%mm6, %%mm0"
135 "\n\t movd %%mm0, %[buf]"
136 :: [buf] "m" (*(buf + i))
137 , [add1] "m" (*(buf + i - priv->screen_width))
138 , [add2] "m" (*(buf + i - priv->screen_width + 1))
139 , [add3] "m" (*(buf + i - priv->screen_width - 1)));
140 }
141
142 __asm __volatile
143 ("\n\t emms");
144 #endif
145 } else {
146 for (i = 0; i < scrsh; i++)
147 {
148 *(buf + i) = (*(buf + i)
149 + *(buf + i + priv->screen_width)
150 + *(buf + i + priv->screen_width + 1)
151 + *(buf + i + priv->screen_width - 1)) >> 2;
152 }
153
154 for (i = priv->screen_size - 1; i > scrsh; i--)
155 {
156 *(buf + i) = (*(buf + i)
157 + *(buf + i - priv->screen_width)
158 + *(buf + i - priv->screen_width + 1)
159 + *(buf + i - priv->screen_width - 1)) >> 2;
160 }
161 }
162 }
163
164 void _oink_gfx_blur_midstrange (OinksiePrivate *priv, uint8_t *buf)
165 {
166 int i;
167 int scrsh = priv->screen_size / 2;
168
169 if (visual_cpu_get_mmx ()) {
170 #if defined(VISUAL_ARCH_X86) || defined(VISUAL_ARCH_X86_64)
171 __asm __volatile
172 ("\n\t pxor %%mm6, %%mm6"
173 ::);
174
175 for (i = scrsh; i > 0; i -= 4) {
176 __asm __volatile
177 ("\n\t movd %[buf], %%mm0"
178 "\n\t movd %[add1], %%mm1"
179 "\n\t punpcklbw %%mm6, %%mm0"
180 "\n\t movd %[add2], %%mm2"
181 "\n\t punpcklbw %%mm6, %%mm1"
182 "\n\t movd %[add3], %%mm3"
183 "\n\t punpcklbw %%mm6, %%mm2"
184 "\n\t paddw %%mm1, %%mm0"
185 "\n\t punpcklbw %%mm6, %%mm3"
186 "\n\t paddw %%mm2, %%mm0"
187 "\n\t paddw %%mm3, %%mm0"
188 "\n\t psrlw $2, %%mm0"
189 "\n\t packuswb %%mm6, %%mm0"
190 "\n\t movd %%mm0, %[buf]"
191 :: [buf] "m" (*(buf + i))
192 , [add1] "m" (*(buf + i + priv->screen_width))
193 , [add2] "m" (*(buf + i + priv->screen_width + 1))
194 , [add3] "m" (*(buf + i + priv->screen_width - 1)));
195 }
196
197 for (i = scrsh; i < priv->screen_size - 2; i += 4) {
198 __asm __volatile
199 ("\n\t movd %[buf], %%mm0"
200 "\n\t movd %[add1], %%mm1"
201 "\n\t punpcklbw %%mm6, %%mm0"
202 "\n\t movd %[add2], %%mm2"
203 "\n\t punpcklbw %%mm6, %%mm1"
204 "\n\t movd %[add3], %%mm3"
205 "\n\t punpcklbw %%mm6, %%mm2"
206 "\n\t paddw %%mm1, %%mm0"
207 "\n\t punpcklbw %%mm6, %%mm3"
208 "\n\t paddw %%mm2, %%mm0"
209 "\n\t paddw %%mm3, %%mm0"
210 "\n\t psrlw $2, %%mm0"
211 "\n\t packuswb %%mm6, %%mm0"
212 "\n\t movd %%mm0, %[buf]"
213 :: [buf] "m" (*(buf + i))
214 , [add1] "m" (*(buf + i - priv->screen_width))
215 , [add2] "m" (*(buf + i - priv->screen_width + 1))
216 , [add3] "m" (*(buf + i - priv->screen_width - 1)));
217 }
218
219 __asm __volatile
220 ("\n\t emms");
221 #endif
222 } else {
223
224 for (i = scrsh; i > 0; i--)
225 {
226 buf[i] = (buf[i]
227 + buf[i + priv->screen_width]
228 + buf[i + priv->screen_width + 1]
229 + buf[i + priv->screen_width - 1]) >> 2;
230 }
231
232 for (i = scrsh; i < priv->screen_size - 2; i++)
233 {
234 buf[i] = (buf[i]
235 + buf[i - priv->screen_width]
236 + buf[i - priv->screen_width + 1]
237 + buf[i - priv->screen_width - 1]) >> 2;
238 }
239 }
240 }
241