source: trunk/SRC/ToBeReviewed/COULEURS/color24.pro @ 132

Last change on this file since 132 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
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
47FUNCTION COLOR24, number
48;
49  compile_opt idl2, strictarrsubs
50;
51
52   ; This FUNCTION accepts a [red, green, blue] triple that
53   ; describes a particular color and returns a 24-bit long
54   ; integer that is equivalent to that color. The color is
55   ; described in terms of a hexidecimal number (e.g., FF206A)
56   ; where the left two digits represent the blue color, the
57   ; middle two digits represent the green color, and the right
58   ; two digits represent the red color.
59   ;
60   ; The triple can be either a row or column vector of 3 elements.
61   
62ON_ERROR, 1
63
64IF N_ELEMENTS(number) NE 3 THEN $
65   MESSAGE, 'Augument must be a three-element vector.'
66
67IF MAX(number) GT 255 OR MIN(number) LT 0 THEN $
68   MESSAGE, 'Argument values must be in range of 0-255'
69
70base16 = [[1L, 16L], [256L, 4096L], [65536L, 1048576L]]
71
72num24bit = 0L
73
74FOR j=0,2 DO num24bit = num24bit + ((number[j] MOD 16) * base16[0,j]) + $
75   (Fix(number[j]/16) * base16[1,j])
76   
77RETURN, num24bit
78END
Note: See TracBrowser for help on using the repository browser.