1 # SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams for Adafruit Industries
3 # SPDX-License-Identifier: MIT
6 `displayio.ondiskbitmap`
7 ================================================================================
11 **Software and Dependencies:**
14 https://github.com/adafruit/Adafruit_Blinka/releases
16 * Author(s): Melissa LeBlanc-Williams
20 from typing import Union, BinaryIO
22 from ._colorconverter import ColorConverter
23 from ._palette import Palette
25 __version__ = "0.0.0+auto.0"
26 __repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git"
31 Loads values straight from disk. This minimizes memory use but can lead to much slower
32 pixel load times. These load times may result in frame tearing where only part of the
35 def __init__(self, file: Union[str, BinaryIO]):
36 self._image = Image.open(file).convert("RGBA")
39 def width(self) -> int:
40 """Width of the bitmap. (read only)"""
41 return self._image.width
44 def height(self) -> int:
45 """Height of the bitmap. (read only)"""
46 return self._image.height
49 def pixel_shader(self) -> Union[ColorConverter, Palette]:
50 """The ColorConverter or Palette for this image. (read only)"""
51 return self._image.getpalette()
53 def __getitem__(self, index: Union[tuple, list, int]) -> int:
55 Returns the value at the given index. The index can either be
56 an x,y tuple or an int equal to `y * width + x`.
58 if isinstance(index, (tuple, list)):
61 elif isinstance(index, int):
62 x = index % self._image._width
63 y = index // self._image._width
64 if not 0 <= x < self._image.width or not 0 <= y < self._image.height:
67 return self._image.getpixel((x, y))