| 16 |
|
|
| 17 |
|
#include "color.h" |
| 18 |
|
|
| 19 |
– |
#include "random.h" |
| 20 |
– |
|
| 19 |
|
#ifndef BSD |
| 20 |
|
#define vfork fork |
| 21 |
|
#endif |
| 23 |
|
#define pscan(y) (ourpict+(y)*hresolu) |
| 24 |
|
#define zscan(y) (ourzbuf+(y)*hresolu) |
| 25 |
|
|
| 28 |
– |
#define PMASK 0xfffffff /* probability mask */ |
| 29 |
– |
#define sampval(x) (long)((x)*(PMASK+1)+.5) |
| 30 |
– |
#define samp(p) ((p) > (random()&PMASK)) |
| 31 |
– |
|
| 26 |
|
#define F_FORE 1 /* fill foreground */ |
| 27 |
|
#define F_BACK 2 /* fill background */ |
| 28 |
|
|
| 47 |
|
char *progname; |
| 48 |
|
|
| 49 |
|
int fillo = F_FORE|F_BACK; /* selected fill options */ |
| 50 |
< |
long sampprob = 0; /* sample probability */ |
| 50 |
> |
int fillsamp = 0; /* sample separation (0 == inf) */ |
| 51 |
|
extern int backfill(), rcalfill(); /* fill functions */ |
| 52 |
|
int (*fillfunc)() = backfill; /* selected fill function */ |
| 53 |
|
COLR backcolr = BLKCOLR; /* background color */ |
| 57 |
|
|
| 58 |
|
VIEW theirview = STDVIEW; /* input view */ |
| 59 |
|
int gotview; /* got input view? */ |
| 60 |
+ |
int wrongformat = 0; /* input in another format? */ |
| 61 |
|
int thresolu, tvresolu; /* input resolution */ |
| 62 |
|
double theirexp; /* input picture exposure */ |
| 63 |
|
double theirs2ours[4][4]; /* transformation matrix */ |
| 64 |
+ |
int hasmatrix = 0; /* has transformation matrix */ |
| 65 |
|
|
| 66 |
|
int childpid = -1; /* id of fill process */ |
| 67 |
|
FILE *psend, *precv; /* pipes to/from fill calculation */ |
| 117 |
|
break; |
| 118 |
|
case 's': /* sample */ |
| 119 |
|
check(3,1); |
| 120 |
< |
sampprob = sampval(atof(argv[++i])); |
| 120 |
> |
fillsamp = atoi(argv[++i]); |
| 121 |
|
break; |
| 122 |
|
case 'c': /* color */ |
| 123 |
|
check(3,3); |
| 196 |
|
addpicture(argv[i], argv[i+1]); |
| 197 |
|
/* fill in spaces */ |
| 198 |
|
if (fillo&F_BACK) |
| 199 |
< |
backpicture(fillfunc, sampprob); |
| 199 |
> |
backpicture(fillfunc, fillsamp); |
| 200 |
|
else |
| 201 |
|
fillpicture(fillfunc); |
| 202 |
|
/* close calculation */ |
| 212 |
|
fputaspect(pixaspect, stdout); |
| 213 |
|
if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) |
| 214 |
|
fputexpos(ourexp, stdout); |
| 215 |
+ |
fputformat(COLRFMT, stdout); |
| 216 |
|
putc('\n', stdout); |
| 217 |
|
/* write picture */ |
| 218 |
|
writepicture(); |
| 235 |
|
{ |
| 236 |
|
static char *altname[] = {VIEWSTR,"rpict","rview","pinterp",NULL}; |
| 237 |
|
register char **an; |
| 238 |
+ |
char fmt[32]; |
| 239 |
|
|
| 240 |
+ |
if (isformat(s)) { |
| 241 |
+ |
formatval(fmt, s); |
| 242 |
+ |
wrongformat = strcmp(fmt, COLRFMT); |
| 243 |
+ |
return; |
| 244 |
+ |
} |
| 245 |
|
putc('\t', stdout); |
| 246 |
|
fputs(s, stdout); |
| 247 |
|
|
| 278 |
|
theirexp = 1.0; |
| 279 |
|
gotview = 0; |
| 280 |
|
printf("%s:\n", pfile); |
| 281 |
< |
getheader(pfp, headline); |
| 282 |
< |
if (!gotview || fgetresolu(&thresolu, &tvresolu, pfp) |
| 283 |
< |
!= (YMAJOR|YDECR)) { |
| 284 |
< |
fprintf(stderr, "%s: picture view error\n", pfile); |
| 281 |
> |
getheader(pfp, headline, NULL); |
| 282 |
> |
if (wrongformat || !gotview || |
| 283 |
> |
fgetresolu(&thresolu, &tvresolu, pfp) != (YMAJOR|YDECR)) { |
| 284 |
> |
|
| 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)); |
| 341 |
|
{ |
| 342 |
|
double m4t[4][4]; |
| 343 |
|
|
| 344 |
+ |
if (vw1->type != VT_PER && vw1->type != VT_PAR) |
| 345 |
+ |
return(0); |
| 346 |
+ |
if (vw2->type != VT_PER && vw2->type != VT_PAR) |
| 347 |
+ |
return(0); |
| 348 |
|
setident4(xfmat); |
| 349 |
|
xfmat[0][0] = vw1->hvec[0]; |
| 350 |
|
xfmat[0][1] = vw1->hvec[1]; |
| 372 |
|
m4t[2][2] = vw2->vdir[2]; |
| 373 |
|
m4t[3][2] = -DOT(vw2->vp,vw2->vdir); |
| 374 |
|
multmat4(xfmat, xfmat, m4t); |
| 375 |
+ |
return(1); |
| 376 |
|
} |
| 377 |
|
|
| 378 |
|
|
| 383 |
|
struct position *lasty; /* input/output */ |
| 384 |
|
{ |
| 385 |
|
extern double sqrt(); |
| 386 |
< |
double pos[3]; |
| 386 |
> |
FVECT pos; |
| 387 |
|
struct position lastx, newpos; |
| 388 |
|
register int x; |
| 389 |
|
|
| 390 |
|
lastx.z = 0; |
| 391 |
|
for (x = thresolu-1; x >= 0; x--) { |
| 392 |
< |
pos[0] = (x+.5)/thresolu + theirview.hoff - .5; |
| 393 |
< |
pos[1] = (y+.5)/tvresolu + theirview.voff - .5; |
| 392 |
> |
pos[0] = (x+.5)/thresolu; |
| 393 |
> |
pos[1] = (y+.5)/tvresolu; |
| 394 |
|
pos[2] = zline[x]; |
| 395 |
< |
if (theirview.type == VT_PER) { |
| 387 |
< |
if (normdist) /* adjust for eye-ray distance */ |
| 388 |
< |
pos[2] /= sqrt( 1. |
| 389 |
< |
+ pos[0]*pos[0]*theirview.hn2 |
| 390 |
< |
+ pos[1]*pos[1]*theirview.vn2 ); |
| 391 |
< |
pos[0] *= pos[2]; |
| 392 |
< |
pos[1] *= pos[2]; |
| 393 |
< |
} |
| 394 |
< |
multp3(pos, pos, theirs2ours); |
| 395 |
< |
if (pos[2] <= 0) { |
| 395 |
> |
if (movepixel(pos) < 0) { |
| 396 |
|
lasty[x].z = lastx.z = 0; /* mark invalid */ |
| 397 |
|
continue; |
| 398 |
|
} |
| 399 |
– |
if (ourview.type == VT_PER) { |
| 400 |
– |
pos[0] /= pos[2]; |
| 401 |
– |
pos[1] /= pos[2]; |
| 402 |
– |
} |
| 403 |
– |
pos[0] += .5 - ourview.hoff; |
| 404 |
– |
pos[1] += .5 - ourview.voff; |
| 399 |
|
newpos.x = pos[0] * hresolu; |
| 400 |
|
newpos.y = pos[1] * vresolu; |
| 401 |
|
newpos.z = zline[x]; |
| 454 |
|
y1 = p0->y + c1*s1y/l1; |
| 455 |
|
for (c2 = l2; c2-- > 0; ) { |
| 456 |
|
x = x1 + c2*s2x/l2; |
| 457 |
+ |
if (x < 0 || x >= hresolu) |
| 458 |
+ |
continue; |
| 459 |
|
y = y1 + c2*s2y/l2; |
| 460 |
+ |
if (y < 0 || y >= vresolu) |
| 461 |
+ |
continue; |
| 462 |
|
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
| 463 |
|
> zeps*zscan(y)[x]) { |
| 464 |
|
zscan(y)[x] = z; |
| 469 |
|
} |
| 470 |
|
|
| 471 |
|
|
| 472 |
< |
backpicture(fill, prob) /* background fill algorithm */ |
| 472 |
> |
movepixel(pos) /* reposition image point */ |
| 473 |
> |
FVECT pos; |
| 474 |
> |
{ |
| 475 |
> |
FVECT pt, direc; |
| 476 |
> |
|
| 477 |
> |
if (pos[2] <= 0) /* empty pixel */ |
| 478 |
> |
return(-1); |
| 479 |
> |
if (hasmatrix) { |
| 480 |
> |
pos[0] += theirview.hoff - .5; |
| 481 |
> |
pos[1] += theirview.voff - .5; |
| 482 |
> |
if (theirview.type == VT_PER) { |
| 483 |
> |
if (normdist) /* adjust for eye-ray distance */ |
| 484 |
> |
pos[2] /= sqrt( 1. |
| 485 |
> |
+ pos[0]*pos[0]*theirview.hn2 |
| 486 |
> |
+ pos[1]*pos[1]*theirview.vn2 ); |
| 487 |
> |
pos[0] *= pos[2]; |
| 488 |
> |
pos[1] *= pos[2]; |
| 489 |
> |
} |
| 490 |
> |
multp3(pos, pos, theirs2ours); |
| 491 |
> |
if (pos[2] <= 0) |
| 492 |
> |
return(-1); |
| 493 |
> |
if (ourview.type == VT_PER) { |
| 494 |
> |
pos[0] /= pos[2]; |
| 495 |
> |
pos[1] /= pos[2]; |
| 496 |
> |
} |
| 497 |
> |
pos[0] += .5 - ourview.hoff; |
| 498 |
> |
pos[1] += .5 - ourview.voff; |
| 499 |
> |
return(0); |
| 500 |
> |
} |
| 501 |
> |
if (viewray(pt, direc, &theirview, pos[0], pos[1]) < 0) |
| 502 |
> |
return(-1); |
| 503 |
> |
pt[0] += direc[0]*pos[2]; |
| 504 |
> |
pt[1] += direc[1]*pos[2]; |
| 505 |
> |
pt[2] += direc[2]*pos[2]; |
| 506 |
> |
viewpixel(&pos[0], &pos[1], &pos[2], &ourview, pt); |
| 507 |
> |
if (pos[2] <= 0) |
| 508 |
> |
return(-1); |
| 509 |
> |
return(0); |
| 510 |
> |
} |
| 511 |
> |
|
| 512 |
> |
|
| 513 |
> |
backpicture(fill, samp) /* background fill algorithm */ |
| 514 |
|
int (*fill)(); |
| 515 |
< |
long prob; |
| 515 |
> |
int samp; |
| 516 |
|
{ |
| 517 |
|
int *yback, xback; |
| 518 |
|
int y; |
| 480 |
– |
COLR pfill; |
| 519 |
|
register int x, i; |
| 520 |
|
/* get back buffer */ |
| 521 |
|
yback = (int *)malloc(hresolu*sizeof(int)); |
| 562 |
|
xback = x-1; |
| 563 |
|
} |
| 564 |
|
/* |
| 565 |
< |
* Check to see if we have no background for |
| 566 |
< |
* this pixel. If not, or sampling was |
| 529 |
< |
* requested, use the given fill function. |
| 565 |
> |
* If we have no background for this pixel, |
| 566 |
> |
* use the given fill function. |
| 567 |
|
*/ |
| 568 |
< |
if ((xback < 0 && yback[x] < 0) || samp(prob)) { |
| 569 |
< |
(*fill)(x,y); |
| 533 |
< |
continue; |
| 534 |
< |
} |
| 568 |
> |
if (xback < 0 && yback[x] < 0) |
| 569 |
> |
goto fillit; |
| 570 |
|
/* |
| 571 |
|
* Compare, and use the background that is |
| 572 |
|
* farther, unless one of them is next to us. |
| 573 |
+ |
* If the background is too distant, call |
| 574 |
+ |
* the fill function. |
| 575 |
|
*/ |
| 576 |
|
if ( yback[x] < 0 |
| 577 |
|
|| (xback >= 0 && ABS(x-xback) <= 1) |
| 578 |
|
|| ( ABS(y-yback[x]) > 1 |
| 579 |
|
&& zscan(yback[x])[x] |
| 580 |
|
< zscan(y)[xback] ) ) { |
| 581 |
+ |
if (samp > 0 && ABS(x-xback) >= samp) |
| 582 |
+ |
goto fillit; |
| 583 |
|
copycolr(pscan(y)[x],pscan(y)[xback]); |
| 584 |
|
zscan(y)[x] = zscan(y)[xback]; |
| 585 |
|
} else { |
| 586 |
+ |
if (samp > 0 && ABS(y-yback[x]) > samp) |
| 587 |
+ |
goto fillit; |
| 588 |
|
copycolr(pscan(y)[x],pscan(yback[x])[x]); |
| 589 |
|
zscan(y)[x] = zscan(yback[x])[x]; |
| 590 |
|
} |
| 591 |
+ |
continue; |
| 592 |
+ |
fillit: |
| 593 |
+ |
(*fill)(x,y); |
| 594 |
+ |
if (fill == rcalfill) { /* use it */ |
| 595 |
+ |
clearqueue(); |
| 596 |
+ |
xback = x; |
| 597 |
+ |
yback[x] = y; |
| 598 |
+ |
} |
| 599 |
|
} else { /* full pixel */ |
| 600 |
|
yback[x] = -2; |
| 601 |
|
xback = -2; |
| 648 |
|
if (donorm) { |
| 649 |
|
double vx, yzn2; |
| 650 |
|
register int x; |
| 651 |
< |
yzn2 = y - .5*(vresolu-1); |
| 651 |
> |
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
| 652 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
| 653 |
|
for (x = 0; x < hresolu; x++) { |
| 654 |
< |
vx = x - .5*(hresolu-1); |
| 654 |
> |
vx = (x+.5)/hresolu + ourview.hoff - .5; |
| 655 |
|
zout[x] = zscan(y)[x] |
| 656 |
|
* sqrt(vx*vx*ourview.hn2 + yzn2); |
| 657 |
|
} |