4 |
|
/* |
5 |
|
* ranimove1.c |
6 |
|
* |
7 |
< |
* Basic frame rendering routines for ranimate(1). |
7 |
> |
* Basic frame rendering routines for ranimove(1). |
8 |
|
* |
9 |
|
* Created by Gregory Ward on Wed Jan 08 2003. |
10 |
|
*/ |
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 |
> |
#if 0 |
58 |
> |
extern void |
59 |
> |
write_map( /* write out float map (debugging) */ |
60 |
> |
float *mp, |
61 |
> |
char *fn |
62 |
> |
) |
63 |
|
{ |
64 |
|
FILE *fp = fopen(fn, "w"); |
65 |
|
COLOR scanbuf[2048]; |
80 |
|
} |
81 |
|
fclose(fp); |
82 |
|
} |
83 |
+ |
#endif |
84 |
|
|
85 |
|
|
86 |
|
static void |
87 |
< |
next_frame() /* prepare next frame buffer */ |
87 |
> |
next_frame(void) /* prepare next frame buffer */ |
88 |
|
{ |
89 |
|
VIEW *fv; |
90 |
|
char *err; |
166 |
|
|
167 |
|
|
168 |
|
static int |
169 |
< |
sample_here(x, y) /* 4x4 quincunx sample at this pixel? */ |
170 |
< |
register int x, y; |
169 |
> |
sample_here( /* 4x4 quincunx sample at this pixel? */ |
170 |
> |
register int x, |
171 |
> |
register int y |
172 |
> |
) |
173 |
|
{ |
174 |
|
if (y & 0x1) /* every other row has samples */ |
175 |
|
return(0); |
179 |
|
} |
180 |
|
|
181 |
|
|
182 |
< |
void |
183 |
< |
sample_pos(hv, x, y, sn) /* compute jittered sample position */ |
184 |
< |
double hv[2]; |
185 |
< |
int x, y; |
186 |
< |
int sn; |
182 |
> |
extern void |
183 |
> |
sample_pos( /* compute jittered sample position */ |
184 |
> |
double hv[2], |
185 |
> |
int x, |
186 |
> |
int y, |
187 |
> |
int sn |
188 |
> |
) |
189 |
|
{ |
190 |
|
int hl[2]; |
191 |
|
|
196 |
|
} |
197 |
|
|
198 |
|
|
199 |
< |
double |
200 |
< |
sample_wt(xo, yo) /* compute interpolant sample weight */ |
201 |
< |
int xo, yo; |
199 |
> |
extern double |
200 |
> |
sample_wt( /* compute interpolant sample weight */ |
201 |
> |
int xo, |
202 |
> |
int yo |
203 |
> |
) |
204 |
|
{ |
205 |
|
static double etab[400]; |
206 |
|
/* we can't use the name rad2 here, for some reason Visual C |
221 |
|
|
222 |
|
|
223 |
|
static int |
224 |
< |
offset_cmp(p1, p2) /* compare offset distances */ |
225 |
< |
const void *p1, *p2; |
224 |
> |
offset_cmp( /* compare offset distances */ |
225 |
> |
const void *p1, |
226 |
> |
const void *p2 |
227 |
> |
) |
228 |
|
{ |
229 |
|
return(*(const int *)p1 - *(const int *)p2); |
230 |
|
} |
231 |
|
|
232 |
|
|
233 |
< |
int |
234 |
< |
getclosest(iarr, nc, x, y) /* get nc closest neighbors on same object */ |
235 |
< |
int *iarr; |
236 |
< |
int nc; |
237 |
< |
int x, y; |
233 |
> |
extern int |
234 |
> |
getclosest( /* get nc closest neighbors on same object */ |
235 |
> |
int *iarr, |
236 |
> |
int nc, |
237 |
> |
int x, |
238 |
> |
int y |
239 |
> |
) |
240 |
|
{ |
241 |
|
#define NSCHECK ((2*SAMPDIST+1)*(2*SAMPDIST+1)) |
242 |
|
static int hro, vro; |
306 |
|
|
307 |
|
|
308 |
|
static void |
309 |
< |
setmotion(n, wpos) /* compute motion vector for this pixel */ |
310 |
< |
register int n; |
311 |
< |
FVECT wpos; |
309 |
> |
setmotion( /* compute motion vector for this pixel */ |
310 |
> |
register int n, |
311 |
> |
FVECT wpos |
312 |
> |
) |
313 |
|
{ |
314 |
|
FVECT ovp; |
293 |
– |
MAT4 xfm; |
294 |
– |
double d; |
315 |
|
int moi; |
316 |
|
int xp, yp; |
317 |
|
/* ID object and update maximum HLS */ |
342 |
|
|
343 |
|
|
344 |
|
static void |
345 |
< |
init_frame_sample() /* sample our initial frame */ |
345 |
> |
init_frame_sample(void) /* sample our initial frame */ |
346 |
|
{ |
347 |
|
RAY ir; |
348 |
|
int x, y; |
369 |
|
continue; |
370 |
|
} |
371 |
|
if (!sample_here(x, y)) { /* just cast */ |
372 |
< |
rayorigin(&ir, NULL, PRIMARY, 1.0); |
372 |
> |
rayorigin(&ir, PRIMARY, NULL, NULL); |
373 |
|
if (!localhit(&ir, &thescene)) { |
374 |
|
if (ir.ro != &Aftplane) |
375 |
|
sourcehit(&ir); |
387 |
|
} |
388 |
|
if (nprocs > 1) { /* get sample */ |
389 |
|
int rval; |
390 |
< |
rayorigin(&ir, NULL, PRIMARY, 1.0); |
390 |
> |
rayorigin(&ir, PRIMARY, NULL, NULL); |
391 |
|
ir.rno = n; |
392 |
|
rval = ray_pqueue(&ir); |
393 |
|
if (!rval) |
444 |
|
} |
445 |
|
|
446 |
|
|
447 |
< |
int |
448 |
< |
getambcolor(clr, obj) /* get ambient color for object if we can */ |
449 |
< |
COLOR clr; |
450 |
< |
int obj; |
447 |
> |
extern int |
448 |
> |
getambcolor( /* get ambient color for object if we can */ |
449 |
> |
COLOR clr, |
450 |
> |
int obj |
451 |
> |
) |
452 |
|
{ |
453 |
|
register OBJREC *op; |
454 |
|
|
515 |
|
} |
516 |
|
|
517 |
|
|
518 |
< |
double |
519 |
< |
estimaterr(cs, cs2, ns, ns0) /* estimate relative error from samples */ |
520 |
< |
COLOR cs, cs2; |
521 |
< |
int ns; |
518 |
> |
extern double |
519 |
> |
estimaterr( /* estimate relative error from samples */ |
520 |
> |
COLOR cs, |
521 |
> |
COLOR cs2, |
522 |
> |
int ns, |
523 |
> |
int ns0 |
524 |
> |
) |
525 |
|
{ |
526 |
|
double d, d2, brt; |
527 |
|
|
541 |
|
} |
542 |
|
|
543 |
|
|
544 |
< |
double |
545 |
< |
comperr(neigh, nc, ns0) /* estimate relative error in neighborhood */ |
546 |
< |
int *neigh; |
547 |
< |
int nc; |
548 |
< |
int ns0; |
544 |
> |
extern double |
545 |
> |
comperr( /* estimate relative error in neighborhood */ |
546 |
> |
int *neigh, |
547 |
> |
int nc, |
548 |
> |
int ns0 |
549 |
> |
) |
550 |
|
{ |
551 |
|
COLOR csum, csum2; |
552 |
|
COLOR ctmp; |
577 |
|
} |
578 |
|
|
579 |
|
|
580 |
< |
void |
581 |
< |
comp_frame_error() /* initialize frame error values */ |
580 |
> |
extern void |
581 |
> |
comp_frame_error(void) /* initialize frame error values */ |
582 |
|
{ |
583 |
|
BYTE *edone = NULL; |
584 |
|
COLOR objamb; |
585 |
|
double eest; |
586 |
|
int neigh[NSAMPOK]; |
587 |
|
int nc; |
588 |
< |
int x, y, i, j; |
588 |
> |
int x, y, i; |
589 |
|
register int n; |
590 |
|
|
591 |
|
if (!silent) { |
656 |
|
} |
657 |
|
|
658 |
|
|
659 |
< |
void |
660 |
< |
init_frame() /* render base (low quality) frame */ |
659 |
> |
extern void |
660 |
> |
init_frame(void) /* render base (low quality) frame */ |
661 |
|
{ |
662 |
|
int restart; |
638 |
– |
|
663 |
|
/* allocate/swap buffers */ |
664 |
|
next_frame(); |
665 |
|
/* check rendering status */ |
666 |
|
restart = (!nobjects || vdef(MOVE)); |
667 |
|
if (!restart && curparams != &lorendparams && nprocs > 1) |
668 |
|
restart = -1; |
645 |
– |
if (restart > 0) { |
646 |
– |
if (nprocs > 1) |
647 |
– |
ray_pdone(1); |
648 |
– |
else |
649 |
– |
ray_done(1); |
650 |
– |
} |
669 |
|
/* post low quality parameters */ |
670 |
|
if (curparams != &lorendparams) |
671 |
|
ray_restore(curparams = &lorendparams); |
697 |
|
init_frame_sample(); |
698 |
|
/* initialize frame error */ |
699 |
|
comp_frame_error(); |
700 |
< |
return; |
700 |
> |
#if 0 |
701 |
|
{ |
702 |
|
float *ebuf = (float *)malloc(sizeof(float)*hres*vres); |
703 |
|
char fnm[256]; |
709 |
|
write_map(ebuf, fnm); |
710 |
|
free((void *)ebuf); |
711 |
|
} |
712 |
+ |
#endif |
713 |
|
} |
714 |
|
|
715 |
|
|
716 |
< |
void |
717 |
< |
filter_frame() /* interpolation, motion-blur, and exposure */ |
716 |
> |
extern void |
717 |
> |
filter_frame(void) /* interpolation, motion-blur, and exposure */ |
718 |
|
{ |
719 |
|
double expval = expspec_val(getexp(fcur)); |
720 |
|
int x, y; |
725 |
|
register int n; |
726 |
|
|
727 |
|
#if 0 |
728 |
< |
/* XXX TEMPORARY!! */ |
729 |
< |
conspicuity(); |
730 |
< |
write_map(cerrmap, "outcmap.pic"); |
731 |
< |
{ |
732 |
< |
float *ebuf = (float *)malloc(sizeof(float)*hres*vres); |
733 |
< |
for (n = hres*vres; n--; ) |
734 |
< |
ebuf[n] = acctab[abuffer[n]]; |
735 |
< |
write_map(ebuf, "outerr.pic"); |
736 |
< |
free((void *)ebuf); |
737 |
< |
} |
728 |
> |
/* XXX TEMPORARY!! */ |
729 |
> |
conspicuity(); |
730 |
> |
write_map(cerrmap, "outcmap.pic"); |
731 |
> |
{ |
732 |
> |
float *ebuf = (float *)malloc(sizeof(float)*hres*vres); |
733 |
> |
for (n = hres*vres; n--; ) |
734 |
> |
ebuf[n] = acctab[abuffer[n]]; |
735 |
> |
write_map(ebuf, "outerr.pic"); |
736 |
> |
free((void *)ebuf); |
737 |
> |
} |
738 |
|
#endif |
739 |
|
|
740 |
|
if (!silent) { |
758 |
|
continue; |
759 |
|
nc = getclosest(neigh, NPINTERP, x, y); |
760 |
|
setcolor(cbuffer[n], 0., 0., 0.); |
761 |
+ |
if (nc <= 0) { /* no acceptable neighbors */ |
762 |
+ |
if (y < vres-1) |
763 |
+ |
nc = fndx(x, y+1); |
764 |
+ |
else if (x < hres-1) |
765 |
+ |
nc = fndx(x+1, y); |
766 |
+ |
else |
767 |
+ |
continue; |
768 |
+ |
copycolor(cbuffer[n], cbuffer[nc]); |
769 |
+ |
continue; |
770 |
+ |
} |
771 |
|
wsum = 0.; |
772 |
|
while (nc-- > 0) { |
773 |
|
copycolor(cval, cbuffer[neigh[nc]]); |
777 |
|
addcolor(cbuffer[n], cval); |
778 |
|
wsum += w; |
779 |
|
} |
780 |
< |
if (wsum > FTINY) { |
781 |
< |
w = 1.0/wsum; |
753 |
< |
scalecolor(cbuffer[n], w); |
754 |
< |
} |
780 |
> |
w = 1.0/wsum; |
781 |
> |
scalecolor(cbuffer[n], w); |
782 |
|
} |
783 |
|
/* motion blur if requested */ |
784 |
|
if (mblur > .02) { |
758 |
– |
int len; |
785 |
|
int xs, ys, xl, yl; |
786 |
|
int rise, run; |
787 |
|
long rise2, run2; |
819 |
|
while (cnt) |
820 |
|
if (rise2 >= run2) { |
821 |
|
if ((xl >= 0) & (xl < hres) & |
822 |
< |
(yl >= 0) & (yl < vres)) { |
822 |
> |
(yl >= 0) & (yl < vres)) { |
823 |
|
n2 = fndx(xl, yl); |
824 |
|
addcolor(outbuffer[n2], |
825 |
|
cval); |
840 |
|
while (cnt) |
841 |
|
if (run2 >= rise2) { |
842 |
|
if ((xl >= 0) & (xl < hres) & |
843 |
< |
(yl >= 0) & (yl < vres)) { |
843 |
> |
(yl >= 0) & (yl < vres)) { |
844 |
|
n2 = fndx(xl, yl); |
845 |
|
addcolor(outbuffer[n2], |
846 |
|
cval); |
867 |
|
} else |
868 |
|
for (n = hres*vres; n--; ) |
869 |
|
copycolor(outbuffer[n], cbuffer[n]); |
870 |
< |
/* |
871 |
< |
for (n = hres*vres; n--; ) |
872 |
< |
if (!sbuffer[n]) |
873 |
< |
setcolor(outbuffer[n], 0., 0., 0.); |
874 |
< |
*/ |
875 |
< |
/* adjust exposure */ |
870 |
> |
/* |
871 |
> |
for (n = hres*vres; n--; ) |
872 |
> |
if (!sbuffer[n]) |
873 |
> |
setcolor(outbuffer[n], 0., 0., 0.); |
874 |
> |
*/ |
875 |
> |
/* adjust exposure */ |
876 |
|
if ((expval < 0.99) | (expval > 1.01)) |
877 |
|
for (n = hres*vres; n--; ) |
878 |
|
scalecolor(outbuffer[n], expval); |
879 |
< |
return; |
880 |
< |
{ |
881 |
< |
float *sbuf = (float *)malloc(sizeof(float)*hres*vres); |
882 |
< |
char fnm[256]; |
883 |
< |
sprintf(fnm, vval(BASENAME), fcur); |
884 |
< |
strcat(fnm, "_outsamp.pic"); |
885 |
< |
for (n = hres*vres; n--; ) |
886 |
< |
sbuf[n] = (float)sbuffer[n]; |
887 |
< |
write_map(sbuf, fnm); |
888 |
< |
free((void *)sbuf); |
879 |
> |
#if 0 |
880 |
> |
{ |
881 |
> |
float *sbuf = (float *)malloc(sizeof(float)*hres*vres); |
882 |
> |
char fnm[256]; |
883 |
> |
sprintf(fnm, vval(BASENAME), fcur); |
884 |
> |
strcat(fnm, "_outsamp.pic"); |
885 |
> |
for (n = hres*vres; n--; ) |
886 |
> |
sbuf[n] = (float)sbuffer[n]; |
887 |
> |
write_map(sbuf, fnm); |
888 |
> |
free((void *)sbuf); |
889 |
> |
} |
890 |
> |
#endif |
891 |
|
} |
864 |
– |
} |
892 |
|
|
893 |
|
|
894 |
< |
void |
895 |
< |
send_frame() /* send frame to destination */ |
894 |
> |
extern void |
895 |
> |
send_frame(void) /* send frame to destination */ |
896 |
|
{ |
897 |
|
char pfname[1024]; |
898 |
|
double d; |
944 |
|
} |
945 |
|
|
946 |
|
|
947 |
< |
void |
948 |
< |
free_frame() /* free frame allocation */ |
947 |
> |
extern void |
948 |
> |
free_frame(void) /* free frame allocation */ |
949 |
|
{ |
950 |
|
if (cbuffer == NULL) |
951 |
|
return; |