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

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

replace some print by some report in some .pro (continuation)

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