[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Benchmarking alpha blits (was Re: How do I make a image transparent?)



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Casey Duncan wrote:
> This is excellent work, thanks for doing it!
> 
> One unexpected observation:
> 
> 06-circle-alpha with colorkey+RLEACCEL is incredibly fast compared to
> 05-circle-noalpha, I wouldn't have expected that. Can anyone explain why
> this might be so? Was that actually blitting anything visible? Actually
> it would be useful to know which cases below result in no visible blit.

The following blits don't draw anything:

02-solid-noalpha, with colorkey
03-solid-alpha, with colorkey
04-solid-randalpha, with colorkey
06-circle-alpha, with colorkey

All of these images are RGB #3cff00, with varying alphas. After
convert(), they're all just solid images of #3cff00. This is why I
constructed 06-circle-alpha-diff. In 06-circle-alpha, the transparent
pixels are (60, 255, 0, 0) (i.e. #3cff00 with a fully-transparent
alpha); in 06-circle-alpha-diff they're the red color (#ff something
something) but fully transparent.

> Since blitting so dominates the performance of games, I think it's very
> important to understand the right way to create images performance-wise
> and the right way to optimize them in the software (using convert() and
> RLEACCEL, etc). I was able to see sizeable performance improvement in my
> own game by sprinkling image.set_alpha(0, RLEACCEL) calls around -- not
> knowing before you could use it with per-pixel alpha, or that it would
> help if I was blitting things fully opaque.

Yeah, as soon as I got these results I made some easy optimizations
too. I'm thinking about adding some RLEACCEL calls to some other
images too.

One other thing I just noticed is that if you look at 02-solid-noalpha:

convert only runs in 0.69166 seconds
nonimage colorkey RLEACCEL runs in 0.24440 seconds!

Any ideas why this happens? Both should be fully-opaque blits, and my
expectation would be that the nonimage colorkey would have to do more
work.

> I find it interesting how much faster colorkey+RLEACCEL can be too. It
> may not look as good at the edges, but in certain cases (like fast
> moving objects, etc) that may not matter much and the increased blitting
> speed is a worthwhile tradeoff.

Contrariwise, it's not that much slower:

05-circle-noalpha, colorkey+RLEACCEL: 0.121339
06-circle-alpha-diff, convert_alpha+RLEACCEL: 0.131071

So for some images, it might be worth it to leave per-pixel alpha on.

Ethan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG8r3fhRlgoLPrRPwRAhoZAJ46ZzLSXoPO7CWEyx2j+vEZ+f2WmQCfXOE2
kmSgF6WAwBECp27SPzbai2g=
=RiV9
-----END PGP SIGNATURE-----