X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka_Displayio.git/blobdiff_plain/5cfe68b419b1e014ae334c500569d87b661e4281..c7480cda3112b5f59882e3037e09ad705038fd82:/displayio/ondiskbitmap.py diff --git a/displayio/ondiskbitmap.py b/displayio/ondiskbitmap.py index a4d758a..5e1de46 100644 --- a/displayio/ondiskbitmap.py +++ b/displayio/ondiskbitmap.py @@ -21,7 +21,7 @@ # THE SOFTWARE. """ -`displayio` +`displayio.ondiskbitmap` ================================================================================ displayio for Blinka @@ -50,7 +50,7 @@ class OnDiskBitmap: image is visible.""" def __init__(self, file): - self._image = Image.open(file) + self._image = Image.open(file).convert("RGBA") @property def width(self): @@ -61,3 +61,19 @@ class OnDiskBitmap: def height(self): """Height of the bitmap. (read only)""" return self._image.height + + def __getitem__(self, index): + """ + Returns the value at the given index. The index can either be + an x,y tuple or an int equal to `y * width + x`. + """ + if isinstance(index, (tuple, list)): + x = index[0] + y = index[1] + elif isinstance(index, int): + x = index % self._image._width + y = index // self._image._width + if not 0 <= x < self._image.width or not 0 <= y < self._image.height: + return 0 + + return self._image.getpixel((x, y))