DIRECTORY ConstantColors, ColorModels, ColorNames, RealFns USING [AlmostZero], ImagerBasic USING [ConstantColor, ColorRep], Rope USING [ROPE], Real; ConstantColorsImpl: CEDAR PROGRAM IMPORTS Real, ColorNames, ColorModels, RealFns EXPORTS ConstantColors ~ BEGIN OPEN ConstantColors; ConstantColor: TYPE ~ ImagerBasic.ConstantColor; -- Color Definitions black: PUBLIC ConstantColor _ NameToColor["Black"]; white: PUBLIC ConstantColor _ NameToColor["White"]; grey: PUBLIC ConstantColor _ NameToColor["Grey"]; darkGrey: PUBLIC ConstantColor _ NameToColor["Dark Grey"]; lightGrey: PUBLIC ConstantColor _ NameToColor["Light Grey"]; veryDarkGrey: PUBLIC ConstantColor _ NameToColor["Very Dark Grey"]; veryLightGrey: PUBLIC ConstantColor _ NameToColor["Very Light Grey"]; red: PUBLIC ConstantColor _ NameToColor["Red"]; green: PUBLIC ConstantColor _ NameToColor["Green"]; blue: PUBLIC ConstantColor _ NameToColor["Blue"]; magenta: PUBLIC ConstantColor _ NameToColor["Magenta"]; cyan: PUBLIC ConstantColor _ NameToColor["Cyan"]; yellow: PUBLIC ConstantColor _ NameToColor["Yellow"]; orange: PUBLIC ConstantColor _ NameToColor["Orange"]; purple: PUBLIC ConstantColor _ NameToColor["Purple"]; brown: PUBLIC ConstantColor _ NameToColor["Brown"]; IntensityToColor: PUBLIC PROC [intensity: REAL, cal: Calibration _ NIL] RETURNS [ConstantColor] ~ { IF intensity <= 0 THEN RETURN [black]; IF intensity >= 1 THEN RETURN [white]; RETURN [MakeRep[x: 0.3101, y: 0.3163, Y: intensity]]; }; HSVToColor: PUBLIC PROC[h,s,v: REAL, cal: Calibration _ NIL] RETURNS[ConstantColor] = { x,y,Y: REAL; r,g,b: REAL; [r: r,g: g,b: b] _ ColorModels.HSVToRGB[h: h, s: s, v: v]; [x: x,y: y,Y: Y] _ ColorModels.RGBToCIE[r: r, g: g, b: b, calibration: Cal[cal]]; RETURN[MakeRep[x: x, y: y,Y: Y]]; }; HSLToColor: PUBLIC PROC[h,s,l: REAL, cal: Calibration _ NIL] RETURNS[ConstantColor] = { x,y,Y: REAL; r,g,b: REAL; [r: r,g: g,b: b] _ ColorModels.HSLToRGB[h: h, s: s, l: l]; [x: x,y: y,Y: Y] _ ColorModels.RGBToCIE[r: r, g: g, b: b, calibration: Cal[cal]]; RETURN[MakeRep[x: x, y: y,Y: Y]]; }; RGBToColor: PUBLIC PROC[r,g,b: REAL, cal: Calibration _ NIL] RETURNS[ConstantColor] = { x,y,Y: REAL; [x: x,y: y,Y: Y] _ ColorModels.RGBToCIE[r: r, g: g, b: b, calibration: Cal[cal]]; RETURN[MakeRep[x: x, y: y,Y: Y]]; }; CIEToColor: PUBLIC PROC [x,y,Y: REAL] RETURNS [ConstantColor] = { RETURN[MakeRep[x: x, y: y,Y: Y]]}; NameToColor: PUBLIC PROC[name: Rope.ROPE, cal: Calibration _ NIL] RETURNS[ConstantColor] = { h,s,l: REAL; [h: h,s: s,l: l] _ ColorNames.ParseColorName[name]; RETURN[HSLToColor[h: h,s: s,l: l, cal: cal]]; }; ColorToIntensity: PUBLIC PROC[color: ConstantColor, cal: Calibration _ NIL] RETURNS[intensity: REAL] = { RETURN[CardToReal[color.Y]]; }; ColorToHSV: PUBLIC PROC[color: ConstantColor, cal: Calibration _ NIL] RETURNS[h, s, v: REAL] = { x,y,Y: REAL; r,g,b: REAL; x _ CardToReal[color.x]; y _ CardToReal[color.y]; Y _ CardToReal[color.Y]; [r: r,g: g,b: b] _ ColorModels.CIEToRGB[x: x, y: y,Y: Y, calibration: Cal[cal]]; [r,g,b] _ Defuzz[r,g,b]; [h: h,s: s,v: v] _ ColorModels.RGBToHSV[r: r, g: g, b: b]; RETURN[h: h,s: s,v: v]; }; ColorToHSL: PUBLIC PROC[color: ConstantColor, cal: Calibration _ NIL] RETURNS[h, s, l: REAL] = { x,y,Y: REAL; r,g,b: REAL; x _ CardToReal[color.x]; y _ CardToReal[color.y]; Y _ CardToReal[color.Y]; [r: r,g: g,b: b] _ ColorModels.CIEToRGB[x: x, y: y,Y: Y, calibration: Cal[cal]]; [r,g,b] _ Defuzz[r,g,b]; [h: h,s: s,l: l] _ ColorModels.RGBToHSL[r: r, g: g, b: b]; RETURN[h: h,s: s,l: l]; }; ColorToRGB: PUBLIC PROC[color: ConstantColor, cal: Calibration _ NIL] RETURNS[r, g, b: REAL] = { x,y,Y: REAL; x _ CardToReal[color.x]; y _ CardToReal[color.y]; Y _ CardToReal[color.Y]; [r: r,g: g,b: b] _ ColorModels.CIEToRGB[x: x, y: y,Y: Y, calibration: Cal[cal]]; [r,g,b] _ Defuzz[r,g,b]; RETURN[r: r, g: g, b: b]; }; Defuzz: PROC [a,b,c: REAL] RETURNS[REAL, REAL, REAL] = { IF RealFns.AlmostZero[a,-10] THEN a _ 0; IF RealFns.AlmostZero[b,-10] THEN b _ 0; IF RealFns.AlmostZero[c,-10] THEN c _ 0; IF RealFns.AlmostZero[a-1.0,-10] THEN a _ 1; IF RealFns.AlmostZero[b-1.0,-10] THEN b _ 1; IF RealFns.AlmostZero[c-1.0,-10] THEN c _ 1; RETURN[a,b,c]; }; ColorToCIE: PROC [color: ConstantColor, cal: Calibration _ NIL] RETURNS [x,y,Y: REAL] = { x _ CardToReal[color.x]; y _ CardToReal[color.y]; Y _ CardToReal[color.Y]; }; ColorToName: PUBLIC PROC [color: ConstantColor, cal: Calibration _ NIL] RETURNS [name: Rope.ROPE] = { h,s,l: REAL; [h: h,s: s,l: l] _ ColorToHSL[color,cal]; name _ ColorNames.HSLToRope[h: h,s: s,l: l]; RETURN[name]; }; Card: PROC [real: REAL] RETURNS [card: CARDINAL] ~ { int: INT _ Real.RoundLI[real*LAST[CARDINAL]]; card _ MAX[MIN[int, LAST[CARDINAL]], 0]; }; CardToReal: PROC [card: CARDINAL] RETURNS [real: REAL] ~ { real _ card; RETURN[real / LAST[CARDINAL]]; }; MakeRep: PROC[x,y,Y: REAL] RETURNS[ConstantColor] = { RETURN [NEW[ImagerBasic.ColorRep[constant] _ [constant[x: Card[x], y: Card[y], Y: Card[Y]]]]]; }; Cal: PROC[cal: ColorModels.Calibration] RETURNS [ColorModels.Calibration] = { RETURN[IF cal=NIL THEN ColorModels.GetPhosphorCalibration[] ELSE cal]; }; END. ώConstantColorsImpl.mesa Copyright c 1984 by Xerox Corporation. All rights reserved. Michael Plass, August 1, 1983 11:43 am Last Edited by: Stone, August 11, 1984 4:30:05 pm PDT Last Edited by: Crow, April 20, 1984 12:29:49 pm PST format utilities Κ‘˜J™Jšœ Οmœ1™