diff options
author | Guido van Rossum <guido@python.org> | 1991-12-03 16:51:06 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1991-12-03 16:51:06 (GMT) |
commit | 3e0d556221ee0048fd831ee4c868ea1dc7809da1 (patch) | |
tree | 24f9cfb2d524f7a11e6124e3a6b5e7c577e1762e | |
parent | 094a9deae679eacbad2d0d6980d3a852da627905 (diff) | |
download | cpython-3e0d556221ee0048fd831ee4c868ea1dc7809da1.zip cpython-3e0d556221ee0048fd831ee4c868ea1dc7809da1.tar.gz cpython-3e0d556221ee0048fd831ee4c868ea1dc7809da1.tar.bz2 |
Improved lay-out.
-rwxr-xr-x | Demo/sgi/video/colorsys.py | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/Demo/sgi/video/colorsys.py b/Demo/sgi/video/colorsys.py index 872b533..b4e4b14 100755 --- a/Demo/sgi/video/colorsys.py +++ b/Demo/sgi/video/colorsys.py @@ -1,20 +1,30 @@ +# Conversions between RGB and YIQ color spaces. # -# Module color - do color conversions -# +# R, G, B are amounts of Red, Green and Blue; +# Y, I, Q are intensity (Y) and two difference signals (I, Q). + + +# Convert a (R, G, B) triple to (Y, I, Q). +# Scale is arbitrary (output uses the same scale as input). + +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 + return y, i, q + + +# Convert a (Y, I, Q) triple to (R, G, B). +# Input and output values are in the interval [0.0 ... 1.0]. -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 - 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 - if r < 0.0: r = 0.0 - if g < 0.0: g = 0.0 - if b < 0.0: b = 0.0 - if r > 1.0: r = 1.0 - if g > 1.0: g = 1.0 - if b > 1.0: b = 1.0 - return (r,g,b) +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 + if r < 0.0: r = 0.0 + if g < 0.0: g = 0.0 + if b < 0.0: b = 0.0 + if r > 1.0: r = 1.0 + if g > 1.0: g = 1.0 + if b > 1.0: b = 1.0 + return r, g, b |