| 10 |
|
|
| 11 |
|
#include "standard.h" |
| 12 |
|
|
| 13 |
+ |
#include <sys/fcntl.h> |
| 14 |
+ |
|
| 15 |
|
#include "view.h" |
| 16 |
|
|
| 17 |
|
#include "color.h" |
| 18 |
|
|
| 19 |
< |
#define pscan(y) (ourpict+(y)*ourview.hresolu) |
| 20 |
< |
#define zscan(y) (ourzbuf+(y)*ourview.hresolu) |
| 19 |
> |
#ifndef BSD |
| 20 |
> |
#define vfork fork |
| 21 |
> |
#endif |
| 22 |
|
|
| 23 |
+ |
#define pscan(y) (ourpict+(y)*hresolu) |
| 24 |
+ |
#define zscan(y) (ourzbuf+(y)*hresolu) |
| 25 |
+ |
|
| 26 |
|
#define F_FORE 1 /* fill foreground */ |
| 27 |
|
#define F_BACK 2 /* fill background */ |
| 28 |
|
|
| 34 |
|
|
| 35 |
|
struct position {int x,y; float z;}; |
| 36 |
|
|
| 37 |
< |
VIEW ourview = STDVIEW(512); /* desired view */ |
| 37 |
> |
VIEW ourview = STDVIEW; /* desired view */ |
| 38 |
> |
int hresolu = 512; /* horizontal resolution */ |
| 39 |
> |
int vresolu = 512; /* vertical resolution */ |
| 40 |
> |
double pixaspect = 1.0; /* pixel aspect ratio */ |
| 41 |
|
|
| 42 |
|
double zeps = .02; /* allowed z epsilon */ |
| 43 |
|
|
| 46 |
|
|
| 47 |
|
char *progname; |
| 48 |
|
|
| 40 |
– |
VIEW theirview = STDVIEW(512); /* input view */ |
| 41 |
– |
int gotview; /* got input view? */ |
| 42 |
– |
|
| 49 |
|
int fill = F_FORE|F_BACK; /* selected fill algorithm */ |
| 50 |
|
extern int backfill(), rcalfill(); /* fill functions */ |
| 51 |
|
int (*deffill)() = backfill; /* selected fill function */ |
| 52 |
|
COLR backcolr = BLKCOLR; /* background color */ |
| 53 |
|
double backz = 0.0; /* background z value */ |
| 54 |
+ |
int normdist = 1; /* normalized distance? */ |
| 55 |
+ |
double ourexp = -1; /* output picture exposure */ |
| 56 |
|
|
| 57 |
+ |
VIEW theirview = STDVIEW; /* input view */ |
| 58 |
+ |
int gotview; /* got input view? */ |
| 59 |
+ |
int thresolu, tvresolu; /* input resolution */ |
| 60 |
+ |
double theirexp; /* input picture exposure */ |
| 61 |
|
double theirs2ours[4][4]; /* transformation matrix */ |
| 50 |
– |
int normdist = 1; /* normalized distance? */ |
| 62 |
|
|
| 63 |
|
int childpid = -1; /* id of fill process */ |
| 64 |
|
FILE *psend, *precv; /* pipes to/from fill calculation */ |
| 75 |
|
int gotvfile = 0; |
| 76 |
|
char *zfile = NULL; |
| 77 |
|
char *err; |
| 78 |
< |
int i; |
| 78 |
> |
int i, rval; |
| 79 |
|
|
| 80 |
|
progname = argv[0]; |
| 81 |
|
|
| 82 |
< |
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
| 82 |
> |
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
| 83 |
> |
rval = getviewopt(&ourview, argc-i, argv+i); |
| 84 |
> |
if (rval >= 0) { |
| 85 |
> |
i += rval; |
| 86 |
> |
continue; |
| 87 |
> |
} |
| 88 |
|
switch (argv[i][1]) { |
| 89 |
|
case 't': /* threshold */ |
| 90 |
|
check(2,1); |
| 139 |
|
break; |
| 140 |
|
case 'x': /* x resolution */ |
| 141 |
|
check(2,1); |
| 142 |
< |
ourview.hresolu = atoi(argv[++i]); |
| 142 |
> |
hresolu = atoi(argv[++i]); |
| 143 |
|
break; |
| 144 |
|
case 'y': /* y resolution */ |
| 145 |
|
check(2,1); |
| 146 |
< |
ourview.vresolu = atoi(argv[++i]); |
| 146 |
> |
vresolu = atoi(argv[++i]); |
| 147 |
|
break; |
| 148 |
< |
case 'v': /* view */ |
| 149 |
< |
switch (argv[i][2]) { |
| 150 |
< |
case 't': /* type */ |
| 151 |
< |
check(4,0); |
| 152 |
< |
ourview.type = argv[i][3]; |
| 153 |
< |
break; |
| 138 |
< |
case 'p': /* point */ |
| 139 |
< |
check(3,3); |
| 140 |
< |
ourview.vp[0] = atof(argv[++i]); |
| 141 |
< |
ourview.vp[1] = atof(argv[++i]); |
| 142 |
< |
ourview.vp[2] = atof(argv[++i]); |
| 143 |
< |
break; |
| 144 |
< |
case 'd': /* direction */ |
| 145 |
< |
check(3,3); |
| 146 |
< |
ourview.vdir[0] = atof(argv[++i]); |
| 147 |
< |
ourview.vdir[1] = atof(argv[++i]); |
| 148 |
< |
ourview.vdir[2] = atof(argv[++i]); |
| 149 |
< |
break; |
| 150 |
< |
case 'u': /* up */ |
| 151 |
< |
check(3,3); |
| 152 |
< |
ourview.vup[0] = atof(argv[++i]); |
| 153 |
< |
ourview.vup[1] = atof(argv[++i]); |
| 154 |
< |
ourview.vup[2] = atof(argv[++i]); |
| 155 |
< |
break; |
| 156 |
< |
case 'h': /* horizontal */ |
| 157 |
< |
check(3,1); |
| 158 |
< |
ourview.horiz = atof(argv[++i]); |
| 159 |
< |
break; |
| 160 |
< |
case 'v': /* vertical */ |
| 161 |
< |
check(3,1); |
| 162 |
< |
ourview.vert = atof(argv[++i]); |
| 163 |
< |
break; |
| 164 |
< |
case 'f': /* file */ |
| 165 |
< |
check(3,1); |
| 166 |
< |
gotvfile = viewfile(argv[++i], &ourview); |
| 167 |
< |
if (gotvfile < 0) { |
| 168 |
< |
perror(argv[i]); |
| 169 |
< |
exit(1); |
| 170 |
< |
} else if (gotvfile == 0) { |
| 171 |
< |
fprintf(stderr, "%s: bad view file\n", |
| 172 |
< |
argv[i]); |
| 173 |
< |
exit(1); |
| 174 |
< |
} |
| 175 |
< |
break; |
| 176 |
< |
default: |
| 148 |
> |
case 'p': /* pixel aspect */ |
| 149 |
> |
check(2,1); |
| 150 |
> |
pixaspect = atof(argv[++i]); |
| 151 |
> |
break; |
| 152 |
> |
case 'v': /* view file */ |
| 153 |
> |
if (argv[i][2] != 'f') |
| 154 |
|
goto badopt; |
| 155 |
+ |
check(3,1); |
| 156 |
+ |
gotvfile = viewfile(argv[++i], &ourview, 0, 0); |
| 157 |
+ |
if (gotvfile < 0) { |
| 158 |
+ |
perror(argv[i]); |
| 159 |
+ |
exit(1); |
| 160 |
+ |
} else if (gotvfile == 0) { |
| 161 |
+ |
fprintf(stderr, "%s: bad view file\n", |
| 162 |
+ |
argv[i]); |
| 163 |
+ |
exit(1); |
| 164 |
|
} |
| 165 |
|
break; |
| 166 |
|
default: |
| 169 |
|
progname, argv[i]); |
| 170 |
|
goto userr; |
| 171 |
|
} |
| 172 |
+ |
} |
| 173 |
|
/* check arguments */ |
| 174 |
|
if ((argc-i)%2) |
| 175 |
|
goto userr; |
| 178 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
| 179 |
|
exit(1); |
| 180 |
|
} |
| 181 |
+ |
normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); |
| 182 |
|
/* allocate frame */ |
| 183 |
< |
ourpict = (COLR *)malloc(ourview.hresolu*ourview.vresolu*sizeof(COLR)); |
| 184 |
< |
ourzbuf = (float *)calloc(ourview.hresolu*ourview.vresolu,sizeof(float)); |
| 183 |
> |
ourpict = (COLR *)malloc(hresolu*vresolu*sizeof(COLR)); |
| 184 |
> |
ourzbuf = (float *)calloc(hresolu*vresolu,sizeof(float)); |
| 185 |
|
if (ourpict == NULL || ourzbuf == NULL) |
| 186 |
|
syserror(); |
| 187 |
|
/* get input */ |
| 201 |
|
fprintview(&ourview, stdout); |
| 202 |
|
printf("\n"); |
| 203 |
|
} |
| 204 |
+ |
if (pixaspect < .99 || pixaspect > 1.01) |
| 205 |
+ |
fputaspect(pixaspect, stdout); |
| 206 |
+ |
if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) |
| 207 |
+ |
fputexpos(ourexp, stdout); |
| 208 |
|
printf("\n"); |
| 209 |
|
/* write picture */ |
| 210 |
|
writepicture(); |
| 215 |
|
exit(0); |
| 216 |
|
userr: |
| 217 |
|
fprintf(stderr, |
| 218 |
< |
"Usage: %s [view opts][-t zthresh][-z zout][-fT][-n] pfile zspec ..\n", |
| 218 |
> |
"Usage: %s [view opts][-t eps][-z zout][-fT][-n] pfile zspec ..\n", |
| 219 |
|
progname); |
| 220 |
|
exit(1); |
| 221 |
|
#undef check |
| 230 |
|
|
| 231 |
|
printf("\t%s", s); |
| 232 |
|
|
| 233 |
+ |
if (isexpos(s)) { |
| 234 |
+ |
theirexp *= exposval(s); |
| 235 |
+ |
return; |
| 236 |
+ |
} |
| 237 |
|
for (an = altname; *an != NULL; an++) |
| 238 |
|
if (!strncmp(*an, s, strlen(*an))) { |
| 239 |
< |
if (sscanview(&theirview, s+strlen(*an)) == 0) |
| 239 |
> |
if (sscanview(&theirview, s+strlen(*an)) > 0) |
| 240 |
|
gotview++; |
| 241 |
|
break; |
| 242 |
|
} |
| 247 |
|
char *pfile, *zspec; |
| 248 |
|
{ |
| 249 |
|
extern double atof(); |
| 250 |
< |
FILE *pfp, *zfp; |
| 250 |
> |
FILE *pfp; |
| 251 |
> |
int zfd; |
| 252 |
|
char *err; |
| 253 |
|
COLR *scanin; |
| 254 |
|
float *zin; |
| 259 |
|
perror(pfile); |
| 260 |
|
exit(1); |
| 261 |
|
} |
| 262 |
< |
/* get header and view */ |
| 263 |
< |
printf("%s:\n", pfile); |
| 262 |
> |
/* get header with exposure and view */ |
| 263 |
> |
theirexp = 1.0; |
| 264 |
|
gotview = 0; |
| 265 |
+ |
printf("%s:\n", pfile); |
| 266 |
|
getheader(pfp, headline); |
| 267 |
< |
if (!gotview || fgetresolu(&theirview.hresolu, &theirview.vresolu, pfp) |
| 267 |
> |
if (!gotview || fgetresolu(&thresolu, &tvresolu, pfp) |
| 268 |
|
!= (YMAJOR|YDECR)) { |
| 269 |
|
fprintf(stderr, "%s: picture view error\n", pfile); |
| 270 |
|
exit(1); |
| 271 |
|
} |
| 272 |
+ |
if (ourexp <= 0) |
| 273 |
+ |
ourexp = theirexp; |
| 274 |
+ |
else if (ABS(theirexp-ourexp) > .01*ourexp) |
| 275 |
+ |
fprintf(stderr, "%s: different exposure (warning)\n", pfile); |
| 276 |
|
if (err = setview(&theirview)) { |
| 277 |
|
fprintf(stderr, "%s: %s\n", pfile, err); |
| 278 |
|
exit(1); |
| 280 |
|
/* compute transformation */ |
| 281 |
|
pixform(theirs2ours, &theirview, &ourview); |
| 282 |
|
/* allocate scanlines */ |
| 283 |
< |
scanin = (COLR *)malloc(theirview.hresolu*sizeof(COLR)); |
| 284 |
< |
zin = (float *)malloc(theirview.hresolu*sizeof(float)); |
| 285 |
< |
plast = (struct position *)calloc(theirview.hresolu, |
| 284 |
< |
sizeof(struct position)); |
| 283 |
> |
scanin = (COLR *)malloc(thresolu*sizeof(COLR)); |
| 284 |
> |
zin = (float *)malloc(thresolu*sizeof(float)); |
| 285 |
> |
plast = (struct position *)calloc(thresolu, sizeof(struct position)); |
| 286 |
|
if (scanin == NULL || zin == NULL || plast == NULL) |
| 287 |
|
syserror(); |
| 288 |
|
/* get z specification or file */ |
| 289 |
< |
if ((zfp = fopen(zspec, "r")) == NULL) { |
| 289 |
> |
if ((zfd = open(zspec, O_RDONLY)) == -1) { |
| 290 |
|
double zvalue; |
| 291 |
|
register int x; |
| 292 |
|
if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) { |
| 293 |
|
perror(zspec); |
| 294 |
|
exit(1); |
| 295 |
|
} |
| 296 |
< |
for (x = 0; x < theirview.hresolu; x++) |
| 296 |
> |
for (x = 0; x < thresolu; x++) |
| 297 |
|
zin[x] = zvalue; |
| 298 |
|
} |
| 299 |
|
/* load image */ |
| 300 |
< |
for (y = theirview.vresolu-1; y >= 0; y--) { |
| 301 |
< |
if (freadcolrs(scanin, theirview.hresolu, pfp) < 0) { |
| 300 |
> |
for (y = tvresolu-1; y >= 0; y--) { |
| 301 |
> |
if (freadcolrs(scanin, thresolu, pfp) < 0) { |
| 302 |
|
fprintf(stderr, "%s: read error\n", pfile); |
| 303 |
|
exit(1); |
| 304 |
|
} |
| 305 |
< |
if (zfp != NULL |
| 306 |
< |
&& fread(zin,sizeof(float),theirview.hresolu,zfp) |
| 306 |
< |
< theirview.hresolu) { |
| 305 |
> |
if (zfd != -1 && read(zfd,zin,thresolu*sizeof(float)) |
| 306 |
> |
< thresolu*sizeof(float)) { |
| 307 |
|
fprintf(stderr, "%s: read error\n", zspec); |
| 308 |
|
exit(1); |
| 309 |
|
} |
| 314 |
|
free((char *)zin); |
| 315 |
|
free((char *)plast); |
| 316 |
|
fclose(pfp); |
| 317 |
< |
if (zfp != NULL) |
| 318 |
< |
fclose(zfp); |
| 317 |
> |
if (zfd != -1) |
| 318 |
> |
close(zfd); |
| 319 |
|
} |
| 320 |
|
|
| 321 |
|
|
| 326 |
|
double m4t[4][4]; |
| 327 |
|
|
| 328 |
|
setident4(xfmat); |
| 329 |
< |
xfmat[0][0] = vw1->vhinc[0]; |
| 330 |
< |
xfmat[0][1] = vw1->vhinc[1]; |
| 331 |
< |
xfmat[0][2] = vw1->vhinc[2]; |
| 332 |
< |
xfmat[1][0] = vw1->vvinc[0]; |
| 333 |
< |
xfmat[1][1] = vw1->vvinc[1]; |
| 334 |
< |
xfmat[1][2] = vw1->vvinc[2]; |
| 329 |
> |
xfmat[0][0] = vw1->hvec[0]; |
| 330 |
> |
xfmat[0][1] = vw1->hvec[1]; |
| 331 |
> |
xfmat[0][2] = vw1->hvec[2]; |
| 332 |
> |
xfmat[1][0] = vw1->vvec[0]; |
| 333 |
> |
xfmat[1][1] = vw1->vvec[1]; |
| 334 |
> |
xfmat[1][2] = vw1->vvec[2]; |
| 335 |
|
xfmat[2][0] = vw1->vdir[0]; |
| 336 |
|
xfmat[2][1] = vw1->vdir[1]; |
| 337 |
|
xfmat[2][2] = vw1->vdir[2]; |
| 339 |
|
xfmat[3][1] = vw1->vp[1]; |
| 340 |
|
xfmat[3][2] = vw1->vp[2]; |
| 341 |
|
setident4(m4t); |
| 342 |
< |
m4t[0][0] = vw2->vhinc[0]/vw2->vhn2; |
| 343 |
< |
m4t[1][0] = vw2->vhinc[1]/vw2->vhn2; |
| 344 |
< |
m4t[2][0] = vw2->vhinc[2]/vw2->vhn2; |
| 345 |
< |
m4t[3][0] = -DOT(vw2->vp,vw2->vhinc)/vw2->vhn2; |
| 346 |
< |
m4t[0][1] = vw2->vvinc[0]/vw2->vvn2; |
| 347 |
< |
m4t[1][1] = vw2->vvinc[1]/vw2->vvn2; |
| 348 |
< |
m4t[2][1] = vw2->vvinc[2]/vw2->vvn2; |
| 349 |
< |
m4t[3][1] = -DOT(vw2->vp,vw2->vvinc)/vw2->vvn2; |
| 342 |
> |
m4t[0][0] = vw2->hvec[0]/vw2->hn2; |
| 343 |
> |
m4t[1][0] = vw2->hvec[1]/vw2->hn2; |
| 344 |
> |
m4t[2][0] = vw2->hvec[2]/vw2->hn2; |
| 345 |
> |
m4t[3][0] = -DOT(vw2->vp,vw2->hvec)/vw2->hn2; |
| 346 |
> |
m4t[0][1] = vw2->vvec[0]/vw2->vn2; |
| 347 |
> |
m4t[1][1] = vw2->vvec[1]/vw2->vn2; |
| 348 |
> |
m4t[2][1] = vw2->vvec[2]/vw2->vn2; |
| 349 |
> |
m4t[3][1] = -DOT(vw2->vp,vw2->vvec)/vw2->vn2; |
| 350 |
|
m4t[0][2] = vw2->vdir[0]; |
| 351 |
|
m4t[1][2] = vw2->vdir[1]; |
| 352 |
|
m4t[2][2] = vw2->vdir[2]; |
| 366 |
|
struct position lastx, newpos; |
| 367 |
|
register int x; |
| 368 |
|
|
| 369 |
< |
for (x = theirview.hresolu-1; x >= 0; x--) { |
| 370 |
< |
pos[0] = x - .5*(theirview.hresolu-1); |
| 371 |
< |
pos[1] = y - .5*(theirview.vresolu-1); |
| 369 |
> |
lastx.z = 0; |
| 370 |
> |
for (x = thresolu-1; x >= 0; x--) { |
| 371 |
> |
pos[0] = (x+.5)/thresolu + theirview.hoff - .5; |
| 372 |
> |
pos[1] = (y+.5)/tvresolu + theirview.voff - .5; |
| 373 |
|
pos[2] = zline[x]; |
| 374 |
|
if (theirview.type == VT_PER) { |
| 375 |
|
if (normdist) /* adjust for eye-ray distance */ |
| 376 |
|
pos[2] /= sqrt( 1. |
| 377 |
< |
+ pos[0]*pos[0]*theirview.vhn2 |
| 378 |
< |
+ pos[1]*pos[1]*theirview.vvn2 ); |
| 377 |
> |
+ pos[0]*pos[0]*theirview.hn2 |
| 378 |
> |
+ pos[1]*pos[1]*theirview.vn2 ); |
| 379 |
|
pos[0] *= pos[2]; |
| 380 |
|
pos[1] *= pos[2]; |
| 381 |
|
} |
| 388 |
|
pos[0] /= pos[2]; |
| 389 |
|
pos[1] /= pos[2]; |
| 390 |
|
} |
| 391 |
< |
pos[0] += .5*ourview.hresolu; |
| 392 |
< |
pos[1] += .5*ourview.vresolu; |
| 393 |
< |
newpos.x = pos[0]; |
| 394 |
< |
newpos.y = pos[1]; |
| 391 |
> |
pos[0] += .5 - ourview.hoff; |
| 392 |
> |
pos[1] += .5 - ourview.voff; |
| 393 |
> |
newpos.x = pos[0] * hresolu; |
| 394 |
> |
newpos.y = pos[1] * vresolu; |
| 395 |
|
newpos.z = zline[x]; |
| 396 |
|
/* add pixel to our image */ |
| 397 |
< |
if (pos[0] >= 0 && newpos.x < ourview.hresolu |
| 398 |
< |
&& pos[1] >= 0 && newpos.y < ourview.vresolu) { |
| 397 |
> |
if (pos[0] >= 0 && newpos.x < hresolu |
| 398 |
> |
&& pos[1] >= 0 && newpos.y < vresolu) { |
| 399 |
|
addpixel(&newpos, &lastx, &lasty[x], pline[x], pos[2]); |
| 400 |
|
lasty[x].x = lastx.x = newpos.x; |
| 401 |
|
lasty[x].y = lastx.y = newpos.y; |
| 466 |
|
COLR pfill; |
| 467 |
|
register int x, i; |
| 468 |
|
/* get back buffer */ |
| 469 |
< |
yback = (int *)malloc(ourview.hresolu*sizeof(int)); |
| 469 |
> |
yback = (int *)malloc(hresolu*sizeof(int)); |
| 470 |
|
if (yback == NULL) |
| 471 |
|
syserror(); |
| 472 |
< |
for (x = 0; x < ourview.hresolu; x++) |
| 472 |
> |
for (x = 0; x < hresolu; x++) |
| 473 |
|
yback[x] = -2; |
| 474 |
|
/* |
| 475 |
|
* Xback and yback are the pixel locations of suitable |
| 478 |
|
* that there is no suitable background in this direction. |
| 479 |
|
*/ |
| 480 |
|
/* fill image */ |
| 481 |
< |
for (y = 0; y < ourview.vresolu; y++) { |
| 481 |
> |
for (y = 0; y < vresolu; y++) { |
| 482 |
|
xback = -2; |
| 483 |
< |
for (x = 0; x < ourview.hresolu; x++) |
| 483 |
> |
for (x = 0; x < hresolu; x++) |
| 484 |
|
if (zscan(y)[x] <= 0) { /* empty pixel */ |
| 485 |
|
/* |
| 486 |
|
* First, find background from above or below. |
| 487 |
|
* (farthest assigned pixel) |
| 488 |
|
*/ |
| 489 |
|
if (yback[x] == -2) { |
| 490 |
< |
for (i = y+1; i < ourview.vresolu; i++) |
| 490 |
> |
for (i = y+1; i < vresolu; i++) |
| 491 |
|
if (zscan(i)[x] > 0) |
| 492 |
|
break; |
| 493 |
< |
if (i < ourview.vresolu |
| 493 |
> |
if (i < vresolu |
| 494 |
|
&& (y <= 0 || zscan(y-1)[x] < zscan(i)[x])) |
| 495 |
|
yback[x] = i; |
| 496 |
|
else |
| 500 |
|
* Next, find background from left or right. |
| 501 |
|
*/ |
| 502 |
|
if (xback == -2) { |
| 503 |
< |
for (i = x+1; i < ourview.hresolu; i++) |
| 503 |
> |
for (i = x+1; i < hresolu; i++) |
| 504 |
|
if (zscan(y)[i] > 0) |
| 505 |
|
break; |
| 506 |
< |
if (i < ourview.hresolu |
| 506 |
> |
if (i < hresolu |
| 507 |
|
&& (x <= 0 || zscan(y)[x-1] < zscan(y)[i])) |
| 508 |
|
xback = i; |
| 509 |
|
else |
| 545 |
|
{ |
| 546 |
|
register int x, y; |
| 547 |
|
|
| 548 |
< |
for (y = 0; y < ourview.vresolu; y++) |
| 549 |
< |
for (x = 0; x < ourview.hresolu; x++) |
| 548 |
> |
for (y = 0; y < vresolu; y++) |
| 549 |
> |
for (x = 0; x < hresolu; x++) |
| 550 |
|
if (zscan(y)[x] <= 0) |
| 551 |
|
(*deffill)(x,y); |
| 552 |
|
} |
| 556 |
|
{ |
| 557 |
|
int y; |
| 558 |
|
|
| 559 |
< |
fputresolu(YMAJOR|YDECR, ourview.hresolu, ourview.vresolu, stdout); |
| 560 |
< |
for (y = ourview.vresolu-1; y >= 0; y--) |
| 561 |
< |
if (fwritecolrs(pscan(y), ourview.hresolu, stdout) < 0) |
| 559 |
> |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout); |
| 560 |
> |
for (y = vresolu-1; y >= 0; y--) |
| 561 |
> |
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
| 562 |
|
syserror(); |
| 563 |
|
} |
| 564 |
|
|
| 568 |
|
{ |
| 569 |
|
extern double sqrt(); |
| 570 |
|
int donorm = normdist && ourview.type == VT_PER; |
| 571 |
< |
FILE *fp; |
| 571 |
> |
int fd; |
| 572 |
|
int y; |
| 573 |
|
float *zout; |
| 574 |
|
|
| 575 |
< |
if ((fp = fopen(fname, "w")) == NULL) { |
| 575 |
> |
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) { |
| 576 |
|
perror(fname); |
| 577 |
|
exit(1); |
| 578 |
|
} |
| 579 |
|
if (donorm |
| 580 |
< |
&& (zout = (float *)malloc(ourview.hresolu*sizeof(float))) == NULL) |
| 580 |
> |
&& (zout = (float *)malloc(hresolu*sizeof(float))) == NULL) |
| 581 |
|
syserror(); |
| 582 |
< |
for (y = ourview.vresolu-1; y >= 0; y--) { |
| 582 |
> |
for (y = vresolu-1; y >= 0; y--) { |
| 583 |
|
if (donorm) { |
| 584 |
|
double vx, yzn2; |
| 585 |
|
register int x; |
| 586 |
< |
yzn2 = y - .5*(ourview.vresolu-1); |
| 587 |
< |
yzn2 = 1. + yzn2*yzn2*ourview.vvn2; |
| 588 |
< |
for (x = 0; x < ourview.hresolu; x++) { |
| 589 |
< |
vx = x - .5*(ourview.hresolu-1); |
| 586 |
> |
yzn2 = y - .5*(vresolu-1); |
| 587 |
> |
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
| 588 |
> |
for (x = 0; x < hresolu; x++) { |
| 589 |
> |
vx = x - .5*(hresolu-1); |
| 590 |
|
zout[x] = zscan(y)[x] |
| 591 |
< |
* sqrt(vx*vx*ourview.vhn2 + yzn2); |
| 591 |
> |
* sqrt(vx*vx*ourview.hn2 + yzn2); |
| 592 |
|
} |
| 593 |
|
} else |
| 594 |
|
zout = zscan(y); |
| 595 |
< |
if (fwrite(zout, sizeof(float), ourview.hresolu, fp) |
| 596 |
< |
< ourview.hresolu) { |
| 595 |
> |
if (write(fd, zout, hresolu*sizeof(float)) |
| 596 |
> |
< hresolu*sizeof(float)) { |
| 597 |
|
perror(fname); |
| 598 |
|
exit(1); |
| 599 |
|
} |
| 600 |
|
} |
| 601 |
|
if (donorm) |
| 602 |
|
free((char *)zout); |
| 603 |
< |
fclose(fp); |
| 603 |
> |
close(fd); |
| 604 |
|
} |
| 605 |
|
|
| 606 |
|
|
| 693 |
|
clearqueue(); |
| 694 |
|
} |
| 695 |
|
/* send new ray */ |
| 696 |
< |
rayview(orig, dir, &ourview, x+.5, y+.5); |
| 696 |
> |
viewray(orig, dir, &ourview, (x+.5)/hresolu, (y+.5)/vresolu); |
| 697 |
|
outbuf[0] = orig[0]; outbuf[1] = orig[1]; outbuf[2] = orig[2]; |
| 698 |
|
outbuf[3] = dir[0]; outbuf[4] = dir[1]; outbuf[5] = dir[2]; |
| 699 |
|
if (fwrite(outbuf, sizeof(float), 6, psend) < 6) |
| 715 |
|
fprintf(stderr, "%s: read error in clearqueue\n", |
| 716 |
|
progname); |
| 717 |
|
exit(1); |
| 718 |
+ |
} |
| 719 |
+ |
if (ourexp > 0 && ourexp != 1.0) { |
| 720 |
+ |
inbuf[0] *= ourexp; |
| 721 |
+ |
inbuf[1] *= ourexp; |
| 722 |
+ |
inbuf[2] *= ourexp; |
| 723 |
|
} |
| 724 |
|
setcolr(pscan(queue[i][1])[queue[i][0]], |
| 725 |
|
inbuf[0], inbuf[1], inbuf[2]); |