10 |
|
|
11 |
|
#include "standard.h" |
12 |
|
|
13 |
+ |
#include <sys/fcntl.h> |
14 |
+ |
|
15 |
|
#include "view.h" |
16 |
|
|
17 |
|
#include "color.h" |
33 |
|
VIEW ourview = STDVIEW; /* desired view */ |
34 |
|
int hresolu = 512; /* horizontal resolution */ |
35 |
|
int vresolu = 512; /* vertical resolution */ |
36 |
+ |
double pixaspect = 1.0; /* pixel aspect ratio */ |
37 |
|
|
38 |
|
double zeps = .02; /* allowed z epsilon */ |
39 |
|
|
141 |
|
check(2,1); |
142 |
|
vresolu = atoi(argv[++i]); |
143 |
|
break; |
144 |
+ |
case 'p': /* pixel aspect */ |
145 |
+ |
check(2,1); |
146 |
+ |
pixaspect = atof(argv[++i]); |
147 |
+ |
break; |
148 |
|
case 'v': /* view file */ |
149 |
|
if (argv[i][2] != 'f') |
150 |
|
goto badopt; |
151 |
|
check(3,1); |
152 |
< |
gotvfile = viewfile(argv[++i], &ourview); |
152 |
> |
gotvfile = viewfile(argv[++i], &ourview, 0, 0); |
153 |
|
if (gotvfile < 0) { |
154 |
|
perror(argv[i]); |
155 |
|
exit(1); |
174 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
175 |
|
exit(1); |
176 |
|
} |
177 |
+ |
normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); |
178 |
|
/* allocate frame */ |
179 |
|
ourpict = (COLR *)malloc(hresolu*vresolu*sizeof(COLR)); |
180 |
|
ourzbuf = (float *)calloc(hresolu*vresolu,sizeof(float)); |
197 |
|
fprintview(&ourview, stdout); |
198 |
|
printf("\n"); |
199 |
|
} |
200 |
< |
if (ourexp > 0 && ourexp != 1.0) |
200 |
> |
if (pixaspect < .99 || pixaspect > 1.01) |
201 |
> |
fputaspect(pixaspect, stdout); |
202 |
> |
if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) |
203 |
|
fputexpos(ourexp, stdout); |
204 |
|
printf("\n"); |
205 |
|
/* write picture */ |
243 |
|
char *pfile, *zspec; |
244 |
|
{ |
245 |
|
extern double atof(); |
246 |
< |
FILE *pfp, *zfp; |
246 |
> |
FILE *pfp; |
247 |
> |
int zfd; |
248 |
|
char *err; |
249 |
|
COLR *scanin; |
250 |
|
float *zin; |
282 |
|
if (scanin == NULL || zin == NULL || plast == NULL) |
283 |
|
syserror(); |
284 |
|
/* get z specification or file */ |
285 |
< |
if ((zfp = fopen(zspec, "r")) == NULL) { |
285 |
> |
if ((zfd = open(zspec, O_RDONLY)) == -1) { |
286 |
|
double zvalue; |
287 |
|
register int x; |
288 |
|
if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) { |
298 |
|
fprintf(stderr, "%s: read error\n", pfile); |
299 |
|
exit(1); |
300 |
|
} |
301 |
< |
if (zfp != NULL |
302 |
< |
&& fread(zin,sizeof(float),thresolu,zfp) < thresolu) { |
301 |
> |
if (zfd != -1 && read(zfd,zin,thresolu*sizeof(float)) |
302 |
> |
< thresolu*sizeof(float)) { |
303 |
|
fprintf(stderr, "%s: read error\n", zspec); |
304 |
|
exit(1); |
305 |
|
} |
310 |
|
free((char *)zin); |
311 |
|
free((char *)plast); |
312 |
|
fclose(pfp); |
313 |
< |
if (zfp != NULL) |
314 |
< |
fclose(zfp); |
313 |
> |
if (zfd != -1) |
314 |
> |
close(zfd); |
315 |
|
} |
316 |
|
|
317 |
|
|
563 |
|
{ |
564 |
|
extern double sqrt(); |
565 |
|
int donorm = normdist && ourview.type == VT_PER; |
566 |
< |
FILE *fp; |
566 |
> |
int fd; |
567 |
|
int y; |
568 |
|
float *zout; |
569 |
|
|
570 |
< |
if ((fp = fopen(fname, "w")) == NULL) { |
570 |
> |
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) { |
571 |
|
perror(fname); |
572 |
|
exit(1); |
573 |
|
} |
587 |
|
} |
588 |
|
} else |
589 |
|
zout = zscan(y); |
590 |
< |
if (fwrite(zout, sizeof(float), hresolu, fp) < hresolu) { |
590 |
> |
if (write(fd, zout, hresolu*sizeof(float)) |
591 |
> |
< hresolu*sizeof(float)) { |
592 |
|
perror(fname); |
593 |
|
exit(1); |
594 |
|
} |
595 |
|
} |
596 |
|
if (donorm) |
597 |
|
free((char *)zout); |
598 |
< |
fclose(fp); |
598 |
> |
close(fd); |
599 |
|
} |
600 |
|
|
601 |
|
|