From 038f9daf2799caeeacfa0fefb3aa6750d4051872 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 31 Dec 2019 16:56:09 +0300 Subject: [PATCH] bring ImageColor.getcolor into line with Convert.c implementation --- src/PIL/ImageColor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PIL/ImageColor.py b/src/PIL/ImageColor.py index 5a8e53bb8..9cf7a9912 100644 --- a/src/PIL/ImageColor.py +++ b/src/PIL/ImageColor.py @@ -134,7 +134,9 @@ def getcolor(color, mode): if Image.getmodebase(mode) == "L": r, g, b = color - color = (r * 299 + g * 587 + b * 114 + 500) // 1000 + # ITU-R Recommendation 601-2 for nonlinear RGB + # scaled to 24 bits to match the convert's implementation. + color = (r * 19595 + g * 38470 + b * 7471 + 0x8000) >> 16 if mode[-1] == "A": return (color, alpha) else: