Mercurial > sdl-ios-xcode
comparison src/video/sdlgenblit.pl @ 1989:5b5f5de5433f
Optimized the copy blitters a little bit
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 28 Aug 2006 14:10:46 +0000 |
parents | 8055185ae4ed |
children | 7387e0514595 |
comparison
equal
deleted
inserted
replaced
1988:1ee02169bbb0 | 1989:5b5f5de5433f |
---|---|
123 sub output_copydefs | 123 sub output_copydefs |
124 { | 124 { |
125 print FILE <<__EOF__; | 125 print FILE <<__EOF__; |
126 #define SDL_RENDERCOPY_MODULATE_COLOR 0x0001 | 126 #define SDL_RENDERCOPY_MODULATE_COLOR 0x0001 |
127 #define SDL_RENDERCOPY_MODULATE_ALPHA 0x0002 | 127 #define SDL_RENDERCOPY_MODULATE_ALPHA 0x0002 |
128 #define SDL_RENDERCOPY_BLEND 0x0010 | 128 #define SDL_RENDERCOPY_MASK 0x0010 |
129 #define SDL_RENDERCOPY_ADD 0x0020 | 129 #define SDL_RENDERCOPY_BLEND 0x0020 |
130 #define SDL_RENDERCOPY_MOD 0x0040 | 130 #define SDL_RENDERCOPY_ADD 0x0040 |
131 #define SDL_RENDERCOPY_MOD 0x0080 | |
131 #define SDL_RENDERCOPY_NEAREST 0x0100 | 132 #define SDL_RENDERCOPY_NEAREST 0x0100 |
132 | 133 |
133 typedef struct { | 134 typedef struct { |
134 void *src; | 135 void *src; |
135 int src_w, src_h; | 136 int src_w, src_h; |
212 { | 213 { |
213 my $src = shift; | 214 my $src = shift; |
214 my $dst = shift; | 215 my $dst = shift; |
215 my $modulate = shift; | 216 my $modulate = shift; |
216 my $blend = shift; | 217 my $blend = shift; |
218 my $s = ""; | |
219 my $d = ""; | |
220 | |
221 # Nice and easy... | |
222 if ( $src eq $dst && !$modulate && !$blend ) { | |
223 print FILE <<__EOF__; | |
224 *dst = *src; | |
225 __EOF__ | |
226 return; | |
227 } | |
228 | |
229 if ( $blend ) { | |
230 get_rgba("src", $src); | |
231 get_rgba("dst", $dst); | |
232 $s = "src"; | |
233 $d = "dst"; | |
234 } else { | |
235 get_rgba("", $src); | |
236 } | |
237 | |
217 if ( $modulate ) { | 238 if ( $modulate ) { |
218 print FILE <<__EOF__; | 239 print FILE <<__EOF__; |
219 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) { | 240 if (flags & SDL_RENDERCOPY_MODULATE_COLOR) { |
220 ${src}R = (${src}R * modulateR) / 255; | 241 ${s}R = (${s}R * modulateR) / 255; |
221 ${src}G = (${src}G * modulateG) / 255; | 242 ${s}G = (${s}G * modulateG) / 255; |
222 ${src}B = (${src}B * modulateB) / 255; | 243 ${s}B = (${s}B * modulateB) / 255; |
223 } | 244 } |
224 __EOF__ | |
225 } | |
226 if ( $modulate && $blend ) { | |
227 print FILE <<__EOF__; | |
228 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) { | 245 if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) { |
229 ${src}A = (${src}A * modulateA) / 255; | 246 ${s}A = (${s}A * modulateA) / 255; |
230 } | 247 } |
231 __EOF__ | 248 __EOF__ |
232 } | 249 } |
233 if ( $blend ) { | 250 if ( $blend ) { |
234 print FILE <<__EOF__; | 251 print FILE <<__EOF__; |
235 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) { | 252 if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) { |
236 /* This goes away if we ever use premultiplied alpha */ | 253 /* This goes away if we ever use premultiplied alpha */ |
237 ${src}R = (${src}R * ${src}A) / 255; | 254 if (${s}A < 255) { |
238 ${src}G = (${src}G * ${src}A) / 255; | 255 ${s}R = (${s}R * ${s}A) / 255; |
239 ${src}B = (${src}B * ${src}A) / 255; | 256 ${s}G = (${s}G * ${s}A) / 255; |
240 } | 257 ${s}B = (${s}B * ${s}A) / 255; |
241 switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) { | 258 } |
259 } | |
260 switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) { | |
261 case SDL_RENDERCOPY_MASK: | |
262 if (${s}A) { | |
263 ${d}R = ${s}R; | |
264 ${d}G = ${s}G; | |
265 ${d}B = ${s}B; | |
266 } | |
267 break; | |
242 case SDL_RENDERCOPY_BLEND: | 268 case SDL_RENDERCOPY_BLEND: |
243 ${dst}R = ${src}R + ((255 - ${src}A) * ${dst}R) / 255; | 269 ${d}R = ${s}R + ((255 - ${s}A) * ${d}R) / 255; |
244 ${dst}G = ${src}G + ((255 - ${src}A) * ${dst}G) / 255; | 270 ${d}G = ${s}G + ((255 - ${s}A) * ${d}G) / 255; |
245 ${dst}B = ${src}B + ((255 - ${src}A) * ${dst}B) / 255; | 271 ${d}B = ${s}B + ((255 - ${s}A) * ${d}B) / 255; |
246 break; | 272 break; |
247 case SDL_RENDERCOPY_ADD: | 273 case SDL_RENDERCOPY_ADD: |
248 ${dst}R = ${src}R + ${dst}R; if (${dst}R > 255) ${dst}R = 255; | 274 ${d}R = ${s}R + ${d}R; if (${d}R > 255) ${d}R = 255; |
249 ${dst}G = ${src}G + ${dst}G; if (${dst}G > 255) ${dst}G = 255; | 275 ${d}G = ${s}G + ${d}G; if (${d}G > 255) ${d}G = 255; |
250 ${dst}B = ${src}B + ${dst}B; if (${dst}B > 255) ${dst}B = 255; | 276 ${d}B = ${s}B + ${d}B; if (${d}B > 255) ${d}B = 255; |
251 break; | 277 break; |
252 case SDL_RENDERCOPY_MOD: | 278 case SDL_RENDERCOPY_MOD: |
253 ${dst}R = (${src}R * ${dst}R) / 255; | 279 ${d}R = (${s}R * ${d}R) / 255; |
254 ${dst}G = (${src}G * ${dst}G) / 255; | 280 ${d}G = (${s}G * ${d}G) / 255; |
255 ${dst}B = (${src}B * ${dst}B) / 255; | 281 ${d}B = (${s}B * ${d}B) / 255; |
256 break; | 282 break; |
257 } | 283 } |
258 __EOF__ | 284 __EOF__ |
285 } | |
286 if ( $blend ) { | |
287 set_rgba("dst", $dst); | |
288 } else { | |
289 set_rgba("", $dst); | |
259 } | 290 } |
260 } | 291 } |
261 | 292 |
262 sub output_copyfunc | 293 sub output_copyfunc |
263 { | 294 { |
323 src = ($format_type{$src} *)(data->src + (srcy * data->src_pitch) + (srcx * $format_size{$src})); | 354 src = ($format_type{$src} *)(data->src + (srcy * data->src_pitch) + (srcx * $format_size{$src})); |
324 __EOF__ | 355 __EOF__ |
325 print FILE <<__EOF__; | 356 print FILE <<__EOF__; |
326 } | 357 } |
327 __EOF__ | 358 __EOF__ |
328 if ( $blend ) { | 359 output_copycore($src, $dst, $modulate, $blend); |
329 get_rgba("src", $src); | |
330 get_rgba("dst", $dst); | |
331 output_copycore("src", "dst", $modulate, $blend); | |
332 set_rgba("dst", $dst); | |
333 } elsif ( $modulate || $src ne $dst ) { | |
334 get_rgba("", $src); | |
335 output_copycore("", "", $modulate, $blend); | |
336 set_rgba("", $dst); | |
337 } else { | |
338 print FILE <<__EOF__; | |
339 *dst = *src; | |
340 __EOF__ | |
341 } | |
342 print FILE <<__EOF__; | 360 print FILE <<__EOF__; |
343 posx += incx; | 361 posx += incx; |
344 ++dst; | 362 ++dst; |
345 } | 363 } |
346 posy += incy; | 364 posy += incy; |
354 $format_type{$src} *src = ($format_type{$src} *)data->src; | 372 $format_type{$src} *src = ($format_type{$src} *)data->src; |
355 $format_type{$dst} *dst = ($format_type{$dst} *)data->dst; | 373 $format_type{$dst} *dst = ($format_type{$dst} *)data->dst; |
356 int n = data->dst_w; | 374 int n = data->dst_w; |
357 while (n--) { | 375 while (n--) { |
358 __EOF__ | 376 __EOF__ |
359 if ( $blend ) { | 377 output_copycore($src, $dst, $modulate, $blend); |
360 get_rgba("src", $src); | |
361 get_rgba("dst", $dst); | |
362 output_copycore("src", "dst", $modulate, $blend); | |
363 set_rgba("dst", $dst); | |
364 } elsif ( $modulate || $src ne $dst ) { | |
365 get_rgba("", $src); | |
366 output_copycore("", "", $modulate, $blend); | |
367 set_rgba("", $dst); | |
368 } else { | |
369 print FILE <<__EOF__; | |
370 *dst = *src; | |
371 __EOF__ | |
372 } | |
373 print FILE <<__EOF__; | 378 print FILE <<__EOF__; |
374 ++src; | 379 ++src; |
375 ++dst; | 380 ++dst; |
376 } | 381 } |
377 data->src += data->src_pitch; | 382 data->src += data->src_pitch; |