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 |
|
*/ |
367 |
|
continue; |
368 |
|
} |
369 |
|
if (!sample_here(x, y)) { /* just cast */ |
370 |
< |
rayorigin(&ir, NULL, PRIMARY, 1.0); |
370 |
> |
rayorigin(&ir, PRIMARY, NULL, NULL); |
371 |
|
if (!localhit(&ir, &thescene)) { |
372 |
|
if (ir.ro != &Aftplane) |
373 |
|
sourcehit(&ir); |
385 |
|
} |
386 |
|
if (nprocs > 1) { /* get sample */ |
387 |
|
int rval; |
388 |
< |
rayorigin(&ir, NULL, PRIMARY, 1.0); |
388 |
> |
rayorigin(&ir, PRIMARY, NULL, NULL); |
389 |
|
ir.rno = n; |
390 |
|
rval = ray_pqueue(&ir); |
391 |
|
if (!rval) |
745 |
|
printf("\tFiltering frame\n"); |
746 |
|
fflush(stdout); |
747 |
|
} |
748 |
< |
/* normalize samples */ |
749 |
< |
for (y = vres; y--; ) { |
750 |
< |
for (x = hres; x--; ) { |
751 |
< |
n = fndx(x, y); |
752 |
< |
if (sbuffer[n] <= 1) |
748 |
> |
/* normalize samples */ |
749 |
> |
for (y = vres; y--; ) |
750 |
> |
for (x = hres; x--; ) { |
751 |
> |
n = fndx(x, y); |
752 |
> |
if (sbuffer[n] <= 1) |
753 |
> |
continue; |
754 |
> |
w = 1.0/(double)sbuffer[n]; |
755 |
> |
scalecolor(cbuffer[n], w); |
756 |
> |
} |
757 |
> |
/* interpolate samples */ |
758 |
> |
for (y = vres; y--; ) |
759 |
> |
for (x = hres; x--; ) { |
760 |
> |
n = fndx(x, y); |
761 |
> |
if (sbuffer[n]) |
762 |
> |
continue; |
763 |
> |
nc = getclosest(neigh, NPINTERP, x, y); |
764 |
> |
setcolor(cbuffer[n], 0., 0., 0.); |
765 |
> |
if (nc <= 0) { /* no acceptable neighbors */ |
766 |
> |
if (y < vres-1) |
767 |
> |
nc = fndx(x, y+1); |
768 |
> |
else if (x < hres-1) |
769 |
> |
nc = fndx(x+1, y); |
770 |
> |
else |
771 |
|
continue; |
772 |
< |
w = 1.0/(double)sbuffer[n]; |
773 |
< |
scalecolor(cbuffer[n], w); |
772 |
> |
copycolor(cbuffer[n], cbuffer[nc]); |
773 |
> |
continue; |
774 |
|
} |
775 |
< |
} |
776 |
< |
/* interpolate samples */ |
777 |
< |
for (y = vres; y--; ) { |
778 |
< |
for (x = hres; x--; ) { |
779 |
< |
n = fndx(x, y); |
780 |
< |
if (sbuffer[n]) |
781 |
< |
continue; |
782 |
< |
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 |
< |
} |
775 |
> |
wsum = 0.; |
776 |
> |
while (nc-- > 0) { |
777 |
> |
copycolor(cval, cbuffer[neigh[nc]]); |
778 |
> |
w = sample_wt((neigh[nc]%hres) - x, |
779 |
> |
(neigh[nc]/hres) - y); |
780 |
> |
scalecolor(cval, w); |
781 |
> |
addcolor(cbuffer[n], cval); |
782 |
> |
wsum += w; |
783 |
|
} |
784 |
< |
} |
785 |
< |
/* motion blur if requested */ |
784 |
> |
w = 1.0/wsum; |
785 |
> |
scalecolor(cbuffer[n], w); |
786 |
> |
} |
787 |
> |
/* motion blur if requested */ |
788 |
|
if (mblur > .02) { |
789 |
< |
int xs, ys, xl, yl; |
790 |
< |
int rise, run; |
791 |
< |
long rise2, run2; |
792 |
< |
int n2; |
793 |
< |
int cnt; |
794 |
< |
/* sum in motion streaks */ |
795 |
< |
memset(outbuffer, '\0', sizeof(COLOR)*hres*vres); |
796 |
< |
memset(wbuffer, '\0', sizeof(float)*hres*vres); |
797 |
< |
for (y = vres; y--; ) { |
798 |
< |
for (x = hres; x--; ) { |
789 |
> |
int xs, ys, xl, yl; |
790 |
> |
int rise, run; |
791 |
> |
long rise2, run2; |
792 |
> |
int n2; |
793 |
> |
int cnt; |
794 |
> |
/* sum in motion streaks */ |
795 |
> |
memset(outbuffer, '\0', sizeof(COLOR)*hres*vres); |
796 |
> |
memset(wbuffer, '\0', sizeof(float)*hres*vres); |
797 |
> |
for (y = vres; y--; ) |
798 |
> |
for (x = hres; x--; ) { |
799 |
|
n = fndx(x, y); |
800 |
|
if (xmbuffer[n] == MO_UNK) { |
801 |
|
run = rise = 0; |
816 |
|
else ys = 1; |
817 |
|
rise2 = run2 = 0L; |
818 |
|
if (rise > run) { |
819 |
< |
cnt = rise + 1; |
820 |
< |
w = 1./cnt; |
821 |
< |
copycolor(cval, cbuffer[n]); |
822 |
< |
scalecolor(cval, w); |
823 |
< |
while (cnt) { |
824 |
< |
if (rise2 >= run2) { |
825 |
< |
if ((xl >= 0) & (xl < hres) & |
819 |
> |
cnt = rise + 1; |
820 |
> |
w = 1./cnt; |
821 |
> |
copycolor(cval, cbuffer[n]); |
822 |
> |
scalecolor(cval, w); |
823 |
> |
while (cnt) |
824 |
> |
if (rise2 >= run2) { |
825 |
> |
if ((xl >= 0) & (xl < hres) & |
826 |
|
(yl >= 0) & (yl < vres)) { |
827 |
< |
n2 = fndx(xl, yl); |
828 |
< |
addcolor(outbuffer[n2], cval); |
829 |
< |
wbuffer[n2] += w; |
830 |
< |
} |
831 |
< |
yl += ys; |
832 |
< |
run2 += run; |
833 |
< |
cnt--; |
834 |
< |
} else { |
835 |
< |
xl += xs; |
836 |
< |
rise2 += rise; |
837 |
< |
} |
838 |
< |
} |
827 |
> |
n2 = fndx(xl, yl); |
828 |
> |
addcolor(outbuffer[n2], |
829 |
> |
cval); |
830 |
> |
wbuffer[n2] += w; |
831 |
> |
} |
832 |
> |
yl += ys; |
833 |
> |
run2 += run; |
834 |
> |
cnt--; |
835 |
> |
} else { |
836 |
> |
xl += xs; |
837 |
> |
rise2 += rise; |
838 |
> |
} |
839 |
|
} else { |
840 |
|
cnt = run + 1; |
841 |
|
w = 1./cnt; |
842 |
|
copycolor(cval, cbuffer[n]); |
843 |
|
scalecolor(cval, w); |
844 |
< |
while (cnt) { |
845 |
< |
if (run2 >= rise2) { |
846 |
< |
if ((xl >= 0) & (xl < hres) & |
844 |
> |
while (cnt) |
845 |
> |
if (run2 >= rise2) { |
846 |
> |
if ((xl >= 0) & (xl < hres) & |
847 |
|
(yl >= 0) & (yl < vres)) { |
848 |
< |
n2 = fndx(xl, yl); |
849 |
< |
addcolor(outbuffer[n2], |
850 |
< |
cval); |
851 |
< |
wbuffer[n2] += w; |
848 |
> |
n2 = fndx(xl, yl); |
849 |
> |
addcolor(outbuffer[n2], |
850 |
> |
cval); |
851 |
> |
wbuffer[n2] += w; |
852 |
> |
} |
853 |
> |
xl += xs; |
854 |
> |
rise2 += rise; |
855 |
> |
cnt--; |
856 |
> |
} else { |
857 |
> |
yl += ys; |
858 |
> |
run2 += run; |
859 |
|
} |
847 |
– |
xl += xs; |
848 |
– |
rise2 += rise; |
849 |
– |
cnt--; |
850 |
– |
} else { |
851 |
– |
yl += ys; |
852 |
– |
run2 += run; |
853 |
– |
} |
854 |
– |
} |
860 |
|
} |
861 |
< |
} |
862 |
< |
/* compute final results */ |
863 |
< |
for (y = vres; y--; ) { |
864 |
< |
for (x = hres; x--; ) { |
865 |
< |
n = fndx(x, y); |
866 |
< |
if (wbuffer[n] <= FTINY) |
867 |
< |
continue; |
868 |
< |
w = 1./wbuffer[n]; |
869 |
< |
scalecolor(outbuffer[n], w); |
870 |
< |
} |
871 |
< |
} |
872 |
< |
} |
868 |
< |
} else { |
869 |
< |
for (n = hres*vres; n--; ) { |
861 |
> |
} |
862 |
> |
/* compute final results */ |
863 |
> |
for (y = vres; y--; ) |
864 |
> |
for (x = hres; x--; ) { |
865 |
> |
n = fndx(x, y); |
866 |
> |
if (wbuffer[n] <= FTINY) |
867 |
> |
continue; |
868 |
> |
w = 1./wbuffer[n]; |
869 |
> |
scalecolor(outbuffer[n], w); |
870 |
> |
} |
871 |
> |
} else |
872 |
> |
for (n = hres*vres; n--; ) |
873 |
|
copycolor(outbuffer[n], cbuffer[n]); |
871 |
– |
} |
872 |
– |
} |
874 |
|
/* |
875 |
|
for (n = hres*vres; n--; ) |
876 |
< |
if (!sbuffer[n]) |
877 |
< |
setcolor(outbuffer[n], 0., 0., 0.); |
876 |
> |
if (!sbuffer[n]) |
877 |
> |
setcolor(outbuffer[n], 0., 0., 0.); |
878 |
|
*/ |
879 |
|
/* adjust exposure */ |
880 |
|
if ((expval < 0.99) | (expval > 1.01)) |
881 |
|
for (n = hres*vres; n--; ) |
882 |
|
scalecolor(outbuffer[n], expval); |
883 |
< |
return; |
883 |
> |
#if 0 |
884 |
|
{ |
885 |
|
float *sbuf = (float *)malloc(sizeof(float)*hres*vres); |
886 |
|
char fnm[256]; |
891 |
|
write_map(sbuf, fnm); |
892 |
|
free((void *)sbuf); |
893 |
|
} |
894 |
+ |
#endif |
895 |
|
} |
896 |
|
|
897 |
|
|