def _convert_ascii_to_rgba()

in gym3/internal/renderer.py [0:0]


def _convert_ascii_to_rgba(arr: np.ndarray, size_px=32) -> np.ndarray:
    """
    Convert an ascii array to an image array using the loaded font
    """
    global FONT
    if FONT is None:
        FONT = np.load(os.path.join(SCRIPT_DIR, "font.bin"))

    charset = FONT[f"{size_px}px"]
    _, char_height, char_width = charset.shape
    height, width = arr.shape
    image = np.ones((height * char_height, width * char_width, 4), dtype=np.uint8) * 255
    for y in range(height):
        for x in range(width):
            ch = arr[y, x]
            image[
                y * char_height : (y + 1) * char_height,
                x * char_width : (x + 1) * char_width,
                3,
            ] = charset[ch]
    return image