55 |
|
|
56 |
|
|
57 |
|
#if 0 |
58 |
< |
extern void |
58 |
> |
void |
59 |
|
write_map( /* write out float map (debugging) */ |
60 |
|
float *mp, |
61 |
|
char *fn |
145 |
|
error(SYSTEM, "out of memory in init_frame"); |
146 |
|
for (n = hres*vres; n--; ) { |
147 |
|
zprev[n] = -1.f; |
148 |
+ |
xmbuffer[n] = ymbuffer[n] = MO_UNK; |
149 |
|
oprev[n] = OVOID; |
150 |
|
} |
151 |
|
frm_stop = getTime() + rtperfrm; |
173 |
|
|
174 |
|
static int |
175 |
|
sample_here( /* 4x4 quincunx sample at this pixel? */ |
176 |
< |
register int x, |
177 |
< |
register int y |
176 |
> |
int x, |
177 |
> |
int y |
178 |
|
) |
179 |
|
{ |
180 |
|
if (y & 0x1) /* every other row has samples */ |
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, |
249 |
|
static int ioffs[NSCHECK]; |
250 |
|
OBJECT myobj; |
251 |
|
int i0, nf; |
252 |
< |
register int i, j; |
252 |
> |
int i, j; |
253 |
|
/* get our object number */ |
254 |
|
myobj = obuffer[fndx(x, y)]; |
255 |
|
/* special case for borders */ |
313 |
|
|
314 |
|
static void |
315 |
|
setmotion( /* compute motion vector for this pixel */ |
316 |
< |
register int n, |
316 |
> |
int n, |
317 |
|
FVECT wpos |
318 |
|
) |
319 |
|
{ |
352 |
|
{ |
353 |
|
RAY ir; |
354 |
|
int x, y; |
355 |
< |
register int n; |
355 |
> |
int n; |
356 |
|
|
357 |
|
if (!silent) { |
358 |
|
printf("\tComputing initial samples..."); |
452 |
|
} |
453 |
|
|
454 |
|
|
455 |
< |
extern int |
455 |
> |
int |
456 |
|
getambcolor( /* get ambient color for object if we can */ |
457 |
|
COLOR clr, |
458 |
|
int obj |
459 |
|
) |
460 |
|
{ |
461 |
< |
register OBJREC *op; |
461 |
> |
OBJREC *op; |
462 |
|
|
463 |
|
if (obj == OVOID) |
464 |
|
return(0); |
520 |
|
} |
521 |
|
|
522 |
|
|
523 |
< |
extern double |
523 |
> |
double |
524 |
|
estimaterr( /* estimate relative error from samples */ |
525 |
|
COLOR cs, |
526 |
|
COLOR cs2, |
546 |
|
} |
547 |
|
|
548 |
|
|
549 |
< |
extern double |
549 |
> |
double |
550 |
|
comperr( /* estimate relative error in neighborhood */ |
551 |
|
int *neigh, |
552 |
|
int nc, |
557 |
|
COLOR ctmp; |
558 |
|
int i; |
559 |
|
int ns; |
560 |
< |
register int n; |
560 |
> |
int n; |
561 |
|
/* add together samples */ |
562 |
|
setcolor(csum, 0., 0., 0.); |
563 |
|
setcolor(csum2, 0., 0., 0.); |
582 |
|
} |
583 |
|
|
584 |
|
|
585 |
< |
extern void |
585 |
> |
void |
586 |
|
comp_frame_error(void) /* initialize frame error values */ |
587 |
|
{ |
588 |
|
uby8 *edone = NULL; |
591 |
|
int neigh[NSAMPOK]; |
592 |
|
int nc; |
593 |
|
int x, y, i; |
594 |
< |
register int n; |
594 |
> |
int n; |
595 |
|
|
596 |
|
if (!silent) { |
597 |
|
printf("\tComputing error map\n"); |
610 |
|
* by the returned ray value -- we take half of this. |
611 |
|
*/ |
612 |
|
edone = (uby8 *)calloc(hres*vres, sizeof(uby8)); |
613 |
< |
for (y = vres; y--; ) |
613 |
< |
for (x = hres; x--; ) { |
614 |
< |
n = fndx(x, y); |
613 |
> |
for (n = hres*vres; n--; ) { |
614 |
|
if ((abuffer[n] != ALOWQ) | (obuffer[n] == OVOID)) |
615 |
|
continue; |
616 |
|
if (!getambcolor(objamb, obuffer[n])) |
627 |
|
else if (i >= ADISTANT/2) i = ADISTANT/2-1; |
628 |
|
abuffer[n] = i; |
629 |
|
edone[n] = 1; |
630 |
< |
} |
630 |
> |
} |
631 |
|
} |
632 |
|
/* final statistical estimate */ |
633 |
|
for (y = vres; y--; ) |
659 |
|
} |
660 |
|
|
661 |
|
|
662 |
< |
extern void |
662 |
> |
void |
663 |
|
init_frame(void) /* render base (low quality) frame */ |
664 |
|
{ |
665 |
|
int restart; |
704 |
|
{ |
705 |
|
float *ebuf = (float *)malloc(sizeof(float)*hres*vres); |
706 |
|
char fnm[256]; |
707 |
< |
register int n; |
707 |
> |
int n; |
708 |
|
for (n = hres*vres; n--; ) |
709 |
|
ebuf[n] = acctab[abuffer[n]]; |
710 |
|
sprintf(fnm, vval(BASENAME), fcur); |
716 |
|
} |
717 |
|
|
718 |
|
|
719 |
< |
extern void |
719 |
> |
void |
720 |
|
filter_frame(void) /* interpolation, motion-blur, and exposure */ |
721 |
|
{ |
722 |
< |
double expval = expspec_val(getexp(fcur)); |
723 |
< |
int x, y; |
724 |
< |
int neigh[NPINTERP]; |
725 |
< |
int nc; |
726 |
< |
COLOR cval; |
727 |
< |
double w, wsum; |
728 |
< |
register int n; |
722 |
> |
const double expval = expspec_val(getexp(fcur)); |
723 |
> |
int x, y; |
724 |
> |
int neigh[NPINTERP]; |
725 |
> |
int nc; |
726 |
> |
COLOR cval; |
727 |
> |
double w, wsum; |
728 |
> |
int n; |
729 |
|
|
730 |
|
#if 0 |
731 |
|
/* XXX TEMPORARY!! */ |
745 |
|
fflush(stdout); |
746 |
|
} |
747 |
|
/* normalize samples */ |
748 |
< |
for (y = vres; y--; ) |
750 |
< |
for (x = hres; x--; ) { |
751 |
< |
n = fndx(x, y); |
748 |
> |
for (n = hres*vres; n--; ) { |
749 |
|
if (sbuffer[n] <= 1) |
750 |
|
continue; |
751 |
|
w = 1.0/(double)sbuffer[n]; |
752 |
|
scalecolor(cbuffer[n], w); |
753 |
< |
} |
753 |
> |
} |
754 |
|
/* interpolate samples */ |
755 |
|
for (y = vres; y--; ) |
756 |
|
for (x = hres; x--; ) { |
857 |
|
} |
858 |
|
} |
859 |
|
/* compute final results */ |
860 |
< |
for (y = vres; y--; ) |
864 |
< |
for (x = hres; x--; ) { |
865 |
< |
n = fndx(x, y); |
860 |
> |
for (n = hres*vres; n--; ) { |
861 |
|
if (wbuffer[n] <= FTINY) |
862 |
|
continue; |
863 |
< |
w = 1./wbuffer[n]; |
863 |
> |
w = expval/wbuffer[n]; |
864 |
|
scalecolor(outbuffer[n], w); |
865 |
< |
} |
866 |
< |
} else |
867 |
< |
for (n = hres*vres; n--; ) |
868 |
< |
copycolor(outbuffer[n], cbuffer[n]); |
865 |
> |
} |
866 |
> |
} else { /* no blur -- just exposure */ |
867 |
> |
memcpy(outbuffer, cbuffer, sizeof(COLOR)*hres*vres); |
868 |
> |
for (n = ((expval < 0.99) | (expval > 1.01))*hres*vres; n--; ) |
869 |
> |
scalecolor(outbuffer[n], expval); |
870 |
> |
} |
871 |
|
/* |
872 |
|
for (n = hres*vres; n--; ) |
873 |
|
if (!sbuffer[n]) |
874 |
|
setcolor(outbuffer[n], 0., 0., 0.); |
875 |
|
*/ |
879 |
– |
/* adjust exposure */ |
880 |
– |
if ((expval < 0.99) | (expval > 1.01)) |
881 |
– |
for (n = hres*vres; n--; ) |
882 |
– |
scalecolor(outbuffer[n], expval); |
876 |
|
#if 0 |
877 |
|
{ |
878 |
|
float *sbuf = (float *)malloc(sizeof(float)*hres*vres); |
888 |
|
} |
889 |
|
|
890 |
|
|
891 |
< |
extern void |
891 |
> |
void |
892 |
|
send_frame(void) /* send frame to destination */ |
893 |
|
{ |
894 |
< |
char pfname[1024]; |
894 |
> |
char fname[1024]; |
895 |
|
double d; |
896 |
|
FILE *fp; |
897 |
|
int y; |
898 |
|
/* open output picture */ |
899 |
< |
sprintf(pfname, vval(BASENAME), fcur); |
900 |
< |
strcat(pfname, ".hdr"); |
901 |
< |
fp = fopen(pfname, "w"); |
899 |
> |
sprintf(fname, vval(BASENAME), fcur); |
900 |
> |
strcat(fname, ".hdr"); |
901 |
> |
fp = fopen(fname, "w"); |
902 |
|
if (fp == NULL) { |
903 |
< |
sprintf(errmsg, "cannot open output frame \"%s\"", pfname); |
903 |
> |
sprintf(errmsg, "cannot open output frame \"%s\"", fname); |
904 |
|
error(SYSTEM, errmsg); |
905 |
|
} |
906 |
|
SET_FILE_BINARY(fp); |
907 |
|
if (!silent) { |
908 |
< |
printf("\tWriting to \"%s\"\n", pfname); |
908 |
> |
printf("\tWriting to \"%s\"\n", fname); |
909 |
|
fflush(stdout); |
910 |
|
} |
911 |
|
/* write header */ |
934 |
|
goto writerr; |
935 |
|
if (fclose(fp) == EOF) |
936 |
|
goto writerr; |
937 |
+ |
if (vdef(ZNAME)) { /* output z-buffer */ |
938 |
+ |
sprintf(fname, vval(ZNAME), fcur); |
939 |
+ |
strcat(fname, ".zbf"); |
940 |
+ |
fp = fopen(fname, "w"); |
941 |
+ |
if (fp == NULL) { |
942 |
+ |
sprintf(errmsg, "cannot open z-file \"%s\"\n", fname); |
943 |
+ |
error(SYSTEM, errmsg); |
944 |
+ |
} |
945 |
+ |
SET_FILE_BINARY(fp); |
946 |
+ |
if (!silent) { |
947 |
+ |
printf("\tWriting depths to \"%s\"\n", fname); |
948 |
+ |
fflush(stdout); |
949 |
+ |
} |
950 |
+ |
for (y = vres; y--; ) |
951 |
+ |
if (fwrite(zbuffer+y*hres, sizeof(float), |
952 |
+ |
hres, fp) != hres) |
953 |
+ |
goto writerr; |
954 |
+ |
if (fclose(fp) == EOF) |
955 |
+ |
goto writerr; |
956 |
+ |
} |
957 |
+ |
if (vdef(MNAME)) { /* output motion buffer */ |
958 |
+ |
unsigned short *mbuffer = (unsigned short *)malloc( |
959 |
+ |
sizeof(unsigned short)*3*hres); |
960 |
+ |
int x; |
961 |
+ |
if (mbuffer == NULL) |
962 |
+ |
error(SYSTEM, "out of memory in send_frame()"); |
963 |
+ |
sprintf(fname, vval(MNAME), fcur); |
964 |
+ |
strcat(fname, ".mvo"); |
965 |
+ |
fp = fopen(fname, "w"); |
966 |
+ |
if (fp == NULL) { |
967 |
+ |
sprintf(errmsg, "cannot open motion file \"%s\"\n", |
968 |
+ |
fname); |
969 |
+ |
error(SYSTEM, errmsg); |
970 |
+ |
} |
971 |
+ |
SET_FILE_BINARY(fp); |
972 |
+ |
if (!silent) { |
973 |
+ |
printf("\tWriting motion vectors to \"%s\"\n", fname); |
974 |
+ |
fflush(stdout); |
975 |
+ |
} |
976 |
+ |
for (y = vres; y--; ) { |
977 |
+ |
for (x = hres; x--; ) { |
978 |
+ |
mbuffer[3*x] = xmbuffer[fndx(x,y)] + 0x8000; |
979 |
+ |
mbuffer[3*x+1] = ymbuffer[fndx(x,y)] + 0x8000; |
980 |
+ |
mbuffer[3*x+2] = (oprev[fndx(x,y)]!=OVOID)*0x8000; |
981 |
+ |
} |
982 |
+ |
if (fwrite(mbuffer, sizeof(*mbuffer), |
983 |
+ |
3*hres, fp) != 3*hres) |
984 |
+ |
goto writerr; |
985 |
+ |
} |
986 |
+ |
free((void *)mbuffer); |
987 |
+ |
if (fclose(fp) == EOF) |
988 |
+ |
goto writerr; |
989 |
+ |
} |
990 |
|
return; /* all is well */ |
991 |
|
writerr: |
992 |
< |
sprintf(errmsg, "error writing frame \"%s\"", pfname); |
992 |
> |
sprintf(errmsg, "error writing file \"%s\"", fname); |
993 |
|
error(SYSTEM, errmsg); |
994 |
|
} |
995 |
|
|
996 |
|
|
997 |
< |
extern void |
997 |
> |
void |
998 |
|
free_frame(void) /* free frame allocation */ |
999 |
|
{ |
1000 |
|
if (cbuffer == NULL) |