getpixel and putpixel also support a list argument

This commit is contained in:
Nulano 2024-06-12 22:17:10 +02:00
parent 2a2033eea1
commit 238110303c
2 changed files with 10 additions and 4 deletions

View File

@ -1676,7 +1676,7 @@ class Image:
del self.info["transparency"]
def getpixel(
self, xy: tuple[SupportsInt, SupportsInt]
self, xy: tuple[int, int] | list[int]
) -> float | tuple[int, ...] | None:
"""
Returns the pixel value at a given position.
@ -2058,7 +2058,9 @@ class Image:
self.palette.mode = "RGB"
self.load() # install new palette
def putpixel(self, xy: tuple[int, int], value: float | tuple[int, ...]) -> None:
def putpixel(
self, xy: tuple[int, int], value: float | tuple[int, ...] | list[int]
) -> None:
"""
Modifies the pixel at the given position. The color is given as
a single numerical value for single-band images, and a tuple for

View File

@ -77,7 +77,11 @@ class PyAccess:
def _post_init(self) -> None:
pass
def __setitem__(self, xy: tuple[int, int], color: float | tuple[int, ...]) -> None:
def __setitem__(
self,
xy: tuple[int, int] | list[int],
color: float | tuple[int, ...] | list[int],
) -> None:
"""
Modifies the pixel at x,y. The color is given as a single
numerical value for single band images, and a tuple for
@ -112,7 +116,7 @@ class PyAccess:
return self.set_pixel(x, y, color)
def __getitem__(self, xy: tuple[int, int]) -> float | tuple[int, ...]:
def __getitem__(self, xy: tuple[int, int] | list[int]) -> float | tuple[int, ...]:
"""
Returns the pixel at x,y. The pixel is returned as a single
value for single band images or a tuple for multiple band