From fc6b148e56c63c5d16db7af5e84814858382eee4 Mon Sep 17 00:00:00 2001
From: Mayur Saxena <mayur.saxena1997@gmail.com>
Date: Mon, 22 Mar 2021 00:18:29 -0400
Subject: [PATCH] Allow draw_image to consume bytes.

Make path and bytes optional parameters where only one can be specified.
---
 ili9341.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/ili9341.py b/ili9341.py
index eee450e..4c52388 100644
--- a/ili9341.py
+++ b/ili9341.py
@@ -3,6 +3,7 @@
 from math import cos, sin, pi, radians
 from sys import implementation
 import ustruct
+from uio import BytesIO
 
 
 def color565(r, g, b):
@@ -315,12 +316,13 @@ def draw_hline(self, x, y, w, color):
             return
         line = color.to_bytes(2, 'big') * w
         self.block(x, y, x + w - 1, y, line)
-
-    def draw_image(self, path, x=0, y=0, w=320, h=240):
+        
+    def draw_image(self, path=None, bytes=None, x=0, y=0, w=320, h=240):
         """Draw image from flash.
 
         Args:
             path (string): Image file path.
+            bytes (bytes): Image bytes.
             x (int): X coordinate of image left.  Default is 0.
             y (int): Y coordinate of image top.  Default is 0.
             w (int): Width of image.  Default is 320.
@@ -330,7 +332,11 @@ def draw_image(self, path, x=0, y=0, w=320, h=240):
         y2 = y + h - 1
         if self.is_off_grid(x, y, x2, y2):
             return
-        with open(path, "rb") as f:
+        
+        if (path is None and bytes is None) or (path is not None and bytes is not None):
+            return
+        
+        with open(path, "rb") if path else BytesIO(bytes) as f:
             chunk_height = 1024 // w
             chunk_count, remainder = divmod(h, chunk_height)
             chunk_size = chunk_height * w * 2