16 |
|
#include "platform.h" |
17 |
|
#include "ranimove.h" |
18 |
|
#include "otypes.h" |
19 |
+ |
#include "otspecial.h" |
20 |
|
#include "source.h" |
21 |
|
#include "random.h" |
22 |
|
|
49 |
|
|
50 |
|
|
51 |
|
static void next_frame(void); |
52 |
< |
static int sample_here(int x, int y); |
53 |
< |
static int offset_cmp(const void *p1, const void *p2); |
54 |
< |
static void setmotion(int n, FVECT wpos); |
52 |
> |
static int sample_here(int x, int y); |
53 |
> |
static int offset_cmp(const void *p1, const void *p2); |
54 |
> |
static void setmotion(int n, FVECT wpos); |
55 |
|
static void init_frame_sample(void); |
56 |
|
|
57 |
|
|
58 |
|
#if 0 |
59 |
< |
extern void |
59 |
> |
void |
60 |
|
write_map( /* write out float map (debugging) */ |
61 |
|
float *mp, |
62 |
|
char *fn |
146 |
|
error(SYSTEM, "out of memory in init_frame"); |
147 |
|
for (n = hres*vres; n--; ) { |
148 |
|
zprev[n] = -1.f; |
149 |
< |
xmbuffer[n] = ymbuffer[n] = MO_UNK; |
149 |
< |
oprev[n] = OVOID; |
149 |
> |
oprev[n] = OVOID; |
150 |
|
} |
151 |
|
frm_stop = getTime() + rtperfrm; |
152 |
|
} else { |
185 |
|
} |
186 |
|
|
187 |
|
|
188 |
< |
extern void |
188 |
> |
void |
189 |
|
sample_pos( /* compute jittered sample position */ |
190 |
|
double hv[2], |
191 |
|
int x, |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
< |
extern double |
205 |
> |
double |
206 |
|
sample_wt( /* compute interpolant sample weight */ |
207 |
|
int xo, |
208 |
|
int yo |
236 |
|
} |
237 |
|
|
238 |
|
|
239 |
< |
extern int |
239 |
> |
int |
240 |
|
getclosest( /* get nc closest neighbors on same object */ |
241 |
|
int *iarr, |
242 |
|
int nc, |
330 |
|
multp3(ovp, wpos, obj_move[moi].bxfm); |
331 |
|
wpos = ovp; |
332 |
|
} |
333 |
< |
viewloc(ovp, &vwprev, wpos); |
334 |
< |
if (ovp[2] <= FTINY) |
333 |
> |
if (viewloc(ovp, &vwprev, wpos) <= 0) |
334 |
|
return; |
335 |
|
xp = (int)(ovp[0]*hres); |
336 |
|
yp = (int)(ovp[1]*vres); |
362 |
|
for (x = hres; x--; ) { |
363 |
|
double hv[2]; |
364 |
|
n = fndx(x, y); |
365 |
< |
xmbuffer[n] = MO_UNK; |
367 |
< |
ymbuffer[n] = MO_UNK; |
365 |
> |
xmbuffer[n] = ymbuffer[n] = MO_UNK; |
366 |
|
sample_pos(hv, x, y, 0); |
367 |
|
ir.rmax = viewray(ir.rorg, ir.rdir, &vw, hv[0], hv[1]); |
368 |
|
if (ir.rmax < -FTINY) { |
450 |
|
} |
451 |
|
|
452 |
|
|
453 |
< |
extern int |
453 |
> |
int |
454 |
|
getambcolor( /* get ambient color for object if we can */ |
455 |
|
COLOR clr, |
456 |
|
int obj |
518 |
|
} |
519 |
|
|
520 |
|
|
521 |
< |
extern double |
521 |
> |
double |
522 |
|
estimaterr( /* estimate relative error from samples */ |
523 |
|
COLOR cs, |
524 |
|
COLOR cs2, |
544 |
|
} |
545 |
|
|
546 |
|
|
547 |
< |
extern double |
547 |
> |
double |
548 |
|
comperr( /* estimate relative error in neighborhood */ |
549 |
|
int *neigh, |
550 |
|
int nc, |
580 |
|
} |
581 |
|
|
582 |
|
|
583 |
< |
extern void |
583 |
> |
void |
584 |
|
comp_frame_error(void) /* initialize frame error values */ |
585 |
|
{ |
586 |
|
uby8 *edone = NULL; |
608 |
|
* by the returned ray value -- we take half of this. |
609 |
|
*/ |
610 |
|
edone = (uby8 *)calloc(hres*vres, sizeof(uby8)); |
611 |
< |
for (y = vres; y--; ) |
614 |
< |
for (x = hres; x--; ) { |
615 |
< |
n = fndx(x, y); |
611 |
> |
for (n = hres*vres; n--; ) { |
612 |
|
if ((abuffer[n] != ALOWQ) | (obuffer[n] == OVOID)) |
613 |
|
continue; |
614 |
|
if (!getambcolor(objamb, obuffer[n])) |
625 |
|
else if (i >= ADISTANT/2) i = ADISTANT/2-1; |
626 |
|
abuffer[n] = i; |
627 |
|
edone[n] = 1; |
628 |
< |
} |
628 |
> |
} |
629 |
|
} |
630 |
|
/* final statistical estimate */ |
631 |
|
for (y = vres; y--; ) |
657 |
|
} |
658 |
|
|
659 |
|
|
660 |
< |
extern void |
660 |
> |
void |
661 |
|
init_frame(void) /* render base (low quality) frame */ |
662 |
|
{ |
663 |
|
int restart; |
714 |
|
} |
715 |
|
|
716 |
|
|
717 |
< |
extern void |
717 |
> |
void |
718 |
|
filter_frame(void) /* interpolation, motion-blur, and exposure */ |
719 |
|
{ |
720 |
< |
double expval = expspec_val(getexp(fcur)); |
721 |
< |
int x, y; |
722 |
< |
int neigh[NPINTERP]; |
723 |
< |
int nc; |
724 |
< |
COLOR cval; |
725 |
< |
double w, wsum; |
726 |
< |
int n; |
720 |
> |
const double expval = expspec_val(getexp(fcur)); |
721 |
> |
int x, y; |
722 |
> |
int neigh[NPINTERP]; |
723 |
> |
int nc; |
724 |
> |
COLOR cval; |
725 |
> |
double w, wsum; |
726 |
> |
int n; |
727 |
|
|
728 |
|
#if 0 |
729 |
|
/* XXX TEMPORARY!! */ |
737 |
|
free((void *)ebuf); |
738 |
|
} |
739 |
|
#endif |
744 |
– |
|
740 |
|
if (!silent) { |
741 |
|
printf("\tFiltering frame\n"); |
742 |
|
fflush(stdout); |
743 |
|
} |
744 |
|
/* normalize samples */ |
745 |
< |
for (y = vres; y--; ) |
751 |
< |
for (x = hres; x--; ) { |
752 |
< |
n = fndx(x, y); |
745 |
> |
for (n = hres*vres; n--; ) { |
746 |
|
if (sbuffer[n] <= 1) |
747 |
|
continue; |
748 |
|
w = 1.0/(double)sbuffer[n]; |
749 |
|
scalecolor(cbuffer[n], w); |
750 |
< |
} |
750 |
> |
} |
751 |
|
/* interpolate samples */ |
752 |
|
for (y = vres; y--; ) |
753 |
|
for (x = hres; x--; ) { |
854 |
|
} |
855 |
|
} |
856 |
|
/* compute final results */ |
857 |
< |
for (y = vres; y--; ) |
865 |
< |
for (x = hres; x--; ) { |
866 |
< |
n = fndx(x, y); |
857 |
> |
for (n = hres*vres; n--; ) { |
858 |
|
if (wbuffer[n] <= FTINY) |
859 |
|
continue; |
860 |
< |
w = 1./wbuffer[n]; |
860 |
> |
w = expval/wbuffer[n]; |
861 |
|
scalecolor(outbuffer[n], w); |
862 |
< |
} |
863 |
< |
} else |
864 |
< |
for (n = hres*vres; n--; ) |
865 |
< |
copycolor(outbuffer[n], cbuffer[n]); |
862 |
> |
} |
863 |
> |
} else { /* no blur -- just exposure */ |
864 |
> |
memcpy(outbuffer, cbuffer, sizeof(COLOR)*hres*vres); |
865 |
> |
for (n = ((expval < 0.99) | (expval > 1.01))*hres*vres; n--; ) |
866 |
> |
scalecolor(outbuffer[n], expval); |
867 |
> |
} |
868 |
|
/* |
869 |
|
for (n = hres*vres; n--; ) |
870 |
|
if (!sbuffer[n]) |
871 |
|
setcolor(outbuffer[n], 0., 0., 0.); |
872 |
|
*/ |
880 |
– |
/* adjust exposure */ |
881 |
– |
if ((expval < 0.99) | (expval > 1.01)) |
882 |
– |
for (n = hres*vres; n--; ) |
883 |
– |
scalecolor(outbuffer[n], expval); |
873 |
|
#if 0 |
874 |
|
{ |
875 |
|
float *sbuf = (float *)malloc(sizeof(float)*hres*vres); |
885 |
|
} |
886 |
|
|
887 |
|
|
888 |
< |
extern void |
888 |
> |
void |
889 |
|
send_frame(void) /* send frame to destination */ |
890 |
|
{ |
891 |
|
char fname[1024]; |
954 |
|
if (vdef(MNAME)) { /* output motion buffer */ |
955 |
|
unsigned short *mbuffer = (unsigned short *)malloc( |
956 |
|
sizeof(unsigned short)*3*hres); |
957 |
< |
int x; |
957 |
> |
int x, n; |
958 |
|
if (mbuffer == NULL) |
959 |
< |
error(SYSTEM, "out of memory in send_frame()"); |
959 |
> |
error(SYSTEM, "out of memory in send_frame"); |
960 |
|
sprintf(fname, vval(MNAME), fcur); |
961 |
|
strcat(fname, ".mvo"); |
962 |
|
fp = fopen(fname, "w"); |
972 |
|
} |
973 |
|
for (y = vres; y--; ) { |
974 |
|
for (x = hres; x--; ) { |
975 |
< |
mbuffer[3*x] = xmbuffer[fndx(x,y)] + 0x8000; |
976 |
< |
mbuffer[3*x+1] = ymbuffer[fndx(x,y)] + 0x8000; |
977 |
< |
mbuffer[3*x+2] = (oprev[fndx(x,y)]!=OVOID)*0x8000; |
975 |
> |
n = fndx(x,y); |
976 |
> |
mbuffer[3*x] = xmbuffer[n] + 0x8000; |
977 |
> |
mbuffer[3*x+1] = ymbuffer[n] + 0x8000; |
978 |
> |
mbuffer[3*x+2] = (oprev[n]!=OVOID)*0x8000; |
979 |
|
} |
980 |
|
if (fwrite(mbuffer, sizeof(*mbuffer), |
981 |
|
3*hres, fp) != 3*hres) |
992 |
|
} |
993 |
|
|
994 |
|
|
995 |
< |
extern void |
995 |
> |
void |
996 |
|
free_frame(void) /* free frame allocation */ |
997 |
|
{ |
998 |
|
if (cbuffer == NULL) |