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 |
|
*/ |
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, |
80 |
|
} |
81 |
|
fclose(fp); |
82 |
|
} |
83 |
+ |
#endif |
84 |
|
|
85 |
|
|
86 |
|
static void |
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) |
660 |
|
init_frame(void) /* render base (low quality) frame */ |
661 |
|
{ |
662 |
|
int restart; |
661 |
– |
|
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; |
668 |
– |
if (restart > 0) { |
669 |
– |
if (nprocs > 1) |
670 |
– |
ray_pdone(1); |
671 |
– |
else |
672 |
– |
ray_done(1); |
673 |
– |
} |
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 |
|
|
741 |
|
printf("\tFiltering frame\n"); |
742 |
|
fflush(stdout); |
743 |
|
} |
744 |
< |
/* normalize samples */ |
745 |
< |
for (y = vres; y--; ) { |
746 |
< |
for (x = hres; x--; ) { |
747 |
< |
n = fndx(x, y); |
748 |
< |
if (sbuffer[n] <= 1) |
744 |
> |
/* normalize samples */ |
745 |
> |
for (y = vres; y--; ) |
746 |
> |
for (x = hres; x--; ) { |
747 |
> |
n = fndx(x, y); |
748 |
> |
if (sbuffer[n] <= 1) |
749 |
> |
continue; |
750 |
> |
w = 1.0/(double)sbuffer[n]; |
751 |
> |
scalecolor(cbuffer[n], w); |
752 |
> |
} |
753 |
> |
/* interpolate samples */ |
754 |
> |
for (y = vres; y--; ) |
755 |
> |
for (x = hres; x--; ) { |
756 |
> |
n = fndx(x, y); |
757 |
> |
if (sbuffer[n]) |
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 |
< |
w = 1.0/(double)sbuffer[n]; |
769 |
< |
scalecolor(cbuffer[n], w); |
768 |
> |
copycolor(cbuffer[n], cbuffer[nc]); |
769 |
> |
continue; |
770 |
|
} |
771 |
< |
} |
772 |
< |
/* interpolate samples */ |
773 |
< |
for (y = vres; y--; ) { |
774 |
< |
for (x = hres; x--; ) { |
775 |
< |
n = fndx(x, y); |
776 |
< |
if (sbuffer[n]) |
777 |
< |
continue; |
778 |
< |
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 |
< |
} |
771 |
> |
wsum = 0.; |
772 |
> |
while (nc-- > 0) { |
773 |
> |
copycolor(cval, cbuffer[neigh[nc]]); |
774 |
> |
w = sample_wt((neigh[nc]%hres) - x, |
775 |
> |
(neigh[nc]/hres) - y); |
776 |
> |
scalecolor(cval, w); |
777 |
> |
addcolor(cbuffer[n], cval); |
778 |
> |
wsum += w; |
779 |
|
} |
780 |
< |
} |
781 |
< |
/* motion blur if requested */ |
780 |
> |
w = 1.0/wsum; |
781 |
> |
scalecolor(cbuffer[n], w); |
782 |
> |
} |
783 |
> |
/* motion blur if requested */ |
784 |
|
if (mblur > .02) { |
785 |
< |
int xs, ys, xl, yl; |
786 |
< |
int rise, run; |
787 |
< |
long rise2, run2; |
788 |
< |
int n2; |
789 |
< |
int cnt; |
790 |
< |
/* sum in motion streaks */ |
791 |
< |
memset(outbuffer, '\0', sizeof(COLOR)*hres*vres); |
792 |
< |
memset(wbuffer, '\0', sizeof(float)*hres*vres); |
793 |
< |
for (y = vres; y--; ) { |
794 |
< |
for (x = hres; x--; ) { |
785 |
> |
int xs, ys, xl, yl; |
786 |
> |
int rise, run; |
787 |
> |
long rise2, run2; |
788 |
> |
int n2; |
789 |
> |
int cnt; |
790 |
> |
/* sum in motion streaks */ |
791 |
> |
memset(outbuffer, '\0', sizeof(COLOR)*hres*vres); |
792 |
> |
memset(wbuffer, '\0', sizeof(float)*hres*vres); |
793 |
> |
for (y = vres; y--; ) |
794 |
> |
for (x = hres; x--; ) { |
795 |
|
n = fndx(x, y); |
796 |
|
if (xmbuffer[n] == MO_UNK) { |
797 |
|
run = rise = 0; |
812 |
|
else ys = 1; |
813 |
|
rise2 = run2 = 0L; |
814 |
|
if (rise > run) { |
815 |
< |
cnt = rise + 1; |
816 |
< |
w = 1./cnt; |
817 |
< |
copycolor(cval, cbuffer[n]); |
818 |
< |
scalecolor(cval, w); |
819 |
< |
while (cnt) { |
820 |
< |
if (rise2 >= run2) { |
821 |
< |
if ((xl >= 0) & (xl < hres) & |
815 |
> |
cnt = rise + 1; |
816 |
> |
w = 1./cnt; |
817 |
> |
copycolor(cval, cbuffer[n]); |
818 |
> |
scalecolor(cval, w); |
819 |
> |
while (cnt) |
820 |
> |
if (rise2 >= run2) { |
821 |
> |
if ((xl >= 0) & (xl < hres) & |
822 |
|
(yl >= 0) & (yl < vres)) { |
823 |
< |
n2 = fndx(xl, yl); |
824 |
< |
addcolor(outbuffer[n2], cval); |
825 |
< |
wbuffer[n2] += w; |
826 |
< |
} |
827 |
< |
yl += ys; |
828 |
< |
run2 += run; |
829 |
< |
cnt--; |
830 |
< |
} else { |
831 |
< |
xl += xs; |
832 |
< |
rise2 += rise; |
833 |
< |
} |
834 |
< |
} |
823 |
> |
n2 = fndx(xl, yl); |
824 |
> |
addcolor(outbuffer[n2], |
825 |
> |
cval); |
826 |
> |
wbuffer[n2] += w; |
827 |
> |
} |
828 |
> |
yl += ys; |
829 |
> |
run2 += run; |
830 |
> |
cnt--; |
831 |
> |
} else { |
832 |
> |
xl += xs; |
833 |
> |
rise2 += rise; |
834 |
> |
} |
835 |
|
} else { |
836 |
|
cnt = run + 1; |
837 |
|
w = 1./cnt; |
838 |
|
copycolor(cval, cbuffer[n]); |
839 |
|
scalecolor(cval, w); |
840 |
< |
while (cnt) { |
841 |
< |
if (run2 >= rise2) { |
842 |
< |
if ((xl >= 0) & (xl < hres) & |
840 |
> |
while (cnt) |
841 |
> |
if (run2 >= rise2) { |
842 |
> |
if ((xl >= 0) & (xl < hres) & |
843 |
|
(yl >= 0) & (yl < vres)) { |
844 |
< |
n2 = fndx(xl, yl); |
845 |
< |
addcolor(outbuffer[n2], |
846 |
< |
cval); |
847 |
< |
wbuffer[n2] += w; |
844 |
> |
n2 = fndx(xl, yl); |
845 |
> |
addcolor(outbuffer[n2], |
846 |
> |
cval); |
847 |
> |
wbuffer[n2] += w; |
848 |
> |
} |
849 |
> |
xl += xs; |
850 |
> |
rise2 += rise; |
851 |
> |
cnt--; |
852 |
> |
} else { |
853 |
> |
yl += ys; |
854 |
> |
run2 += run; |
855 |
|
} |
847 |
– |
xl += xs; |
848 |
– |
rise2 += rise; |
849 |
– |
cnt--; |
850 |
– |
} else { |
851 |
– |
yl += ys; |
852 |
– |
run2 += run; |
853 |
– |
} |
854 |
– |
} |
856 |
|
} |
857 |
< |
} |
858 |
< |
/* compute final results */ |
859 |
< |
for (y = vres; y--; ) { |
860 |
< |
for (x = hres; x--; ) { |
861 |
< |
n = fndx(x, y); |
862 |
< |
if (wbuffer[n] <= FTINY) |
863 |
< |
continue; |
864 |
< |
w = 1./wbuffer[n]; |
865 |
< |
scalecolor(outbuffer[n], w); |
866 |
< |
} |
867 |
< |
} |
868 |
< |
} |
868 |
< |
} else { |
869 |
< |
for (n = hres*vres; n--; ) { |
857 |
> |
} |
858 |
> |
/* compute final results */ |
859 |
> |
for (y = vres; y--; ) |
860 |
> |
for (x = hres; x--; ) { |
861 |
> |
n = fndx(x, y); |
862 |
> |
if (wbuffer[n] <= FTINY) |
863 |
> |
continue; |
864 |
> |
w = 1./wbuffer[n]; |
865 |
> |
scalecolor(outbuffer[n], w); |
866 |
> |
} |
867 |
> |
} else |
868 |
> |
for (n = hres*vres; n--; ) |
869 |
|
copycolor(outbuffer[n], cbuffer[n]); |
871 |
– |
} |
872 |
– |
} |
870 |
|
/* |
871 |
|
for (n = hres*vres; n--; ) |
872 |
< |
if (!sbuffer[n]) |
873 |
< |
setcolor(outbuffer[n], 0., 0., 0.); |
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; |
879 |
> |
#if 0 |
880 |
|
{ |
881 |
|
float *sbuf = (float *)malloc(sizeof(float)*hres*vres); |
882 |
|
char fnm[256]; |
887 |
|
write_map(sbuf, fnm); |
888 |
|
free((void *)sbuf); |
889 |
|
} |
890 |
+ |
#endif |
891 |
|
} |
892 |
|
|
893 |
|
|
900 |
|
int y; |
901 |
|
/* open output picture */ |
902 |
|
sprintf(pfname, vval(BASENAME), fcur); |
903 |
< |
strcat(pfname, ".pic"); |
903 |
> |
strcat(pfname, ".hdr"); |
904 |
|
fp = fopen(pfname, "w"); |
905 |
|
if (fp == NULL) { |
906 |
|
sprintf(errmsg, "cannot open output frame \"%s\"", pfname); |