]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/commitdiff
More bug fixes and it is working
authorMelissa LeBlanc-Williams <melissa@adafruit.com>
Tue, 26 Sep 2023 20:00:32 +0000 (13:00 -0700)
committerMelissa LeBlanc-Williams <melissa@adafruit.com>
Tue, 26 Sep 2023 20:00:32 +0000 (13:00 -0700)
displayio/_display.py
displayio/_displaycore.py
displayio/_tilegrid.py

index 74ee0957b697e3a494dfec6fa29ed009916fac3a..d06ccbecdd1456309a1b45b7b3ac9c75c7b8f5af 100644 (file)
@@ -368,9 +368,7 @@ class Display:
                 buffer_size += 1
 
         # TODO: Optimize with memoryview
-        buffer = bytearray([0] * (buffer_size * struct.calcsize("I")))
-        mask_length = (pixels_per_buffer // 32) + 1
-        mask = array("L", [0] * mask_length)
+        mask_length = (pixels_per_buffer // 8) + 1  # 1 bit per pixel + 1
         remaining_rows = clipped.height()
 
         for subrect_index in range(subrectangles):
@@ -393,6 +391,8 @@ class Display:
                     8 // self._core.colorspace.depth
                 )
 
+            buffer = bytearray([0] * (buffer_size * struct.calcsize("I")))
+            mask = bytearray([0] * mask_length)
             self._core.fill_area(subrectangle, mask, buffer)
             self._core.begin_transaction()
             self._send_pixels(buffer[:subrectangle_size_bytes])
index fd42b4d4200c53649b17a19441bacfdae3263963..42218ec7baa5bb9d32b9251038fdcf442ca43a71 100644 (file)
@@ -254,7 +254,8 @@ class _DisplayCore:
         if not overlaps:
             return False
 
-        # Expand the area if we have multiple pixels per byte and we need to byte align the bounds
+        # Expand the area if we have multiple pixels per byte and we need to byte
+        # align the bounds
         if self.colorspace.depth < 8:
             pixels_per_byte = (
                 8 // self.colorspace.depth * self.colorspace.bytes_per_cell
index 91b32326c6244f117cc5f30e2fd914531b339e56..6705601681d16bae4a6ad9ce820847d44aa478f1 100644 (file)
@@ -244,10 +244,12 @@ class TileGrid:
 
         if self._hidden_tilegrid or self._hidden_by_parent:
             return False
-
         overlap = Area()  # area, current_area, overlap
         if not area.compute_overlap(self._current_area, overlap):
             return False
+        # else:
+        #    print("Checking", area.x1, area.y1, area.x2, area.y2)
+        #    print("Overlap", overlap.x1, overlap.y1, overlap.x2, overlap.y2)
 
         if self._bitmap.width <= 0 or self._bitmap.height <= 0:
             return False
@@ -317,7 +319,7 @@ class TileGrid:
                 )  # In Pixels
 
                 # Check the mask first to see if the pixel has already been set
-                if mask[offset // 32] & (1 << (offset % 32)):
+                if mask[offset // 8] & (1 << (offset % 8)):
                     continue
                 local_x = input_pixel.x // self._absolute_transform.scale
                 tile_location = (
@@ -361,7 +363,8 @@ class TileGrid:
                 if not output_pixel.opaque:
                     full_coverage = False
                 else:
-                    mask[offset // 32] |= 1 << (offset % 32)
+                    mask[offset // 8] |= 1 << (offset % 8)
+                    # print("Mask", mask)
                     if colorspace.depth == 16:
                         struct.pack_into(
                             "H",
@@ -440,7 +443,7 @@ class TileGrid:
         if isinstance(self._bitmap, Bitmap):
             self._bitmap._get_refresh_areas(areas)  # pylint: disable=protected-access
             refresh_area = areas[-1] if areas else None
-            if tail != refresh_area:
+            if refresh_area != tail:
                 # 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:
@@ -529,6 +532,29 @@ class TileGrid:
         )
         self._full_change = True
 
+    def _set_tile(self, x: int, y: int, tile_index: int) -> None:
+        self._tiles[y * self._width_in_tiles + x] = tile_index
+        temp_area = Area()
+        if not self._partial_change:
+            tile_area = self._dirty_area
+        else:
+            tile_area = temp_area
+        top_x = (x - self._top_left_x) % self._width_in_tiles
+        if top_x < 0:
+            top_x += self._width_in_tiles
+        tile_area.x1 = top_x * self._tile_width
+        tile_area.x2 = tile_area.x1 + self._tile_width
+        top_y = (y - self._top_left_y) % self._height_in_tiles
+        if top_y < 0:
+            top_y += self._height_in_tiles
+        tile_area.y1 = top_y * self._tile_height
+        tile_area.y2 = tile_area.y1 + self._tile_height
+
+        if self._partial_change:
+            self._dirty_area.union(temp_area, self._dirty_area)
+
+        self._partial_change = True
+
     def _set_top_left(self, x: int, y: int) -> None:
         self._top_left_x = x
         self._top_left_y = y
@@ -679,23 +705,23 @@ class TileGrid:
             or index >= len(self._tiles)
         ):
             raise ValueError("Tile index out of bounds")
-        return index
+        return x, y
 
     def __getitem__(self, index: Union[Tuple[int, int], int]) -> int:
         """Returns the tile index at the given index. The index can either be
         an x,y tuple or an int equal to ``y * width + x``'.
         """
-        index = self._extract_and_check_index(index)
-        return self._tiles[index]
+        x, y = self._extract_and_check_index(index)
+        return self._tiles[y * self._width_in_tiles + x]
 
     def __setitem__(self, index: Union[Tuple[int, int], int], value: int) -> None:
         """Sets the tile index at the given index. The index can either be
         an x,y tuple or an int equal to ``y * width + x``.
         """
-        index = self._extract_and_check_index(index)
+        x, y = self._extract_and_check_index(index)
         if not 0 <= value <= 255:
             raise ValueError("Tile value out of bounds")
-        self._tiles[index] = value
+        self._set_tile(x, y, value)
 
     @property
     def width(self) -> int: