[2] | 1 | ;+ |
---|
| 2 | ; NAME: |
---|
| 3 | ; COLOR24 |
---|
| 4 | ; |
---|
| 5 | ; PURPOSE: |
---|
| 6 | ; The purpose of this function is to convert a RGB color triple |
---|
| 7 | ; into the equivalent 24-big long integer. |
---|
| 8 | ; |
---|
| 9 | ; CATEGORY: |
---|
| 10 | ; Graphics, Color Specification. |
---|
| 11 | ; |
---|
| 12 | ; CALLING SEQUENCE: |
---|
| 13 | ; color = COLOR24(rgb_triple) |
---|
| 14 | ; |
---|
| 15 | ; INPUTS: |
---|
| 16 | ; RGB_TRIPLE: A three-element column or row array representing |
---|
| 17 | ; a color triple. The values of the elements must be between |
---|
| 18 | ; 0 and 255. |
---|
| 19 | ; |
---|
| 20 | ; KEYWORD PARAMETERS: |
---|
| 21 | ; None. |
---|
| 22 | ; |
---|
| 23 | ; COMMON BLOCKS: |
---|
| 24 | ; None. |
---|
| 25 | ; |
---|
| 26 | ; SIDE EFFECTS: |
---|
| 27 | ; None. |
---|
| 28 | ; |
---|
| 29 | ; RESTRICTIONS: |
---|
| 30 | ; None. |
---|
| 31 | ; |
---|
| 32 | ; EXAMPLE: |
---|
| 33 | ; To convert the color triple for the color YELLOW, |
---|
| 34 | ; (255, 255, 0), to the hexadecimal value '00FFFF'x |
---|
| 35 | ; or the decimal number 65535, type: |
---|
| 36 | ; |
---|
| 37 | ; color = COLOR24([255, 255, 0]) |
---|
| 38 | ; |
---|
| 39 | ; This routine was written to be used with routines like |
---|
| 40 | ; COLORS or GETCOLOR |
---|
| 41 | ; |
---|
| 42 | ; MODIFICATION HISTORY: |
---|
| 43 | ; Written by: David Fanning, 3 February 96. |
---|
| 44 | ;- |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | FUNCTION COLOR24, number |
---|
| 48 | |
---|
| 49 | ; This FUNCTION accepts a [red, green, blue] triple that |
---|
| 50 | ; describes a particular color and returns a 24-bit long |
---|
| 51 | ; integer that is equivalent to that color. The color is |
---|
| 52 | ; described in terms of a hexidecimal number (e.g., FF206A) |
---|
| 53 | ; where the left two digits represent the blue color, the |
---|
| 54 | ; middle two digits represent the green color, and the right |
---|
| 55 | ; two digits represent the red color. |
---|
| 56 | ; |
---|
| 57 | ; The triple can be either a row or column vector of 3 elements. |
---|
| 58 | |
---|
| 59 | ON_ERROR, 1 |
---|
| 60 | |
---|
| 61 | IF N_ELEMENTS(number) NE 3 THEN $ |
---|
| 62 | MESSAGE, 'Augument must be a three-element vector.' |
---|
| 63 | |
---|
| 64 | IF MAX(number) GT 255 OR MIN(number) LT 0 THEN $ |
---|
| 65 | MESSAGE, 'Argument values must be in range of 0-255' |
---|
| 66 | |
---|
| 67 | base16 = [[1L, 16L], [256L, 4096L], [65536L, 1048576L]] |
---|
| 68 | |
---|
| 69 | num24bit = 0L |
---|
| 70 | |
---|
| 71 | FOR j=0,2 DO num24bit = num24bit + ((number(j) MOD 16) * base16(0,j)) + $ |
---|
| 72 | (Fix(number(j)/16) * base16(1,j)) |
---|
| 73 | |
---|
| 74 | RETURN, num24bit |
---|
| 75 | END |
---|