[2] | 1 | ;+ |
---|
| 2 | ; |
---|
[231] | 3 | ; @file_comments |
---|
[133] | 4 | ; The purpose of this function is to convert a RGB color triple |
---|
[231] | 5 | ; into the equivalent 24-big long integer. |
---|
[237] | 6 | ; This routine was written to be used with routines like |
---|
| 7 | ; COLORS <!--++ COLORS is not a routine--> or |
---|
[231] | 8 | ; <pro>GETCOLOR</pro>. |
---|
[2] | 9 | ; |
---|
[231] | 10 | ; @categories |
---|
| 11 | ; Graphics, Color |
---|
[2] | 12 | ; |
---|
[231] | 13 | ; @param rgb_triple {in}{required} |
---|
| 14 | ; A three-element column or row array representing |
---|
[136] | 15 | ; a color triple. The values of the elements must be between 0 and 255. |
---|
[2] | 16 | ; |
---|
[231] | 17 | ; @returns |
---|
| 18 | ; a 24-bit long integer that is equivalent the input color. |
---|
[136] | 19 | ; The color is described in terms of a hexadecimal number (e.g., FF206A) |
---|
[231] | 20 | ; where the left two digits represent the blue color, the |
---|
| 21 | ; middle two digits represent the green color, and the right |
---|
[133] | 22 | ; two digits represent the red color. |
---|
[2] | 23 | ; |
---|
[231] | 24 | ; @examples |
---|
| 25 | ; To convert the color triple for the color YELLOW, |
---|
| 26 | ; (255, 255, 0), to the hexadecimal value '00FFFF'x |
---|
[136] | 27 | ; or the decimal number 65535, type: |
---|
[2] | 28 | ; |
---|
[136] | 29 | ; IDL> color = COLOR24([255, 255, 0]) |
---|
[2] | 30 | ; |
---|
[231] | 31 | ; |
---|
[133] | 32 | ; @history |
---|
[2] | 33 | ; Written by: David Fanning, 3 February 96. |
---|
[133] | 34 | ; |
---|
[231] | 35 | ; @version |
---|
| 36 | ; $Id$ |
---|
[133] | 37 | ; |
---|
[2] | 38 | ;- |
---|
[163] | 39 | FUNCTION color24, rgb_triple |
---|
[114] | 40 | ; |
---|
| 41 | compile_opt idl2, strictarrsubs |
---|
[231] | 42 | ; |
---|
[2] | 43 | ON_ERROR, 1 |
---|
| 44 | |
---|
[136] | 45 | IF N_ELEMENTS(rgb_triple) NE 3 THEN $ |
---|
[242] | 46 | ras= report('Argument must be a three-element vector.') |
---|
[2] | 47 | |
---|
[136] | 48 | IF MAX(rgb_triple) GT 255 OR MIN(rgb_triple) LT 0 THEN $ |
---|
[242] | 49 | ras = report('Argument values must be in range of 0-255') |
---|
[2] | 50 | |
---|
| 51 | base16 = [[1L, 16L], [256L, 4096L], [65536L, 1048576L]] |
---|
| 52 | |
---|
| 53 | num24bit = 0L |
---|
| 54 | |
---|
[136] | 55 | FOR j=0,2 DO num24bit = num24bit + ((rgb_triple[j] MOD 16) * base16[0,j]) + $ |
---|
| 56 | (Fix(rgb_triple[j]/16) * base16[1,j]) |
---|
[231] | 57 | |
---|
[2] | 58 | RETURN, num24bit |
---|
[231] | 59 | END |
---|