Faster than PyGame for displaying a large image?

I use PyGame to display images (photos). For large image sizes, the loading and conversion process is slow (for example, it takes 2-3 seconds for an image of 6000x4485 size). Actual code that is slow:

image = pg.image.load(fname).convert() 

Is there an alternative library or method that will give better performance? My target platforms are windows7 and os x, and I'm fine with separate solutions for each (although one solution would be better).

+8
python image image-processing pygame
source share
3 answers

If your jpeg library supports it, you can set the scaling options. You probably don't need to display a 6kx4k image if you display it on the screen, and it can speed up several times.

http://jpegclub.org/djpeg/

+3
source share

You might be lucky using a GUI library like TkInter or GTK + on top of PyGame. If you need to use a game library, you might like PyGlet. For PyGame, someone said it speeds it up: comments.gmane.org/gmane.comp.python.pygame/9015. You can also check out libjpeg-turbo as stated in the comments on libjpeg-turbo.virtualgl.org. But, as I said, you might be better off using a GUI library or porting everything to C / C ++ to avoid multilingual calls. Good luck

0
source share

You can try PyTurboJPEG , which is a Python libjpeg-turbo shell with insanely fast scaling (1/2, 1/4, 1/8) when decoding a large JPEG image, as shown below,

 import pygame from turbojpeg import TurboJPEG # specifying library path explicitly # jpeg = TurboJPEG(r'D:\turbojpeg.dll') # jpeg = TurboJPEG('/usr/lib64/libturbojpeg.so') # jpeg = TurboJPEG('/usr/local/lib/libturbojpeg.dylib') # using default library installation jpeg = TurboJPEG() # direct rescaling 1/2 while decoding input.jpg to RGBA pixel array pixel_array = jpeg.decode( open('input.jpg', 'rb').read(), pixel_format=TJPF_RGBA, scaling_factor=(1, 2)) height, width, _ = pixel_array.shape image = pygame.image.frombuffer(pixel_array.data, (width, height), 'RGBA') 

libjpeg-turbo prebuilt binaries for macOS and Windows 7 are also available here .

0
source share

All Articles