<A HREF="COL_.htm"><img align=center src="contents.gif" ALT="Contents"></A> Up Previous Next


HSI: Hue Saturation Lightness.

RGB to HLS (Foley and VanDam)

  max = maximum of RGB
  min = minimum of RGB
  l = (max+min) / 2
  if max = min, S = 0, H = undefined

  if l <= 0.5, S = (max-min)/(max+min)
    else, S = (max-min)/(2 - max - min)

  delta = max-min

  if R = max, H = (G-B)/delta
  if G = max, H = 2 + (B-R)/delta
  if B = max, H = 4 + (R-G)/delta

  H = H * 60
  if H < 0, H = H + 360
HLS to RGB (Foley and VanDam)
  if L <= 0.5, m2 = L * (1+S)
   else m2 = L + S - L * S

  m2 = 2 * L - m2

  if S = 0 and H = undefined, R = G = B = L
  
  R = value(m1,m2,h+120)
  G = value(m1,m2,H)
  B = value(m1,m2,h-120)
where value(a,b,c) is the following function
value(n1,n2,hue)
  if hue > 360, hue = hue - 360
  else if hue < 0, hue = hue + 360

  if hue < 60,  value = n1 + (n2 - n1) * hue / 60
   else if hue < 180, value = n2
   else if hue < 240, value = n1 + (n2 - n1) * (240 - hue) / 60
   else value = n1

  return value