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