Skip to content

Commit e52a594

Browse files
authored
Update SDL_image bindings for release 2.8.0 (#274)
* Bump CI binaries to latest release * Update bindings to image 2.8.0 * Skip pallete tests on very old SDL2 * Sync hints with SDL 2.28.5 * Handle new macOS DMG layout * Add test for new image function * Updated NEWS.rst * Fixed silly test bug
1 parent dd9609b commit e52a594

File tree

10 files changed

+82
-18
lines changed

10 files changed

+82
-18
lines changed

.ci/getsdl2.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
}
3535

3636
libversions = {
37+
'2.28.5': {
38+
'SDL2': '2.28.5',
39+
'SDL2_mixer': '2.6.3',
40+
'SDL2_ttf': '2.20.2',
41+
'SDL2_image': '2.8.1',
42+
'SDL2_gfx': '1.0.4'
43+
},
3744
'2.28.0': {
3845
'SDL2': '2.28.0',
3946
'SDL2_mixer': '2.6.0',
@@ -166,6 +173,8 @@ def getDLLs(platform_name, version):
166173
dllname = lib + '.framework'
167174
dllpath = os.path.join(mountpoint, dllname)
168175
dlloutpath = os.path.join(dlldir, dllname)
176+
optpath = os.path.join(mountpoint, 'optional')
177+
extraframeworkpath = os.path.join(dlloutpath, 'Versions', 'A', 'Frameworks')
169178

170179
# Download disk image containing library
171180
libversion = libversions[version][lib]
@@ -177,6 +186,8 @@ def getDLLs(platform_name, version):
177186
# Mount image, extract framework, then unmount
178187
sub.check_call(['hdiutil', 'attach', outpath, '-mountpoint', mountpoint])
179188
shutil.copytree(dllpath, dlloutpath, symlinks=True)
189+
if os.path.isdir(optpath):
190+
shutil.copytree(optpath, extraframeworkpath, symlinks=True)
180191
sub.call(['hdiutil', 'unmount', mountpoint])
181192

182193
elif platform_name in ['win32', 'win-amd64']:

.github/workflows/run_tests.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
strategy:
2323
matrix:
24-
sdl2: ['2.28.0']
24+
sdl2: ['2.28.5']
2525

2626
env:
2727
PYSDL2_DLL_VERSION: ${{ matrix.sdl2 }}
@@ -56,14 +56,14 @@ jobs:
5656
fail-fast: false
5757
matrix:
5858
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
59-
sdl2: ['2.28.0']
59+
sdl2: ['2.28.5']
6060
name-prefix: ['Linux (Python ']
6161
include:
6262
- python-version: 'pypy-2.7'
63-
sdl2: '2.28.0'
63+
sdl2: '2.28.5'
6464
name-prefix: 'Experimental / Linux ('
6565
- python-version: 'pypy-3.8'
66-
sdl2: '2.28.0'
66+
sdl2: '2.28.5'
6767
name-prefix: 'Experimental / Linux ('
6868

6969
env:
@@ -105,7 +105,7 @@ jobs:
105105
fail-fast: false
106106
matrix:
107107
python-version: ['3.10']
108-
sdl2: ['2.28.0', '2.26.5', '2.24.0']
108+
sdl2: ['2.28.5', '2.26.5', '2.24.0']
109109
name-prefix: ['macOS (Python ']
110110
include:
111111
- python-version: '3.10'
@@ -159,14 +159,14 @@ jobs:
159159
python-version: ['3.10']
160160
architecture: ['x64']
161161
sdl2: [
162-
'2.28.0', '2.26.5', '2.24.0', '2.0.22', '2.0.20', '2.0.18', '2.0.16', '2.0.14',
162+
'2.28.5', '2.26.5', '2.24.0', '2.0.22', '2.0.20', '2.0.18', '2.0.16', '2.0.14',
163163
'2.0.12', '2.0.10', '2.0.9', '2.0.8', '2.0.7', '2.0.6', '2.0.5'
164164
]
165165
name-prefix: ['Windows (Python ']
166166
include:
167167
- python-version: '3.8'
168168
architecture: 'x86'
169-
sdl2: '2.28.0'
169+
sdl2: '2.28.5'
170170
name-prefix: 'Windows 32-bit (Python '
171171
- python-version: '3.8'
172172
architecture: 'x86'
@@ -218,7 +218,7 @@ jobs:
218218
fail-fast: false
219219
matrix:
220220
architecture: ['x86']
221-
sdl2: ['2.28.0', '2.0.5']
221+
sdl2: ['2.28.5', '2.0.5']
222222

223223
env:
224224
PYSDL2_DLL_VERSION: ${{ matrix.sdl2 }}

doc/modules/sdl2_sdlimage.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ Animation objects and functions
190190

191191
.. autofunction:: IMG_LoadGIFAnimation_RW
192192

193+
.. autofunction:: IMG_LoadWEBPAnimation_RW
194+
193195
.. autofunction:: IMG_FreeAnimation
194196

195197

doc/news.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ This describes the latest changes between the PySDL2 releases.
55
0.9.17 (Unreleased)
66
-------------------
77

8+
New Features:
9+
10+
* Updated to wrap new function added in SDL_image 2.8.0 (PR #274).
11+
* Updated to wrap new hints added in SDL 2.28.2 and 2.28.5 (PR #274).
12+
13+
14+
Fixed Bugs:
15+
16+
* Fixed proper exporting of controller enum constants for the NVidia Shield and
17+
Joycon controllers.
18+
819

920
0.9.16
1021
------

sdl2/hints.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"SDL_HINT_JOYSTICK_HIDAPI_CORRELATE_XINPUT",
8484
"SDL_HINT_JOYSTICK_ROG_CHAKRAM",
8585
"SDL_HINT_JOYSTICK_THREAD",
86+
"SDL_HINT_JOYSTICK_WGI",
8687
"SDL_HINT_KMSDRM_REQUIRE_DRM_MASTER",
8788
"SDL_HINT_JOYSTICK_DEVICE",
8889
"SDL_HINT_LINUX_DIGITAL_HATS",
@@ -120,6 +121,7 @@
120121
"SDL_HINT_RENDER_OPENGL_SHADERS",
121122
"SDL_HINT_RENDER_SCALE_QUALITY",
122123
"SDL_HINT_RENDER_VSYNC",
124+
"SDL_HINT_RENDER_METAL_PREFER_LOW_POWER_DEVICE",
123125
"SDL_HINT_PS2_DYNAMIC_VSYNC",
124126
"SDL_HINT_RETURN_KEY_HIDES_IME",
125127
"SDL_HINT_RPI_VIDEO_LAYER",
@@ -214,6 +216,7 @@
214216
SDL_HINT_RENDER_LINE_METHOD = b"SDL_RENDER_LINE_METHOD"
215217
SDL_HINT_RENDER_DRIVER = b"SDL_RENDER_DRIVER"
216218
SDL_HINT_RENDER_LOGICAL_SIZE_MODE = b"SDL_RENDER_LOGICAL_SIZE_MODE"
219+
SDL_HINT_RENDER_METAL_PREFER_LOW_POWER_DEVICE = b"SDL_RENDER_METAL_PREFER_LOW_POWER_DEVICE"
217220
SDL_HINT_RENDER_OPENGL_SHADERS = b"SDL_RENDER_OPENGL_SHADERS"
218221
SDL_HINT_RENDER_SCALE_QUALITY = b"SDL_RENDER_SCALE_QUALITY"
219222
SDL_HINT_RENDER_VSYNC = b"SDL_RENDER_VSYNC"
@@ -336,6 +339,7 @@
336339
SDL_HINT_JOYSTICK_RAWINPUT_CORRELATE_XINPUT = b"SDL_JOYSTICK_RAWINPUT_CORRELATE_XINPUT"
337340
SDL_HINT_JOYSTICK_ROG_CHAKRAM = b"SDL_JOYSTICK_ROG_CHAKRAM"
338341
SDL_HINT_JOYSTICK_THREAD = b"SDL_JOYSTICK_THREAD"
342+
SDL_HINT_JOYSTICK_WGI = b"SDL_JOYSTICK_WGI"
339343
SDL_HINT_JOYSTICK_DEVICE = b"SDL_JOYSTICK_DEVICE"
340344

341345

sdl2/sdlimage.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def get_dll_file():
4747
# Constants, enums, type definitions, and macros
4848

4949
SDL_IMAGE_MAJOR_VERSION = 2
50-
SDL_IMAGE_MINOR_VERSION = 6
51-
SDL_IMAGE_PATCHLEVEL = 0
50+
SDL_IMAGE_MINOR_VERSION = 8
51+
SDL_IMAGE_PATCHLEVEL = 1
5252

5353
def SDL_IMAGE_VERSION(x):
5454
x.major = SDL_IMAGE_MAJOR_VERSION
@@ -173,6 +173,7 @@ class IMG_Animation(Structure):
173173
SDLFunc("IMG_LoadAnimationTyped_RW", [_P(SDL_RWops), c_int, c_char_p], _P(IMG_Animation), added='2.6.0'),
174174
SDLFunc("IMG_FreeAnimation", [_P(IMG_Animation)], added='2.6.0'),
175175
SDLFunc("IMG_LoadGIFAnimation_RW", [_P(SDL_RWops)], _P(IMG_Animation), added='2.6.0'),
176+
SDLFunc("IMG_LoadWEBPAnimation_RW", [_P(SDL_RWops)], _P(IMG_Animation), added='2.8.0'),
176177
]
177178
_ctypes = AttributeDict()
178179
for f in _funcdefs:
@@ -1114,8 +1115,8 @@ def IMG_LoadAnimation(file):
11141115
"""Loads an animated image from a file.
11151116
11161117
For more information on how to work with imported animations, see the
1117-
:class:`IMG_Animation` documentation. As of SDL_image 2.6.0, this currently
1118-
only supports GIF animations.
1118+
:class:`IMG_Animation` documentation. As of SDL_image 2.8.0, this currently
1119+
supports GIF and WEBP animations.
11191120
11201121
`Note: Added in SDL_image 2.6.0`
11211122
@@ -1134,8 +1135,8 @@ def IMG_LoadAnimation_RW(src, freesrc):
11341135
"""Loads an animated image from an SDL file object.
11351136
11361137
For more information on how to work with imported animations, see the
1137-
:class:`IMG_Animation` documentation. As of SDL_image 2.6.0, this currently
1138-
only supports GIF animations.
1138+
:class:`IMG_Animation` documentation. As of SDL_image 2.8.0, this currently
1139+
supports GIF and WEBP animations.
11391140
11401141
`Note: Added in SDL_image 2.6.0`
11411142
@@ -1156,8 +1157,8 @@ def IMG_LoadAnimationTyped_RW(src, freesrc, type):
11561157
"""Loads an animated image from an SDL file object as a specific format.
11571158
11581159
For more information on how to work with imported animations, see the
1159-
:class:`IMG_Animation` documentation. As of SDL_image 2.6.0, the only
1160-
supported animation type is ``b'GIF'``.
1160+
:class:`IMG_Animation` documentation. As of SDL_image 2.8.0, the only
1161+
supported animation types are ``b'GIF'`` and ``b'WEBP'``.
11611162
11621163
`Note: Added in SDL_image 2.6.0`
11631164
@@ -1210,6 +1211,25 @@ def IMG_LoadGIFAnimation_RW(src):
12101211
"""
12111212
return _ctypes["IMG_LoadGIFAnimation_RW"](src)
12121213

1214+
def IMG_LoadWEBPAnimation_RW(src):
1215+
"""Loads a WEBP animation from an SDL file object.
1216+
1217+
For more information on how to work with imported animations, see the
1218+
:class:`IMG_Animation` documentation. Use the :func:`IMG_GetError`
1219+
function to check for any errors.
1220+
1221+
`Note: Added in SDL_image 2.8.0`
1222+
1223+
Args:
1224+
src (:obj:`SDL_RWops`): The file object from which to load the WEBP.
1225+
1226+
Returns:
1227+
POINTER(:obj:`IMG_Animation`): A pointer to an animation object, or a
1228+
a null pointer if there was an error.
1229+
1230+
"""
1231+
return _ctypes["IMG_LoadWEBPAnimation_RW"](src)
1232+
12131233

12141234
IMG_SetError = SDL_SetError
12151235
IMG_GetError = SDL_GetError
536 Bytes
Binary file not shown.

sdl2/test/sdl2ext_image_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ def test_pillow_to_image(with_sdl):
216216
check_image_contents(sf)
217217
surf.SDL_FreeSurface(sf)
218218

219+
# Pallete conversion not working reliably on 2.0.5 64-bit
220+
if sdl2.dll.version_tuple < (2, 0, 6):
221+
pytest.skip("Requires SDL2 >= 2.0.6")
222+
219223
# Try converting a palette image
220224
palette_img = pil_img.convert("P", palette=WEB_PALETTE)
221225
sfp = sdl2ext.pillow_to_surface(palette_img)

sdl2/test/sdlimage_test.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
]
3838

3939
animation_formats = [
40-
"gif",
40+
"gif", "webp",
4141
]
4242

4343

@@ -53,6 +53,10 @@
5353
if img_ver < 2060:
5454
formats.remove("qoi")
5555

56+
# WEBP animations unsupported on SDL2_image < 2.8.0
57+
if img_ver < 2080:
58+
animation_formats.remove("webp")
59+
5660
# SVG unsupported on SDL2_image < 2.0.2 as well as in Conda's current (2.0.5)
5761
# Windows binaries
5862
if img_ver < 2002 or (isconda and iswindows):
@@ -727,3 +731,11 @@ def test_IMG_LoadGIFAnimation_RW():
727731
fp.close()
728732
_verify_anim_load(anim)
729733
sdlimage.IMG_FreeAnimation(anim)
734+
735+
@pytest.mark.skipif(sdlimage.dll.version < 2080, reason="Added in 2.8.0")
736+
def test_IMG_LoadWEBPAnimation_RW():
737+
fp = io.open(_get_animation_path("webp"), "rb")
738+
anim = sdlimage.IMG_LoadWEBPAnimation_RW(rwops.rw_from_object(fp))
739+
fp.close()
740+
_verify_anim_load(anim)
741+
sdlimage.IMG_FreeAnimation(anim)

sdl2/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
SDL_MAJOR_VERSION = 2
2222
SDL_MINOR_VERSION = 28
23-
SDL_PATCHLEVEL = 0
23+
SDL_PATCHLEVEL = 5
2424

2525
def SDL_VERSION(x):
2626
x.major = SDL_MAJOR_VERSION

0 commit comments

Comments
 (0)