Skip to content

Commit

Permalink
Merge pull request #2839 from pygame-community/permissive-converting
Browse files Browse the repository at this point in the history
relax convert conditions
  • Loading branch information
robertpfeiffer authored May 23, 2024
2 parents 8a0744d + 34c1e0c commit 0d1e826
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 2 additions & 0 deletions docs/reST/ref/surface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@
as Surface subclass inherit this method without the need to override,
unless subclass specific instance attributes also need copying.

.. versionchanged:: 2.5.0 converting to a known format will succeed without a window/display surface.

.. ## Surface.convert ##
.. method:: convert_alpha
Expand Down
9 changes: 5 additions & 4 deletions src_c/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1423,13 +1423,14 @@ surf_convert(pgSurfaceObject *self, PyObject *args)
Uint8 key_r, key_g, key_b, key_a = 255;
int has_colorkey = SDL_FALSE;

if (!SDL_WasInit(SDL_INIT_VIDEO))
return RAISE(pgExc_SDLError,
"cannot convert without pygame.display initialized");

if (!PyArg_ParseTuple(args, "|Oi", &argobject, &flags))
return NULL;

if (!argobject && !SDL_WasInit(SDL_INIT_VIDEO))
return RAISE(pgExc_SDLError,
"cannot convert without format "
"when pygame.display is not initialized");

SURF_INIT_CHECK(surf)

pgSurface_Prep(self);
Expand Down
6 changes: 1 addition & 5 deletions test/surface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,8 +1215,6 @@ def test_image_convert_bug_131(self):

pygame.display.init()
try:
pygame.display.set_mode((640, 480))

im = pygame.image.load(example_path(os.path.join("data", "city.png")))
im2 = pygame.image.load(example_path(os.path.join("data", "brick.png")))

Expand Down Expand Up @@ -1246,7 +1244,7 @@ def test_convert_init(self):
filename = example_path(os.path.join("data", "alien3.png")) # 8bit PNG
surf8bit = pygame.image.load(filename)

self.assertRaisesRegex(pygame.error, "display initialized", surf.convert)
self.assertRaisesRegex(pygame.error, "display is not initialized", surf.convert)

pygame.display.init()
try:
Expand Down Expand Up @@ -1308,8 +1306,6 @@ def test_convert_alpha_SRCALPHA(self):
def test_convert_palettize(self):
pygame.display.init()
try:
pygame.display.set_mode((640, 480))

surf = pygame.Surface((150, 250))
surf.fill((255, 50, 0))
surf = surf.convert(8)
Expand Down

0 comments on commit 0d1e826

Please sign in to comment.