sdl2.ext.pixelaccess - 2D and 3D direct pixel access

class sdl2.ext.pixelaccess.PixelView(source : object)

2D sdl2.ext.array.MemoryView for sdl2.ext.sprite.SoftwareSprite and sdl2.surface.SDL_surface pixel access.

Note

If necessary, the source surface will be locked for accessing its pixel data. The lock will be removed once the PixelView is garbage-collected or deleted.

The PixelView?  uses a y/x-layout. Accessing ``view[N]` will operate on the Nth row of the underlying surface. To access a specific column within that row, view[N][C] has to be used.

Note

:class`PixelView` is implemented on top of the sdl2.ext.array.MemoryView class. As such it makes heavy use of recursion to access rows and columns and can be considered as slow in contrast to optimised ndim-array solutions such as numpy.

sdl2.ext.pixelaccess.pixels2d(source : object)

Creates a 2D pixel array, based on numpy.ndarray, from the passed source. source can be a sdl2.ext.sprite.SoftwareSprite or sdl2.surface.SDL_Surface. The source its SDL_Surface will be locked and unlocked automatically.

The source pixels will be accessed and manipulated directly.

Note

pixels2d() is only usable, if the numpy package is available within the target environment. If numpy could not be imported, a sdl2.ext.compat.UnsupportedError will be raised.

sdl2.ext.pixelaccess.pixels3d(source : object)

Creates a 3D pixel array, based on numpy.ndarray, from the passed source. source can be a sdl2.ext.sprite.SoftwareSprite or sdl2.surface.SDL_Surface. The source its SDL_Surface will be locked and unlocked automatically.

The source pixels will be accessed and manipulated directly.

Note

pixels3d() is only usable, if the numpy package is available within the target environment. If numpy could not be imported, a sdl2.ext.compat.UnsupportedError will be raised.

Previous topic

sdl2.ext.particles - A simple particle system

Next topic

sdl2.ext.resources - Resource management

This Page