# TODO: refactor to only do a few pixels at a time because python is really slow
# Keeping this function here in the meantime because it wasn't easy to figure
# out how to write it.
def tensor_to_surface(source):
shape = source.shape
height = shape[0]
width = shape[1]
surface = sdl2.surface.SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0)
pixels = sdl2.ext.pixels2d(surface.contents, False)
# pixels are 4 bytes: b g r 0
for y in range(0,height):
row = source[y]
d_row = pixels[y]
for x in range(0,width):
pixel = row[x]
d_row[x] = pixel[0] * 65536 + pixel[1] * 256 + pixel[2]
print(y)
return surface