Skip to content

Commit

Permalink
Accept float values for putdata() in Python 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 27, 2021
1 parent 35004da commit 2ca79fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Tests/test_image_putdata.py
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/_imaging.c
Expand Up @@ -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++;
}
Expand Down

0 comments on commit 2ca79fe

Please sign in to comment.