summaryrefslogtreecommitdiffstats
path: root/Lib/colorsys.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-08-06 08:51:23 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-08-06 08:51:23 (GMT)
commit9b855de8d2808f725566e5e74a4134fd366689ea (patch)
treefc7714ad92a3e0f07735e8c5014440290e1545d6 /Lib/colorsys.py
parent536f9fdcf3bbaf3dbe52d8ff77e525fefcf60c09 (diff)
downloadcpython-9b855de8d2808f725566e5e74a4134fd366689ea.zip
cpython-9b855de8d2808f725566e5e74a4134fd366689ea.tar.gz
cpython-9b855de8d2808f725566e5e74a4134fd366689ea.tar.bz2
Issue #14323: Expanded the number of digits in the coefficients for the
RGB -- YIQ conversions so that they match the FCC NTSC versions.
Diffstat (limited to 'Lib/colorsys.py')
-rw-r--r--Lib/colorsys.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/Lib/colorsys.py b/Lib/colorsys.py
index a6c0cf6..b93e384 100644
--- a/Lib/colorsys.py
+++ b/Lib/colorsys.py
@@ -33,17 +33,25 @@ TWO_THIRD = 2.0/3.0
# YIQ: used by composite video signals (linear combinations of RGB)
# Y: perceived grey level (0.0 == black, 1.0 == white)
# I, Q: color components
+#
+# There are a great many versions of the constants used in these formulae.
+# The ones in this library uses constants from the FCC version of NTSC.
def rgb_to_yiq(r, g, b):
y = 0.30*r + 0.59*g + 0.11*b
- i = 0.60*r - 0.28*g - 0.32*b
- q = 0.21*r - 0.52*g + 0.31*b
+ i = 0.74*(r-y) - 0.27*(b-y)
+ q = 0.48*(r-y) + 0.41*(b-y)
return (y, i, q)
def yiq_to_rgb(y, i, q):
- r = y + 0.948262*i + 0.624013*q
- g = y - 0.276066*i - 0.639810*q
- b = y - 1.105450*i + 1.729860*q
+ # r = y + (0.27*q + 0.41*i) / (0.74*0.41 + 0.27*0.48)
+ # b = y + (0.74*q - 0.48*i) / (0.74*0.41 + 0.27*0.48)
+ # g = y - (0.30*(r-y) + 0.11*(b-y)) / 0.59
+
+ r = y + 0.9468822170900693*i + 0.6235565819861433*q
+ g = y - 0.27478764629897834*i - 0.6356910791873801*q
+ b = y - 1.1085450346420322*i + 1.7090069284064666*q
+
if r < 0.0:
r = 0.0
if g < 0.0: