def tile(srf, tile=0, cols=1, rows=1, padding=0):
    """Return a tile subsurface"""
    w, h = srf.get_size()
    n = cols * rows
    if tile < 0:
        tile += n
    if tile >= n or tile < 0:
        raise IndexError('tile index is out of range')
    w = w // cols
    h = h // rows
    x = tile % cols * w + padding
    y = tile // cols * h + padding
    padding *= 2
    return srf.subsurface(x, y, w - padding, h - padding)
