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.20 by greg, Tue Oct 2 21:56:20 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 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                          oprev[n] = OVOID;
154                  }
155                  frm_stop = getTime() + rtperfrm;
156 <        } else {
152 <                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 569 | 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),
574 <                        colval(cbuffer[n],GRN)*colval(cbuffer[n],GRN),
575 <                        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 779 | 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 802 | Line 812 | filter_frame(void)                     /* interpolation, motion-blur, an
812                                  wbuffer[n] += 1.;
813                                  continue;
814                          }
815 <                        xl = x - run/4;
806 <                        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 854 | Line 863 | filter_frame(void)                     /* interpolation, motion-blur, an
863                          }
864                      }
865                                          /* compute final results */
866 <                for (n = hres*vres; n--; ) {
867 <                        if (wbuffer[n] <= FTINY)
868 <                                continue;
869 <                        w = expval/wbuffer[n];
870 <                        scalecolor(outbuffer[n], w);
871 <                }
872 <        } else {                        /* no blur -- just exposure */
873 <                memcpy(outbuffer, cbuffer, sizeof(COLOR)*hres*vres);
874 <                for (n = ((expval < 0.99) | (expval > 1.01))*hres*vres; n--; )
875 <                        scalecolor(outbuffer[n], expval);
866 >                for (n = hres*vres; 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])
# Line 997 | Line 1009 | 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