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.18 by greg, Fri Sep 28 22:20:49 2012 UTC vs.
Revision 3.21 by greg, Fri Oct 5 00:59:38 2012 UTC

# Line 32 | Line 32 | short          *xmbuffer;      /* x motion at each pixel */
32   short           *ymbuffer;      /* y motion at each pixel */
33   uby8            *abuffer;       /* accuracy at each pixel */
34   uby8            *sbuffer;       /* sample count per pixel */
35 + COLOR           *outbuffer;     /* output buffer (may equal cbuffer) */
36  
37   VIEW            vwprev;         /* last frame's view */
38   COLOR           *cprev;         /* last frame colors */
# Line 48 | Line 49 | double         hlsmax;         /* maximum high-level saliency this f
49  
50  
51   static void next_frame(void);
52 < static int sample_here(int      x, int  y);
53 < static int offset_cmp(const void        *p1, const void *p2);
54 < static void setmotion(int       n, FVECT        wpos);
52 > static int sample_here(int x, int y);
53 > static int offset_cmp(const void *p1, const void *p2);
54 > static void setmotion(int n, FVECT wpos);
55   static void init_frame_sample(void);
56  
57  
58   #if 0
59 < extern void
59 > void
60   write_map(              /* write out float map (debugging) */
61          float   *mp,
62          char    *fn
# Line 107 | Line 108 | next_frame(void)                       /* prepare next frame buffer */
108                  error(USER, errmsg);
109          }
110          if (cbuffer == NULL) {
111 <                int     n;
111 <                                        /* compute resolution and allocate */
111 >                int     n;              /* compute resolution and allocate */
112                  switch (sscanf(vval(RESOLUTION), "%d %d %lf",
113                                  &hres, &vres, &pixaspect)) {
114                  case 1:
# Line 137 | Line 137 | next_frame(void)                       /* prepare next frame buffer */
137                  zprev = (float *)malloc(sizeof(float)*hres*vres);
138                  oprev = (OBJECT *)malloc(sizeof(OBJECT)*hres*vres);
139                  aprev = (uby8 *)malloc(sizeof(uby8)*hres*vres);
140 +                if (mblur > .02)
141 +                        outbuffer = (COLOR *)malloc(sizeof(COLOR)*hres*vres);
142 +                else
143 +                        outbuffer = cbuffer;
144                  if ((cbuffer==NULL) | (zbuffer==NULL) | (obuffer==NULL) |
145                                  (xmbuffer==NULL) | (ymbuffer==NULL) |
146                                  (abuffer==NULL) | (sbuffer==NULL) |
147                                  (cprev==NULL) | (zprev == NULL) |
148 <                                (oprev==NULL) | (aprev==NULL))
148 >                                (oprev==NULL) | (aprev==NULL) |
149 >                                (outbuffer==NULL))
150                          error(SYSTEM, "out of memory in init_frame");
151                  for (n = hres*vres; n--; ) {
152                          zprev[n] = -1.f;
153 <                        xmbuffer[n] = ymbuffer[n] = MO_UNK;
149 <                        oprev[n] = OVOID;
153 >                        oprev[n] = OVOID;
154                  }
155                  frm_stop = getTime() + rtperfrm;
156 <        } else {
153 <                COLOR   *cp;            /* else just swap buffers */
156 >        } else {                        /* else just swap buffers */
157                  float   *fp;
158                  OBJECT  *op;
159                  uby8    *bp;
160 <                cp = cprev; cprev = cbuffer; cbuffer = cp;
160 >                if (outbuffer != cbuffer) {
161 >                        COLOR   *cp = cprev;
162 >                        cprev = cbuffer; cbuffer = cp;
163 >                } else {
164 >                        outbuffer = cprev; cprev = cbuffer;
165 >                        cbuffer = outbuffer;
166 >                }
167                  fp = zprev; zprev = zbuffer; zbuffer = fp;
168                  op = oprev; oprev = obuffer; obuffer = op;
169                  bp = aprev; aprev = abuffer; abuffer = bp;
170 <                memset(abuffer, '\0', sizeof(uby8)*hres*vres);
171 <                memset(sbuffer, '\0', sizeof(uby8)*hres*vres);
170 >                memset(abuffer, 0, sizeof(uby8)*hres*vres);
171 >                memset(sbuffer, 0, sizeof(uby8)*hres*vres);
172                  frm_stop += rtperfrm;
173          }
174          cerrmap = NULL;
# Line 185 | Line 194 | sample_here(           /* 4x4 quincunx sample at this pixel? */
194   }
195  
196  
197 < extern void
197 > void
198   sample_pos(     /* compute jittered sample position */
199          double  hv[2],
200          int     x,
# Line 202 | Line 211 | sample_pos(    /* compute jittered sample position */
211   }
212  
213  
214 < extern double
214 > double
215   sample_wt(              /* compute interpolant sample weight */
216          int     xo,
217          int yo
# Line 236 | Line 245 | offset_cmp(            /* compare offset distances */
245   }
246  
247  
248 < extern int
248 > int
249   getclosest(     /* get nc closest neighbors on same object */
250          int     *iarr,
251          int     nc,
# Line 363 | Line 372 | init_frame_sample(void)                /* sample our initial frame *
372              for (x = hres; x--; ) {
373                  double  hv[2];
374                  n = fndx(x, y);
375 <                xmbuffer[n] = MO_UNK;
367 <                ymbuffer[n] = MO_UNK;
375 >                xmbuffer[n] = ymbuffer[n] = MO_UNK;
376                  sample_pos(hv, x, y, 0);
377                  ir.rmax = viewray(ir.rorg, ir.rdir, &vw, hv[0], hv[1]);
378                  if (ir.rmax < -FTINY) {
# Line 452 | Line 460 | init_frame_sample(void)                /* sample our initial frame *
460   }
461  
462  
463 < extern int
463 > int
464   getambcolor(            /* get ambient color for object if we can */
465                  COLOR   clr,
466                  int     obj
# Line 520 | Line 528 | getambcolor(           /* get ambient color for object if we ca
528   }
529  
530  
531 < extern double
531 > double
532   estimaterr(             /* estimate relative error from samples */
533                  COLOR   cs,
534                  COLOR   cs2,
# Line 546 | Line 554 | estimaterr(            /* estimate relative error from samples *
554   }
555  
556  
557 < extern double
557 > double
558   comperr(                /* estimate relative error in neighborhood */
559                  int     *neigh,
560                  int     nc,
# Line 571 | Line 579 | comperr(               /* estimate relative error in neighborhood *
579                  }
580                  if (sbuffer[n] != 1)
581                          error(CONSISTENCY, "bad count in comperr");
582 <                setcolor(ctmp,
583 <                        colval(cbuffer[n],RED)*colval(cbuffer[n],RED),
576 <                        colval(cbuffer[n],GRN)*colval(cbuffer[n],GRN),
577 <                        colval(cbuffer[n],BLU)*colval(cbuffer[n],BLU));
582 >                copycolor(ctmp, cbuffer[n]);
583 >                multcolor(ctmp, ctmp);
584                  addcolor(csum2, ctmp);
585                  ns++;
586          }
# Line 582 | Line 588 | comperr(               /* estimate relative error in neighborhood *
588   }
589  
590  
591 < extern void
591 > void
592   comp_frame_error(void)          /* initialize frame error values */
593   {
594          uby8    *edone = NULL;
# Line 610 | Line 616 | comp_frame_error(void)         /* initialize frame error valu
616                   * by the returned ray value -- we take half of this.
617                   */
618                  edone = (uby8 *)calloc(hres*vres, sizeof(uby8));
619 <                for (y = vres; y--; )
614 <                    for (x = hres; x--; ) {
615 <                        n = fndx(x, y);
619 >                for (n = hres*vres; n--; ) {
620                          if ((abuffer[n] != ALOWQ) | (obuffer[n] == OVOID))
621                                  continue;
622                          if (!getambcolor(objamb, obuffer[n]))
# Line 629 | Line 633 | comp_frame_error(void)         /* initialize frame error valu
633                          else if (i >= ADISTANT/2) i = ADISTANT/2-1;
634                          abuffer[n] = i;
635                          edone[n] = 1;
636 <                    }
636 >                }
637          }
638                                          /* final statistical estimate */
639          for (y = vres; y--; )
# Line 661 | Line 665 | comp_frame_error(void)         /* initialize frame error valu
665   }
666  
667  
668 < extern void
668 > void
669   init_frame(void)                        /* render base (low quality) frame */
670   {
671          int     restart;
# Line 718 | Line 722 | init_frame(void)                       /* render base (low quality) frame
722   }
723  
724  
725 < extern void
725 > void
726   filter_frame(void)                      /* interpolation, motion-blur, and exposure */
727   {
728 <        double  expval = expspec_val(getexp(fcur));
729 <        int     x, y;
730 <        int     neigh[NPINTERP];
731 <        int     nc;
732 <        COLOR   cval;
733 <        double  w, wsum;
734 <        int     n;
728 >        const double    expval = expspec_val(getexp(fcur));
729 >        int             x, y;
730 >        int             neigh[NPINTERP];
731 >        int             nc;
732 >        COLOR           cval;
733 >        double          w, wsum;
734 >        int             n;
735  
736   #if 0
737          /* XXX TEMPORARY!! */
# Line 741 | Line 745 | filter_frame(void)                     /* interpolation, motion-blur, an
745                  free((void *)ebuf);
746          }
747   #endif
744
748          if (!silent) {
749                  printf("\tFiltering frame\n");
750                  fflush(stdout);
751          }
752                                          /* normalize samples */
753 <        for (y = vres; y--; )
751 <            for (x = hres; x--; ) {
752 <                n = fndx(x, y);
753 >        for (n = hres*vres; n--; ) {
754                  if (sbuffer[n] <= 1)
755                          continue;
756                  w = 1.0/(double)sbuffer[n];
757                  scalecolor(cbuffer[n], w);
758 <            }
758 >        }
759                                          /* interpolate samples */
760          for (y = vres; y--; )
761              for (x = hres; x--; ) {
# Line 786 | Line 787 | filter_frame(void)                     /* interpolation, motion-blur, an
787                  scalecolor(cbuffer[n], w);
788              }
789                                          /* motion blur if requested */
790 <        if (mblur > .02) {
790 >        if (outbuffer != cbuffer) {
791                  int     xs, ys, xl, yl;
792                  int     rise, run;
793                  long    rise2, run2;
794                  int     n2;
795                  int     cnt;
796 + fprintf(stderr, "outbuffer=0x%lx, cbuffer=0x%lx, cprev=0x%lx\n",
797 + (size_t)outbuffer, (size_t)cbuffer, (size_t)cprev);
798                                          /* sum in motion streaks */
799 <                memset(outbuffer, '\0', sizeof(COLOR)*hres*vres);
800 <                memset(wbuffer, '\0', sizeof(float)*hres*vres);
799 >                memset(outbuffer, 0, sizeof(COLOR)*hres*vres);
800 >                memset(wbuffer, 0, sizeof(float)*hres*vres);
801                  for (y = vres; y--; )
802                      for (x = hres; x--; ) {
803                          n = fndx(x, y);
# Line 809 | Line 812 | filter_frame(void)                     /* interpolation, motion-blur, an
812                                  wbuffer[n] += 1.;
813                                  continue;
814                          }
815 <                        xl = x - run/4;
813 <                        yl = y - rise/4;
815 >                        xl = x; yl = y;
816                          if (run < 0) { xs = -1; run = -run; }
817                          else xs = 1;
818                          if (rise < 0) { ys = -1; rise = -rise; }
# Line 861 | Line 863 | filter_frame(void)                     /* interpolation, motion-blur, an
863                          }
864                      }
865                                          /* compute final results */
864                for (y = vres; y--; )
865                    for (x = hres; x--; ) {
866                        n = fndx(x, y);
867                        if (wbuffer[n] <= FTINY)
868                                continue;
869                        w = 1./wbuffer[n];
870                        scalecolor(outbuffer[n], w);
871                    }
872        } else
866                  for (n = hres*vres; n--; )
867 <                        copycolor(outbuffer[n], cbuffer[n]);
867 >                        if (wbuffer[n] > 1.02) {
868 >                                w = 1./wbuffer[n];
869 >                                scalecolor(outbuffer[n], w);
870 >                        } else if (wbuffer[n] < 0.98) {
871 >                                w = 1.-wbuffer[n];
872 >                                copycolor(cval, cprev[n]);
873 >                                scalecolor(cval, w);
874 >                                addcolor(outbuffer[n], cval);
875 >                        }
876 >        }
877 >                                        /* adjust exposure */
878 >        for (n = ((expval < 0.98) | (expval > 1.02))*hres*vres; n--; )
879 >                scalecolor(outbuffer[n], expval);
880          /*
881             for (n = hres*vres; n--; )
882                     if (!sbuffer[n])
883                             setcolor(outbuffer[n], 0., 0., 0.);
884           */
880        /* adjust exposure */
881        if ((expval < 0.99) | (expval > 1.01))
882                for (n = hres*vres; n--; )
883                        scalecolor(outbuffer[n], expval);
885   #if 0
886          {
887                  float   *sbuf = (float *)malloc(sizeof(float)*hres*vres);
# Line 896 | Line 897 | filter_frame(void)                     /* interpolation, motion-blur, an
897   }
898  
899  
900 < extern void
900 > void
901   send_frame(void)                        /* send frame to destination */
902   {
903          char    fname[1024];
# Line 965 | Line 966 | send_frame(void)                       /* send frame to destination */
966          if (vdef(MNAME)) {              /* output motion buffer */
967                  unsigned short  *mbuffer = (unsigned short *)malloc(
968                                                  sizeof(unsigned short)*3*hres);
969 <                int             x;
969 >                int             x, n;
970                  if (mbuffer == NULL)
971 <                        error(SYSTEM, "out of memory in send_frame()");
971 >                        error(SYSTEM, "out of memory in send_frame");
972                  sprintf(fname, vval(MNAME), fcur);
973                  strcat(fname, ".mvo");
974                  fp = fopen(fname, "w");
# Line 983 | Line 984 | send_frame(void)                       /* send frame to destination */
984                  }
985                  for (y = vres; y--; ) {
986                          for (x = hres; x--; ) {
987 <                                mbuffer[3*x] = xmbuffer[fndx(x,y)] + 0x8000;
988 <                                mbuffer[3*x+1] = ymbuffer[fndx(x,y)] + 0x8000;
989 <                                mbuffer[3*x+2] = (oprev[fndx(x,y)]!=OVOID)*0x8000;
987 >                                n = fndx(x,y);
988 >                                mbuffer[3*x] = xmbuffer[n] + 0x8000;
989 >                                mbuffer[3*x+1] = ymbuffer[n] + 0x8000;
990 >                                mbuffer[3*x+2] = (oprev[n]!=OVOID)*0x8000;
991                          }
992                          if (fwrite(mbuffer, sizeof(*mbuffer),
993                                                  3*hres, fp) != 3*hres)
# Line 1002 | Line 1004 | writerr:
1004   }
1005  
1006  
1007 < extern void
1007 > void
1008   free_frame(void)                        /* free frame allocation */
1009   {
1010          if (cbuffer == NULL)
1011                  return;
1012 +        if (outbuffer != cbuffer)
1013 +                free((void *)outbuffer);
1014 +        outbuffer = NULL;
1015          free((void *)cbuffer); cbuffer = NULL;
1016          free((void *)zbuffer); zbuffer = NULL;
1017          free((void *)obuffer); obuffer = NULL;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines