4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
5 |
|
#endif |
6 |
|
|
7 |
– |
/* Copyright (c) 1992 Regents of the University of California */ |
8 |
– |
|
9 |
– |
#ifndef lint |
10 |
– |
static char SCCSid[] = "$SunId$ LBL"; |
11 |
– |
#endif |
12 |
– |
|
7 |
|
/* |
8 |
|
* Radiance picture to PostScript file translator -- one way! |
9 |
|
*/ |
10 |
|
|
11 |
|
#include <stdio.h> |
12 |
+ |
#ifdef MSDOS |
13 |
+ |
#include <fcntl.h> |
14 |
+ |
#endif |
15 |
|
#include "color.h" |
16 |
|
#include "random.h" |
17 |
|
|
24 |
|
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@+"; |
25 |
|
|
26 |
|
int wrongformat = 0; /* input in wrong format? */ |
27 |
< |
double pixaspect = 1.0; /* pixel aspect ratio */ |
27 |
> |
double pixaspect = 1.0; /* pixel aspect ratio */ |
28 |
|
|
29 |
|
int bradj = 0; /* brightness adjustment */ |
30 |
+ |
int ncopies = 1; /* number of copies */ |
31 |
|
|
32 |
|
char *progname; |
33 |
|
|
34 |
|
int xmax, ymax; |
35 |
|
|
36 |
+ |
extern char *malloc(); |
37 |
|
|
38 |
+ |
|
39 |
|
headline(s) /* check header line */ |
40 |
|
char *s; |
41 |
|
{ |
65 |
|
goto userr; |
66 |
|
bradj = atoi(argv[++i]); |
67 |
|
break; |
68 |
+ |
case 'n': /* number of copies */ |
69 |
+ |
ncopies = atoi(argv[++i]); |
70 |
+ |
break; |
71 |
|
default: |
72 |
|
goto userr; |
73 |
|
} |
86 |
|
progname, argv[i+1]); |
87 |
|
exit(1); |
88 |
|
} |
89 |
+ |
#ifdef MSDOS |
90 |
+ |
setmode(fileno(stdin), O_BINARY); |
91 |
+ |
#endif |
92 |
|
/* get our header */ |
93 |
|
getheader(stdin, headline, NULL); |
94 |
|
if (wrongformat || fgetresolu(&xmax, &ymax, stdin) < 0) |
121 |
|
char *name; |
122 |
|
{ |
123 |
|
int landscape = 0; |
124 |
< |
double pwidth, pheight; |
124 |
> |
double pwidth, pheight; |
125 |
> |
double iwidth, iheight; |
126 |
|
|
127 |
|
printf("%%!\n"); |
128 |
|
printf("%%%%Title: %s\n", name); |
129 |
|
printf("%%%%Creator: %s\n", progname); |
130 |
< |
printf("%%%%Pages: 1\n"); |
130 |
> |
printf("%%%%Pages: %d\n", ncopies); |
131 |
|
if (landscape = xmax > pixaspect*ymax) |
132 |
|
printf("%%%%Landscape\n"); |
133 |
|
else |
134 |
|
printf("%%%%Portrait\n"); |
135 |
|
printf("%%%%EndComments\n"); |
129 |
– |
printf("gsave\n"); |
136 |
|
printf("64 dict begin\n"); |
137 |
+ |
/* define image reader */ |
138 |
+ |
PSprocdef("read6bit"); |
139 |
|
/* set up transformation matrix */ |
140 |
< |
printf("%f %f translate 1 -1 scale\n", HMARGIN, VMARGIN+PHEIGHT); |
140 |
> |
printf("%f %f translate\n", HMARGIN, VMARGIN); |
141 |
|
if (PWIDTH > PHEIGHT ^ landscape) { |
142 |
|
printf("0 %f translate\n", PHEIGHT); |
143 |
< |
printf("90 rotate\n"); |
143 |
> |
printf("-90 rotate\n"); |
144 |
|
pwidth = PHEIGHT; |
145 |
|
pheight = PWIDTH; |
146 |
|
} else { |
148 |
|
pheight = PHEIGHT; |
149 |
|
} |
150 |
|
if (pheight/pwidth > pixaspect*ymax/xmax) { |
151 |
< |
printf("%f %f matrix scale\n", pwidth/xmax, |
152 |
< |
pixaspect*pwidth/xmax); |
145 |
< |
printf("0 %f matrix translate\n", |
146 |
< |
.5*(pheight-pwidth*pixaspect*ymax/xmax)); |
151 |
> |
iwidth = pwidth; |
152 |
> |
iheight = pwidth*pixaspect*ymax/xmax; |
153 |
|
} else { |
154 |
< |
printf("%f %f matrix scale\n", pheight/(ymax*pixaspect), |
155 |
< |
pheight/ymax); |
150 |
< |
printf("%f 0 matrix translate\n", |
151 |
< |
.5*(pwidth-pheight*xmax/(ymax*pixaspect))); |
154 |
> |
iheight = pheight; |
155 |
> |
iwidth = pheight*xmax/(pixaspect*ymax); |
156 |
|
} |
157 |
< |
printf("matrix concatmatrix /imat exch def\n"); |
158 |
< |
PSprocdef("read6bit"); |
157 |
> |
printf("%f %f translate\n", (pwidth-iwidth)*.5, (pheight-iheight)*.5); |
158 |
> |
printf("%f %f scale\n", iwidth, iheight); |
159 |
|
printf("%%%%EndProlog\n"); |
160 |
< |
printf("%d %d 8 imat {read6bit} image", xmax, ymax); |
160 |
> |
/* start image procedure */ |
161 |
> |
printf("%d %d 8 [%d 0 0 %d 0 %d] {read6bit} image", xmax, ymax, |
162 |
> |
xmax, -ymax, ymax); |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
|
PStrailer() /* print PostScript trailer */ |
167 |
|
{ |
168 |
|
puts("%%Trailer"); |
169 |
< |
puts("end"); |
169 |
> |
if (ncopies > 1) |
170 |
> |
printf("/#copies %d def\n", ncopies); |
171 |
|
puts("showpage"); |
172 |
< |
puts("grestore"); |
172 |
> |
puts("end"); |
173 |
|
puts("%%EOF"); |
174 |
|
} |
175 |
|
|
179 |
|
{ |
180 |
|
short itab[128]; |
181 |
|
register int i; |
182 |
< |
|
183 |
< |
for (i = 0; i < 128; i++) |
182 |
> |
/* assign code values */ |
183 |
> |
for (i = 0; i < 128; i++) /* clear */ |
184 |
|
itab[i] = -1; |
185 |
< |
for (i = 0; i < 64; i++) |
185 |
> |
for (i = 1; i < 63; i++) /* assign greys */ |
186 |
|
itab[code[i]] = i<<2 | 2; |
187 |
+ |
itab[code[0]] = 0; /* black is black */ |
188 |
+ |
itab[code[63]] = 255; /* and white is white */ |
189 |
|
printf("/decode ["); |
190 |
|
for (i = 0; i < 128; i++) { |
191 |
|
if (!(i & 0xf)) |
217 |
|
for (y = ymax-1; y >= 0; y--) { |
218 |
|
if (freadcolrs(scanin, xmax, stdin) < 0) |
219 |
|
quiterr("error reading Radiance picture"); |
220 |
< |
normcolrs(scanin, xmax, bradj); /* normalize */ |
220 |
> |
normcolrs(scanin, xmax, bradj); /* normalize */ |
221 |
|
for (x = 0; x < xmax; x++) { |
222 |
|
if (!(col++ & 0x3f)) |
223 |
|
putchar('\n'); |