DEFINITION MODULE Palette;

(*
    Title: 	Standard Colours for GKS
    LastEdit:	"Wed Apr 30 14:56:38 1986"
    Author: 	jd / jacs
		Cambridge University Computer Laboratory
*)

(*  Updated 30/4/86 to provide 16 colour interface.
*)

(* This module provides a standard colour palette of the more generally
   useful colours. It is not part of GKS, and is an addition to it purely
   for convenience.
   
   The module provides a standard translation of an enumerated type COLOURS
   into red, green, and blue intensities, and also the reverse translation,
   in each case making the best approximation possible. Clients of GKS will
   find the COLOUR -> (r,g,b) most useful, and GKS back ends will find the
   (r,g,b) to COLOUR most useful.
*)

EXPORT QUALIFIED
    COLOUR, PALETTE, INTENSITY, Intensity, Colour, Rainbow, Rainbow16;

TYPE
    COLOUR = (Black, Red, Green, Yellow, Blue, Magenta, Cyan, White,
              Orange, GreenYellow, GreenCyan, BlueCyan, BlueMagenta, 
              RedMagenta, DarkGrey, LightGrey);  
        (* corresponding to full or 0 intensity on the three primaries with
           blue most significant, and green least significant. Thus Cyan
           corresponds to blue=1.0, green=1.0, red=0.0
        *)
     PALETTE = SET OF COLOUR;
     INTENSITY = RECORD R, G, B: REAL END;

CONST
    Rainbow = 
        PALETTE {Black, Red, Green, Yellow, Blue, Magenta, Cyan, White};
    
    Rainbow16 =
        PALETTE {Black, Red, Green, Yellow, Blue, Magenta, Cyan, White,
                 Orange, GreenYellow, GreenCyan, BlueCyan,  BlueMagenta, 
                 RedMagenta, DarkGrey, LightGrey};

PROCEDURE Intensity (c: COLOUR; VAR i: INTENSITY);
    (* translates COLOURs to INTENSITYs *)

PROCEDURE Colour (i: INTENSITY; p: PALETTE): COLOUR;
    (* returns the colour in p with the intensity closest to i. If there
       is more than one closest approximation, the lowest colour among them
       is chosen.
    *)


END Palette.
