Skip to content

Commit 2ca79fe

Browse files
committed
Accept float values for putdata() in Python 3.10
1 parent 35004da commit 2ca79fe

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Tests/test_image_putdata.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ def test_pypy_performance():
4747
im.putdata(list(range(256)) * 256)
4848

4949

50+
def test_mode_with_L_with_float():
51+
im = Image.new("L", (1, 1), 0)
52+
im.putdata([2.0])
53+
assert im.getpixel((0, 0)) == 2
54+
55+
5056
def test_mode_i():
5157
src = hopper("L")
5258
data = list(src.getdata())

src/_imaging.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ _putdata(ImagingObject *self, PyObject *args) {
15261526
/* Clipped data */
15271527
for (i = x = y = 0; i < n; i++) {
15281528
op = PySequence_Fast_GET_ITEM(seq, i);
1529-
image->image8[y][x] = (UINT8)CLIP8(PyLong_AsLong(op));
1529+
image->image8[y][x] = (UINT8)CLIP8((int)PyFloat_AsDouble(op));
15301530
if (++x >= (int)image->xsize) {
15311531
x = 0, y++;
15321532
}

0 commit comments

Comments
 (0)