source: trunk/SRC/ToBeReviewed/POSTSCRIPT/chcolps.pro @ 325

Last change on this file since 325 was 325, checked in by pinsard, 16 years ago

modification of some headers (+some corrections) to prepare usage of the new idldoc

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1;+
2;
3; @file_comments
4;
5; @categories
6;
7; @param TABLE
8;
9; @restrictions
10;
11; @examples
12;
13; @history
14;
15;
16; @version
17; $Id$
18;
19;-
20PRO format_colortable_hexa, table
21;
22  compile_opt idl2, strictarrsubs
23;
24
25    tvlct, r, g, b, /get
26
27    z = strarr(256)
28    y = strarr(256)
29    for k=0,255 do z[k]='00'+strtrim(string(r[k], format = '(Z)'),2)
30    for k=0,255 do y[k]=y[k]+strmid(z[k],strlen(z[k])-2,2)
31
32    for k=0,255 do z[k]='00'+strtrim(string(g[k], format = '(Z)'),2)
33    for k=0,255 do y[k]=y[k]+strmid(z[k],strlen(z[k])-2,2)
34
35    for k=0,255 do z[k]='00'+strtrim(string(b[k], format = '(Z)'),2)
36    for k=0,255 do y[k]=y[k]+strmid(z[k],strlen(z[k])-2,2)
37   
38    table =  strlowcase(y)
39
40END
41;
42;+
43;
44; @file_comments
45; Build a bloc of colortable
46;
47; @categories
48;
49; @param TABLEOUT
50;
51; @restrictions
52;
53; @examples
54;
55; @history
56;
57; @version
58; $Id$
59;
60;-
61PRO build_table, tableout
62;
63  compile_opt idl2, strictarrsubs
64;
65
66    format_colortable_hexa, table
67
68
69    tableout = strarr(25)
70
71    tableout[0] = '/COLORTAB < '
72    FOR k = 0, 8 DO tableout[0] = tableout[0]+table[k]+' '
73    FOR i = 1, 22 DO BEGIN
74          FOR k = 11*i-2, 11*i+8 DO tableout[i] = tableout[i]+table[k]+' '
75    ENDFOR
76    FOR k = 251, 255 DO tableout[i] = tableout[i]+table[k]+' '
77    tableout[i] = tableout[i]+'> def'
78   
79END
80;
81;+
82;
83; @file_comments
84; Modify colors of a postscript file
85;
86; @categories
87;
88; @param N1 {in}{required}
89; Number of elements in the first dimension
90;
91; @param N2 {in}{required}
92; Number of elements in the second dimension
93;
94; @param FILE
95; A scalar of string type, the name of the ".pro" file to be tested
96; if necessary, the input name is completed with '.pro' and its path
97; found in !path
98;
99; @keyword PALIT1
100;
101; @keyword PALIT2
102;
103; @restrictions
104;
105; @examples
106;
107; @history
108; G. Roullet 1999
109;
110; @version
111; $Id$
112;
113;-
114PRO chcolps, n1, n2, file, PALIT1 = palit1, PALIT2 = palit2
115;
116  compile_opt idl2, strictarrsubs
117;
118; recuperate palettes
119;
120    lct, n1
121    IF keyword_set(palit1) THEN palit, palit1
122    tvlct, red, green, blue, /get
123
124    lct, n2
125    IF keyword_set(palit2) THEN palit, palit2
126    tvlct, red1, green1, blue1, /get
127;
128;
129;
130    filein = file
131    fileout = file+'.new'
132   
133    openr, numin, filein, /get_lun
134    openw, numout, fileout, /get_lun
135    ligne = ''
136    nl = 0
137    colortab = 0
138;
139; Scan le fichier
140;
141    WHILE NOT(eof(numin)) DO BEGIN
142          readf, numin, ligne, format = '(A)'
143          nl = nl+1
144;
145; Replace setrgbcolor statements
146;
147          pos = strpos(ligne, 'setrgbcolor')
148          IF pos NE -1 THEN BEGIN
149                r = round(float(strmid(ligne, pos-18, 6))*255)
150                g = round(float(strmid(ligne, pos-12, 6))*255)
151                b = round(float(strmid(ligne, pos-6, 6))*255)         
152                ind = where(r EQ red AND g EQ green AND b EQ blue)
153                ind = ind[0]
154                IF ind[0] NE -1 THEN BEGIN
155                      r1 = red1[ind]/255.
156                      g1 = green1[ind]/255.
157                      b1 = blue1[ind]/255.
158                      color = string(r1, g1, b1, format = '(3(F5.3,:,X))')
159                      strput, ligne, color, pos-18
160                ENDIF ELSE BEGIN
161;                     ras = report('erreur ligne :' + string(nl))
162                      dist = abs(r-red)+abs(g-green)+abs(b-blue)
163                      ind = (where(dist EQ min(dist)))[0]
164                      ind = ind[0]
165;                      ras = report( $
166;                       ['I found ' + string(long([r, g, b])), $
167;                       'I replace it by ' + string([red[ind], green[ind], blue[ind]])])
168                      r1 = red1[ind]/255.
169                      g1 = green1[ind]/255.
170                      b1 = blue1[ind]/255.
171                      color = string(r1, g1, b1, format = '(3(F5.3,:,X))')
172                      strput, ligne, color, pos-18
173                ENDELSE
174          ENDIF           
175;
176; Replace COLORTAB
177;
178          pos = strpos(ligne, '/COLORTAB')
179          IF pos NE -1 THEN BEGIN
180                build_table, table
181                n = 0
182                colortab = 1
183          ENDIF
184
185          IF colortab THEN BEGIN
186                ligne = table[n]
187                n = n+1
188                IF n EQ 24 THEN colortab = 0
189          ENDIF
190;
191; Ecrit le fichier de sortie
192;
193          printf, numout, ligne, format = '(A)'
194    ENDWHILE
195    close, numin
196    close, numout
197    free_lun, numin
198    free_lun, numout
199
200    spawn, 'gs '+fileout
201
202END
203
Note: See TracBrowser for help on using the repository browser.