ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/ranimove1.c
(Generate patch)

Comparing ray/src/util/ranimove1.c (file contents):
Revision 3.7 by schorsch, Tue Oct 21 19:19:29 2003 UTC vs.
Revision 3.8 by schorsch, Fri Mar 26 21:36:20 2004 UTC

# Line 16 | Line 16 | static const char      RCSid[] = "$Id$";
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 */
# Line 46 | Line 47 | double         frm_stop;       /* when to stop rendering this frame
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 > extern void
58 > write_map(              /* write out float map (debugging) */
59 >        float   *mp,
60 >        char    *fn
61 > )
62   {
63          FILE    *fp = fopen(fn, "w");
64          COLOR   scanbuf[2048];
# Line 73 | Line 82 | char   *fn;
82  
83  
84   static void
85 < next_frame()                    /* prepare next frame buffer */
85 > next_frame(void)                        /* prepare next frame buffer */
86   {
87          VIEW    *fv;
88          char    *err;
# Line 155 | Line 164 | next_frame()                   /* prepare next frame buffer */
164  
165  
166   static int
167 < sample_here(x, y)               /* 4x4 quincunx sample at this pixel? */
168 < register int    x, y;
167 > sample_here(            /* 4x4 quincunx sample at this pixel? */
168 >        register int    x,
169 >        register int    y
170 > )
171   {
172          if (y & 0x1)            /* every other row has samples */
173                  return(0);
# Line 166 | Line 177 | register int   x, y;
177   }
178  
179  
180 < void
181 < sample_pos(hv, x, y, sn)        /* compute jittered sample position */
182 < double  hv[2];
183 < int     x, y;
184 < int     sn;
180 > extern void
181 > sample_pos(     /* compute jittered sample position */
182 >        double  hv[2],
183 >        int     x,
184 >        int     y,
185 >        int     sn
186 > )
187   {
188          int     hl[2];
189  
# Line 181 | Line 194 | int    sn;
194   }
195  
196  
197 < double
198 < sample_wt(xo, yo)               /* compute interpolant sample weight */
199 < int     xo, yo;
197 > extern double
198 > sample_wt(              /* compute interpolant sample weight */
199 >        int     xo,
200 >        int yo
201 > )
202   {
203          static double   etab[400];
204          /* we can't use the name rad2 here, for some reason Visual C
# Line 204 | Line 219 | int    xo, yo;
219  
220  
221   static int
222 < offset_cmp(p1, p2)              /* compare offset distances */
223 < const void      *p1, *p2;
222 > offset_cmp(             /* compare offset distances */
223 >        const void      *p1,
224 >        const void      *p2
225 > )
226   {
227          return(*(const int *)p1 - *(const int *)p2);
228   }
229  
230  
231 < int
232 < getclosest(iarr, nc, x, y)      /* get nc closest neighbors on same object */
233 < int     *iarr;
234 < int     nc;
235 < int     x, y;
231 > extern int
232 > getclosest(     /* get nc closest neighbors on same object */
233 >        int     *iarr,
234 >        int     nc,
235 >        int     x,
236 >        int     y
237 > )
238   {
239   #define NSCHECK         ((2*SAMPDIST+1)*(2*SAMPDIST+1))
240          static int      hro, vro;
# Line 285 | Line 304 | int    x, y;
304  
305  
306   static void
307 < setmotion(n, wpos)              /* compute motion vector for this pixel */
308 < register int    n;
309 < FVECT   wpos;
307 > setmotion(              /* compute motion vector for this pixel */
308 >                register int    n,
309 >                FVECT   wpos
310 > )
311   {
312          FVECT   ovp;
293        MAT4    xfm;
294        double  d;
313          int     moi;
314          int     xp, yp;
315                                          /* ID object and update maximum HLS */
# Line 322 | Line 340 | FVECT  wpos;
340  
341  
342   static void
343 < init_frame_sample()             /* sample our initial frame */
343 > init_frame_sample(void)         /* sample our initial frame */
344   {
345          RAY     ir;
346          int     x, y;
# Line 424 | Line 442 | init_frame_sample()            /* sample our initial frame */
442   }
443  
444  
445 < int
446 < getambcolor(clr, obj)           /* get ambient color for object if we can */
447 < COLOR   clr;
448 < int     obj;
445 > extern int
446 > getambcolor(            /* get ambient color for object if we can */
447 >                COLOR   clr,
448 >                int     obj
449 > )
450   {
451          register OBJREC *op;
452  
# Line 494 | Line 513 | int    obj;
513   }
514  
515  
516 < double
517 < estimaterr(cs, cs2, ns, ns0)    /* estimate relative error from samples */
518 < COLOR   cs, cs2;
519 < int     ns;
516 > extern double
517 > estimaterr(             /* estimate relative error from samples */
518 >                COLOR   cs,
519 >                COLOR   cs2,
520 >                int     ns,
521 >                int ns0
522 > )
523   {
524          double  d, d2, brt;
525  
# Line 517 | Line 539 | int    ns;
539   }
540  
541  
542 < double
543 < comperr(neigh, nc, ns0)         /* estimate relative error in neighborhood */
544 < int     *neigh;
545 < int     nc;
546 < int     ns0;
542 > extern double
543 > comperr(                /* estimate relative error in neighborhood */
544 >                int     *neigh,
545 >                int     nc,
546 >                int     ns0
547 > )
548   {
549          COLOR   csum, csum2;
550          COLOR   ctmp;
# Line 552 | Line 575 | int    ns0;
575   }
576  
577  
578 < void
579 < comp_frame_error()              /* initialize frame error values */
578 > extern void
579 > comp_frame_error(void)          /* initialize frame error values */
580   {
581          BYTE    *edone = NULL;
582          COLOR   objamb;
583          double  eest;
584          int     neigh[NSAMPOK];
585          int     nc;
586 <        int     x, y, i, j;
586 >        int     x, y, i;
587          register int    n;
588  
589          if (!silent) {
# Line 631 | Line 654 | comp_frame_error()             /* initialize frame error values *
654   }
655  
656  
657 < void
658 < init_frame()                    /* render base (low quality) frame */
657 > extern void
658 > init_frame(void)                        /* render base (low quality) frame */
659   {
660          int     restart;
661  
# Line 694 | Line 717 | return;
717   }
718  
719  
720 < void
721 < filter_frame()                  /* interpolation, motion-blur, and exposure */
720 > extern void
721 > filter_frame(void)                      /* interpolation, motion-blur, and exposure */
722   {
723          double  expval = expspec_val(getexp(fcur));
724          int     x, y;
# Line 706 | Line 729 | filter_frame()                 /* interpolation, motion-blur, and ex
729          register int    n;
730  
731   #if 0
732 < /* XXX TEMPORARY!! */
733 < conspicuity();
734 < write_map(cerrmap, "outcmap.pic");
735 < {
736 <        float   *ebuf = (float *)malloc(sizeof(float)*hres*vres);
737 <        for (n = hres*vres; n--; )
738 <                ebuf[n] = acctab[abuffer[n]];
739 <        write_map(ebuf, "outerr.pic");
740 <        free((void *)ebuf);
741 < }
732 >        /* XXX TEMPORARY!! */
733 >        conspicuity();
734 >        write_map(cerrmap, "outcmap.pic");
735 >        {
736 >                float   *ebuf = (float *)malloc(sizeof(float)*hres*vres);
737 >                for (n = hres*vres; n--; )
738 >                        ebuf[n] = acctab[abuffer[n]];
739 >                write_map(ebuf, "outerr.pic");
740 >                free((void *)ebuf);
741 >        }
742   #endif
743  
744          if (!silent) {
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)
753 <                        continue;
754 <                w = 1.0/(double)sbuffer[n];
732 <                scalecolor(cbuffer[n], w);
733 <            }
734 <                                        /* interpolate samples */
735 <        for (y = vres; y--; )
736 <            for (x = hres; x--; ) {
737 <                n = fndx(x, y);
738 <                if (sbuffer[n])
739 <                        continue;
740 <                nc = getclosest(neigh, NPINTERP, x, y);
741 <                setcolor(cbuffer[n], 0., 0., 0.);
742 <                wsum = 0.;
743 <                while (nc-- > 0) {
744 <                        copycolor(cval, cbuffer[neigh[nc]]);
745 <                        w = sample_wt((neigh[nc]%hres) - x,
746 <                                        (neigh[nc]/hres) - y);
747 <                        scalecolor(cval, w);
748 <                        addcolor(cbuffer[n], cval);
749 <                        wsum += w;
750 <                }
751 <                if (wsum > FTINY) {
752 <                        w = 1.0/wsum;
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 <            }
758 <                                        /* motion blur if requested */
757 >        }
758 >        /* interpolate samples */
759 >        for (y = vres; y--; ) {
760 >                for (x = hres; x--; ) {
761 >                        n = fndx(x, y);
762 >                        if (sbuffer[n])
763 >                                continue;
764 >                        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 >                        }
779 >                }
780 >        }
781 >        /* motion blur if requested */
782          if (mblur > .02) {
783 <                int     len;
784 <                int     xs, ys, xl, yl;
785 <                int     rise, run;
786 <                long    rise2, run2;
787 <                int     n2;
788 <                int     cnt;
789 <                                        /* sum in motion streaks */
790 <                memset(outbuffer, '\0', sizeof(COLOR)*hres*vres);
791 <                memset(wbuffer, '\0', sizeof(float)*hres*vres);
792 <                for (y = vres; y--; )
768 <                    for (x = hres; x--; ) {
783 >            int xs, ys, xl, yl;
784 >            int rise, run;
785 >            long        rise2, run2;
786 >            int n2;
787 >            int cnt;
788 >            /* sum in motion streaks */
789 >            memset(outbuffer, '\0', sizeof(COLOR)*hres*vres);
790 >            memset(wbuffer, '\0', sizeof(float)*hres*vres);
791 >            for (y = vres; y--; ) {
792 >                for (x = hres; x--; ) {
793                          n = fndx(x, y);
794                          if (xmbuffer[n] == MO_UNK) {
795                                  run = rise = 0;
# Line 786 | Line 810 | write_map(cerrmap, "outcmap.pic");
810                          else ys = 1;
811                          rise2 = run2 = 0L;
812                          if (rise > run) {
813 <                                cnt = rise + 1;
814 <                                w = 1./cnt;
815 <                                copycolor(cval, cbuffer[n]);
816 <                                scalecolor(cval, w);
817 <                                while (cnt)
818 <                                        if (rise2 >= run2) {
819 <                                                if ((xl >= 0) & (xl < hres) &
820 <                                                        (yl >= 0) & (yl < vres)) {
821 <                                                        n2 = fndx(xl, yl);
822 <                                                        addcolor(outbuffer[n2],
823 <                                                                        cval);
824 <                                                        wbuffer[n2] += w;
825 <                                                }
826 <                                                yl += ys;
827 <                                                run2 += run;
828 <                                                cnt--;
829 <                                        } else {
830 <                                                xl += xs;
831 <                                                rise2 += rise;
832 <                                        }
813 >                            cnt = rise + 1;
814 >                            w = 1./cnt;
815 >                            copycolor(cval, cbuffer[n]);
816 >                            scalecolor(cval, w);
817 >                            while (cnt) {
818 >                                if (rise2 >= run2) {
819 >                                    if ((xl >= 0) & (xl < hres) &
820 >                                                    (yl >= 0) & (yl < vres)) {
821 >                                            n2 = fndx(xl, yl);
822 >                                            addcolor(outbuffer[n2], cval);
823 >                                            wbuffer[n2] += w;
824 >                                    }
825 >                                    yl += ys;
826 >                                    run2 += run;
827 >                                    cnt--;
828 >                                } else {
829 >                                        xl += xs;
830 >                                        rise2 += rise;
831 >                                }
832 >                            }
833                          } else {
834                                  cnt = run + 1;
835                                  w = 1./cnt;
836                                  copycolor(cval, cbuffer[n]);
837                                  scalecolor(cval, w);
838 <                                while (cnt)
839 <                                        if (run2 >= rise2) {
840 <                                                if ((xl >= 0) & (xl < hres) &
841 <                                                        (yl >= 0) & (yl < vres)) {
842 <                                                        n2 = fndx(xl, yl);
843 <                                                        addcolor(outbuffer[n2],
844 <                                                                        cval);
845 <                                                        wbuffer[n2] += w;
822 <                                                }
823 <                                                xl += xs;
824 <                                                rise2 += rise;
825 <                                                cnt--;
826 <                                        } else {
827 <                                                yl += ys;
828 <                                                run2 += run;
838 >                                while (cnt) {
839 >                                    if (run2 >= rise2) {
840 >                                        if ((xl >= 0) & (xl < hres) &
841 >                                                    (yl >= 0) & (yl < vres)) {
842 >                                                n2 = fndx(xl, yl);
843 >                                                addcolor(outbuffer[n2],
844 >                                                                cval);
845 >                                                wbuffer[n2] += w;
846                                          }
847 +                                        xl += xs;
848 +                                        rise2 += rise;
849 +                                        cnt--;
850 +                                    } else {
851 +                                            yl += ys;
852 +                                            run2 += run;
853 +                                    }
854 +                                }
855                          }
856 <                    }
857 <                                        /* compute final results */
858 <                for (y = vres; y--; )
859 <                    for (x = hres; x--; ) {
860 <                        n = fndx(x, y);
861 <                        if (wbuffer[n] <= FTINY)
862 <                                continue;
863 <                        w = 1./wbuffer[n];
864 <                        scalecolor(outbuffer[n], w);
865 <                    }
866 <        } else
867 <                for (n = hres*vres; n--; )
856 >                }
857 >                /* compute final results */
858 >                for (y = vres; y--; ) {
859 >                        for (x = hres; x--; ) {
860 >                                n = fndx(x, y);
861 >                                if (wbuffer[n] <= FTINY)
862 >                                        continue;
863 >                                w = 1./wbuffer[n];
864 >                                scalecolor(outbuffer[n], w);
865 >                        }
866 >                }
867 >            }
868 >        } else {
869 >                for (n = hres*vres; n--; ) {
870                          copycolor(outbuffer[n], cbuffer[n]);
871 < /*
872 < for (n = hres*vres; n--; )
873 <        if (!sbuffer[n])
874 <                setcolor(outbuffer[n], 0., 0., 0.);
875 < */
876 <                                /* adjust exposure */
871 >                }
872 >        }
873 >        /*
874 >           for (n = hres*vres; n--; )
875 >           if (!sbuffer[n])
876 >           setcolor(outbuffer[n], 0., 0., 0.);
877 >         */
878 >        /* adjust exposure */
879          if ((expval < 0.99) | (expval > 1.01))
880                  for (n = hres*vres; n--; )
881                          scalecolor(outbuffer[n], expval);
882 < return;
883 < {
884 <        float   *sbuf = (float *)malloc(sizeof(float)*hres*vres);
885 <        char    fnm[256];
886 <        sprintf(fnm, vval(BASENAME), fcur);
887 <        strcat(fnm, "_outsamp.pic");
888 <        for (n = hres*vres; n--; )
889 <                sbuf[n] = (float)sbuffer[n];
890 <        write_map(sbuf, fnm);
891 <        free((void *)sbuf);
882 >        return;
883 >        {
884 >                float   *sbuf = (float *)malloc(sizeof(float)*hres*vres);
885 >                char    fnm[256];
886 >                sprintf(fnm, vval(BASENAME), fcur);
887 >                strcat(fnm, "_outsamp.pic");
888 >                for (n = hres*vres; n--; )
889 >                        sbuf[n] = (float)sbuffer[n];
890 >                write_map(sbuf, fnm);
891 >                free((void *)sbuf);
892 >        }
893   }
864 }
894  
895  
896 < void
897 < send_frame()                    /* send frame to destination */
896 > extern void
897 > send_frame(void)                        /* send frame to destination */
898   {
899          char    pfname[1024];
900          double  d;
# Line 917 | Line 946 | writerr:
946   }
947  
948  
949 < void
950 < free_frame()                    /* free frame allocation */
949 > extern void
950 > free_frame(void)                        /* free frame allocation */
951   {
952          if (cbuffer == NULL)
953                  return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines