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 */ |
115 |
|
break; |
116 |
|
case 's': /* sample */ |
117 |
|
check(3,1); |
118 |
< |
sampprob = sampval(atof(argv[++i])); |
118 |
> |
fillsamp = atoi(argv[++i]); |
119 |
|
break; |
120 |
|
case 'c': /* color */ |
121 |
|
check(3,3); |
194 |
|
addpicture(argv[i], argv[i+1]); |
195 |
|
/* fill in spaces */ |
196 |
|
if (fillo&F_BACK) |
197 |
< |
backpicture(fillfunc, sampprob); |
197 |
> |
backpicture(fillfunc, fillsamp); |
198 |
|
else |
199 |
|
fillpicture(fillfunc); |
200 |
|
/* close calculation */ |
465 |
|
} |
466 |
|
|
467 |
|
|
468 |
< |
backpicture(fill, prob) /* background fill algorithm */ |
468 |
> |
backpicture(fill, samp) /* background fill algorithm */ |
469 |
|
int (*fill)(); |
470 |
< |
long prob; |
470 |
> |
int samp; |
471 |
|
{ |
472 |
|
int *yback, xback; |
473 |
|
int y; |
518 |
|
xback = x-1; |
519 |
|
} |
520 |
|
/* |
521 |
< |
* Check to see if we have no background for |
522 |
< |
* this pixel. If not, or sampling was |
529 |
< |
* requested, use the given fill function. |
521 |
> |
* If we have no background for this pixel, |
522 |
> |
* use the given fill function. |
523 |
|
*/ |
524 |
< |
if ((xback < 0 && yback[x] < 0) || samp(prob)) { |
525 |
< |
(*fill)(x,y); |
533 |
< |
continue; |
534 |
< |
} |
524 |
> |
if (xback < 0 && yback[x] < 0) |
525 |
> |
goto fillit; |
526 |
|
/* |
527 |
|
* Compare, and use the background that is |
528 |
|
* farther, unless one of them is next to us. |
529 |
+ |
* If the background is too distant, call |
530 |
+ |
* the fill function. |
531 |
|
*/ |
532 |
|
if ( yback[x] < 0 |
533 |
|
|| (xback >= 0 && ABS(x-xback) <= 1) |
534 |
|
|| ( ABS(y-yback[x]) > 1 |
535 |
|
&& zscan(yback[x])[x] |
536 |
|
< zscan(y)[xback] ) ) { |
537 |
+ |
if (samp > 0 && ABS(x-xback) >= samp) |
538 |
+ |
goto fillit; |
539 |
|
copycolr(pscan(y)[x],pscan(y)[xback]); |
540 |
|
zscan(y)[x] = zscan(y)[xback]; |
541 |
|
} else { |
542 |
+ |
if (samp > 0 && ABS(y-yback[x]) > samp) |
543 |
+ |
goto fillit; |
544 |
|
copycolr(pscan(y)[x],pscan(yback[x])[x]); |
545 |
|
zscan(y)[x] = zscan(yback[x])[x]; |
546 |
+ |
} |
547 |
+ |
continue; |
548 |
+ |
fillit: |
549 |
+ |
(*fill)(x,y); |
550 |
+ |
if (fill == rcalfill) { /* use it */ |
551 |
+ |
clearqueue(); |
552 |
+ |
xback = x; |
553 |
+ |
yback[x] = y; |
554 |
|
} |
555 |
|
} else { /* full pixel */ |
556 |
|
yback[x] = -2; |