Skip to content

Allow draw_image to draw from a stream of bytes. #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions ili9341.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down