Accept float values for putdata() in Python 3.10

This commit is contained in:
Andrew Murray 2021-12-27 17:48:55 +11:00
parent 020308a7be
commit e9294d890f
2 changed files with 7 additions and 1 deletions

View File

@ -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())

View File

@ -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++;
}