]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/commitdiff
Fixed buffer and get_refresh_areas
authorMelissa LeBlanc-Williams <melissa@adafruit.com>
Fri, 22 Sep 2023 22:29:38 +0000 (15:29 -0700)
committerMelissa LeBlanc-Williams <melissa@adafruit.com>
Fri, 22 Sep 2023 22:29:38 +0000 (15:29 -0700)
displayio/_display.py
displayio/_displaycore.py
displayio/_group.py
displayio/_tilegrid.py

index cdf9f7860e54310306422d09d3b6b9a65779feab..ac719817987fc5e586d9922ff1370b1279ece781 100644 (file)
@@ -19,6 +19,7 @@ displayio for Blinka
 
 import time
 import struct
+from array import array
 from typing import Optional
 import digitalio
 from PIL import Image
@@ -372,9 +373,9 @@ class Display:
             if pixels_per_buffer % pixels_per_word:
                 buffer_size += 1
 
-        buffer = bytearray(buffer_size)
+        buffer = bytearray([0] * (buffer_size * struct.calcsize("I")))
         mask_length = (pixels_per_buffer // 32) + 1
-        mask = bytearray(mask_length)
+        mask = array("L", [0] * mask_length)
         remaining_rows = clipped.height()
 
         for subrect_index in range(subrectangles):
index d2f298a07a992fd8f232823e39285da901c9c4b9..8db49e01892ba21bb4829879a3fe314fded23e2a 100644 (file)
@@ -405,7 +405,7 @@ class _DisplayCore:
         """
         Send the data to the current bus
         """
-        print(data_type, chip_select, data)
+        print(data_type, chip_select, data)
         self._send(data_type, chip_select, data)
 
     def begin_transaction(self) -> None:
index 903d7218380bfb84f145907081df9adc978e3cdf..ed90f8e105a1f705f9bb7d6190ddb4be4587bedb 100644 (file)
@@ -19,6 +19,7 @@ displayio for Blinka
 
 from __future__ import annotations
 from typing import Union, Callable
+import circuitpython_typing
 from ._structs import TransformStruct
 from ._tilegrid import TileGrid
 from ._colorspace import Colorspace
@@ -145,7 +146,11 @@ class Group:
         del self._layers[index]
 
     def _fill_area(
-        self, colorspace: Colorspace, area: Area, mask: int, buffer: bytearray
+        self,
+        colorspace: Colorspace,
+        area: Area,
+        mask: circuitpython_typing.WriteableBuffer,
+        buffer: circuitpython_typing.WriteableBuffer,
     ) -> bool:
         if self._hidden_group:
             return False
index 72e57c006f111b5c97f486f8e7727a905583cfa7..ec5e45f0640c171c3b102bb18d86d9d3ad6387cf 100644 (file)
@@ -19,6 +19,7 @@ displayio for Blinka
 
 import struct
 from typing import Union, Optional, Tuple
+import circuitpython_typing
 from ._bitmap import Bitmap
 from ._colorconverter import ColorConverter
 from ._ondiskbitmap import OnDiskBitmap
@@ -211,7 +212,11 @@ class TileGrid:
         image.putalpha(alpha.convert("L"))
 
     def _fill_area(
-        self, colorspace: Colorspace, area: Area, mask: bytearray, buffer: bytearray
+        self,
+        colorspace: Colorspace,
+        area: Area,
+        mask: circuitpython_typing.WriteableBuffer,
+        buffer: circuitpython_typing.WriteableBuffer,
     ) -> bool:
         """Draw onto the image"""
         # pylint: disable=too-many-locals,too-many-branches,too-many-statements
@@ -400,22 +405,24 @@ class TileGrid:
             areas.append(self._previous_area)
             return
 
-        tail = areas[-1]
+        tail = areas[-1] if areas else None
         # If we have an in-memory bitmap, then check it for modifications
         if isinstance(self._bitmap, Bitmap):
             self._bitmap._get_refresh_areas(areas)  # pylint: disable=protected-access
-            if tail != areas[-1]:
+            refresh_area = areas[-1] if areas else None
+            if tail != refresh_area:
                 # Special case a TileGrid that shows a full bitmap and use its
                 # dirty area. Copy it to ours so we can transform it.
                 if self._tiles_in_bitmap == 1:
-                    areas[-1].copy_into(self._dirty_area)
+                    refresh_area.copy_into(self._dirty_area)
                     self._partial_change = True
                 else:
                     self._full_change = True
         elif isinstance(self._bitmap, Shape):
             self._bitmap._get_refresh_areas(areas)  # pylint: disable=protected-access
-            if areas[-1] != tail:
-                areas[-1].copy_into(self._dirty_area)
+            refresh_area = areas[-1] if areas else None
+            if refresh_area != tail:
+                refresh_area.copy_into(self._dirty_area)
                 self._partial_change = True
 
         self._full_change = self._full_change or (