Skip to content

Commit 205d60e

Browse files
authored
Merge pull request #3444 from damusss/load_animation-float
2 parents b0fa4ab + 40a6380 commit 205d60e

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

buildconfig/stubs/pygame/image.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ def load_sized_svg(file: FileLike, size: Point) -> Surface:
136136
.. versionadded:: 2.4.0
137137
"""
138138

139-
def load_animation(file: FileLike, namehint: str = "") -> list[tuple[Surface, int]]:
140-
"""Load an animation (GIF/WEBP) from a file (or file-like object).
139+
def load_animation(file: FileLike, namehint: str = "") -> list[tuple[Surface, float]]:
140+
"""Load an animation (GIF/WEBP) from a file (or file-like object) as a list of frames.
141141
142142
Load an animation (GIF/WEBP) from a file source. You can pass either a
143143
filename, a Python file-like object, or a pathlib.Path. If you pass a raw
@@ -146,7 +146,7 @@ def load_animation(file: FileLike, namehint: str = "") -> list[tuple[Surface, in
146146
format.
147147
148148
This returns a list of tuples (corresponding to every frame of the animation),
149-
where each tuple is a (surface, delay) pair for that frame.
149+
where each tuple is a (surface, delay in milliseconds) pair for that frame.
150150
151151
This function requires SDL_image 2.6.0 or above. If pygame was compiled with
152152
an older version, ``pygame.error`` will be raised when this function is

src_c/doc/image_doc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define DOC_IMAGE "Pygame module for image transfer."
33
#define DOC_IMAGE_LOAD "load(file, namehint='') -> Surface\nLoad new image from a file (or file-like object)."
44
#define DOC_IMAGE_LOADSIZEDSVG "load_sized_svg(file, size) -> Surface\nLoad an SVG image from a file (or file-like object) with the given size."
5-
#define DOC_IMAGE_LOADANIMATION "load_animation(file, namehint='') -> list[tuple[Surface, int]]\nLoad an animation (GIF/WEBP) from a file (or file-like object)."
5+
#define DOC_IMAGE_LOADANIMATION "load_animation(file, namehint='') -> list[tuple[Surface, float]]\nLoad an animation (GIF/WEBP) from a file (or file-like object) as a list of frames."
66
#define DOC_IMAGE_SAVE "save(surface, file, namehint='') -> None\nSave an image to file (or file-like object)."
77
#define DOC_IMAGE_GETSDLIMAGEVERSION "get_sdl_image_version(linked=True) -> Optional[tuple[int, int, int]]\nGet version number of the SDL_Image library being used."
88
#define DOC_IMAGE_GETEXTENDED "get_extended() -> bool\nTest if extended image formats can be loaded."

src_c/imageext.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ imageext_load_animation(PyObject *self, PyObject *arg, PyObject *kwargs)
264264
* to null in the animation to prevent double free */
265265
surfs->frames[i] = NULL;
266266

267-
PyObject *listentry = Py_BuildValue("(Oi)", frame, surfs->delays[i]);
267+
PyObject *listentry =
268+
Py_BuildValue("(Od)", frame, (double)surfs->delays[i]);
268269
Py_DECREF(frame);
269270
if (!listentry) {
270271
goto error;

test/image_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ def test_load_sized_svg_erroring(self):
13691369
def test_load_animation(self):
13701370
# test loading from a file
13711371
SAMPLE_FRAMES = 10
1372-
SAMPLE_DELAY = 150
1372+
SAMPLE_DELAY = 150.0
13731373
SAMPLE_SIZE = (312, 312)
13741374
gif_path = pathlib.Path(example_path("data/animated_sample.gif"))
13751375
for inp in (
@@ -1390,7 +1390,7 @@ def test_load_animation(self):
13901390
frame, delay = val
13911391
self.assertIsInstance(frame, pygame.Surface)
13921392
self.assertEqual(frame.size, SAMPLE_SIZE)
1393-
self.assertIsInstance(delay, int)
1393+
self.assertIsInstance(delay, float)
13941394
self.assertEqual(delay, SAMPLE_DELAY)
13951395

13961396
def test_load_pathlib(self):

0 commit comments

Comments
 (0)