Changeset 133 for trunk/SRC/Colors/getcolor.pro
- Timestamp:
- 07/07/06 11:57:27 (18 years ago)
- Location:
- trunk/SRC/Colors
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/Colors/getcolor.pro
r132 r133 1 1 ;+ 2 ; NAME: 3 ; GETCOLOR 4 ; 5 ; PURPOSE: 6 ; The original purpose of this function was to enable the 7 ; user to specify one of the 16 colors supported by the 8 ; McIDAS color map by name. Over time, however, the function 9 ; has become a general purpose function for handling and 10 ; supporting drawing colors in a device-independent way. 11 ; In particular, I have been looking for ways to write color 12 ; handling code that will work transparently on both 8-bit and 13 ; 24-bit machines. On 24-bit machines, the code should work the 14 ; same where color decomposition is turned on or off. 2 ; 3 ; @file_comments 4 ; The original purpose of this function was to enable the 5 ; user to specify one of the 16 colors supported by the 6 ; McIDAS color map by name. Over time, however, the function 7 ; has become a general purpose function for handling and 8 ; supporting drawing colors in a device-independent way. 9 ; In particular, I have been looking for ways to write color 10 ; handling code that will work transparently on both 8-bit and 11 ; 24-bit machines. On 24-bit machines, the code should work the 12 ; same where color decomposition is turned on or off. 15 13 ; 16 14 ; (The 16 supported colors in GETCOLOR come from the McIDAS color 17 15 ; table offered on the IDL newsgroup by Liam Gumley.) 18 16 ; 19 ; CATEGORY: 20 ; Graphics, Color Specification. 21 ; 22 ; CALLING SEQUENCE: 23 ; result = GETCOLOR(color) 24 ; 25 ; OPTIONAL INPUT PARAMETERS: 26 ; COLOR: A string with the "name" of the color. Valid names are: 17 ; @categories Graphics, Color Specification. 18 ; 19 ; @param thisColor {in}{optional} A string with the "name" of the color. Valid names are: 27 20 ; black 28 21 ; magenta … … 53 46 ; IDL 5.2 or higher. 54 47 ; 55 ; INDEX:The color table index where the specified color should be loaded.48 ; @param index {in}{optional} The color table index where the specified color should be loaded. 56 49 ; If this parameter is passed, then the return value of the function is the 57 50 ; index number and not the color triple. (If color decomposition is turned … … 69 62 ; TVLCT, colors, 100 70 63 ; 71 ; 72 ; INPUT KEYWORD PARAMETERS: 73 ; 74 ; NAMES: If this keyword is set, the return value of the function is 64 ; @keyword NAMES If this keyword is set, the return value of the function is 75 65 ; a 16-element string array containing the names of the colors. 76 66 ; These names would be appropriate, for example, in building … … 80 70 ; listID = Widget_List(baseID, Value=GetColor(/Names), YSize=16) 81 71 ; 82 ; LOAD:If this keyword is set, all 16 colors are automatically loaded72 ; @keyword LOAD If this keyword is set, all 16 colors are automatically loaded 83 73 ; starting at the color index specified by the START keyword. 84 74 ; Note that setting this keyword means that the return value of the … … 92 82 ; byte array or a long integer value. 93 83 ; 94 ; START:The starting color index number if the LOAD keyword is set. This keyword84 ; @keyword START The starting color index number if the LOAD keyword is set. This keyword 95 85 ; value is ignored unless the LOAD keyword is also set. The keyword is also 96 86 ; ignored if the TRUE keyword is set or if color decomposition in on in … … 98 88 ; !D.TABLE_SIZE - 17. 99 89 ; 100 ; TRUE:If this keyword is set, the specified color triple is returned90 ; @keyword TRUE If this keyword is set, the specified color triple is returned 101 91 ; as a 24-bit integer equivalent. The lowest 8 bits correspond to 102 92 ; the red value; the middle 8 bits to the green value; and the … … 105 95 ; were set. 106 96 ; 107 ; COMMON BLOCKS: 108 ; None. 109 ; 110 ; SIDE EFFECTS: 111 ; None. 112 ; 113 ; RESTRICTIONS: 114 ; The TRUE keyword causes the START keyword to be ignored. 97 ; @restrictions The TRUE keyword causes the START keyword to be ignored. 115 98 ; The NAMES keyword causes the COLOR, INDEX, START, and TRUE parameters to be ignored. 116 99 ; The COLOR parameter is ignored if the LOAD keyword is used. … … 119 102 ; returned if color decomposition is ON. 120 103 ; 121 ; EXAMPLE:122 ; 123 ; 124 ; yellow = GETCOLOR('yellow', 100)125 ; PLOT, data, COLOR=yellow104 ; 105 ; @examples To load a yellow color in color index 100 and plot in yellow, type: 106 ; 107 ; IDL> yellow = GETCOLOR('yellow', 100) 108 ; IDL> PLOT, data, COLOR=yellow 126 109 ; 127 110 ; or, 128 111 ; 129 ; PLOT, data, COLOR=GETCOLOR('yellow', 100)112 ; IDL> PLOT, data, COLOR=GETCOLOR('yellow', 100) 130 113 ; 131 114 ; To do the same thing on a 24-bit color system with decomposed color on, type: 132 115 ; 133 ; PLOT, data, COLOR=GETCOLOR('yellow', /TRUE)116 ; IDL> PLOT, data, COLOR=GETCOLOR('yellow', /TRUE) 134 117 ; 135 118 ; or in IDL 5.2 and higher, 136 119 ; 137 ; DEVICE, Decomposed=1138 ; PLOT, data, COLOR=GETCOLOR('yellow')120 ; IDL> DEVICE, Decomposed=1 121 ; IDL> PLOT, data, COLOR=GETCOLOR('yellow') 139 122 ; 140 123 ; To load all 16 colors into the current color table, starting at 141 124 ; color index 200, type: 142 125 ; 143 ; TVLCT, GETCOLOR(), 200126 ; IDL> TVLCT, GETCOLOR(), 200 144 127 ; 145 128 ; To add the color names to a list widget: 146 129 ; 147 ; listID = Widget_List(baseID, Value=GetColor(/Names), YSize=16)130 ; IDL> listID = Widget_List(baseID, Value=GetColor(/Names), YSize=16) 148 131 ; 149 132 ; To load all 16 colors and have the color indices returned in a structure: 150 133 ; 151 ; DEVICE, Decomposed=0152 ; colors = GetColor(/Load, Start=1)153 ; HELP, colors, /Structure134 ; IDL> DEVICE, Decomposed=0 135 ; IDL> colors = GetColor(/Load, Start=1) 136 ; IDL> HELP, colors, /Structure 154 137 ; PLOT, data, COLOR=colors.yellow 155 138 ; 156 139 ; To get the direct color values as 24-bit integers in color structure fields: 157 140 ; 158 ; DEVICE, Decomposed=1159 ; colors = GetColor(/Load)160 ; PLOT, data, COLOR=colors.yellow141 ; IDL> DEVICE, Decomposed=1 142 ; IDL> colors = GetColor(/Load) 143 ; IDL> PLOT, data, COLOR=colors.yellow 161 144 ; 162 145 ; Note that the START keyword value is ignored if on a 24-bit device, … … 164 147 ; writing code like this: 165 148 ; 166 ; colors = GetColor(/Load) 167 ; PLOT, data, Color=colors.yellow 168 ; 169 ; MODIFICATION HISTORY: 170 ; Written by: David Fanning, 10 February 96. 149 ; IDL> colors = GetColor(/Load) 150 ; IDL> PLOT, data, Color=colors.yellow; IDL> DEVICE, Decomposed=0 151 ; IDL> colors = GetColor(/Load, Start=1) 152 ; IDL> HELP, colors, /Structure 153 ; PLOT, data, COLOR=colors.yellow 154 ; 155 ; To get the direct color values as 24-bit integers in color structure fields: 156 ; 157 ; IDL> DEVICE, Decomposed=1 158 ; IDL> colors = GetColor(/Load) 159 ; IDL> PLOT, data, COLOR=colors.yellow 160 ; 161 ; Note that the START keyword value is ignored if on a 24-bit device, 162 ; so it is possible to write completely device-independent code by 163 ; writing code like this: 164 ; 165 ; IDL> colors = GetColor(/Load) 166 ; IDL> PLOT, data, Color=colors.yellow 167 ; 168 ; @history Written by: David Fanning, 10 February 96. 171 169 ; Fixed a bug in which N_ELEMENTS was spelled wrong. 7 Dec 96. DWF 172 170 ; Added the McIDAS colors to the program. 24 Feb 99. DWF … … 176 174 ; Added automatic recognition of DECOMPOSED=1 state. 7 June 99. DWF 177 175 ; Added LOAD AND START keywords. 7 June 99. DWF. 176 ; 177 ; @version $Id$ 178 178 ;- 179 180 181 182 FUNCTION COLOR24, number183 ;184 compile_opt idl2, strictarrsubs185 ;186 187 ; This FUNCTION accepts a [red, green, blue] triple that188 ; describes a particular color and returns a 24-bit long189 ; integer that is equivalent to that color. The color is190 ; described in terms of a hexidecimal number (e.g., FF206A)191 ; where the left two digits represent the blue color, the192 ; middle two digits represent the green color, and the right193 ; two digits represent the red color.194 ;195 ; The triple can be either a row or column vector of 3 elements.196 197 ON_ERROR, 1198 199 IF N_ELEMENTS(number) NE 3 THEN $200 MESSAGE, 'Augument must be a three-element vector.'201 202 IF MAX(number) GT 255 OR MIN(number) LT 0 THEN $203 MESSAGE, 'Argument values must be in range of 0-255'204 205 base16 = [[1L, 16L], [256L, 4096L], [65536L, 1048576L]]206 207 num24bit = 0L208 209 FOR j=0,2 DO num24bit = num24bit + ((number[j] MOD 16) * base16[0,j]) + $210 (Fix(number[j]/16) * base16[1,j])211 212 RETURN, num24bit213 END ; ************************ of COLOR24 ******************************214 215 216 179 217 180 FUNCTION GETCOLOR, thisColor, index, TRUE=truecolor, $
Note: See TracChangeset
for help on using the changeset viewer.