changeset 5:5b3f67e8e475

Send the exact number of pixels when drawing rectangles
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Tue, 07 Jun 2016 01:35:00 +0200
parents b0969b4aad63
children 56f0b98d656e
files ili9341.py
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ili9341.py	Tue Jun 07 01:10:01 2016 +0200
+++ b/ili9341.py	Tue Jun 07 01:35:00 2016 +0200
@@ -110,9 +110,13 @@
         w = min(self.width - x, max(1, w))
         h = min(self.height - y, max(1, h))
         self._write_block(x, y, x + w - 1, y + h - 1, b'')
-        data = ustruct.pack(">H", color) * 512
-        for count in range(w*h // 512):
-            self._write_data(data)
+        chunks, rest = divmod(w * h, 512)
+        if chunks:
+            data = ustruct.pack(">H", color) * 512
+            for count in range(chunks):
+                self._write_data(data)
+        data = ustruct.pack(">H", color) * rest
+        self._write_data(data)
 
     def fill(self, color):
         self.fill_rectangle(0, 0, self.width, self.height, color)