11 |
|
|
12 |
|
#include "copyright.h" |
13 |
|
|
14 |
+ |
#include <string.h> |
15 |
+ |
|
16 |
+ |
#include "platform.h" |
17 |
|
#include "ranimove.h" |
18 |
|
#include "otypes.h" |
19 |
+ |
#include "source.h" |
20 |
|
#include "random.h" |
21 |
|
|
22 |
|
double acctab[256]; /* accuracy value table */ |
47 |
|
double hlsmax; /* maximum high-level saliency this frame */ |
48 |
|
|
49 |
|
|
50 |
< |
void |
51 |
< |
write_map(mp, fn) /* write out float map (debugging) */ |
52 |
< |
float *mp; |
53 |
< |
char *fn; |
50 |
> |
static void next_frame(void); |
51 |
> |
static int sample_here(int x, int y); |
52 |
> |
static int offset_cmp(const void *p1, const void *p2); |
53 |
> |
static void setmotion(int n, FVECT wpos); |
54 |
> |
static void init_frame_sample(void); |
55 |
> |
|
56 |
> |
|
57 |
> |
extern void |
58 |
> |
write_map( /* write out float map (debugging) */ |
59 |
> |
float *mp, |
60 |
> |
char *fn |
61 |
> |
) |
62 |
|
{ |
63 |
|
FILE *fp = fopen(fn, "w"); |
64 |
|
COLOR scanbuf[2048]; |
82 |
|
|
83 |
|
|
84 |
|
static void |
85 |
< |
next_frame() /* prepare next frame buffer */ |
85 |
> |
next_frame(void) /* prepare next frame buffer */ |
86 |
|
{ |
87 |
|
VIEW *fv; |
88 |
|
char *err; |
89 |
|
/* get previous view */ |
90 |
|
if (vw.type != 0) |
91 |
< |
copystruct(&vwprev, &vw); |
91 |
> |
vwprev = vw; |
92 |
|
else if (fcur > 1 && (fv = getview(fcur-1)) != NULL) { |
93 |
< |
copystruct(&vwprev, fv); |
93 |
> |
vwprev = *fv; |
94 |
|
if (setview(&vwprev) != NULL) |
95 |
|
vwprev.type = 0; |
96 |
|
} |
99 |
|
sprintf(errmsg, "cannot get view for frame %d", fcur); |
100 |
|
error(USER, errmsg); |
101 |
|
} |
102 |
< |
copystruct(&vw, fv); |
102 |
> |
vw = *fv; |
103 |
|
if ((err = setview(&vw)) != NULL) { |
104 |
|
sprintf(errmsg, "view error at frame %d: %s", fcur, err); |
105 |
|
error(USER, errmsg); |
115 |
|
pixaspect = 1.; |
116 |
|
/* fall through */ |
117 |
|
case 3: |
118 |
< |
if ((hres > 0 & vres > 0)) |
118 |
> |
if ((hres > 0) & (vres > 0)) |
119 |
|
break; |
120 |
|
/* fall through */ |
121 |
|
default: |
134 |
|
zprev = (float *)malloc(sizeof(float)*hres*vres); |
135 |
|
oprev = (OBJECT *)malloc(sizeof(OBJECT)*hres*vres); |
136 |
|
aprev = (BYTE *)malloc(sizeof(BYTE)*hres*vres); |
137 |
< |
if ((cbuffer==NULL | zbuffer==NULL | obuffer==NULL | |
138 |
< |
xmbuffer==NULL | ymbuffer==NULL | |
139 |
< |
abuffer==NULL | sbuffer==NULL | |
140 |
< |
cprev==NULL | zprev == NULL | |
141 |
< |
oprev==NULL | aprev==NULL)) |
137 |
> |
if ((cbuffer==NULL) | (zbuffer==NULL) | (obuffer==NULL) | |
138 |
> |
(xmbuffer==NULL) | (ymbuffer==NULL) | |
139 |
> |
(abuffer==NULL) | (sbuffer==NULL) | |
140 |
> |
(cprev==NULL) | (zprev == NULL) | |
141 |
> |
(oprev==NULL) | (aprev==NULL)) |
142 |
|
error(SYSTEM, "out of memory in init_frame"); |
143 |
|
frm_stop = getTime() + rtperfrm; |
144 |
|
} else { |
150 |
|
fp = zprev; zprev = zbuffer; zbuffer = fp; |
151 |
|
op = oprev; oprev = obuffer; obuffer = op; |
152 |
|
bp = aprev; aprev = abuffer; abuffer = bp; |
153 |
< |
bzero(abuffer, sizeof(BYTE)*hres*vres); |
154 |
< |
bzero(sbuffer, sizeof(BYTE)*hres*vres); |
153 |
> |
memset(abuffer, '\0', sizeof(BYTE)*hres*vres); |
154 |
> |
memset(sbuffer, '\0', sizeof(BYTE)*hres*vres); |
155 |
|
frm_stop += rtperfrm; |
156 |
|
} |
157 |
|
cerrmap = NULL; |
164 |
|
|
165 |
|
|
166 |
|
static int |
167 |
< |
sample_here(x, y) /* 4x4 quincunx sample at this pixel? */ |
168 |
< |
register int x, y; |
167 |
> |
sample_here( /* 4x4 quincunx sample at this pixel? */ |
168 |
> |
register int x, |
169 |
> |
register int y |
170 |
> |
) |
171 |
|
{ |
172 |
|
if (y & 0x1) /* every other row has samples */ |
173 |
|
return(0); |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
< |
void |
181 |
< |
sample_pos(hv, x, y, sn) /* compute jittered sample position */ |
182 |
< |
double hv[2]; |
183 |
< |
int x, y; |
184 |
< |
int sn; |
180 |
> |
extern void |
181 |
> |
sample_pos( /* compute jittered sample position */ |
182 |
> |
double hv[2], |
183 |
> |
int x, |
184 |
> |
int y, |
185 |
> |
int sn |
186 |
> |
) |
187 |
|
{ |
188 |
|
int hl[2]; |
189 |
|
|
194 |
|
} |
195 |
|
|
196 |
|
|
197 |
< |
double |
198 |
< |
sample_wt(xo, yo) /* compute interpolant sample weight */ |
199 |
< |
int xo, yo; |
197 |
> |
extern double |
198 |
> |
sample_wt( /* compute interpolant sample weight */ |
199 |
> |
int xo, |
200 |
> |
int yo |
201 |
> |
) |
202 |
|
{ |
203 |
|
static double etab[400]; |
204 |
< |
int rad2 = xo*xo + yo*yo; |
204 |
> |
/* we can't use the name rad2 here, for some reason Visual C |
205 |
> |
thinks that is a constant (compiler bug?) */ |
206 |
> |
int rad_2 = xo*xo + yo*yo; |
207 |
|
int i; |
208 |
|
|
209 |
|
if (etab[0] <= FTINY) /* initialize exponent table */ |
211 |
|
etab[i] = exp(-0.1*i); |
212 |
|
|
213 |
|
/* look up Gaussian */ |
214 |
< |
i = (int)((10.*3./(double)SAMPDIST2)*rad2 + .5); |
214 |
> |
i = (int)((10.*3./(double)SAMPDIST2)*rad_2 + .5); |
215 |
|
if (i >= 400) |
216 |
|
return(0.0); |
217 |
|
return(etab[i]); |
219 |
|
|
220 |
|
|
221 |
|
static int |
222 |
< |
offset_cmp(p1, p2) /* compare offset distances */ |
223 |
< |
const void *p1, *p2; |
222 |
> |
offset_cmp( /* compare offset distances */ |
223 |
> |
const void *p1, |
224 |
> |
const void *p2 |
225 |
> |
) |
226 |
|
{ |
227 |
|
return(*(const int *)p1 - *(const int *)p2); |
228 |
|
} |
229 |
|
|
230 |
|
|
231 |
< |
int |
232 |
< |
getclosest(iarr, nc, x, y) /* get nc closest neighbors on same object */ |
233 |
< |
int *iarr; |
234 |
< |
int nc; |
235 |
< |
int x, y; |
231 |
> |
extern int |
232 |
> |
getclosest( /* get nc closest neighbors on same object */ |
233 |
> |
int *iarr, |
234 |
> |
int nc, |
235 |
> |
int x, |
236 |
> |
int y |
237 |
> |
) |
238 |
|
{ |
239 |
|
#define NSCHECK ((2*SAMPDIST+1)*(2*SAMPDIST+1)) |
240 |
|
static int hro, vro; |
245 |
|
/* get our object number */ |
246 |
|
myobj = obuffer[fndx(x, y)]; |
247 |
|
/* special case for borders */ |
248 |
< |
if ((x < SAMPDIST | x >= hres-SAMPDIST | |
249 |
< |
y < SAMPDIST | y >= vres-SAMPDIST)) { |
248 |
> |
if ((x < SAMPDIST) | (x >= hres-SAMPDIST) | |
249 |
> |
(y < SAMPDIST) | (y >= vres-SAMPDIST)) { |
250 |
|
int tndx[NSCHECK][2]; |
251 |
|
nf = 0; |
252 |
|
for (j = y - SAMPDIST; j <= y + SAMPDIST; j++) { |
258 |
|
i0 = fndx(i, j); |
259 |
|
if (!sbuffer[i0]) |
260 |
|
continue; |
261 |
< |
if ((myobj != OVOID & obuffer[i0] != myobj)) |
261 |
> |
if ((myobj != OVOID) & (obuffer[i0] != myobj)) |
262 |
|
continue; |
263 |
|
tndx[nf][0] = (i-x)*(i-x) + (j-y)*(j-y); |
264 |
|
tndx[nf][1] = i0; |
273 |
|
return(nf); |
274 |
|
} |
275 |
|
/* initialize offset array */ |
276 |
< |
if ((hres != hro | vres != vro)) { |
276 |
> |
if ((hres != hro) | (vres != vro)) { |
277 |
|
int toffs[NSCHECK][2]; |
278 |
|
i0 = fndx(SAMPDIST, SAMPDIST); |
279 |
|
nf = 0; |
292 |
|
} |
293 |
|
/* find up to nc neighbors */ |
294 |
|
i0 = fndx(x, y); |
295 |
< |
for (j = 0, nf = 0; (j < NSCHECK & nf < nc); j++) { |
295 |
> |
for (j = 0, nf = 0; (j < NSCHECK) & (nf < nc); j++) { |
296 |
|
i = i0 + ioffs[j]; |
297 |
< |
if (sbuffer[i] && (myobj == OVOID | obuffer[i] == myobj)) |
297 |
> |
if (sbuffer[i] && (myobj == OVOID) | (obuffer[i] == myobj)) |
298 |
|
iarr[nf++] = i; |
299 |
|
} |
300 |
|
/* return number found */ |
304 |
|
|
305 |
|
|
306 |
|
static void |
307 |
< |
setmotion(n, wpos) /* compute motion vector for this pixel */ |
308 |
< |
register int n; |
309 |
< |
FVECT wpos; |
307 |
> |
setmotion( /* compute motion vector for this pixel */ |
308 |
> |
register int n, |
309 |
> |
FVECT wpos |
310 |
> |
) |
311 |
|
{ |
312 |
|
FVECT ovp; |
288 |
– |
MAT4 xfm; |
289 |
– |
double d; |
313 |
|
int moi; |
314 |
|
int xp, yp; |
315 |
|
/* ID object and update maximum HLS */ |
329 |
|
yp = (int)(ovp[1]*vres); |
330 |
|
xmbuffer[n] = xp - (n % hres); |
331 |
|
ymbuffer[n] = yp - (n / hres); |
332 |
< |
if ((xp < 0 | xp >= hres)) |
332 |
> |
if ((xp < 0) | (xp >= hres)) |
333 |
|
return; |
334 |
< |
if ((yp < 0 | yp >= vres)) |
334 |
> |
if ((yp < 0) | (yp >= vres)) |
335 |
|
return; |
336 |
|
n = fndx(xp, yp); |
337 |
< |
if ((zprev[n] < 0.97*ovp[2] | zprev[n] > 1.03*ovp[2])) |
337 |
> |
if ((zprev[n] < 0.97*ovp[2]) | (zprev[n] > 1.03*ovp[2])) |
338 |
|
oprev[n] = OVOID; /* assume it's a bad match */ |
339 |
|
} |
340 |
|
|
341 |
|
|
342 |
|
static void |
343 |
< |
init_frame_sample() /* sample our initial frame */ |
343 |
> |
init_frame_sample(void) /* sample our initial frame */ |
344 |
|
{ |
345 |
|
RAY ir; |
346 |
|
int x, y; |
427 |
|
n = fndx(x, y); |
428 |
|
if ((obj = obuffer[n]) == OVOID) |
429 |
|
continue; |
430 |
< |
if ((obuffer[n+1] != OVOID & obuffer[n+1] != obj)) { |
430 |
> |
if ((obuffer[n+1] != OVOID) & (obuffer[n+1] != obj)) { |
431 |
|
obuffer[n] = OVOID; |
432 |
|
obuffer[n+1] = OVOID; |
433 |
|
} |
434 |
< |
if ((obuffer[n+hres] != OVOID & obuffer[n+hres] != obj)) { |
434 |
> |
if ((obuffer[n+hres] != OVOID) & (obuffer[n+hres] != obj)) { |
435 |
|
obuffer[n] = OVOID; |
436 |
|
obuffer[n+hres] = OVOID; |
437 |
|
} |
442 |
|
} |
443 |
|
|
444 |
|
|
445 |
< |
int |
446 |
< |
getambcolor(clr, obj) /* get ambient color for object if we can */ |
447 |
< |
COLOR clr; |
448 |
< |
int obj; |
445 |
> |
extern int |
446 |
> |
getambcolor( /* get ambient color for object if we can */ |
447 |
> |
COLOR clr, |
448 |
> |
int obj |
449 |
> |
) |
450 |
|
{ |
451 |
|
register OBJREC *op; |
452 |
|
|
453 |
|
if (obj == OVOID) |
454 |
|
return(0); |
455 |
|
op = objptr(obj); |
456 |
< |
if ((op->otype == OBJ_INSTANCE & op->omod == OVOID)) |
456 |
> |
if ((op->otype == OBJ_INSTANCE) & (op->omod == OVOID)) |
457 |
|
return(0); |
458 |
|
/* search for material */ |
459 |
|
do { |
513 |
|
} |
514 |
|
|
515 |
|
|
516 |
< |
double |
517 |
< |
estimaterr(cs, cs2, ns, ns0) /* estimate relative error from samples */ |
518 |
< |
COLOR cs, cs2; |
519 |
< |
int ns; |
516 |
> |
extern double |
517 |
> |
estimaterr( /* estimate relative error from samples */ |
518 |
> |
COLOR cs, |
519 |
> |
COLOR cs2, |
520 |
> |
int ns, |
521 |
> |
int ns0 |
522 |
> |
) |
523 |
|
{ |
524 |
|
double d, d2, brt; |
525 |
|
|
539 |
|
} |
540 |
|
|
541 |
|
|
542 |
< |
double |
543 |
< |
comperr(neigh, nc, ns0) /* estimate relative error in neighborhood */ |
544 |
< |
int *neigh; |
545 |
< |
int nc; |
546 |
< |
int ns0; |
542 |
> |
extern double |
543 |
> |
comperr( /* estimate relative error in neighborhood */ |
544 |
> |
int *neigh, |
545 |
> |
int nc, |
546 |
> |
int ns0 |
547 |
> |
) |
548 |
|
{ |
549 |
|
COLOR csum, csum2; |
550 |
|
COLOR ctmp; |
554 |
|
/* add together samples */ |
555 |
|
setcolor(csum, 0., 0., 0.); |
556 |
|
setcolor(csum2, 0., 0., 0.); |
557 |
< |
for (i = 0, ns = 0; (i < nc & ns < NSAMPOK); i++) { |
557 |
> |
for (i = 0, ns = 0; (i < nc) & (ns < NSAMPOK); i++) { |
558 |
|
n = neigh[i]; |
559 |
|
addcolor(csum, cbuffer[n]); |
560 |
|
if (val2map != NULL) { |
575 |
|
} |
576 |
|
|
577 |
|
|
578 |
< |
void |
579 |
< |
comp_frame_error() /* initialize frame error values */ |
578 |
> |
extern void |
579 |
> |
comp_frame_error(void) /* initialize frame error values */ |
580 |
|
{ |
581 |
|
BYTE *edone = NULL; |
582 |
|
COLOR objamb; |
583 |
|
double eest; |
584 |
|
int neigh[NSAMPOK]; |
585 |
|
int nc; |
586 |
< |
int x, y, i, j; |
586 |
> |
int x, y, i; |
587 |
|
register int n; |
588 |
|
|
589 |
|
if (!silent) { |
606 |
|
for (y = vres; y--; ) |
607 |
|
for (x = hres; x--; ) { |
608 |
|
n = fndx(x, y); |
609 |
< |
if ((abuffer[n] != ALOWQ | obuffer[n] == OVOID)) |
609 |
> |
if ((abuffer[n] != ALOWQ) | (obuffer[n] == OVOID)) |
610 |
|
continue; |
611 |
|
if (!getambcolor(objamb, obuffer[n])) |
612 |
|
continue; |
654 |
|
} |
655 |
|
|
656 |
|
|
657 |
< |
void |
658 |
< |
init_frame() /* render base (low quality) frame */ |
657 |
> |
extern void |
658 |
> |
init_frame(void) /* render base (low quality) frame */ |
659 |
|
{ |
660 |
|
int restart; |
661 |
|
|
665 |
|
restart = (!nobjects || vdef(MOVE)); |
666 |
|
if (!restart && curparams != &lorendparams && nprocs > 1) |
667 |
|
restart = -1; |
668 |
< |
if (restart > 0) |
668 |
> |
if (restart > 0) { |
669 |
|
if (nprocs > 1) |
670 |
|
ray_pdone(1); |
671 |
|
else |
672 |
|
ray_done(1); |
673 |
+ |
} |
674 |
|
/* post low quality parameters */ |
675 |
|
if (curparams != &lorendparams) |
676 |
|
ray_restore(curparams = &lorendparams); |
717 |
|
} |
718 |
|
|
719 |
|
|
720 |
< |
void |
721 |
< |
filter_frame() /* interpolation, motion-blur, and exposure */ |
720 |
> |
extern void |
721 |
> |
filter_frame(void) /* interpolation, motion-blur, and exposure */ |
722 |
|
{ |
723 |
|
double expval = expspec_val(getexp(fcur)); |
724 |
|
int x, y; |
729 |
|
register int n; |
730 |
|
|
731 |
|
#if 0 |
732 |
< |
/* XXX TEMPORARY!! */ |
733 |
< |
conspicuity(); |
734 |
< |
write_map(cerrmap, "outcmap.pic"); |
735 |
< |
{ |
736 |
< |
float *ebuf = (float *)malloc(sizeof(float)*hres*vres); |
737 |
< |
for (n = hres*vres; n--; ) |
738 |
< |
ebuf[n] = acctab[abuffer[n]]; |
739 |
< |
write_map(ebuf, "outerr.pic"); |
740 |
< |
free((void *)ebuf); |
741 |
< |
} |
732 |
> |
/* XXX TEMPORARY!! */ |
733 |
> |
conspicuity(); |
734 |
> |
write_map(cerrmap, "outcmap.pic"); |
735 |
> |
{ |
736 |
> |
float *ebuf = (float *)malloc(sizeof(float)*hres*vres); |
737 |
> |
for (n = hres*vres; n--; ) |
738 |
> |
ebuf[n] = acctab[abuffer[n]]; |
739 |
> |
write_map(ebuf, "outerr.pic"); |
740 |
> |
free((void *)ebuf); |
741 |
> |
} |
742 |
|
#endif |
743 |
|
|
744 |
|
if (!silent) { |
745 |
|
printf("\tFiltering frame\n"); |
746 |
|
fflush(stdout); |
747 |
|
} |
748 |
< |
/* normalize samples */ |
749 |
< |
for (y = vres; y--; ) |
750 |
< |
for (x = hres; x--; ) { |
751 |
< |
n = fndx(x, y); |
752 |
< |
if (sbuffer[n] <= 1) |
753 |
< |
continue; |
754 |
< |
w = 1.0/(double)sbuffer[n]; |
726 |
< |
scalecolor(cbuffer[n], w); |
727 |
< |
} |
728 |
< |
/* interpolate samples */ |
729 |
< |
for (y = vres; y--; ) |
730 |
< |
for (x = hres; x--; ) { |
731 |
< |
n = fndx(x, y); |
732 |
< |
if (sbuffer[n]) |
733 |
< |
continue; |
734 |
< |
nc = getclosest(neigh, NPINTERP, x, y); |
735 |
< |
setcolor(cbuffer[n], 0., 0., 0.); |
736 |
< |
wsum = 0.; |
737 |
< |
while (nc-- > 0) { |
738 |
< |
copycolor(cval, cbuffer[neigh[nc]]); |
739 |
< |
w = sample_wt((neigh[nc]%hres) - x, |
740 |
< |
(neigh[nc]/hres) - y); |
741 |
< |
scalecolor(cval, w); |
742 |
< |
addcolor(cbuffer[n], cval); |
743 |
< |
wsum += w; |
744 |
< |
} |
745 |
< |
if (wsum > FTINY) { |
746 |
< |
w = 1.0/wsum; |
748 |
> |
/* normalize samples */ |
749 |
> |
for (y = vres; y--; ) { |
750 |
> |
for (x = hres; x--; ) { |
751 |
> |
n = fndx(x, y); |
752 |
> |
if (sbuffer[n] <= 1) |
753 |
> |
continue; |
754 |
> |
w = 1.0/(double)sbuffer[n]; |
755 |
|
scalecolor(cbuffer[n], w); |
756 |
|
} |
757 |
< |
} |
758 |
< |
/* motion blur if requested */ |
757 |
> |
} |
758 |
> |
/* interpolate samples */ |
759 |
> |
for (y = vres; y--; ) { |
760 |
> |
for (x = hres; x--; ) { |
761 |
> |
n = fndx(x, y); |
762 |
> |
if (sbuffer[n]) |
763 |
> |
continue; |
764 |
> |
nc = getclosest(neigh, NPINTERP, x, y); |
765 |
> |
setcolor(cbuffer[n], 0., 0., 0.); |
766 |
> |
wsum = 0.; |
767 |
> |
while (nc-- > 0) { |
768 |
> |
copycolor(cval, cbuffer[neigh[nc]]); |
769 |
> |
w = sample_wt((neigh[nc]%hres) - x, |
770 |
> |
(neigh[nc]/hres) - y); |
771 |
> |
scalecolor(cval, w); |
772 |
> |
addcolor(cbuffer[n], cval); |
773 |
> |
wsum += w; |
774 |
> |
} |
775 |
> |
if (wsum > FTINY) { |
776 |
> |
w = 1.0/wsum; |
777 |
> |
scalecolor(cbuffer[n], w); |
778 |
> |
} |
779 |
> |
} |
780 |
> |
} |
781 |
> |
/* motion blur if requested */ |
782 |
|
if (mblur > .02) { |
783 |
< |
int len; |
784 |
< |
int xs, ys, xl, yl; |
785 |
< |
int rise, run; |
786 |
< |
long rise2, run2; |
787 |
< |
int n2; |
788 |
< |
int cnt; |
789 |
< |
/* sum in motion streaks */ |
790 |
< |
bzero(outbuffer, sizeof(COLOR)*hres*vres); |
791 |
< |
bzero(wbuffer, sizeof(float)*hres*vres); |
792 |
< |
for (y = vres; y--; ) |
762 |
< |
for (x = hres; x--; ) { |
783 |
> |
int xs, ys, xl, yl; |
784 |
> |
int rise, run; |
785 |
> |
long rise2, run2; |
786 |
> |
int n2; |
787 |
> |
int cnt; |
788 |
> |
/* sum in motion streaks */ |
789 |
> |
memset(outbuffer, '\0', sizeof(COLOR)*hres*vres); |
790 |
> |
memset(wbuffer, '\0', sizeof(float)*hres*vres); |
791 |
> |
for (y = vres; y--; ) { |
792 |
> |
for (x = hres; x--; ) { |
793 |
|
n = fndx(x, y); |
794 |
|
if (xmbuffer[n] == MO_UNK) { |
795 |
|
run = rise = 0; |
810 |
|
else ys = 1; |
811 |
|
rise2 = run2 = 0L; |
812 |
|
if (rise > run) { |
813 |
< |
cnt = rise + 1; |
814 |
< |
w = 1./cnt; |
815 |
< |
copycolor(cval, cbuffer[n]); |
816 |
< |
scalecolor(cval, w); |
817 |
< |
while (cnt) |
818 |
< |
if (rise2 >= run2) { |
819 |
< |
if ((xl >= 0 & xl < hres & |
820 |
< |
yl >= 0 & yl < vres)) { |
821 |
< |
n2 = fndx(xl, yl); |
822 |
< |
addcolor(outbuffer[n2], |
823 |
< |
cval); |
824 |
< |
wbuffer[n2] += w; |
825 |
< |
} |
826 |
< |
yl += ys; |
827 |
< |
run2 += run; |
828 |
< |
cnt--; |
829 |
< |
} else { |
830 |
< |
xl += xs; |
831 |
< |
rise2 += rise; |
832 |
< |
} |
813 |
> |
cnt = rise + 1; |
814 |
> |
w = 1./cnt; |
815 |
> |
copycolor(cval, cbuffer[n]); |
816 |
> |
scalecolor(cval, w); |
817 |
> |
while (cnt) { |
818 |
> |
if (rise2 >= run2) { |
819 |
> |
if ((xl >= 0) & (xl < hres) & |
820 |
> |
(yl >= 0) & (yl < vres)) { |
821 |
> |
n2 = fndx(xl, yl); |
822 |
> |
addcolor(outbuffer[n2], cval); |
823 |
> |
wbuffer[n2] += w; |
824 |
> |
} |
825 |
> |
yl += ys; |
826 |
> |
run2 += run; |
827 |
> |
cnt--; |
828 |
> |
} else { |
829 |
> |
xl += xs; |
830 |
> |
rise2 += rise; |
831 |
> |
} |
832 |
> |
} |
833 |
|
} else { |
834 |
|
cnt = run + 1; |
835 |
|
w = 1./cnt; |
836 |
|
copycolor(cval, cbuffer[n]); |
837 |
|
scalecolor(cval, w); |
838 |
< |
while (cnt) |
839 |
< |
if (run2 >= rise2) { |
840 |
< |
if ((xl >= 0 & xl < hres & |
841 |
< |
yl >= 0 & yl < vres)) { |
842 |
< |
n2 = fndx(xl, yl); |
843 |
< |
addcolor(outbuffer[n2], |
844 |
< |
cval); |
845 |
< |
wbuffer[n2] += w; |
816 |
< |
} |
817 |
< |
xl += xs; |
818 |
< |
rise2 += rise; |
819 |
< |
cnt--; |
820 |
< |
} else { |
821 |
< |
yl += ys; |
822 |
< |
run2 += run; |
838 |
> |
while (cnt) { |
839 |
> |
if (run2 >= rise2) { |
840 |
> |
if ((xl >= 0) & (xl < hres) & |
841 |
> |
(yl >= 0) & (yl < vres)) { |
842 |
> |
n2 = fndx(xl, yl); |
843 |
> |
addcolor(outbuffer[n2], |
844 |
> |
cval); |
845 |
> |
wbuffer[n2] += w; |
846 |
|
} |
847 |
+ |
xl += xs; |
848 |
+ |
rise2 += rise; |
849 |
+ |
cnt--; |
850 |
+ |
} else { |
851 |
+ |
yl += ys; |
852 |
+ |
run2 += run; |
853 |
+ |
} |
854 |
+ |
} |
855 |
|
} |
856 |
< |
} |
857 |
< |
/* compute final results */ |
858 |
< |
for (y = vres; y--; ) |
859 |
< |
for (x = hres; x--; ) { |
860 |
< |
n = fndx(x, y); |
861 |
< |
if (wbuffer[n] <= FTINY) |
862 |
< |
continue; |
863 |
< |
w = 1./wbuffer[n]; |
864 |
< |
scalecolor(outbuffer[n], w); |
865 |
< |
} |
866 |
< |
} else |
867 |
< |
for (n = hres*vres; n--; ) |
856 |
> |
} |
857 |
> |
/* compute final results */ |
858 |
> |
for (y = vres; y--; ) { |
859 |
> |
for (x = hres; x--; ) { |
860 |
> |
n = fndx(x, y); |
861 |
> |
if (wbuffer[n] <= FTINY) |
862 |
> |
continue; |
863 |
> |
w = 1./wbuffer[n]; |
864 |
> |
scalecolor(outbuffer[n], w); |
865 |
> |
} |
866 |
> |
} |
867 |
> |
} |
868 |
> |
} else { |
869 |
> |
for (n = hres*vres; n--; ) { |
870 |
|
copycolor(outbuffer[n], cbuffer[n]); |
871 |
< |
/* |
872 |
< |
for (n = hres*vres; n--; ) |
873 |
< |
if (!sbuffer[n]) |
874 |
< |
setcolor(outbuffer[n], 0., 0., 0.); |
875 |
< |
*/ |
876 |
< |
/* adjust exposure */ |
877 |
< |
if ((expval < 0.99 | expval > 1.01)) |
871 |
> |
} |
872 |
> |
} |
873 |
> |
/* |
874 |
> |
for (n = hres*vres; n--; ) |
875 |
> |
if (!sbuffer[n]) |
876 |
> |
setcolor(outbuffer[n], 0., 0., 0.); |
877 |
> |
*/ |
878 |
> |
/* adjust exposure */ |
879 |
> |
if ((expval < 0.99) | (expval > 1.01)) |
880 |
|
for (n = hres*vres; n--; ) |
881 |
|
scalecolor(outbuffer[n], expval); |
882 |
< |
return; |
883 |
< |
{ |
884 |
< |
float *sbuf = (float *)malloc(sizeof(float)*hres*vres); |
885 |
< |
char fnm[256]; |
886 |
< |
sprintf(fnm, vval(BASENAME), fcur); |
887 |
< |
strcat(fnm, "_outsamp.pic"); |
888 |
< |
for (n = hres*vres; n--; ) |
889 |
< |
sbuf[n] = (float)sbuffer[n]; |
890 |
< |
write_map(sbuf, fnm); |
891 |
< |
free((void *)sbuf); |
882 |
> |
return; |
883 |
> |
{ |
884 |
> |
float *sbuf = (float *)malloc(sizeof(float)*hres*vres); |
885 |
> |
char fnm[256]; |
886 |
> |
sprintf(fnm, vval(BASENAME), fcur); |
887 |
> |
strcat(fnm, "_outsamp.pic"); |
888 |
> |
for (n = hres*vres; n--; ) |
889 |
> |
sbuf[n] = (float)sbuffer[n]; |
890 |
> |
write_map(sbuf, fnm); |
891 |
> |
free((void *)sbuf); |
892 |
> |
} |
893 |
|
} |
858 |
– |
} |
894 |
|
|
895 |
|
|
896 |
< |
void |
897 |
< |
send_frame() /* send frame to destination */ |
896 |
> |
extern void |
897 |
> |
send_frame(void) /* send frame to destination */ |
898 |
|
{ |
899 |
|
char pfname[1024]; |
900 |
|
double d; |
908 |
|
sprintf(errmsg, "cannot open output frame \"%s\"", pfname); |
909 |
|
error(SYSTEM, errmsg); |
910 |
|
} |
911 |
< |
#ifdef MSDOS |
877 |
< |
setmode(fileno(fp), O_BINARY); |
878 |
< |
#endif |
911 |
> |
SET_FILE_BINARY(fp); |
912 |
|
if (!silent) { |
913 |
|
printf("\tWriting to \"%s\"\n", pfname); |
914 |
|
fflush(stdout); |
921 |
|
fputnow(fp); |
922 |
|
fputs(VIEWSTR, fp); fprintview(&vw, fp); fputc('\n', fp); |
923 |
|
d = expspec_val(getexp(fcur)); |
924 |
< |
if ((d < 0.99 | d > 1.01)) |
924 |
> |
if ((d < 0.99) | (d > 1.01)) |
925 |
|
fputexpos(d, fp); |
926 |
|
d = viewaspect(&vw) * hres / vres; |
927 |
< |
if ((d < 0.99 | d > 1.01)) |
927 |
> |
if ((d < 0.99) | (d > 1.01)) |
928 |
|
fputaspect(d, fp); |
929 |
|
fputformat(COLRFMT, fp); |
930 |
|
fputc('\n', fp); /* end header */ |
946 |
|
} |
947 |
|
|
948 |
|
|
949 |
< |
void |
950 |
< |
free_frame() /* free frame allocation */ |
949 |
> |
extern void |
950 |
> |
free_frame(void) /* free frame allocation */ |
951 |
|
{ |
952 |
|
if (cbuffer == NULL) |
953 |
|
return; |