diff --git a/buildconfig/stubs/pygame/pixelarray.pyi b/buildconfig/stubs/pygame/pixelarray.pyi index a10bb66e42..128748fe9b 100644 --- a/buildconfig/stubs/pygame/pixelarray.pyi +++ b/buildconfig/stubs/pygame/pixelarray.pyi @@ -1,8 +1,10 @@ from typing import Any, Dict, Tuple, Union, overload from pygame.surface import Surface +from pygame.color import Color +from pygame.typing import SequenceLike -from pygame.typing import ColorLike, SequenceLike +_ColorLike = int | Color | tuple[int, int, int] | tuple[int, int, int, int] class PixelArray: surface: Surface @@ -34,14 +36,14 @@ class PixelArray: def make_surface(self) -> Surface: ... def replace( self, - color: ColorLike, - repcolor: ColorLike, + color: _ColorLike, + repcolor: _ColorLike, distance: float = 0, weights: SequenceLike[float] = (0.299, 0.587, 0.114), ) -> None: ... def extract( self, - color: ColorLike, + color: _ColorLike, distance: float = 0, weights: SequenceLike[float] = (0.299, 0.587, 0.114), ) -> PixelArray: ... diff --git a/src_c/pixelarray_methods.c b/src_c/pixelarray_methods.c index 62f33a796a..8ecbebdb91 100644 --- a/src_c/pixelarray_methods.c +++ b/src_c/pixelarray_methods.c @@ -46,16 +46,6 @@ _get_color_from_object(PyObject *val, SDL_Surface *surf, Uint32 *color) val, surf, color, PG_COLOR_HANDLE_INT | PG_COLOR_HANDLE_RESTRICT_SEQ); } -static int -_get_color_from_object_all(PyObject *val, SDL_Surface *surf, Uint32 *color) -{ - if (!val) { - return 0; - } - - return pg_MappedColorFromObj(val, surf, color, PG_COLOR_HANDLE_ALL); -} - /** * Retrieves a single pixel located at index from the surface pixel * array. @@ -385,8 +375,8 @@ _replace_color(pgPixelArrayObject *array, PyObject *args, PyObject *kwds) format = surf->format; bpp = PG_SURF_BytesPerPixel(surf); - if (!_get_color_from_object_all(delcolor, surf, &dcolor) || - !_get_color_from_object_all(replcolor, surf, &rcolor)) { + if (!_get_color_from_object(delcolor, surf, &dcolor) || + !_get_color_from_object(replcolor, surf, &rcolor)) { return 0; } @@ -591,7 +581,7 @@ _extract_color(pgPixelArrayObject *array, PyObject *args, PyObject *kwds) black = SDL_MapRGBA(format, 0, 0, 0, 255); white = SDL_MapRGBA(format, 255, 255, 255, 255); - if (!_get_color_from_object_all(excolor, surf, &color)) { + if (!_get_color_from_object(excolor, surf, &color)) { Py_DECREF(new_array); return 0; } diff --git a/test/pixelarray_test.py b/test/pixelarray_test.py index e56f11ed0e..af8117ceeb 100644 --- a/test/pixelarray_test.py +++ b/test/pixelarray_test.py @@ -1041,11 +1041,6 @@ def test_replace(self): self.assertEqual(ar[8][9], oval) self.assertEqual(ar[9][9], oval) - for color in [(20, 20, 20), 10, "green", pygame.Color("blue")]: - sf = pygame.Surface((10, 10)) - ar = pygame.PixelArray(sf) - ar.replace(color, color) - def test_extract(self): for bpp in (8, 16, 24, 32): sf = pygame.Surface((10, 10), 0, bpp) @@ -1073,11 +1068,6 @@ def test_extract(self): self.assertEqual(newar[8][9], black) self.assertEqual(newar[9][9], black) - for color in [(20, 20, 20), 10, "green", pygame.Color("blue")]: - sf = pygame.Surface((10, 10)) - ar = pygame.PixelArray(sf) - ar.extract(color) - def test_2dslice_assignment(self): w = 2 * 5 * 8 h = 3 * 5 * 9