+
+ 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))