__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git"
-ALIGN_BITS = 8 * struct.calcsize("I")
-
def stride(width: int, bits_per_pixel: int) -> int:
"""Return the number of bytes per row of a bitmap with the given width and bits per pixel."""
row_width = width * bits_per_pixel
- return (row_width + (ALIGN_BITS - 1)) // ALIGN_BITS
+ return (row_width + (31)) // 32
class Bitmap:
self._x_shift = 0
power_of_two = 1
- while power_of_two < ALIGN_BITS // bits_per_value:
+ while power_of_two < 32 // bits_per_value:
self._x_shift += 1
power_of_two = power_of_two << 1
if bytes_per_value < 1:
word = self._data[row_start + (x >> self._x_shift)]
return (
- word
- >> (
- struct.calcsize("I") * 8
- - ((x & self._x_mask) + 1) * self._bits_per_value
- )
+ word >> (32 - ((x & self._x_mask) + 1) * self._bits_per_value)
) & self._bitmask
row = memoryview(self._data)[row_start : row_start + self._stride]
if bytes_per_value == 1:
row_start = y * self._stride
bytes_per_value = self._bits_per_value // 8
if bytes_per_value < 1:
- bit_position = (
- struct.calcsize("I") * 8
- - ((x & self._x_mask) + 1) * self._bits_per_value
- )
+ bit_position = 32 - ((x & self._x_mask) + 1) * self._bits_per_value
index = row_start + (x >> self._x_shift)
word = self._data[index]
word &= ~(self._bitmask << bit_position)
"""
import time
-import struct
from array import array
from typing import Optional
import digitalio
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()
subrectangles = 1
buffer_size = pixels_per_buffer // pixels_per_word
if pixels_per_buffer % pixels_per_word:
buffer_size += 1
-
- # TODO: Optimize with memoryview
mask_length = (pixels_per_buffer // 8) + 1 # 1 bit per pixel + 1
remaining_rows = clipped.height()
8 // self._core.colorspace.depth
)
- buffer = bytearray([0] * (buffer_size * struct.calcsize("I")))
- mask = bytearray([0] * mask_length)
+ 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])
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)
"""
-import struct
from ._bitmap import Bitmap
from ._area import Area
from ._helpers import clamp
height //= 2
height += self._height % 2
self._half_height = height
- self._data = bytearray(height * struct.calcsize("HH"))
+ self._data = bytearray(height * 4)
for i in range(height):
self._data[2 * i] = 0
self._data[2 * i + 1] = width
--- /dev/null
+# SPDX-FileCopyrightText: 2023 Melissa LeBlanc-Williams for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
\ No newline at end of file
--- /dev/null
+SPDX-FileCopyrightText: 2023 Melissa LeBlanc-Williams, written for Adafruit Industries
+
+SPDX-License-Identifier: MIT
--- /dev/null
+SPDX-FileCopyrightText: 2023 Melissa LeBlanc-Williams, written for Adafruit Industries
+
+SPDX-License-Identifier: MIT
"""
+import os
from typing import Union, Tuple, Optional
from PIL import ImageFont
from displayio import Bitmap
__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git"
+DEFAULT_FONT = "displayio/resources/ter-u12n.pil"
+
class FontProtocol(Protocol):
"""A protocol shared by `BuiltinFont` and classes in ``adafruit_bitmap_font``"""
"""Simulate a font built into CircuitPython"""
def __init__(self):
- self._font = ImageFont.load_default()
+ self._font = ImageFont.load(os.path.dirname(__file__) + "/" + DEFAULT_FONT)
self._generate_bitmap(0x20, 0x7E)
def _generate_bitmap(self, start_range, end_range):