X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka_Displayio.git/blobdiff_plain/a53c930973a24a7c55db9448e45d7ca7974cb56e..7c8fcb8b324e839a65d45174da42bf9a7ab1a217:/displayio/_display.py diff --git a/displayio/_display.py b/displayio/_display.py index 74ee095..3f6d7b6 100644 --- a/displayio/_display.py +++ b/displayio/_display.py @@ -18,7 +18,6 @@ displayio for Blinka """ import time -import struct from array import array from typing import Optional import digitalio @@ -329,7 +328,6 @@ class Display: def _refresh_area(self, area) -> bool: """Loop through dirty areas and redraw that area.""" # pylint: disable=too-many-locals - buffer_size = 128 clipped = Area() # Clip the area to the display by overlapping the areas. @@ -338,9 +336,12 @@ class Display: return True rows_per_buffer = clipped.height() - pixels_per_word = (struct.calcsize("I") * 8) // self._core.colorspace.depth + pixels_per_word = 32 // self._core.colorspace.depth pixels_per_buffer = clipped.size() + # We should have lots of memory + buffer_size = clipped.size() // pixels_per_word + subrectangles = 1 # for SH1107 and other boundary constrained controllers # write one single row at a time @@ -366,11 +367,7 @@ class Display: buffer_size = pixels_per_buffer // pixels_per_word if pixels_per_buffer % pixels_per_word: 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 +390,8 @@ class Display: 8 // self._core.colorspace.depth ) + buffer = memoryview(bytearray([0] * (buffer_size * 4))) + mask = memoryview(bytearray([0] * mask_length)) self._core.fill_area(subrectangle, mask, buffer) self._core.begin_transaction() self._send_pixels(buffer[:subrectangle_size_bytes]) @@ -405,13 +404,13 @@ class Display: raise ValueError("Display must have a 16 bit colorspace.") area = Area(0, y, self._core.width, y + 1) - pixels_per_word = (struct.calcsize("I") * 8) // self._core.colorspace.depth + pixels_per_word = 32 // self._core.colorspace.depth buffer_size = self._core.width // pixels_per_word pixels_per_buffer = area.size() if pixels_per_buffer % pixels_per_word: buffer_size += 1 - buffer = bytearray([0] * (buffer_size * struct.calcsize("I"))) + buffer = bytearray([0] * (buffer_size * 4)) mask_length = (pixels_per_buffer // 32) + 1 mask = array("L", [0x00000000] * mask_length) self._core.fill_area(area, mask, buffer) @@ -461,7 +460,7 @@ class Display: self._core.send( DISPLAY_COMMAND, CHIP_SELECT_TOGGLE_EVERY_BYTE, - bytes([self._brightness_command, 0xFF * value]), + bytes([self._brightness_command, round(0xFF * value)]), ) else: self._core.send(