The ST7735 module internally converts a PIL image to a buffer of 16-bit 565 RGB bytes for writing to the display. When tested in isolation, the following version is 3x faster:
def image_to_data(image, rotation=0):
"""Generator function to convert a PIL image to 16-bit 565 RGB bytes."""
# NumPy is much faster at doing this. NumPy code provided by:
# Keith (https://www.blogger.com/profile/02555547344016007163)
# Updated to use byteswap/tobytes instead of dstack.
pb = np.rot90(np.array(image.convert('RGB')), rotation // 90).astype('uint16')
color = ((pb[:, :, 0] & 0xF8) << 8) | ((pb[:, :, 1] & 0xFC) << 3) | (pb[:, :, 2] >> 3)
return color.byteswap(inplace=True).tobytes()
However, when I ran it with the framerate.py example, I actually saw my framerates drop (very slightly) on the pi0.
Any ideas?
-Pach
2 posts - 2 participants