14 |
|
#endif |
15 |
|
#include "color.h" |
16 |
|
|
17 |
+ |
#define GRY -1 /* artificial index for grey */ |
18 |
+ |
|
19 |
|
#define HMARGIN (.5*72) /* horizontal margin */ |
20 |
|
#define VMARGIN (.5*72) /* vertical margin */ |
21 |
|
#define PWIDTH (8.5*72-2*HMARGIN) /* width of device */ |
32 |
|
int wrongformat = 0; /* input in wrong format? */ |
33 |
|
double pixaspect = 1.0; /* pixel aspect ratio */ |
34 |
|
|
35 |
+ |
int docolor = 0; /* produce color image? */ |
36 |
|
int bradj = 0; /* brightness adjustment */ |
37 |
|
int ncopies = 1; /* number of copies */ |
38 |
|
|
67 |
|
for (i = 1; i < argc; i++) |
68 |
|
if (argv[i][0] == '-') |
69 |
|
switch (argv[i][1]) { |
70 |
+ |
case 'c': /* produce color PostScript */ |
71 |
+ |
docolor++; |
72 |
+ |
break; |
73 |
|
case 'e': /* exposure adjustment */ |
74 |
|
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
75 |
|
goto userr; |
111 |
|
PStrailer(); |
112 |
|
exit(0); |
113 |
|
userr: |
114 |
< |
fprintf(stderr, "Usage: %s [-e +/-stops] [input [output]]\n", progname); |
114 |
> |
fprintf(stderr, "Usage: %s [-c][-e +/-stops] [input [output]]\n", |
115 |
> |
progname); |
116 |
|
exit(1); |
117 |
|
} |
118 |
|
|
135 |
|
double pwidth, pheight; |
136 |
|
double iwidth, iheight; |
137 |
|
/* EPS comments */ |
138 |
< |
puts("%%!PS-Adobe-2.0 EPSF-2.0"); |
138 |
> |
puts("%!PS-Adobe-2.0 EPSF-2.0"); |
139 |
|
printf("%%%%Title: %s\n", name); |
140 |
|
printf("%%%%Creator: %s = %s\n", progname, SCCSid); |
141 |
|
printf("%%%%Pages: %d\n", ncopies); |
173 |
|
puts("save"); |
174 |
|
puts("64 dict begin"); |
175 |
|
/* define image reader */ |
176 |
< |
PSprocdef("read6bitRLE"); |
176 |
> |
if (docolor) { |
177 |
> |
printf("/redline %d string def\n", xmax); |
178 |
> |
printf("/grnline %d string def\n", xmax); |
179 |
> |
printf("/bluline %d string def\n", xmax); |
180 |
> |
printf("/rgbline %d string def\n", 3*xmax); |
181 |
> |
PSprocdef("read6bitRLE", "interleave"); |
182 |
> |
} else { |
183 |
> |
printf("/greyline %d string def\n", xmax); |
184 |
> |
PSprocdef("read6bitRLE", NULL); |
185 |
> |
} |
186 |
|
/* set up transformation matrix */ |
187 |
|
printf("%f %f translate\n", HMARGIN, VMARGIN); |
188 |
|
if (pwidth == PHEIGHT) { |
191 |
|
} |
192 |
|
printf("%f %f translate\n", (pwidth-iwidth)*.5, (pheight-iheight)*.5); |
193 |
|
printf("%f %f scale\n", iwidth, iheight); |
194 |
< |
puts("%%%%EndProlog"); |
194 |
> |
puts("%%EndProlog"); |
195 |
|
/* start image procedure */ |
196 |
< |
printf("%d %d 8 [%d 0 0 %d 0 %d] {read6bitRLE} image\n", xmax, ymax, |
197 |
< |
xmax, -ymax, ymax); |
196 |
> |
printf("%d %d 8 [%d 0 0 %d 0 %d] ", xmax, ymax, xmax, -ymax, ymax); |
197 |
> |
if (docolor) { |
198 |
> |
puts("{redline read6bitRLE grnline read6bitRLE"); |
199 |
> |
puts("\tbluline read6bitRLE rgbline interleave} false 3 colorimage"); |
200 |
> |
} else |
201 |
> |
puts("{greyline read6bitRLE} image"); |
202 |
|
} |
203 |
|
|
204 |
|
|
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
< |
PSprocdef(nam) /* define PS procedure to read image */ |
218 |
< |
char *nam; |
217 |
> |
PSprocdef(nam, inam) /* define PS procedure to read image */ |
218 |
> |
char *nam, *inam; |
219 |
|
{ |
220 |
|
short itab[128]; |
221 |
|
register int i; |
233 |
|
printf(" %3d", itab[i]); |
234 |
|
} |
235 |
|
printf("\n] def\n"); |
216 |
– |
printf("/scanline %d string def\n", xmax); |
236 |
|
printf("/nrept 0 def\n"); |
237 |
< |
printf("/readbyte { currentfile read not {stop} if } def\n"); |
238 |
< |
printf("/decode { codetab exch get } def\n"); |
239 |
< |
printf("/%s {\n", nam); |
237 |
> |
printf("/readbyte { currentfile read not {stop} if } bind def\n"); |
238 |
> |
printf("/decode { codetab exch get } bind def\n"); |
239 |
> |
printf("/%s {\t%% scanbuffer\n", nam); |
240 |
> |
printf("\t/scanline exch def\n"); |
241 |
|
printf("\t{ 0 1 %d { scanline exch\n", xmax-1); |
242 |
|
printf("\t\tnrept 0 le\n"); |
243 |
|
printf("\t\t\t{ { readbyte dup %d eq\n", RUNCHR); |
251 |
|
printf("\t\t} for\n"); |
252 |
|
printf("\t} stopped {pop pop 0 string} {scanline} ifelse\n"); |
253 |
|
printf("} bind def\n"); |
254 |
+ |
if (inam == NULL) |
255 |
+ |
return; |
256 |
+ |
/* define interleaving procedure */ |
257 |
+ |
printf("/%s {\t%% redscn grnscn bluscn rgbscn\n", inam); |
258 |
+ |
printf("\t/rgbscan exch def /bscan exch def\n"); |
259 |
+ |
printf("\t/gscan exch def /rscan exch def\n"); |
260 |
+ |
printf("\trscan length %d eq gscan length %d eq and ", xmax, xmax); |
261 |
+ |
printf("bscan length %d eq and \n", xmax); |
262 |
+ |
printf("\t{ 0 1 %d { /ndx exch def\n", xmax-1); |
263 |
+ |
printf("\t\trgbscan ndx 3 mul rscan ndx get put\n"); |
264 |
+ |
printf("\t\trgbscan ndx 3 mul 1 add gscan ndx get put\n"); |
265 |
+ |
printf("\t\trgbscan ndx 3 mul 2 add bscan ndx get put\n"); |
266 |
+ |
printf("\t\t} for rgbscan }\n"); |
267 |
+ |
printf("\t{0 string} ifelse\n"); |
268 |
+ |
printf("} bind def\n"); |
269 |
|
} |
270 |
|
|
271 |
|
|
272 |
|
ra2ps() /* convert Radiance scanlines to 6-bit */ |
273 |
|
{ |
274 |
|
register COLR *scanin; |
240 |
– |
register int c; |
241 |
– |
int lastc, cnt; |
242 |
– |
register int x; |
275 |
|
int y; |
276 |
|
/* allocate scanline */ |
277 |
|
scanin = (COLR *)malloc(xmax*sizeof(COLR)); |
282 |
|
if (freadcolrs(scanin, xmax, stdin) < 0) |
283 |
|
quiterr("error reading Radiance picture"); |
284 |
|
normcolrs(scanin, xmax, bradj); /* normalize */ |
285 |
< |
lastc = -1; cnt = 0; |
286 |
< |
for (x = 0; x < xmax; x++) { |
287 |
< |
c = normbright(scanin[x]) + 2; |
288 |
< |
if (c > 255) c = 255; |
289 |
< |
c = code[c>>2]; |
290 |
< |
if (c == lastc && cnt < MAXRUN) |
259 |
< |
cnt++; |
260 |
< |
else { |
261 |
< |
putrle(cnt, lastc); |
262 |
< |
lastc = c; |
263 |
< |
cnt = 1; |
264 |
< |
} |
265 |
< |
} |
266 |
< |
putrle(cnt, lastc); |
285 |
> |
if (docolor) { |
286 |
> |
putprim(scanin, RED); |
287 |
> |
putprim(scanin, GRN); |
288 |
> |
putprim(scanin, BLU); |
289 |
> |
} else |
290 |
> |
putprim(scanin, GRY); |
291 |
|
if (ferror(stdout)) |
292 |
|
quiterr("error writing PostScript file"); |
293 |
|
} |
294 |
|
putchar('\n'); |
295 |
|
/* free scanline */ |
296 |
|
free((char *)scanin); |
297 |
+ |
} |
298 |
+ |
|
299 |
+ |
|
300 |
+ |
putprim(scn, pri) /* put out one primary from scanline */ |
301 |
+ |
COLR *scn; |
302 |
+ |
int pri; |
303 |
+ |
{ |
304 |
+ |
register int c; |
305 |
+ |
register int x; |
306 |
+ |
int lastc, cnt; |
307 |
+ |
|
308 |
+ |
lastc = -1; cnt = 0; |
309 |
+ |
for (x = 0; x < xmax; x++) { |
310 |
+ |
if (pri == GRY) |
311 |
+ |
c = normbright(scn[x]) + 2; |
312 |
+ |
else |
313 |
+ |
c = scn[x][pri] + 2; |
314 |
+ |
if (c > 255) c = 255; |
315 |
+ |
c = code[c>>2]; |
316 |
+ |
if (c == lastc && cnt < MAXRUN) |
317 |
+ |
cnt++; |
318 |
+ |
else { |
319 |
+ |
putrle(cnt, lastc); |
320 |
+ |
lastc = c; |
321 |
+ |
cnt = 1; |
322 |
+ |
} |
323 |
+ |
} |
324 |
+ |
putrle(cnt, lastc); |
325 |
|
} |
326 |
|
|
327 |
|
|