diff --git a/Tests/test_image_putdata.py b/Tests/test_image_putdata.py index 54712fd6c9d..e8e754aaa8b 100644 --- a/Tests/test_image_putdata.py +++ b/Tests/test_image_putdata.py @@ -47,6 +47,12 @@ def test_pypy_performance(): im.putdata(list(range(256)) * 256) +def test_mode_with_L_with_float(): + im = Image.new("L", (1, 1), 0) + im.putdata([2.0]) + assert im.getpixel((0, 0)) == 2 + + def test_mode_i(): src = hopper("L") data = list(src.getdata()) diff --git a/src/_imaging.c b/src/_imaging.c index aba907f88ba..ef8466e864b 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -1526,7 +1526,7 @@ _putdata(ImagingObject *self, PyObject *args) { /* Clipped data */ for (i = x = y = 0; i < n; i++) { op = PySequence_Fast_GET_ITEM(seq, i); - image->image8[y][x] = (UINT8)CLIP8(PyLong_AsLong(op)); + image->image8[y][x] = (UINT8)CLIP8((int)PyFloat_AsDouble(op)); if (++x >= (int)image->xsize) { x = 0, y++; }