def fix_corners(surface, corner_size, bg_color, colorkey):
    """Remove pixels outside rounded corners."""
    pixels = []
    w, h = corner_size
    if colorkey:
        colorkey = *colorkey, 0
    for y in range(h):
        for x in range(w):
            if surface.get_at((x, y)) == bg_color:
                pixels.append((x, y))
                continue
            break
    for y in range(surface.get_height() - h, surface.get_height()):
        for x in range(w):
            if surface.get_at((x, y)) == bg_color:
                pixels.append((x, y))
                continue
            break
    for y in range(h):
        for x in reversed(range(surface.get_width() - w, surface.get_width())):
            if surface.get_at((x, y)) == bg_color:
                pixels.append((x, y))
                continue
            break
    for y in range(surface.get_height() - h, surface.get_height()):
        for x in reversed(range(surface.get_width() - w, surface.get_width())):
            if surface.get_at((x, y)) == bg_color:
                pixels.append((x, y))
                continue
            break
    for pixel in pixels:
        surface.set_at(pixel, colorkey)
    surface.set_colorkey(colorkey)
