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

Last change on this file since 378 was 327, checked in by pinsard, 17 years ago

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.3 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    filein = file
129    fileout = file+'.new'
130   
131    openr, numin, filein, /get_lun
132    openw, numout, fileout, /get_lun
133    ligne = ''
134    nl = 0
135    colortab = 0
136;
137; Scan le fichier
138;
139    WHILE NOT(eof(numin)) DO BEGIN
140          readf, numin, ligne, format = '(A)'
141          nl = nl+1
142;
143; Replace setrgbcolor statements
144;
145          pos = strpos(ligne, 'setrgbcolor')
146          IF pos NE -1 THEN BEGIN
147                r = round(float(strmid(ligne, pos-18, 6))*255)
148                g = round(float(strmid(ligne, pos-12, 6))*255)
149                b = round(float(strmid(ligne, pos-6, 6))*255)         
150                ind = where(r EQ red AND g EQ green AND b EQ blue)
151                ind = ind[0]
152                IF ind[0] NE -1 THEN BEGIN
153                      r1 = red1[ind]/255.
154                      g1 = green1[ind]/255.
155                      b1 = blue1[ind]/255.
156                      color = string(r1, g1, b1, format = '(3(F5.3,:,X))')
157                      strput, ligne, color, pos-18
158                ENDIF ELSE BEGIN
159;                     ras = report('erreur ligne :' + string(nl))
160                      dist = abs(r-red)+abs(g-green)+abs(b-blue)
161                      ind = (where(dist EQ min(dist)))[0]
162                      ind = ind[0]
163;                      ras = report( $
164;                       ['I found ' + string(long([r, g, b])), $
165;                       'I replace it by ' + string([red[ind], green[ind], blue[ind]])])
166                      r1 = red1[ind]/255.
167                      g1 = green1[ind]/255.
168                      b1 = blue1[ind]/255.
169                      color = string(r1, g1, b1, format = '(3(F5.3,:,X))')
170                      strput, ligne, color, pos-18
171                ENDELSE
172          ENDIF           
173;
174; Replace COLORTAB
175;
176          pos = strpos(ligne, '/COLORTAB')
177          IF pos NE -1 THEN BEGIN
178                build_table, table
179                n = 0
180                colortab = 1
181          ENDIF
182
183          IF colortab THEN BEGIN
184                ligne = table[n]
185                n = n+1
186                IF n EQ 24 THEN colortab = 0
187          ENDIF
188;
189; write output file
190;
191          printf, numout, ligne, format = '(A)'
192    ENDWHILE
193    close, numin
194    close, numout
195    free_lun, numin
196    free_lun, numout
197
198    spawn, 'gs '+fileout
199
200END
Note: See TracBrowser for help on using the repository browser.