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.22 by greg, Fri Oct 5 01:03:22 2012 UTC

# Line 48 | Line 48 | double         hlsmax;         /* maximum high-level saliency this f
48  
49  
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);
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   #if 0
58 < extern void
58 > void
59   write_map(              /* write out float map (debugging) */
60          float   *mp,
61          char    *fn
# Line 145 | Line 145 | next_frame(void)                       /* prepare next frame buffer */
145                          error(SYSTEM, "out of memory in init_frame");
146                  for (n = hres*vres; n--; ) {
147                          zprev[n] = -1.f;
148 <                        xmbuffer[n] = ymbuffer[n] = MO_UNK;
149 <                        oprev[n] = OVOID;
148 >                        oprev[n] = OVOID;
149                  }
150                  frm_stop = getTime() + rtperfrm;
151          } else {
# Line 185 | Line 184 | sample_here(           /* 4x4 quincunx sample at this pixel? */
184   }
185  
186  
187 < extern void
187 > void
188   sample_pos(     /* compute jittered sample position */
189          double  hv[2],
190          int     x,
# Line 202 | Line 201 | sample_pos(    /* compute jittered sample position */
201   }
202  
203  
204 < extern double
204 > double
205   sample_wt(              /* compute interpolant sample weight */
206          int     xo,
207          int yo
# Line 236 | Line 235 | offset_cmp(            /* compare offset distances */
235   }
236  
237  
238 < extern int
238 > int
239   getclosest(     /* get nc closest neighbors on same object */
240          int     *iarr,
241          int     nc,
# Line 363 | Line 362 | init_frame_sample(void)                /* sample our initial frame *
362              for (x = hres; x--; ) {
363                  double  hv[2];
364                  n = fndx(x, y);
365 <                xmbuffer[n] = MO_UNK;
367 <                ymbuffer[n] = MO_UNK;
365 >                xmbuffer[n] = ymbuffer[n] = MO_UNK;
366                  sample_pos(hv, x, y, 0);
367                  ir.rmax = viewray(ir.rorg, ir.rdir, &vw, hv[0], hv[1]);
368                  if (ir.rmax < -FTINY) {
# Line 452 | Line 450 | init_frame_sample(void)                /* sample our initial frame *
450   }
451  
452  
453 < extern int
453 > int
454   getambcolor(            /* get ambient color for object if we can */
455                  COLOR   clr,
456                  int     obj
# Line 520 | Line 518 | getambcolor(           /* get ambient color for object if we ca
518   }
519  
520  
521 < extern double
521 > double
522   estimaterr(             /* estimate relative error from samples */
523                  COLOR   cs,
524                  COLOR   cs2,
# Line 546 | Line 544 | estimaterr(            /* estimate relative error from samples *
544   }
545  
546  
547 < extern double
547 > double
548   comperr(                /* estimate relative error in neighborhood */
549                  int     *neigh,
550                  int     nc,
# Line 582 | Line 580 | comperr(               /* estimate relative error in neighborhood *
580   }
581  
582  
583 < extern void
583 > void
584   comp_frame_error(void)          /* initialize frame error values */
585   {
586          uby8    *edone = NULL;
# Line 610 | Line 608 | comp_frame_error(void)         /* initialize frame error valu
608                   * by the returned ray value -- we take half of this.
609                   */
610                  edone = (uby8 *)calloc(hres*vres, sizeof(uby8));
611 <                for (y = vres; y--; )
614 <                    for (x = hres; x--; ) {
615 <                        n = fndx(x, y);
611 >                for (n = hres*vres; n--; ) {
612                          if ((abuffer[n] != ALOWQ) | (obuffer[n] == OVOID))
613                                  continue;
614                          if (!getambcolor(objamb, obuffer[n]))
# Line 629 | Line 625 | comp_frame_error(void)         /* initialize frame error valu
625                          else if (i >= ADISTANT/2) i = ADISTANT/2-1;
626                          abuffer[n] = i;
627                          edone[n] = 1;
628 <                    }
628 >                }
629          }
630                                          /* final statistical estimate */
631          for (y = vres; y--; )
# Line 661 | Line 657 | comp_frame_error(void)         /* initialize frame error valu
657   }
658  
659  
660 < extern void
660 > void
661   init_frame(void)                        /* render base (low quality) frame */
662   {
663          int     restart;
# Line 718 | Line 714 | init_frame(void)                       /* render base (low quality) frame
714   }
715  
716  
717 < extern void
717 > void
718   filter_frame(void)                      /* interpolation, motion-blur, and exposure */
719   {
720 <        double  expval = expspec_val(getexp(fcur));
721 <        int     x, y;
722 <        int     neigh[NPINTERP];
723 <        int     nc;
724 <        COLOR   cval;
725 <        double  w, wsum;
726 <        int     n;
720 >        const double    expval = expspec_val(getexp(fcur));
721 >        int             x, y;
722 >        int             neigh[NPINTERP];
723 >        int             nc;
724 >        COLOR           cval;
725 >        double          w, wsum;
726 >        int             n;
727  
728   #if 0
729          /* XXX TEMPORARY!! */
# Line 741 | Line 737 | filter_frame(void)                     /* interpolation, motion-blur, an
737                  free((void *)ebuf);
738          }
739   #endif
744
740          if (!silent) {
741                  printf("\tFiltering frame\n");
742                  fflush(stdout);
743          }
744                                          /* normalize samples */
745 <        for (y = vres; y--; )
751 <            for (x = hres; x--; ) {
752 <                n = fndx(x, y);
745 >        for (n = hres*vres; n--; ) {
746                  if (sbuffer[n] <= 1)
747                          continue;
748                  w = 1.0/(double)sbuffer[n];
749                  scalecolor(cbuffer[n], w);
750 <            }
750 >        }
751                                          /* interpolate samples */
752          for (y = vres; y--; )
753              for (x = hres; x--; ) {
# Line 861 | Line 854 | filter_frame(void)                     /* interpolation, motion-blur, an
854                          }
855                      }
856                                          /* compute final results */
857 <                for (y = vres; y--; )
865 <                    for (x = hres; x--; ) {
866 <                        n = fndx(x, y);
857 >                for (n = hres*vres; n--; ) {
858                          if (wbuffer[n] <= FTINY)
859                                  continue;
860 <                        w = 1./wbuffer[n];
860 >                        w = expval/wbuffer[n];
861                          scalecolor(outbuffer[n], w);
862 <                    }
863 <        } else
864 <                for (n = hres*vres; n--; )
865 <                        copycolor(outbuffer[n], cbuffer[n]);
862 >                }
863 >        } else {                        /* no blur -- just exposure */
864 >                memcpy(outbuffer, cbuffer, sizeof(COLOR)*hres*vres);
865 >                for (n = ((expval < 0.99) | (expval > 1.01))*hres*vres; n--; )
866 >                        scalecolor(outbuffer[n], expval);
867 >        }
868          /*
869             for (n = hres*vres; n--; )
870                     if (!sbuffer[n])
871                             setcolor(outbuffer[n], 0., 0., 0.);
872           */
880        /* adjust exposure */
881        if ((expval < 0.99) | (expval > 1.01))
882                for (n = hres*vres; n--; )
883                        scalecolor(outbuffer[n], expval);
873   #if 0
874          {
875                  float   *sbuf = (float *)malloc(sizeof(float)*hres*vres);
# Line 896 | Line 885 | filter_frame(void)                     /* interpolation, motion-blur, an
885   }
886  
887  
888 < extern void
888 > void
889   send_frame(void)                        /* send frame to destination */
890   {
891          char    fname[1024];
# Line 965 | Line 954 | send_frame(void)                       /* send frame to destination */
954          if (vdef(MNAME)) {              /* output motion buffer */
955                  unsigned short  *mbuffer = (unsigned short *)malloc(
956                                                  sizeof(unsigned short)*3*hres);
957 <                int             x;
957 >                int             x, n;
958                  if (mbuffer == NULL)
959 <                        error(SYSTEM, "out of memory in send_frame()");
959 >                        error(SYSTEM, "out of memory in send_frame");
960                  sprintf(fname, vval(MNAME), fcur);
961                  strcat(fname, ".mvo");
962                  fp = fopen(fname, "w");
# Line 983 | Line 972 | send_frame(void)                       /* send frame to destination */
972                  }
973                  for (y = vres; y--; ) {
974                          for (x = hres; x--; ) {
975 <                                mbuffer[3*x] = xmbuffer[fndx(x,y)] + 0x8000;
976 <                                mbuffer[3*x+1] = ymbuffer[fndx(x,y)] + 0x8000;
977 <                                mbuffer[3*x+2] = (oprev[fndx(x,y)]!=OVOID)*0x8000;
975 >                                n = fndx(x,y);
976 >                                mbuffer[3*x] = xmbuffer[n] + 0x8000;
977 >                                mbuffer[3*x+1] = ymbuffer[n] + 0x8000;
978 >                                mbuffer[3*x+2] = (oprev[n]!=OVOID)*0x8000;
979                          }
980                          if (fwrite(mbuffer, sizeof(*mbuffer),
981                                                  3*hres, fp) != 3*hres)
# Line 1002 | Line 992 | writerr:
992   }
993  
994  
995 < extern void
995 > void
996   free_frame(void)                        /* free frame allocation */
997   {
998          if (cbuffer == NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines