# 2D and 3D direct pixel access

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

  2D `MemoryView` for `SoftwareSprite` and `sdl2.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

  `PixelView` is implemented on top of the `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.``pixels2d`(source : object)

  Creates a 2D pixel array, based on `numpy.ndarray`, from the passed source. source can be a `SoftwareSprite` or `sdl2.SDL_Surface`. The `SDL_Surface` of the source 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.``pixels3d`(source : object)

  Creates a 3D pixel array, based on `numpy.ndarray`, from the passed source. source can be a `SoftwareSprite` or `sdl2.SDL_Surface`. The `SDL_Surface` of the source 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.