Skip to content

Commit 41f8924

Browse files
committed
Address requested changes
1 parent 237b17e commit 41f8924

File tree

3 files changed

+9
-27
lines changed

3 files changed

+9
-27
lines changed

buildconfig/stubs/pygame/pixelarray.pyi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from typing import Any, Dict, Tuple, Union, overload
22

33
from pygame.surface import Surface
4+
from pygame.color import Color
5+
from pygame.typing import SequenceLike
46

5-
from pygame.typing import ColorLike, SequenceLike
7+
_ColorLike = int | Color | tuple[int, int, int] | tuple[int, int, int, int]
68

79
class PixelArray:
810
surface: Surface
@@ -34,14 +36,14 @@ class PixelArray:
3436
def make_surface(self) -> Surface: ...
3537
def replace(
3638
self,
37-
color: ColorLike,
38-
repcolor: ColorLike,
39+
color: _ColorLike,
40+
repcolor: _ColorLike,
3941
distance: float = 0,
4042
weights: SequenceLike[float] = (0.299, 0.587, 0.114),
4143
) -> None: ...
4244
def extract(
4345
self,
44-
color: ColorLike,
46+
color: _ColorLike,
4547
distance: float = 0,
4648
weights: SequenceLike[float] = (0.299, 0.587, 0.114),
4749
) -> PixelArray: ...

src_c/pixelarray_methods.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,6 @@ _get_color_from_object(PyObject *val, SDL_Surface *surf, Uint32 *color)
4646
val, surf, color, PG_COLOR_HANDLE_INT | PG_COLOR_HANDLE_RESTRICT_SEQ);
4747
}
4848

49-
static int
50-
_get_color_from_object_all(PyObject *val, SDL_Surface *surf, Uint32 *color)
51-
{
52-
if (!val) {
53-
return 0;
54-
}
55-
56-
return pg_MappedColorFromObj(val, surf, color, PG_COLOR_HANDLE_ALL);
57-
}
58-
5949
/**
6050
* Retrieves a single pixel located at index from the surface pixel
6151
* array.
@@ -385,8 +375,8 @@ _replace_color(pgPixelArrayObject *array, PyObject *args, PyObject *kwds)
385375
format = surf->format;
386376
bpp = PG_SURF_BytesPerPixel(surf);
387377

388-
if (!_get_color_from_object_all(delcolor, surf, &dcolor) ||
389-
!_get_color_from_object_all(replcolor, surf, &rcolor)) {
378+
if (!_get_color_from_object(delcolor, surf, &dcolor) ||
379+
!_get_color_from_object(replcolor, surf, &rcolor)) {
390380
return 0;
391381
}
392382

@@ -591,7 +581,7 @@ _extract_color(pgPixelArrayObject *array, PyObject *args, PyObject *kwds)
591581
black = SDL_MapRGBA(format, 0, 0, 0, 255);
592582
white = SDL_MapRGBA(format, 255, 255, 255, 255);
593583

594-
if (!_get_color_from_object_all(excolor, surf, &color)) {
584+
if (!_get_color_from_object(excolor, surf, &color)) {
595585
Py_DECREF(new_array);
596586
return 0;
597587
}

test/pixelarray_test.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,11 +1041,6 @@ def test_replace(self):
10411041
self.assertEqual(ar[8][9], oval)
10421042
self.assertEqual(ar[9][9], oval)
10431043

1044-
for color in [(20, 20, 20), 10, "green", pygame.Color("blue")]:
1045-
sf = pygame.Surface((10, 10))
1046-
ar = pygame.PixelArray(sf)
1047-
ar.replace(color, color)
1048-
10491044
def test_extract(self):
10501045
for bpp in (8, 16, 24, 32):
10511046
sf = pygame.Surface((10, 10), 0, bpp)
@@ -1073,11 +1068,6 @@ def test_extract(self):
10731068
self.assertEqual(newar[8][9], black)
10741069
self.assertEqual(newar[9][9], black)
10751070

1076-
for color in [(20, 20, 20), 10, "green", pygame.Color("blue")]:
1077-
sf = pygame.Surface((10, 10))
1078-
ar = pygame.PixelArray(sf)
1079-
ar.extract(color)
1080-
10811071
def test_2dslice_assignment(self):
10821072
w = 2 * 5 * 8
10831073
h = 3 * 5 * 9

0 commit comments

Comments
 (0)