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

Re: [pygame] Rotation Performance



Bram,

Maybe sending this to you now is too late to be helpful, but I put together a GIF rotation demo and attached it to this e-mail. It shows use of a fast image caching technique throughout. Also, lines 23-28 demonstrate a work-around for the Surface.convert method's tendency to lose colorkey information if the GIF's colorkey color has the same RGB values as another color in the GIF's palette. (At least I think that's what was happening when I was using convert.) Lines 39-56 keep the rotated images the same size as the source image; only use this technique if you're rotating an image that is blank in its corners. Lastly, manual control of garbage collection timing (as shown in lines 3, 127 and 144) improves the smoothness of the animation.

Jason


From: Bram Cymet <bcymet@xxxxxxxxx>
To: pygame-users@xxxxxxxx
Cc: Brian Fisher <brian@xxxxxxxxxxxxxxxxxxx>
Sent: Thu, January 21, 2010 10:57:00 AM
Subject: Re: [pygame] Rotation Performance

Thanks everyone for the help. I used the suggestion of caching the rotations and that works really well. 

On 01/21/2010 11:55 AM, Brian Fisher wrote:
.2 seconds to rotate an image sounds ridiculously long - that sounds broken. Are you sure it can take that long just to do the rotation?

How big is this image?

Can you share a minimal sample (like 1 file + the image) that does the rotations and prints out the timings, which goes really slow for you? If you do that, then others can run it as well to see if they get the same slowness you do.


On Wed, Jan 20, 2010 at 5:08 PM, Bram Cymet <bcymet@xxxxxxxxx> wrote:
Hi All,

I did some profiling of my pygame application and I found that it was
spending a lot of time doing rotation operations. Basically I have some
balls on the screen that are represented by gifs with transparent
backgrounds and I want to make them spin.

I use the following code:


These first two lines are only run in init for the object
    self.image = pygame.image.load('image.gif')
    self.image = self.image.convert()

 self.image = pygame.transform.rotate(self.image, degrees)
 self.rect = self.image.get_rect()

Then I return the rect and blit and update that part of the screen. A
lot of time is spent on that pygame.transform.rotate command. On my
laptop with a dual core 2.2 ghz processor if works fine. However on the
target hardware which is:

Atom 330 (dual core 1.6 ghz) with an ION chipset and graphics

it runs very slow and can take up to 0.2 seconds to execute just that
one line of code.

Is there something I am doing wrong? Is there some way I can make this
faster.

I am not sure if it matters but just for the sake of completeness: the
application is multi-threaded but only one thread is running during this
part of the application.

Any help would be great.

Thanks,

--
Bram Cymet
Software Developer
Canadian Bank Note Co. Ltd.
Cell: 613-608-9752





-- 
Bram Cymet
Software Developer
Canadian Bank Note Co. Ltd.
Cell: 613-608-9752


Attachment: ball.zip
Description: Zip archive