class Framebuffer(object): def __init__(self, device_no: int): self.path = "/dev/fb%d" % device_no config_dir = "/sys/class/graphics/fb%d/" % device_no self.size = tuple(_read_and_convert_to_ints( config_dir + "/virtual_size")) self.stride = _read_and_convert_to_ints(config_dir + "/stride")[0] self.bits_per_pixel = _read_and_convert_to_ints( config_dir + "/bits_per_pixel")[0] assert self.stride == self.bits_per_pixel // 8 * self.size[0] def __str__(self): args = (self.path, self.size, self.stride, self.bits_per_pixel) return "%s size:%s stride:%s bits_per_pixel:%s" % args # Note: performance is terrible even for medium resolutions def show(self, image: Image): converter = _CONVERTER[(image.mode, self.bits_per_pixel)] assert image.size == self.size out = converter(image) with open(self.path, "wb") as fp: fp.write(out) def on(self): pass def off(self): pass