30 |
|
OBJECT *obuffer; /* object id at each pixel */ |
31 |
|
short *xmbuffer; /* x motion at each pixel */ |
32 |
|
short *ymbuffer; /* y motion at each pixel */ |
33 |
< |
BYTE *abuffer; /* accuracy at each pixel */ |
34 |
< |
BYTE *sbuffer; /* sample count per pixel */ |
33 |
> |
uby8 *abuffer; /* accuracy at each pixel */ |
34 |
> |
uby8 *sbuffer; /* sample count per pixel */ |
35 |
|
|
36 |
|
VIEW vwprev; /* last frame's view */ |
37 |
|
COLOR *cprev; /* last frame colors */ |
38 |
|
float *zprev; /* last frame depth */ |
39 |
|
OBJECT *oprev; /* last frame objects */ |
40 |
< |
BYTE *aprev; /* last frame accuracy */ |
40 |
> |
uby8 *aprev; /* last frame accuracy */ |
41 |
|
|
42 |
|
float *cerrmap; /* conspicuous error map */ |
43 |
|
COLOR *val2map; /* value-squared map for variance */ |
48 |
|
|
49 |
|
|
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); |
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 |
|
#if 0 |
58 |
< |
extern void |
58 |
> |
void |
59 |
|
write_map( /* write out float map (debugging) */ |
60 |
|
float *mp, |
61 |
|
char *fn |
131 |
|
obuffer = (OBJECT *)malloc(sizeof(OBJECT)*hres*vres); |
132 |
|
xmbuffer = (short *)malloc(sizeof(short)*hres*vres); |
133 |
|
ymbuffer = (short *)malloc(sizeof(short)*hres*vres); |
134 |
< |
abuffer = (BYTE *)calloc(hres*vres, sizeof(BYTE)); |
135 |
< |
sbuffer = (BYTE *)calloc(hres*vres, sizeof(BYTE)); |
134 |
> |
abuffer = (uby8 *)calloc(hres*vres, sizeof(uby8)); |
135 |
> |
sbuffer = (uby8 *)calloc(hres*vres, sizeof(uby8)); |
136 |
|
cprev = (COLOR *)malloc(sizeof(COLOR)*hres*vres); |
137 |
|
zprev = (float *)malloc(sizeof(float)*hres*vres); |
138 |
|
oprev = (OBJECT *)malloc(sizeof(OBJECT)*hres*vres); |
139 |
< |
aprev = (BYTE *)malloc(sizeof(BYTE)*hres*vres); |
139 |
> |
aprev = (uby8 *)malloc(sizeof(uby8)*hres*vres); |
140 |
|
if ((cbuffer==NULL) | (zbuffer==NULL) | (obuffer==NULL) | |
141 |
|
(xmbuffer==NULL) | (ymbuffer==NULL) | |
142 |
|
(abuffer==NULL) | (sbuffer==NULL) | |
145 |
|
error(SYSTEM, "out of memory in init_frame"); |
146 |
|
for (n = hres*vres; n--; ) { |
147 |
|
zprev[n] = -1.f; |
148 |
< |
oprev[n] = OVOID; |
148 |
> |
oprev[n] = OVOID; |
149 |
|
} |
150 |
|
frm_stop = getTime() + rtperfrm; |
151 |
|
} else { |
152 |
|
COLOR *cp; /* else just swap buffers */ |
153 |
|
float *fp; |
154 |
|
OBJECT *op; |
155 |
< |
BYTE *bp; |
155 |
> |
uby8 *bp; |
156 |
|
cp = cprev; cprev = cbuffer; cbuffer = cp; |
157 |
|
fp = zprev; zprev = zbuffer; zbuffer = fp; |
158 |
|
op = oprev; oprev = obuffer; obuffer = op; |
159 |
|
bp = aprev; aprev = abuffer; abuffer = bp; |
160 |
< |
memset(abuffer, '\0', sizeof(BYTE)*hres*vres); |
161 |
< |
memset(sbuffer, '\0', sizeof(BYTE)*hres*vres); |
160 |
> |
memset(abuffer, '\0', sizeof(uby8)*hres*vres); |
161 |
> |
memset(sbuffer, '\0', sizeof(uby8)*hres*vres); |
162 |
|
frm_stop += rtperfrm; |
163 |
|
} |
164 |
|
cerrmap = NULL; |
172 |
|
|
173 |
|
static int |
174 |
|
sample_here( /* 4x4 quincunx sample at this pixel? */ |
175 |
< |
register int x, |
176 |
< |
register int y |
175 |
> |
int x, |
176 |
> |
int y |
177 |
|
) |
178 |
|
{ |
179 |
|
if (y & 0x1) /* every other row has samples */ |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
< |
extern void |
187 |
> |
void |
188 |
|
sample_pos( /* compute jittered sample position */ |
189 |
|
double hv[2], |
190 |
|
int x, |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
< |
extern double |
204 |
> |
double |
205 |
|
sample_wt( /* compute interpolant sample weight */ |
206 |
|
int xo, |
207 |
|
int yo |
235 |
|
} |
236 |
|
|
237 |
|
|
238 |
< |
extern int |
238 |
> |
int |
239 |
|
getclosest( /* get nc closest neighbors on same object */ |
240 |
|
int *iarr, |
241 |
|
int nc, |
248 |
|
static int ioffs[NSCHECK]; |
249 |
|
OBJECT myobj; |
250 |
|
int i0, nf; |
251 |
< |
register int i, j; |
251 |
> |
int i, j; |
252 |
|
/* get our object number */ |
253 |
|
myobj = obuffer[fndx(x, y)]; |
254 |
|
/* special case for borders */ |
312 |
|
|
313 |
|
static void |
314 |
|
setmotion( /* compute motion vector for this pixel */ |
315 |
< |
register int n, |
315 |
> |
int n, |
316 |
|
FVECT wpos |
317 |
|
) |
318 |
|
{ |
329 |
|
multp3(ovp, wpos, obj_move[moi].bxfm); |
330 |
|
wpos = ovp; |
331 |
|
} |
332 |
< |
viewloc(ovp, &vwprev, wpos); |
333 |
< |
if (ovp[2] <= FTINY) |
332 |
> |
if (viewloc(ovp, &vwprev, wpos) <= 0) |
333 |
|
return; |
334 |
|
xp = (int)(ovp[0]*hres); |
335 |
|
yp = (int)(ovp[1]*vres); |
350 |
|
{ |
351 |
|
RAY ir; |
352 |
|
int x, y; |
353 |
< |
register int n; |
353 |
> |
int n; |
354 |
|
|
355 |
|
if (!silent) { |
356 |
|
printf("\tComputing initial samples..."); |
361 |
|
for (x = hres; x--; ) { |
362 |
|
double hv[2]; |
363 |
|
n = fndx(x, y); |
364 |
< |
xmbuffer[n] = MO_UNK; |
366 |
< |
ymbuffer[n] = MO_UNK; |
364 |
> |
xmbuffer[n] = ymbuffer[n] = MO_UNK; |
365 |
|
sample_pos(hv, x, y, 0); |
366 |
|
ir.rmax = viewray(ir.rorg, ir.rdir, &vw, hv[0], hv[1]); |
367 |
|
if (ir.rmax < -FTINY) { |
449 |
|
} |
450 |
|
|
451 |
|
|
452 |
< |
extern int |
452 |
> |
int |
453 |
|
getambcolor( /* get ambient color for object if we can */ |
454 |
|
COLOR clr, |
455 |
|
int obj |
456 |
|
) |
457 |
|
{ |
458 |
< |
register OBJREC *op; |
458 |
> |
OBJREC *op; |
459 |
|
|
460 |
|
if (obj == OVOID) |
461 |
|
return(0); |
517 |
|
} |
518 |
|
|
519 |
|
|
520 |
< |
extern double |
520 |
> |
double |
521 |
|
estimaterr( /* estimate relative error from samples */ |
522 |
|
COLOR cs, |
523 |
|
COLOR cs2, |
543 |
|
} |
544 |
|
|
545 |
|
|
546 |
< |
extern double |
546 |
> |
double |
547 |
|
comperr( /* estimate relative error in neighborhood */ |
548 |
|
int *neigh, |
549 |
|
int nc, |
554 |
|
COLOR ctmp; |
555 |
|
int i; |
556 |
|
int ns; |
557 |
< |
register int n; |
557 |
> |
int n; |
558 |
|
/* add together samples */ |
559 |
|
setcolor(csum, 0., 0., 0.); |
560 |
|
setcolor(csum2, 0., 0., 0.); |
579 |
|
} |
580 |
|
|
581 |
|
|
582 |
< |
extern void |
582 |
> |
void |
583 |
|
comp_frame_error(void) /* initialize frame error values */ |
584 |
|
{ |
585 |
< |
BYTE *edone = NULL; |
585 |
> |
uby8 *edone = NULL; |
586 |
|
COLOR objamb; |
587 |
|
double eest; |
588 |
|
int neigh[NSAMPOK]; |
589 |
|
int nc; |
590 |
|
int x, y, i; |
591 |
< |
register int n; |
591 |
> |
int n; |
592 |
|
|
593 |
|
if (!silent) { |
594 |
|
printf("\tComputing error map\n"); |
606 |
|
* error should be less than the ambient value divided |
607 |
|
* by the returned ray value -- we take half of this. |
608 |
|
*/ |
609 |
< |
edone = (BYTE *)calloc(hres*vres, sizeof(BYTE)); |
610 |
< |
for (y = vres; y--; ) |
613 |
< |
for (x = hres; x--; ) { |
614 |
< |
n = fndx(x, y); |
609 |
> |
edone = (uby8 *)calloc(hres*vres, sizeof(uby8)); |
610 |
> |
for (n = hres*vres; n--; ) { |
611 |
|
if ((abuffer[n] != ALOWQ) | (obuffer[n] == OVOID)) |
612 |
|
continue; |
613 |
|
if (!getambcolor(objamb, obuffer[n])) |
624 |
|
else if (i >= ADISTANT/2) i = ADISTANT/2-1; |
625 |
|
abuffer[n] = i; |
626 |
|
edone[n] = 1; |
627 |
< |
} |
627 |
> |
} |
628 |
|
} |
629 |
|
/* final statistical estimate */ |
630 |
|
for (y = vres; y--; ) |
656 |
|
} |
657 |
|
|
658 |
|
|
659 |
< |
extern void |
659 |
> |
void |
660 |
|
init_frame(void) /* render base (low quality) frame */ |
661 |
|
{ |
662 |
|
int restart; |
701 |
|
{ |
702 |
|
float *ebuf = (float *)malloc(sizeof(float)*hres*vres); |
703 |
|
char fnm[256]; |
704 |
< |
register int n; |
704 |
> |
int n; |
705 |
|
for (n = hres*vres; n--; ) |
706 |
|
ebuf[n] = acctab[abuffer[n]]; |
707 |
|
sprintf(fnm, vval(BASENAME), fcur); |
713 |
|
} |
714 |
|
|
715 |
|
|
716 |
< |
extern void |
716 |
> |
void |
717 |
|
filter_frame(void) /* interpolation, motion-blur, and exposure */ |
718 |
|
{ |
719 |
< |
double expval = expspec_val(getexp(fcur)); |
720 |
< |
int x, y; |
721 |
< |
int neigh[NPINTERP]; |
722 |
< |
int nc; |
723 |
< |
COLOR cval; |
724 |
< |
double w, wsum; |
725 |
< |
register int n; |
719 |
> |
const double expval = expspec_val(getexp(fcur)); |
720 |
> |
int x, y; |
721 |
> |
int neigh[NPINTERP]; |
722 |
> |
int nc; |
723 |
> |
COLOR cval; |
724 |
> |
double w, wsum; |
725 |
> |
int n; |
726 |
|
|
727 |
|
#if 0 |
728 |
|
/* XXX TEMPORARY!! */ |
736 |
|
free((void *)ebuf); |
737 |
|
} |
738 |
|
#endif |
743 |
– |
|
739 |
|
if (!silent) { |
740 |
|
printf("\tFiltering frame\n"); |
741 |
|
fflush(stdout); |
742 |
|
} |
743 |
|
/* normalize samples */ |
744 |
< |
for (y = vres; y--; ) |
750 |
< |
for (x = hres; x--; ) { |
751 |
< |
n = fndx(x, y); |
744 |
> |
for (n = hres*vres; n--; ) { |
745 |
|
if (sbuffer[n] <= 1) |
746 |
|
continue; |
747 |
|
w = 1.0/(double)sbuffer[n]; |
748 |
|
scalecolor(cbuffer[n], w); |
749 |
< |
} |
749 |
> |
} |
750 |
|
/* interpolate samples */ |
751 |
|
for (y = vres; y--; ) |
752 |
|
for (x = hres; x--; ) { |
853 |
|
} |
854 |
|
} |
855 |
|
/* compute final results */ |
856 |
< |
for (y = vres; y--; ) |
864 |
< |
for (x = hres; x--; ) { |
865 |
< |
n = fndx(x, y); |
856 |
> |
for (n = hres*vres; n--; ) { |
857 |
|
if (wbuffer[n] <= FTINY) |
858 |
|
continue; |
859 |
< |
w = 1./wbuffer[n]; |
859 |
> |
w = expval/wbuffer[n]; |
860 |
|
scalecolor(outbuffer[n], w); |
861 |
< |
} |
862 |
< |
} else |
863 |
< |
for (n = hres*vres; n--; ) |
864 |
< |
copycolor(outbuffer[n], cbuffer[n]); |
861 |
> |
} |
862 |
> |
} else { /* no blur -- just exposure */ |
863 |
> |
memcpy(outbuffer, cbuffer, sizeof(COLOR)*hres*vres); |
864 |
> |
for (n = ((expval < 0.99) | (expval > 1.01))*hres*vres; n--; ) |
865 |
> |
scalecolor(outbuffer[n], expval); |
866 |
> |
} |
867 |
|
/* |
868 |
|
for (n = hres*vres; n--; ) |
869 |
|
if (!sbuffer[n]) |
870 |
|
setcolor(outbuffer[n], 0., 0., 0.); |
871 |
|
*/ |
879 |
– |
/* adjust exposure */ |
880 |
– |
if ((expval < 0.99) | (expval > 1.01)) |
881 |
– |
for (n = hres*vres; n--; ) |
882 |
– |
scalecolor(outbuffer[n], expval); |
872 |
|
#if 0 |
873 |
|
{ |
874 |
|
float *sbuf = (float *)malloc(sizeof(float)*hres*vres); |
884 |
|
} |
885 |
|
|
886 |
|
|
887 |
< |
extern void |
887 |
> |
void |
888 |
|
send_frame(void) /* send frame to destination */ |
889 |
|
{ |
890 |
< |
char pfname[1024]; |
890 |
> |
char fname[1024]; |
891 |
|
double d; |
892 |
|
FILE *fp; |
893 |
|
int y; |
894 |
|
/* open output picture */ |
895 |
< |
sprintf(pfname, vval(BASENAME), fcur); |
896 |
< |
strcat(pfname, ".hdr"); |
897 |
< |
fp = fopen(pfname, "w"); |
895 |
> |
sprintf(fname, vval(BASENAME), fcur); |
896 |
> |
strcat(fname, ".hdr"); |
897 |
> |
fp = fopen(fname, "w"); |
898 |
|
if (fp == NULL) { |
899 |
< |
sprintf(errmsg, "cannot open output frame \"%s\"", pfname); |
899 |
> |
sprintf(errmsg, "cannot open output frame \"%s\"", fname); |
900 |
|
error(SYSTEM, errmsg); |
901 |
|
} |
902 |
|
SET_FILE_BINARY(fp); |
903 |
|
if (!silent) { |
904 |
< |
printf("\tWriting to \"%s\"\n", pfname); |
904 |
> |
printf("\tWriting to \"%s\"\n", fname); |
905 |
|
fflush(stdout); |
906 |
|
} |
907 |
|
/* write header */ |
930 |
|
goto writerr; |
931 |
|
if (fclose(fp) == EOF) |
932 |
|
goto writerr; |
933 |
+ |
if (vdef(ZNAME)) { /* output z-buffer */ |
934 |
+ |
sprintf(fname, vval(ZNAME), fcur); |
935 |
+ |
strcat(fname, ".zbf"); |
936 |
+ |
fp = fopen(fname, "w"); |
937 |
+ |
if (fp == NULL) { |
938 |
+ |
sprintf(errmsg, "cannot open z-file \"%s\"\n", fname); |
939 |
+ |
error(SYSTEM, errmsg); |
940 |
+ |
} |
941 |
+ |
SET_FILE_BINARY(fp); |
942 |
+ |
if (!silent) { |
943 |
+ |
printf("\tWriting depths to \"%s\"\n", fname); |
944 |
+ |
fflush(stdout); |
945 |
+ |
} |
946 |
+ |
for (y = vres; y--; ) |
947 |
+ |
if (fwrite(zbuffer+y*hres, sizeof(float), |
948 |
+ |
hres, fp) != hres) |
949 |
+ |
goto writerr; |
950 |
+ |
if (fclose(fp) == EOF) |
951 |
+ |
goto writerr; |
952 |
+ |
} |
953 |
+ |
if (vdef(MNAME)) { /* output motion buffer */ |
954 |
+ |
unsigned short *mbuffer = (unsigned short *)malloc( |
955 |
+ |
sizeof(unsigned short)*3*hres); |
956 |
+ |
int x, n; |
957 |
+ |
if (mbuffer == NULL) |
958 |
+ |
error(SYSTEM, "out of memory in send_frame"); |
959 |
+ |
sprintf(fname, vval(MNAME), fcur); |
960 |
+ |
strcat(fname, ".mvo"); |
961 |
+ |
fp = fopen(fname, "w"); |
962 |
+ |
if (fp == NULL) { |
963 |
+ |
sprintf(errmsg, "cannot open motion file \"%s\"\n", |
964 |
+ |
fname); |
965 |
+ |
error(SYSTEM, errmsg); |
966 |
+ |
} |
967 |
+ |
SET_FILE_BINARY(fp); |
968 |
+ |
if (!silent) { |
969 |
+ |
printf("\tWriting motion vectors to \"%s\"\n", fname); |
970 |
+ |
fflush(stdout); |
971 |
+ |
} |
972 |
+ |
for (y = vres; y--; ) { |
973 |
+ |
for (x = hres; x--; ) { |
974 |
+ |
n = fndx(x,y); |
975 |
+ |
mbuffer[3*x] = xmbuffer[n] + 0x8000; |
976 |
+ |
mbuffer[3*x+1] = ymbuffer[n] + 0x8000; |
977 |
+ |
mbuffer[3*x+2] = (oprev[n]!=OVOID)*0x8000; |
978 |
+ |
} |
979 |
+ |
if (fwrite(mbuffer, sizeof(*mbuffer), |
980 |
+ |
3*hres, fp) != 3*hres) |
981 |
+ |
goto writerr; |
982 |
+ |
} |
983 |
+ |
free((void *)mbuffer); |
984 |
+ |
if (fclose(fp) == EOF) |
985 |
+ |
goto writerr; |
986 |
+ |
} |
987 |
|
return; /* all is well */ |
988 |
|
writerr: |
989 |
< |
sprintf(errmsg, "error writing frame \"%s\"", pfname); |
989 |
> |
sprintf(errmsg, "error writing file \"%s\"", fname); |
990 |
|
error(SYSTEM, errmsg); |
991 |
|
} |
992 |
|
|
993 |
|
|
994 |
< |
extern void |
994 |
> |
void |
995 |
|
free_frame(void) /* free frame allocation */ |
996 |
|
{ |
997 |
|
if (cbuffer == NULL) |