Skip to content

Commit 3ee0ae4

Browse files
committed
Fix sdl2.ext.draw on 1bpp surfaces
1 parent ca440b9 commit 3ee0ae4

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

AUTHORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ with contributions from
1111

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

14+
* A-Wpro
1415
* Andreas Schiefer
1516
* Bao "Mantle" Rong
1617
* Ben Greiner

doc/news.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Fixed Bugs:
2121

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

2526

2627
0.9.13

sdl2/ext/draw.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ def line(target, color, dline, width=1):
148148

149149
if bpp == 3:
150150
raise UnsupportedError("24bpp surfaces are not currently supported.")
151-
if bpp == 2:
151+
if bpp == 1:
152+
pxbuf = ctypes.cast(rtarget.pixels, ctypes.POINTER(ctypes.c_uint8))
153+
elif bpp == 2:
152154
pxbuf = ctypes.cast(rtarget.pixels, ctypes.POINTER(ctypes.c_uint16))
153155
elif bpp == 4:
154156
pxbuf = ctypes.cast(rtarget.pixels, ctypes.POINTER(ctypes.c_uint32))

sdl2/test/sdl2ext_draw_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ def test_line(testsurf):
109109
assert all(x == 255 for x in view[-1][-1][:3])
110110
assert all(x == 0 for x in view[1][5][:3])
111111

112+
# Test surfaces with nonstandard bpp values
113+
fmts = ["RGB332", "RGBA4444"]
114+
for f in fmts:
115+
sf2 = _create_surface((10, 10), fmt=f)
116+
sdl2ext.line(sf2.contents, WHITE, (1, 1, 9, 9))
117+
SDL_FreeSurface(sf2)
118+
112119
# Test exception on bad input
113120
with pytest.raises(ValueError):
114121
sdl2ext.line(sf.contents, WHITE, (1, 2, 3))

0 commit comments

Comments
 (0)