Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
colorsys Namespace Reference

Functions

def rgb_to_yiq
 
def yiq_to_rgb
 
def rgb_to_hls
 
def hls_to_rgb
 
def rgb_to_hsv
 
def hsv_to_rgb
 

Variables

list __all__
 
float ONE_THIRD = 1.0
 
float ONE_SIXTH = 1.0
 
float TWO_THIRD = 2.0
 

Detailed Description

Conversion functions between RGB and other color systems.

This modules provides two functions for each color system ABC:

  rgb_to_abc(r, g, b) --> a, b, c
  abc_to_rgb(a, b, c) --> r, g, b

All inputs and outputs are triples of floats in the range [0.0...1.0].
Inputs outside this range may cause exceptions or invalid outputs.

Supported color systems:
RGB: Red, Green, Blue components
YIQ: used by composite video signals
HLS: Hue, Luminance, Saturation
HSV: Hue, Saturation, Value

Function Documentation

def colorsys.hls_to_rgb (   h,
  l,
  s 
)

Definition at line 75 of file colorsys.py.

75 
76 def hls_to_rgb(h, l, s):
77  if s == 0.0: return l, l, l
78  if l <= 0.5: m2 = l * (1.0+s)
79  else: m2 = l+s-(l*s)
80  m1 = 2.0*l - m2
81  return (_v(m1, m2, h+ONE_THIRD), _v(m1, m2, h), _v(m1, m2, h-ONE_THIRD))
def colorsys.hsv_to_rgb (   h,
  s,
  v 
)

Definition at line 110 of file colorsys.py.

111 def hsv_to_rgb(h, s, v):
112  if s == 0.0: return v, v, v
113  i = int(h*6.0) # XXX assume int() truncates!
114  f = (h*6.0) - i
115  p = v*(1.0 - s)
116  q = v*(1.0 - s*f)
117  t = v*(1.0 - s*(1.0-f))
118  if i%6 == 0: return v, t, p
119  if i == 1: return q, v, p
120  if i == 2: return p, v, t
121  if i == 3: return p, q, v
122  if i == 4: return t, p, v
123  if i == 5: return v, p, q
124  # Cannot get here
def colorsys.rgb_to_hls (   r,
  g,
  b 
)

Definition at line 58 of file colorsys.py.

References sre_parse.max, and sre_parse.min.

58 
59 def rgb_to_hls(r, g, b):
60  maxc = max(r, g, b)
61  minc = min(r, g, b)
62  # XXX Can optimize (maxc+minc) and (maxc-minc)
63  l = (minc+maxc)/2.0
64  if minc == maxc: return 0.0, l, 0.0
65  if l <= 0.5: s = (maxc-minc) / (maxc+minc)
66  else: s = (maxc-minc) / (2.0-maxc-minc)
67  rc = (maxc-r) / (maxc-minc)
68  gc = (maxc-g) / (maxc-minc)
69  bc = (maxc-b) / (maxc-minc)
70  if r == maxc: h = bc-gc
71  elif g == maxc: h = 2.0+rc-bc
72  else: h = 4.0+gc-rc
73  h = (h/6.0) % 1.0
74  return h, l, s
def colorsys.rgb_to_hsv (   r,
  g,
  b 
)

Definition at line 95 of file colorsys.py.

References sre_parse.max, and sre_parse.min.

95 
96 def rgb_to_hsv(r, g, b):
97  maxc = max(r, g, b)
98  minc = min(r, g, b)
99  v = maxc
100  if minc == maxc: return 0.0, 0.0, v
101  s = (maxc-minc) / maxc
102  rc = (maxc-r) / (maxc-minc)
103  gc = (maxc-g) / (maxc-minc)
104  bc = (maxc-b) / (maxc-minc)
105  if r == maxc: h = bc-gc
106  elif g == maxc: h = 2.0+rc-bc
107  else: h = 4.0+gc-rc
108  h = (h/6.0) % 1.0
109  return h, s, v
def colorsys.rgb_to_yiq (   r,
  g,
  b 
)

Definition at line 34 of file colorsys.py.

34 
35 def rgb_to_yiq(r, g, b):
36  y = 0.30*r + 0.59*g + 0.11*b
37  i = 0.60*r - 0.28*g - 0.32*b
38  q = 0.21*r - 0.52*g + 0.31*b
39  return (y, i, q)
def colorsys.yiq_to_rgb (   y,
  i,
  q 
)

Definition at line 40 of file colorsys.py.

40 
41 def yiq_to_rgb(y, i, q):
42  r = y + 0.948262*i + 0.624013*q
43  g = y - 0.276066*i - 0.639810*q
44  b = y - 1.105450*i + 1.729860*q
45  if r < 0.0: r = 0.0
46  if g < 0.0: g = 0.0
47  if b < 0.0: b = 0.0
48  if r > 1.0: r = 1.0
49  if g > 1.0: g = 1.0
50  if b > 1.0: b = 1.0
51  return (r, g, b)
52 
53 
54 # HLS: Hue, Luminance, S???
55 # H: position in the spectrum
56 # L: ???
57 # S: ???

Variable Documentation

list __all__
Initial value:
1 = ["rgb_to_yiq","yiq_to_rgb","rgb_to_hls","hls_to_rgb",
2  "rgb_to_hsv","hsv_to_rgb"]

Definition at line 20 of file colorsys.py.

float ONE_SIXTH = 1.0

Definition at line 26 of file colorsys.py.

float ONE_THIRD = 1.0

Definition at line 25 of file colorsys.py.

float TWO_THIRD = 2.0

Definition at line 27 of file colorsys.py.