source: trunk/SRC/Colors/color24.pro @ 134

Last change on this file since 134 was 134, checked in by navarro, 18 years ago

change *.pro file properties (del eof-style, del executable, set keywords Id

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
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;
7; @categories Graphics, Color Specification.
8;
9; @param RGB_TRIPLE {in}{required} A three-element column or row array representing
10;       a color triple. The values of the elements must be between
11;       0 and 255.
12;
13; @returns a 24-bit long integer that is equivalent the input color.
14; The color is
15; described in terms of a hexidecimal number (e.g., FF206A)
16; where the left two digits represent the blue color, the
17; middle two digits represent the green color, and the right
18; two digits represent the red color.
19;
20; @examples To convert the color triple for the color YELLOW,
21;       (255, 255, 0), to the hexadecimal value '00FFFF'x
22;       or the decimal number 65535, type:
23;
24;       color = COLOR24([255, 255, 0])
25;       
26;       This routine was written to be used with routines like
27;       COLORS or GETCOLOR
28;
29; @history
30;       Written by:     David Fanning, 3 February 96.
31;
32; @version $Id$
33;
34;-
35FUNCTION COLOR24, number
36;
37  compile_opt idl2, strictarrsubs
38;   
39ON_ERROR, 1
40
41IF N_ELEMENTS(number) NE 3 THEN $
42   MESSAGE, 'Augument must be a three-element vector.'
43
44IF MAX(number) GT 255 OR MIN(number) LT 0 THEN $
45   MESSAGE, 'Argument values must be in range of 0-255'
46
47base16 = [[1L, 16L], [256L, 4096L], [65536L, 1048576L]]
48
49num24bit = 0L
50
51FOR j=0,2 DO num24bit = num24bit + ((number[j] MOD 16) * base16[0,j]) + $
52   (Fix(number[j]/16) * base16[1,j])
53   
54RETURN, num24bit
55END
Note: See TracBrowser for help on using the repository browser.