]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/blobdiff - displayio/_tilegrid.py
Remove more of PIL
[hackapet/Adafruit_Blinka_Displayio.git] / displayio / _tilegrid.py
index ec5e45f0640c171c3b102bb18d86d9d3ad6387cf..cd2766263c42904870de9e67b023cdb685ca081d 100644 (file)
@@ -19,7 +19,7 @@ displayio for Blinka
 
 import struct
 from typing import Union, Optional, Tuple
-import circuitpython_typing
+from circuitpython_typing import WriteableBuffer
 from ._bitmap import Bitmap
 from ._colorconverter import ColorConverter
 from ._ondiskbitmap import OnDiskBitmap
@@ -215,8 +215,8 @@ class TileGrid:
         self,
         colorspace: Colorspace,
         area: Area,
-        mask: circuitpython_typing.WriteableBuffer,
-        buffer: circuitpython_typing.WriteableBuffer,
+        mask: WriteableBuffer,
+        buffer: WriteableBuffer,
     ) -> bool:
         """Draw onto the image"""
         # pylint: disable=too-many-locals,too-many-branches,too-many-statements
@@ -335,16 +335,18 @@ class TileGrid:
                 else:
                     mask[offset // 32] |= 1 << (offset % 32)
                     if colorspace.depth == 16:
-                        buffer = (
-                            buffer[:offset]
-                            + struct.pack("H", output_pixel.pixel)
-                            + buffer[offset + 2 :]
+                        struct.pack_into(
+                            "H",
+                            buffer,
+                            offset,
+                            output_pixel.pixel,
                         )
                     elif colorspace.depth == 32:
-                        buffer = (
-                            buffer[:offset]
-                            + struct.pack("I", output_pixel.pixel)
-                            + buffer[offset + 4 :]
+                        struct.pack_into(
+                            "I",
+                            buffer,
+                            offset,
+                            output_pixel.pixel,
                         )
                     elif colorspace.depth == 8:
                         buffer[offset] = output_pixel.pixel & 0xFF