diff --git a/Tests/test_image_convert.py b/Tests/test_image_convert.py index 1ffd012aab9..727c282d7e5 100644 --- a/Tests/test_image_convert.py +++ b/Tests/test_image_convert.py @@ -70,6 +70,11 @@ def test_16bit(): with Image.open("Tests/images/16bit.cropped.tif") as im: _test_float_conversion(im) + for color in (65535, 65536): + im = Image.new("I", (1, 1), color) + im_i16 = im.convert("I;16") + assert im_i16.getpixel((0, 0)) == 65535 + def test_16bit_workaround(): with Image.open("Tests/images/16bit.cropped.tif") as im: diff --git a/src/libImaging/Convert.c b/src/libImaging/Convert.c index 5a632ca4259..ba57deca192 100644 --- a/src/libImaging/Convert.c +++ b/src/libImaging/Convert.c @@ -37,7 +37,7 @@ #define MAX(a, b) (a) > (b) ? (a) : (b) #define MIN(a, b) (a) < (b) ? (a) : (b) -#define CLIP16(v) ((v) <= -32768 ? -32768 : (v) >= 32767 ? 32767 : (v)) +#define CLIP16(v) ((v) <= 0 ? 0 : (v) >= 65535 ? 65535 : (v)) /* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ #define L(rgb) ((INT32)(rgb)[0] * 299 + (INT32)(rgb)[1] * 587 + (INT32)(rgb)[2] * 114)