Skip to content

Commit

Permalink
Merge pull request #6112 from radarhere/i_i16_conversion
Browse files Browse the repository at this point in the history
Clip I;16 to be unsigned, not signed
  • Loading branch information
hugovk committed Mar 10, 2022
2 parents 29960c6 + c8b69a7 commit 652542c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Tests/test_image_convert.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/libImaging/Convert.c
Expand Up @@ -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)
Expand Down

0 comments on commit 652542c

Please sign in to comment.