2D and 3D direct pixel access
- class sdl2.ext.PixelView(source: object)[source]
2D
MemoryViewforSoftwareSpriteandsdl2.SDL_surfacepixel access.Note
If necessary, the source surface will be locked for accessing its pixel data. The lock will be removed once the
PixelViewis garbage-collected or deleted.The
PixelViewuses a y/x-layout. Accessingview[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
PixelViewis implemented on top of theMemoryViewclass. 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 asnumpy.
- sdl2.ext.pixels2d(source: object, transpose: bool)
Creates a 2D pixel array, based on
numpy.ndarray, from the passed source. source can be aSoftwareSpriteorsdl2.SDL_Surface. TheSDL_Surfaceof the source will be locked and unlocked automatically.By default, the returned array is formatted so that the first dimension corresponds to height on the source and the second dimension corresponds to width, contrary to PIL and PyOpenGL convention. To obtain an array where the first dimension is width and second dimension is height, set the transpose argument to False.
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, asdl2.ext.compat.UnsupportedErrorwill be raised.
- sdl2.ext.pixels3d(source: object, transpose: bool)
Creates a 3D pixel array, based on
numpy.ndarray, from the passed source. source can be aSoftwareSpriteorsdl2.SDL_Surface. TheSDL_Surfaceof the source will be locked and unlocked automatically.By default, the returned array is formatted so that the first dimension corresponds to height on the source and the second dimension corresponds to width, contrary to PIL and PyOpenGL convention. To obtain an array where the first dimension is width and second dimension is height, set the transpose argument to False.
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, asdl2.ext.compat.UnsupportedErrorwill be raised.