From: Melissa LeBlanc-Williams Date: Sat, 30 Sep 2023 01:56:13 +0000 (-0700) Subject: Bug fixes and optimizations. Super close now X-Git-Tag: 1.1.0^2~7 X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka_Displayio.git/commitdiff_plain/b39699fa4b1ed4838b72d068f0c13fdf62ef95de Bug fixes and optimizations. Super close now --- diff --git a/displayio/_display.py b/displayio/_display.py index 8551f8c..d8b49c7 100644 --- a/displayio/_display.py +++ b/displayio/_display.py @@ -18,7 +18,6 @@ displayio for Blinka """ import time -from array import array from typing import Optional import digitalio import microcontroller @@ -378,15 +377,15 @@ class Display: buffer_size = pixels_per_buffer // pixels_per_word if pixels_per_buffer % pixels_per_word: buffer_size += 1 - mask_length = (pixels_per_buffer // 8) + 1 # 1 bit per pixel + 1 + mask_length = (pixels_per_buffer // 32) + 1 # 1 bit per pixel + 1 remaining_rows = clipped.height() for subrect_index in range(subrectangles): subrectangle = Area( - clipped.x1, - clipped.y1 + rows_per_buffer * subrect_index, - clipped.x2, - clipped.y1 + rows_per_buffer * (subrect_index + 1), + x1=clipped.x1, + y1=clipped.y1 + rows_per_buffer * subrect_index, + x2=clipped.x2, + y2=clipped.y1 + rows_per_buffer * (subrect_index + 1), ) if remaining_rows < rows_per_buffer: subrectangle.y2 = subrectangle.y1 + remaining_rows @@ -401,8 +400,8 @@ class Display: 8 // self._core.colorspace.depth ) - buffer = memoryview(bytearray([0] * (buffer_size * 4))) - mask = memoryview(bytearray([0] * mask_length)) + buffer = memoryview(bytearray([0] * (buffer_size * 4))).cast("I") + mask = memoryview(bytearray([0] * mask_length)).cast("I") self._core.fill_area(subrectangle, mask, buffer) # Can't acquire display bus; skip the rest of the data. @@ -410,7 +409,7 @@ class Display: return False self._core.begin_transaction() - self._send_pixels(buffer[:subrectangle_size_bytes]) + self._send_pixels(buffer.tobytes()[:subrectangle_size_bytes]) self._core.end_transaction() return True @@ -426,9 +425,9 @@ class Display: if pixels_per_buffer % pixels_per_word: buffer_size += 1 - buffer = bytearray([0] * (buffer_size * 4)) + buffer = memoryview(bytearray([0] * (buffer_size * 4))).cast("I") mask_length = (pixels_per_buffer // 32) + 1 - mask = array("L", [0x00000000] * mask_length) + mask = memoryview(bytearray([0] * (mask_length * 4))).cast("I") self._core.fill_area(area, mask, buffer) return buffer @@ -512,7 +511,15 @@ class Display: def rotation(self, value: int): if value % 90 != 0: raise ValueError("Display rotation must be in 90 degree increments") + transposed = self._core.rotation in (90, 270) + will_transposed = value in (90, 270) + if transposed != will_transposed: + self._core.width, self._core.height = self._core.height, self._core.width self._core.set_rotation(value) + if self._core.current_group is not None: + self._core.current_group._update_transform( # pylint: disable=protected-access + self._core.transform + ) @property def bus(self) -> _DisplayBus: diff --git a/displayio/_displaycore.py b/displayio/_displaycore.py index 0672513..9e1ba4b 100644 --- a/displayio/_displaycore.py +++ b/displayio/_displaycore.py @@ -118,16 +118,13 @@ class _DisplayCore: self.rotation = rotation self.transform = TransformStruct() + self.set_rotation(rotation) + def set_rotation(self, rotation: int) -> None: """ Sets the rotation of the display as an int in degrees. """ # pylint: disable=protected-access, too-many-branches - transposed = self.rotation in (90, 270) - will_be_transposed = rotation in (90, 270) - if transposed != will_be_transposed: - self.width, self.height = self.height, self.width - height = self.height width = self.width @@ -176,9 +173,6 @@ class _DisplayCore: self.transform.y = height self.transform.dy = -1 - if self.current_group is not None: - self.current_group._update_transform(self.transform) - def set_root_group(self, root_group: Group) -> bool: """ Switches to displaying the given group of layers. When group is `None`, the @@ -289,7 +283,7 @@ class _DisplayCore: else: region_y1 //= pixels_per_byte * self.colorspace.bytes_per_cell region_y2 //= pixels_per_byte * self.colorspace.bytes_per_cell - + print(region_y2) region_x2 -= 1 region_y2 -= 1 diff --git a/displayio/_epaperdisplay.py b/displayio/_epaperdisplay.py index 9560469..1f0731c 100644 --- a/displayio/_epaperdisplay.py +++ b/displayio/_epaperdisplay.py @@ -371,7 +371,10 @@ class EPaperDisplay: # If there is no overlap then we're done. if not self._core.clip_area(area, clipped): return True - + print("---------------") + print(area.x1, area.y1, area.x2, area.y2) + print(clipped.x1, clipped.y1, clipped.x2, clipped.y2) + print("---------------") subrectangles = 1 rows_per_buffer = clipped.height() pixels_per_word = 32 // self._core.colorspace.depth @@ -392,7 +395,7 @@ class EPaperDisplay: if pixels_per_buffer % pixels_per_word: buffer_size += 1 - mask_length = (pixels_per_buffer // 8) + 1 # 1 bit per pixel + 1 + mask_length = (pixels_per_buffer // 32) + 1 # 1 bit per pixel + 1 passes = 1 if self._write_color_ram_command != NO_COMMAND: @@ -412,10 +415,10 @@ class EPaperDisplay: for subrect_index in range(subrectangles): subrectangle = Area( - clipped.x1, - clipped.y1 + rows_per_buffer * subrect_index, - clipped.x2, - clipped.y1 + rows_per_buffer * (subrect_index + 1), + x1=clipped.x1, + y1=clipped.y1 + rows_per_buffer * subrect_index, + x2=clipped.x2, + y2=clipped.y1 + rows_per_buffer * (subrect_index + 1), ) if remaining_rows < rows_per_buffer: subrectangle.y2 = subrectangle.y1 + remaining_rows @@ -425,8 +428,8 @@ class EPaperDisplay: 8 // self._core.colorspace.depth ) - buffer = memoryview(bytearray([0] * (buffer_size * 4))) - mask = memoryview(bytearray([0] * mask_length)) + buffer = memoryview(bytearray([0] * (buffer_size * 4))).cast("I") + mask = memoryview(bytearray([0] * (mask_length * 4))).cast("I") if not self._acep: self._core.colorspace.grayscale = True @@ -454,7 +457,9 @@ class EPaperDisplay: # Can't acquire display bus; skip the rest of the data. Try next display. return False self._core.send( - DISPLAY_DATA, self._chip_select, buffer[:subrectangle_size_bytes] + DISPLAY_DATA, + self._chip_select, + buffer.tobytes()[:subrectangle_size_bytes], ) self._core.end_transaction() return True @@ -547,6 +552,10 @@ class EPaperDisplay: if transposed != will_transposed: self._core.width, self._core.height = self._core.height, self._core.width self._core.set_rotation(value) + if self._core.current_group is not None: + self._core.current_group._update_transform( # pylint: disable=protected-access + self._core.transform + ) @property def time_to_refresh(self) -> float: diff --git a/displayio/_tilegrid.py b/displayio/_tilegrid.py index 5abfad4..9287e98 100644 --- a/displayio/_tilegrid.py +++ b/displayio/_tilegrid.py @@ -319,7 +319,7 @@ class TileGrid: ) # In Pixels # Check the mask first to see if the pixel has already been set - if mask[offset // 8] & (1 << (offset % 8)): + if mask[offset // 32] & (1 << (offset % 32)): continue local_x = input_pixel.x // self._absolute_transform.scale tile_location = ( @@ -363,24 +363,24 @@ class TileGrid: if not output_pixel.opaque: full_coverage = False else: - mask[offset // 8] |= 1 << (offset % 8) + mask[offset // 32] |= 1 << (offset % 32) # print("Mask", mask) if colorspace.depth == 16: struct.pack_into( "H", - buffer, - offset * 2, + buffer.cast("H"), + offset, output_pixel.pixel, ) elif colorspace.depth == 32: struct.pack_into( "I", buffer, - offset * 4, + offset, output_pixel.pixel, ) elif colorspace.depth == 8: - buffer[offset] = output_pixel.pixel & 0xFF + buffer.cast("B")[offset] = output_pixel.pixel & 0xFF elif colorspace.depth < 8: # Reorder the offsets to pack multiple rows into # a byte (meaning they share a column). @@ -399,7 +399,9 @@ class TileGrid: if colorspace.reverse_pixels_in_byte: # Reverse the shift by subtracting it from the leftmost shift shift = (pixels_per_byte - 1) * colorspace.depth - shift - buffer[offset // pixels_per_byte] |= output_pixel.pixel << shift + buffer.cast("B")[offset // pixels_per_byte] |= ( + output_pixel.pixel << shift + ) return full_coverage