Python Pixel Manipulation Library
So, I'm looking at the early stages of building a game in Python, and I'm looking for a library that can manipulate and shine pixels relatively quickly.
My first thought was pygame as it deals with clean 2D surfaces, but it only allows access to pixels through pygame.get_at()
, pygame.set_at()
and pygame.get_buffer()
, all of which block the surface every time they are called making them slow to use. I can also use the PixelArray
and classes surfarray
, but they are locked for the duration of their life, and the only way to fire them up on the surface is to either copy the pixels to a new surface, or use surfarray.blit_array
, which requires creating a sub-surface of the screen and mixing with it if the array is smaller than the screen (if more, I can just use a slice of the array, which is no problem).
I don't have much experience with PyOpenGL or Pyglet, but I'm wondering if there is a faster library for handling pixels or if there is a faster method in Pygame for generating pixel manipulation. I've done some work with SDL and OpenGL in C and I love the idea of adding vertex / fragment shaders to my program.
My program will mainly deal with image loading and writing / reading to / from surfaces.
a source to share
Have you tried Python Imaging Library ? You will still have to pipe data back to pygame via buffer or somesuch to do blitting, but PIL can handle pixel access.
a source to share
I tested pie and saw that it works well for static collision per pixel when the image is manipulated too little; however I am not sure how well it works with a dynamic image.
In short, I am looking for a library capable of quickly rendering a pixel buffer. This buffer will be constantly changing, so fast access and blits are needed. This can be done in C with relative ease using SDL; however, I am looking for a similar method in Python. I'm not even too worried about hardware acceleration at the moment, although that would be nice.
a source to share
Check Python Bindings Simple and fast multimedia library . From its documentation :
It implements the same 2D drawings and OpenGL-related functionality (see their sf :: RenderTarget base class for details ), the difference is that the result is stored in an off-screen texture rather than being displayed in the window.
Texture rendering can be useful in a variety of situations:
- pre-compute complex static texture (e.g. background level from multiple fragments)
- applying post effects to the entire scene with shaders
- creating a sprite from a 3D object created with OpenGL
- and etc.
Also check that the methods contain and intersect the sf :: Rect <T> Class template .
a source to share