Skip to content

Commit

Permalink
Fix sdl2.ext.draw on 1bpp surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
a-hurst committed Sep 2, 2022
1 parent ca440b9 commit 3ee0ae4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ with contributions from

Thanks to everyone else for their assistance, support, fixes and improvements:

* A-Wpro
* Andreas Schiefer
* Bao "Mantle" Rong
* Ben Greiner
Expand Down
1 change: 1 addition & 0 deletions doc/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Fixed Bugs:

* Fixed broken behaviour (and potential segfaults) with usage of
:func:`sdl2.SDL_GUIDToString` on Python 3.6 and older (PR #246).
* Fixed :func:`sdl2.ext.draw` when drawing on 1bpp surfaces (PR #242).


0.9.13
Expand Down
4 changes: 3 additions & 1 deletion sdl2/ext/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ def line(target, color, dline, width=1):

if bpp == 3:
raise UnsupportedError("24bpp surfaces are not currently supported.")
if bpp == 2:
if bpp == 1:
pxbuf = ctypes.cast(rtarget.pixels, ctypes.POINTER(ctypes.c_uint8))
elif bpp == 2:
pxbuf = ctypes.cast(rtarget.pixels, ctypes.POINTER(ctypes.c_uint16))
elif bpp == 4:
pxbuf = ctypes.cast(rtarget.pixels, ctypes.POINTER(ctypes.c_uint32))
Expand Down
7 changes: 7 additions & 0 deletions sdl2/test/sdl2ext_draw_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ def test_line(testsurf):
assert all(x == 255 for x in view[-1][-1][:3])
assert all(x == 0 for x in view[1][5][:3])

# Test surfaces with nonstandard bpp values
fmts = ["RGB332", "RGBA4444"]
for f in fmts:
sf2 = _create_surface((10, 10), fmt=f)
sdl2ext.line(sf2.contents, WHITE, (1, 1, 9, 9))
SDL_FreeSurface(sf2)

# Test exception on bad input
with pytest.raises(ValueError):
sdl2ext.line(sf.contents, WHITE, (1, 2, 3))
Expand Down

0 comments on commit 3ee0ae4

Please sign in to comment.