Skip to content

Commit

Permalink
getpixel and putpixel also support a list argument
Browse files Browse the repository at this point in the history
  • Loading branch information
nulano committed Jun 12, 2024
1 parent 2a2033e commit 2381103
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1676,7 +1676,7 @@ def apply_transparency(self) -> None:
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.
Expand Down Expand Up @@ -2058,7 +2058,9 @@ def putpalette(self, data, rawmode="RGB") -> None:
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
Expand Down
8 changes: 6 additions & 2 deletions src/PIL/PyAccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def __init__(self, img: Image.Image, readonly: bool = False) -> None:
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
Expand Down Expand Up @@ -112,7 +116,7 @@ def __setitem__(self, xy: tuple[int, int], color: float | tuple[int, ...]) -> No

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
Expand Down

0 comments on commit 2381103

Please sign in to comment.