From 5f7b50b159e0356209db4cc8673b438389e9584f Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 10 Sep 2020 11:12:14 -0700 Subject: [PATCH] Added RGB888 support to image function --- adafruit_framebuf.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/adafruit_framebuf.py b/adafruit_framebuf.py index 8d0c63a..61360a0 100755 --- a/adafruit_framebuf.py +++ b/adafruit_framebuf.py @@ -427,8 +427,12 @@ def image(self, img): height = self.height if self.rotation == 1 or self.rotation == 3: width, height = height, width - if img.mode != "1": + + if isinstance(self.format, RGB888Format) and img.mode != "RGB": + raise ValueError("Image must be in mode RGB.") + if isinstance(self.format, (MHMSBFormat, MVLSBFormat)) and img.mode != "1": raise ValueError("Image must be in mode 1.") + imwidth, imheight = img.size if imwidth != width or imheight != height: raise ValueError( @@ -444,7 +448,9 @@ def image(self, img): # Iterate through the pixels for x in range(width): # yes this double loop is slow, for y in range(height): # but these displays are small! - if pixels[(x, y)]: + if img.mode == "RGB": + self.pixel(x, y, pixels[(x, y)]) + elif pixels[(x, y)]: self.pixel(x, y, 1) # only write if pixel is true