Skip to content

Commit

Permalink
Address requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
damusss committed Nov 16, 2024
1 parent 237b17e commit 41f8924
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 27 deletions.
10 changes: 6 additions & 4 deletions buildconfig/stubs/pygame/pixelarray.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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: ...
Expand Down
16 changes: 3 additions & 13 deletions src_c/pixelarray_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 0 additions & 10 deletions test/pixelarray_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 41f8924

Please sign in to comment.