[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Rotation Performance
Some thoughts:
- You might try using rotozoom, which probably isn't faster, but will give you much better quality.
- Don't rotate a single image/surface multiple times, as rotation is lossy, and will make the surface grow much larger than necessary. Instead only rotate from the original image each time.
- As mentioned, pre-caching the rotated surfaces will perform much much better than rotating in real-time. This is a classic space for time trade, which is usually a win nowadays.
- If you must do the rotation in real-time, consider using OpenGL which can take advantage of hardware acceleration where available. Real-time rotation with even a cheapo graphics processor is practically free nowadays.
-Casey
On Jan 20, 2010, at 6:08 PM, Bram Cymet 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
>
>