diff --git a/gfxlcd/demos/assets/numbers.jpg b/gfxlcd/demos/assets/numbers.jpg new file mode 100644 index 0000000..f8904ad Binary files /dev/null and b/gfxlcd/demos/assets/numbers.jpg differ diff --git a/gfxlcd/demos/ili_image.py b/gfxlcd/demos/ili_image.py index a1274f2..057e9d6 100644 --- a/gfxlcd/demos/ili_image.py +++ b/gfxlcd/demos/ili_image.py @@ -17,3 +17,7 @@ RPi.GPIO.output(LED, 1) image_file = Image.open("assets/japan_temple_240x320.jpg") lcd_tft.draw_image(0, 0, image_file) + +numbers_image = Image.open("assets/dsp2017_101_64.png") +lcd_tft.transparency_color = (0, 0, 0) +lcd_tft.draw_image(10, 10, numbers_image) \ No newline at end of file diff --git a/gfxlcd/drawing/area.py b/gfxlcd/drawing/area.py index 9712b39..f631c69 100644 --- a/gfxlcd/drawing/area.py +++ b/gfxlcd/drawing/area.py @@ -132,6 +132,36 @@ class Area(Pixel): pos_x + width - 1, pos_y + height - 1 ) - for r, g, b in list(image_file.getdata()): - self.color = (r, g, b) - self.driver.data(self._converted_color(), None) \ No newline at end of file + row = 0 + col = 0 + area = None + temporary_area = None + for red, green, blue in list(image_file.getdata()): + if self._is_transparent((red, green, blue)): + area = (pos_x, pos_y + row + 1, pos_x + width - 1, pos_y + height - 1) + temporary_area = (pos_x + col + 1, pos_y + row, pos_x + width - 1, pos_y + row) + else: + if temporary_area is not None: + self._set_area(*temporary_area) + temporary_area = None + self.color = (red, green, blue) + self.driver.data(self._converted_color(), None) + + col += 1 + if col > width - 1: + col = 0 + row += 1 + if area is not None: + self._set_area(*area) + area = None + + def _is_transparent(self, color): + """check if color is a transparency color""" + if self.options['transparency_color'] is None: + return False + elif type(self.options['transparency_color'][0]) == int and color == self.options['transparency_color']: + return True + elif type(self.options['transparency_color'][0]) == list and color in self.options['transparency_color']: + return True + + return False \ No newline at end of file