File: surface.py

package info (click to toggle)
pysdl2 0.9.9%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,276 kB
  • sloc: python: 18,592; makefile: 148; sh: 40
file content (19 lines) | stat: -rw-r--r-- 805 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""Surface manipulation."""
from ..surface import SDL_CreateRGBSurfaceFrom

__all__ = ["subsurface"]

def subsurface(surface, area):
    """Creates a surface from a part of another surface.

    The two surfaces share pixel data. The subsurface *must not* be used after
    its parent has been freed!
    """
    surface_format = surface.format[0]
    subpixels = (surface.pixels + surface.pitch*area[1] +
                 surface_format.BytesPerPixel*area[0])
    return SDL_CreateRGBSurfaceFrom(subpixels, area[2], area[3],
                                    surface_format.BitsPerPixel,
                                    surface.pitch, surface_format.Rmask,
                                    surface_format.Gmask, surface_format.Bmask,
                                    surface_format.Amask)[0]