Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed PixelAccess protocol #39

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions docs/reference/PixelAccess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,43 @@ Access using negative indexes is also possible. ::
-----------------------------

.. class:: PixelAccess
:canonical: PIL.Image.PixelAccess
:canonical: PIL.core.PixelAccess

.. automethod:: PIL.Image.PixelAccess.__getitem__
.. automethod:: PIL.Image.PixelAccess.__setitem__
.. method:: __setitem__(self, xy, color):

Modifies the pixel at x,y. The color is given as a single
numerical value for single band images, and a tuple for
multi-band images

:param xy: The pixel coordinate, given as (x, y).
:param color: The pixel value according to its mode. e.g. tuple (r, g, b) for RGB mode)

.. method:: __getitem__(self, xy):

Returns the pixel at x,y. The pixel is returned as a single
value for single band images or a tuple for multiple band
images

:param xy: The pixel coordinate, given as (x, y).
:returns: a pixel value for single band images, a tuple of
pixel values for multiband images.

.. method:: putpixel(self, xy, color):

Modifies the pixel at x,y. The color is given as a single
numerical value for single band images, and a tuple for
multi-band images. In addition to this, RGB and RGBA tuples
are accepted for P and PA images.

:param xy: The pixel coordinate, given as (x, y).
:param color: The pixel value according to its mode. e.g. tuple (r, g, b) for RGB mode)

.. method:: getpixel(self, xy):

Returns the pixel at x,y. The pixel is returned as a single
value for single band images or a tuple for multiple band
images

:param xy: The pixel coordinate, given as (x, y).
:returns: a pixel value for single band images, a tuple of
pixel values for multiband images.
31 changes: 3 additions & 28 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class Quantize(IntEnum):
# Registries

if TYPE_CHECKING:
from . import ImageFile
from . import ImageFile, PyAccess
ID: list[str] = []
OPEN: dict[
str,
Expand Down Expand Up @@ -512,31 +512,6 @@ def _getscaleoffset(expr):
# Implementation wrapper


class PixelAccess(Protocol):
def __getitem__(self, xy: tuple[int, 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 multi-band images.

:param xy: The pixel coordinate, given as (x, y).
:returns: a pixel value for single band images, a tuple of
pixel values for multiband images.
"""
raise NotImplementedError()

def __setitem__(self, xy: tuple[int, int], color: float | tuple[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
multi-band images.

:param xy: The pixel coordinate, given as (x, y).
:param color: The pixel value according to its mode,
e.g. tuple (r, g, b) for RGB mode.
"""
raise NotImplementedError()


class SupportsGetData(Protocol):
def getdata(
self,
Expand Down Expand Up @@ -897,7 +872,7 @@ def frombytes(self, data: bytes, decoder_name: str = "raw", *args) -> None:
msg = "cannot decode image data"
raise ValueError(msg)

def load(self) -> PixelAccess | None:
def load(self) -> core.PixelAccess | PyAccess.PyAccess | None:
"""
Allocates storage for the image and loads the pixel data. In
normal cases, you don't need to call this method, since the
Expand All @@ -910,7 +885,7 @@ def load(self) -> PixelAccess | None:
operations. See :ref:`file-handling` for more information.

:returns: An image access object.
:rtype: :py:class:`.PixelAccess` or :py:class:`.PyAccess`
:rtype: :ref:`PixelAccess` or :py:class:`.PyAccess`
"""
if self.im is not None and self.palette and self.palette.dirty:
# realize palette
Expand Down
4 changes: 4 additions & 0 deletions src/PIL/_imaging.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class ImagingDraw:
def __getattr__(self, name: str) -> Any: ...

class PixelAccess:
def __getitem__(self, xy: tuple[int, int]) -> float | tuple[int, ...]: ...
def __setitem__(
self, xy: tuple[int, int], color: float | tuple[int, ...]
) -> None: ...
def __getattr__(self, name: str) -> Any: ...

def font(image, glyphdata: bytes) -> ImagingFont: ...
Expand Down
Loading