| 1 |
+ |
/* Copyright (c) 1991 Regents of the University of California */ |
| 2 |
+ |
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 5 |
|
#endif |
| 18 |
|
|
| 19 |
|
#include "color.h" |
| 20 |
|
|
| 21 |
+ |
#include "resolu.h" |
| 22 |
+ |
|
| 23 |
|
#ifndef BSD |
| 24 |
|
#define vfork fork |
| 25 |
|
#endif |
| 61 |
|
|
| 62 |
|
VIEW theirview = STDVIEW; /* input view */ |
| 63 |
|
int gotview; /* got input view? */ |
| 64 |
< |
int thresolu, tvresolu; /* input resolution */ |
| 64 |
> |
int wrongformat = 0; /* input in another format? */ |
| 65 |
> |
RESOLU tresolu; /* input resolution */ |
| 66 |
|
double theirexp; /* input picture exposure */ |
| 67 |
|
double theirs2ours[4][4]; /* transformation matrix */ |
| 68 |
+ |
int hasmatrix = 0; /* has transformation matrix */ |
| 69 |
|
|
| 70 |
|
int childpid = -1; /* id of fill process */ |
| 71 |
|
FILE *psend, *precv; /* pipes to/from fill calculation */ |
| 78 |
|
char *argv[]; |
| 79 |
|
{ |
| 80 |
|
#define check(olen,narg) if (argv[i][olen] || narg >= argc-i) goto badopt |
| 75 |
– |
extern double atof(); |
| 81 |
|
int gotvfile = 0; |
| 82 |
|
char *zfile = NULL; |
| 83 |
|
char *err; |
| 215 |
|
fputaspect(pixaspect, stdout); |
| 216 |
|
if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) |
| 217 |
|
fputexpos(ourexp, stdout); |
| 218 |
+ |
fputformat(COLRFMT, stdout); |
| 219 |
|
putc('\n', stdout); |
| 220 |
|
/* write picture */ |
| 221 |
|
writepicture(); |
| 238 |
|
{ |
| 239 |
|
static char *altname[] = {VIEWSTR,"rpict","rview","pinterp",NULL}; |
| 240 |
|
register char **an; |
| 241 |
+ |
char fmt[32]; |
| 242 |
|
|
| 243 |
+ |
if (isformat(s)) { |
| 244 |
+ |
formatval(fmt, s); |
| 245 |
+ |
wrongformat = strcmp(fmt, COLRFMT); |
| 246 |
+ |
return; |
| 247 |
+ |
} |
| 248 |
|
putc('\t', stdout); |
| 249 |
|
fputs(s, stdout); |
| 250 |
|
|
| 264 |
|
addpicture(pfile, zspec) /* add picture to output */ |
| 265 |
|
char *pfile, *zspec; |
| 266 |
|
{ |
| 255 |
– |
extern double atof(); |
| 267 |
|
FILE *pfp; |
| 268 |
|
int zfd; |
| 269 |
|
char *err; |
| 280 |
|
theirexp = 1.0; |
| 281 |
|
gotview = 0; |
| 282 |
|
printf("%s:\n", pfile); |
| 283 |
< |
getheader(pfp, headline); |
| 284 |
< |
if (!gotview || fgetresolu(&thresolu, &tvresolu, pfp) |
| 285 |
< |
!= (YMAJOR|YDECR)) { |
| 275 |
< |
fprintf(stderr, "%s: picture view error\n", pfile); |
| 283 |
> |
getheader(pfp, headline, NULL); |
| 284 |
> |
if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) { |
| 285 |
> |
fprintf(stderr, "%s: picture format error\n", pfile); |
| 286 |
|
exit(1); |
| 287 |
|
} |
| 288 |
|
if (ourexp <= 0) |
| 294 |
|
exit(1); |
| 295 |
|
} |
| 296 |
|
/* compute transformation */ |
| 297 |
< |
pixform(theirs2ours, &theirview, &ourview); |
| 297 |
> |
hasmatrix = pixform(theirs2ours, &theirview, &ourview); |
| 298 |
|
/* allocate scanlines */ |
| 299 |
< |
scanin = (COLR *)malloc(thresolu*sizeof(COLR)); |
| 300 |
< |
zin = (float *)malloc(thresolu*sizeof(float)); |
| 301 |
< |
plast = (struct position *)calloc(thresolu, sizeof(struct position)); |
| 299 |
> |
scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); |
| 300 |
> |
zin = (float *)malloc(scanlen(&tresolu)*sizeof(float)); |
| 301 |
> |
plast = (struct position *)calloc(scanlen(&tresolu), |
| 302 |
> |
sizeof(struct position)); |
| 303 |
|
if (scanin == NULL || zin == NULL || plast == NULL) |
| 304 |
|
syserror(); |
| 305 |
|
/* get z specification or file */ |
| 310 |
|
perror(zspec); |
| 311 |
|
exit(1); |
| 312 |
|
} |
| 313 |
< |
for (x = 0; x < thresolu; x++) |
| 313 |
> |
for (x = scanlen(&tresolu); x-- > 0; ) |
| 314 |
|
zin[x] = zvalue; |
| 315 |
|
} |
| 316 |
|
/* load image */ |
| 317 |
< |
for (y = tvresolu-1; y >= 0; y--) { |
| 318 |
< |
if (freadcolrs(scanin, thresolu, pfp) < 0) { |
| 317 |
> |
for (y = 0; y < numscans(&tresolu); y++) { |
| 318 |
> |
if (freadcolrs(scanin, scanlen(&tresolu), pfp) < 0) { |
| 319 |
|
fprintf(stderr, "%s: read error\n", pfile); |
| 320 |
|
exit(1); |
| 321 |
|
} |
| 322 |
< |
if (zfd != -1 && read(zfd,(char *)zin,thresolu*sizeof(float)) |
| 323 |
< |
< thresolu*sizeof(float)) { |
| 322 |
> |
if (zfd != -1 && read(zfd,(char *)zin, |
| 323 |
> |
scanlen(&tresolu)*sizeof(float)) |
| 324 |
> |
< scanlen(&tresolu)*sizeof(float)) { |
| 325 |
|
fprintf(stderr, "%s: read error\n", zspec); |
| 326 |
|
exit(1); |
| 327 |
|
} |
| 343 |
|
{ |
| 344 |
|
double m4t[4][4]; |
| 345 |
|
|
| 346 |
+ |
if (vw1->type != VT_PER && vw1->type != VT_PAR) |
| 347 |
+ |
return(0); |
| 348 |
+ |
if (vw2->type != VT_PER && vw2->type != VT_PAR) |
| 349 |
+ |
return(0); |
| 350 |
|
setident4(xfmat); |
| 351 |
|
xfmat[0][0] = vw1->hvec[0]; |
| 352 |
|
xfmat[0][1] = vw1->hvec[1]; |
| 374 |
|
m4t[2][2] = vw2->vdir[2]; |
| 375 |
|
m4t[3][2] = -DOT(vw2->vp,vw2->vdir); |
| 376 |
|
multmat4(xfmat, xfmat, m4t); |
| 377 |
+ |
return(1); |
| 378 |
|
} |
| 379 |
|
|
| 380 |
|
|
| 385 |
|
struct position *lasty; /* input/output */ |
| 386 |
|
{ |
| 387 |
|
extern double sqrt(); |
| 388 |
< |
double pos[3]; |
| 388 |
> |
FVECT pos; |
| 389 |
|
struct position lastx, newpos; |
| 390 |
|
register int x; |
| 391 |
|
|
| 392 |
|
lastx.z = 0; |
| 393 |
< |
for (x = thresolu-1; x >= 0; x--) { |
| 394 |
< |
pos[0] = (x+.5)/thresolu + theirview.hoff - .5; |
| 378 |
< |
pos[1] = (y+.5)/tvresolu + theirview.voff - .5; |
| 393 |
> |
for (x = scanlen(&tresolu); x-- > 0; ) { |
| 394 |
> |
pix2loc(pos, &tresolu, x, y); |
| 395 |
|
pos[2] = zline[x]; |
| 396 |
< |
if (theirview.type == VT_PER) { |
| 381 |
< |
if (normdist) /* adjust for eye-ray distance */ |
| 382 |
< |
pos[2] /= sqrt( 1. |
| 383 |
< |
+ pos[0]*pos[0]*theirview.hn2 |
| 384 |
< |
+ pos[1]*pos[1]*theirview.vn2 ); |
| 385 |
< |
pos[0] *= pos[2]; |
| 386 |
< |
pos[1] *= pos[2]; |
| 387 |
< |
} |
| 388 |
< |
multp3(pos, pos, theirs2ours); |
| 389 |
< |
if (pos[2] <= 0) { |
| 396 |
> |
if (movepixel(pos) < 0) { |
| 397 |
|
lasty[x].z = lastx.z = 0; /* mark invalid */ |
| 398 |
|
continue; |
| 399 |
|
} |
| 393 |
– |
if (ourview.type == VT_PER) { |
| 394 |
– |
pos[0] /= pos[2]; |
| 395 |
– |
pos[1] /= pos[2]; |
| 396 |
– |
} |
| 397 |
– |
pos[0] += .5 - ourview.hoff; |
| 398 |
– |
pos[1] += .5 - ourview.voff; |
| 400 |
|
newpos.x = pos[0] * hresolu; |
| 401 |
|
newpos.y = pos[1] * vresolu; |
| 402 |
|
newpos.z = zline[x]; |
| 470 |
|
} |
| 471 |
|
|
| 472 |
|
|
| 473 |
+ |
movepixel(pos) /* reposition image point */ |
| 474 |
+ |
FVECT pos; |
| 475 |
+ |
{ |
| 476 |
+ |
FVECT pt, direc; |
| 477 |
+ |
|
| 478 |
+ |
if (pos[2] <= 0) /* empty pixel */ |
| 479 |
+ |
return(-1); |
| 480 |
+ |
if (hasmatrix) { |
| 481 |
+ |
pos[0] += theirview.hoff - .5; |
| 482 |
+ |
pos[1] += theirview.voff - .5; |
| 483 |
+ |
if (theirview.type == VT_PER) { |
| 484 |
+ |
if (normdist) /* adjust for eye-ray distance */ |
| 485 |
+ |
pos[2] /= sqrt( 1. |
| 486 |
+ |
+ pos[0]*pos[0]*theirview.hn2 |
| 487 |
+ |
+ pos[1]*pos[1]*theirview.vn2 ); |
| 488 |
+ |
pos[0] *= pos[2]; |
| 489 |
+ |
pos[1] *= pos[2]; |
| 490 |
+ |
} |
| 491 |
+ |
multp3(pos, pos, theirs2ours); |
| 492 |
+ |
if (pos[2] <= 0) |
| 493 |
+ |
return(-1); |
| 494 |
+ |
if (ourview.type == VT_PER) { |
| 495 |
+ |
pos[0] /= pos[2]; |
| 496 |
+ |
pos[1] /= pos[2]; |
| 497 |
+ |
} |
| 498 |
+ |
pos[0] += .5 - ourview.hoff; |
| 499 |
+ |
pos[1] += .5 - ourview.voff; |
| 500 |
+ |
return(0); |
| 501 |
+ |
} |
| 502 |
+ |
if (viewray(pt, direc, &theirview, pos[0], pos[1]) < 0) |
| 503 |
+ |
return(-1); |
| 504 |
+ |
pt[0] += direc[0]*pos[2]; |
| 505 |
+ |
pt[1] += direc[1]*pos[2]; |
| 506 |
+ |
pt[2] += direc[2]*pos[2]; |
| 507 |
+ |
viewloc(pos, &ourview, pt); |
| 508 |
+ |
if (pos[2] <= 0) |
| 509 |
+ |
return(-1); |
| 510 |
+ |
return(0); |
| 511 |
+ |
} |
| 512 |
+ |
|
| 513 |
+ |
|
| 514 |
|
backpicture(fill, samp) /* background fill algorithm */ |
| 515 |
|
int (*fill)(); |
| 516 |
|
int samp; |
| 517 |
|
{ |
| 518 |
|
int *yback, xback; |
| 519 |
|
int y; |
| 478 |
– |
COLR pfill; |
| 520 |
|
register int x, i; |
| 521 |
|
/* get back buffer */ |
| 522 |
|
yback = (int *)malloc(hresolu*sizeof(int)); |
| 622 |
|
{ |
| 623 |
|
int y; |
| 624 |
|
|
| 625 |
< |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout); |
| 625 |
> |
fprtresolu(hresolu, vresolu, stdout); |
| 626 |
|
for (y = vresolu-1; y >= 0; y--) |
| 627 |
|
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
| 628 |
|
syserror(); |