Colors and IDL Graphic Systems
IDL supports two graphics systems: Object Graphics and Direct Graphics. This section provides detailed descriptions of how color is represented and interpreted in the Direct Graphics system.
Using Color in Object Graphics
For complete details regarding color and Object Graphics, see Color in Object Graphics (Object Programming).
Using Color in Direct Graphics
More information on the following topics is available in X Windows Visuals (IDL Reference Guide).
Visuals on UNIX Platforms
When IDL creates its first Direct Graphics window, it must select a visual to be associated with that window. By default, IDL selects an X Visual Class by requesting (in order) from the following table until a supported visual is found, but a specific visual can be explicitly requested at the beginning of an IDL session by setting the appropriate keyword to the DEVICE procedure:
To request an 8-bit PseudoColor visual, the syntax would be:
Another approach to setting the visual information is to include the idl.gr_visual and idl.gr_depth resources in your .Xdefaults file.
A visual is selected once per IDL session (when the first graphic window is created). Once selected, the same visual will be used for all Direct Graphics windows in that IDL session.
Private versus Shared Colormaps
On UNIX platforms, when a window manager is started, it creates a default colormap that can be shared among applications using the display. This is called the shared colormap.
A given application may request to use its own colormap that is not shared with other applications. This is called a private colormap.
IDL attempts, whenever possible, to get color table entries in the shared colormap. If enough colors are not available in the shared colormap, a private colormap is used. If an X Visual class and depth are specified and they do not match the default visual of the screen (see xdpyinfo), a private colormap is used.
If a private colormap is used, then colormap flashing may occur when an IDL window is made current (in which case, the colors of other applications on the desktop may no longer appear as you would expect), or when an application using the shared colormap is made current (in which case, the colors within the IDL graphics window may no longer appear as you would expect). This flashing behavior is to be expected. By design, the IDL graphics window has been assigned a dedicated color table so that the full range of requested colors can be utilized for image display.
Visuals on Windows Platforms
On Windows platforms, the visual that IDL uses is dependent upon the system setting. For more information, Setting a Visual on Windows Platforms.
IDL Color Table
IDL maintains a single current color table for Direct Graphics. Refer to the sections Loading a Default Color Table and Modifying and Converting Color Tables. IDL provides 41 pre-defined color tables.
Foreground Color
In IDL Direct Graphics, colors used for drawing graphic primitives (such as lines, text annotations, etc.) are represented in one of two ways:
- Indexed - each color is an index into the current IDL color table
- RGB - each color is a long integer that contains the red value in the first eight bits, the green value in the next eight bits, and the blue value in the next eight bits. In other words, a color can be represented using the following equation:
The RGB form is only supported on TrueColor display devices.
The DECOMPOSED keyword to the DEVICE procedure is used to notify IDL whether color is to be interpreted as an index or as a composite RGB value. IDL then maps any requested color to an encoding that is appropriate for the current display device.
The foreground color (used for drawing) can be set by assigning a color value to the !P.COLOR system variable field (or by setting the COLOR keyword on the individual graphic routine).
If a color value is to be interpreted as an index, then inform IDL by setting the DECOMPOSED keyword of the DEVICE routine to 0:
The foreground color can then be specified by setting !P.COLOR to an index into the IDL color table. For example, if the foreground color is to be set to the RGB value stored at entry 25 in the IDL color table, then use the following IDL command:
If a color value is to be interpreted as a composite RGB value, then inform IDL by setting the DECOMPOSED keyword of the DEVICE routine to 1:
The foreground color can then be specified by setting !P.COLOR to a composite RGB value. For example, if the foreground color is to be set to the color yellow, [255,255,0], then use the following IDL command:
Image Colors
Color for image data is handled in a fashion similar to other graphic primitives, except that some special cases apply based upon the organization of the image data and the visual of the current display device.
If the image is organized as a:
- two-dimensional array -
- If the display device is PseudoColor, then each pixel is interpreted as an index into the IDL color table
- If the display device is TrueColor and if the DECOMPOSED keyword for the DEVICE procedure is set to 0, then each pixel value is interpreted as an index into the IDL color table (thereby emulating a PseudoColor display device).
- If the display device is TrueColor and if the DECOMPOSED keyword for the DEVICE procedure is set to 1, then each pixel value is interpreted as the value to be copied to each of the red, green, and blue components of the RGB color.
- RGB array - (Supported only for TrueColor display devices)
To display an RGB image on a PseudoColor device, use the COLOR_QUAN routine to convert it to an indexed form. Refer to the section Converting Between Image Types.
The TV command can be used to display the image in IDL. For RGB images, the TRUE keyword can be used to indicate which form of interleaving is used.