Parent Topic: ALGORITHM
R = Red, G = Green, B = Blue I = Intensity, H = Hue, S = Saturation Max = Maximum(R,G,B) Min = Minimum(R,G,B) Delta = Max - Min I = Max If (Max <> 0) S = Delta / Max If (Max = 0) S = 0 If (S = 0) H = 0 (Hue is undefined) If (R = Max) H = (G - B) / Delta (between yellow and magenta) If (G = Max) H = 2 + (B - R) / Delta (between cyan and yellow) If (B = Max) H = 4 + (R - G) / Delta (between magenta and cyan) H = H * 60 (convert Hue to degrees) If (H < 0) H = H + 360 (Hue must be positive) If (H >= 360) H = H - 360 (Hue must be less than 360)If output channels are all 8-bit, then Hue and Saturation values are scaled between 0 and 255:
H = H * (255 / 360) S = S * 255The above algorithm was obtained from page 592 of the following text book:
Foley, J.D., A. van Dam, S.K. Feiner and J.F. Hughes, 1990. Computer Graphics: Principles and Practice (second edition). Addison-Wesley Publishing Company.