1C*GRXRGB -- convert HLS color to RGB color 2C+ 3 SUBROUTINE GRXRGB (H,L,S,R,G,B) 4C 5C GRPCKG: Convert a color specified in the HLS color model to one in 6C the RGB model. This is a support routine: no graphics I/O occurs. 7C The inverse transformation is accomplished with routine GRXHLS. 8C Reference: SIGGRAPH Status Report of the Graphic Standards Planning 9C Committee, Computer Graphics, Vol.13, No.3, Association for 10C Computing Machinery, New York, NY, 1979. 11C 12C Arguments: 13C 14C H,L,S (real, input): hue (0 to 360), lightness (0 to 1.0), and 15C saturation (0 to 1.0). 16C R,G,B (real, output): red, green, blue color coordinates, each in the 17C range 0.0 to 1.0. 18C-- 19C 2-Jul-1984 - new routine [TJP]. 20C 29-Sep-1994 - take H module 360 [TJP]. 21C 26-Nov-1996 - force results to be in range (avoid rounding error 22C problems on some machines) [TJP]. 23C----------------------------------------------------------------------- 24 REAL H,L,S, R,G,B, MA, MI, HM 25C 26 HM = MOD(H, 360.0) 27 IF (HM.LT.0.0) HM = HM+360.0 28 IF (L.LE.0.5) THEN 29 MA = L*(1.0+S) 30 ELSE 31 MA = L + S - L*S 32 END IF 33 MI = 2.0*L-MA 34C 35C R component 36C 37 IF (HM.LT.60.0) THEN 38 R = MI + (MA-MI)*HM/60.0 39 ELSE IF (HM.LT.180.0) THEN 40 R = MA 41 ELSE IF (HM.LT.240.0) THEN 42 R = MI + (MA-MI)*(240.0-HM)/60.0 43 ELSE 44 R = MI 45 END IF 46C 47C G component 48C 49 IF (HM.LT.120.0) THEN 50 G = MI 51 ELSE IF (HM.LT.180.0) THEN 52 G = MI + (MA-MI)*(HM-120.0)/60.0 53 ELSE IF (HM.LT.300.0) THEN 54 G = MA 55 ELSE 56 G = MI + (MA-MI)*(360.0-HM)/60.0 57 END IF 58C 59C B component 60C 61 IF (HM.LT.60.0 .OR. HM.GE.300.0) THEN 62 B = MA 63 ELSE IF (HM.LT.120.0) THEN 64 B = MI + (MA-MI)*(120.0-HM)/60.0 65 ELSE IF (HM.LT.240.0) THEN 66 B = MI 67 ELSE 68 B = MI + (MA-MI)*(HM-240.0)/60.0 69 END IF 70C 71 R = MIN(1.0, MAX(0.0,R)) 72 G = MIN(1.0, MAX(0.0,G)) 73 B = MIN(1.0, MAX(0.0,B)) 74C 75 END 76