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.23 by greg, Wed Jan 24 04:39:52 2018 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 330 | Line 329 | setmotion(             /* compute motion vector for this pixel */
329                  multp3(ovp, wpos, obj_move[moi].bxfm);
330                  wpos = ovp;
331          }
332 <        viewloc(ovp, &vwprev, wpos);
334 <        if (ovp[2] <= FTINY)
332 >        if (viewloc(ovp, &vwprev, wpos) <= 0)
333                  return;
334          xp = (int)(ovp[0]*hres);
335          yp = (int)(ovp[1]*vres);
# Line 363 | Line 361 | init_frame_sample(void)                /* sample our initial frame *
361              for (x = hres; x--; ) {
362                  double  hv[2];
363                  n = fndx(x, y);
364 <                xmbuffer[n] = MO_UNK;
367 <                ymbuffer[n] = MO_UNK;
364 >                xmbuffer[n] = ymbuffer[n] = MO_UNK;
365                  sample_pos(hv, x, y, 0);
366                  ir.rmax = viewray(ir.rorg, ir.rdir, &vw, hv[0], hv[1]);
367                  if (ir.rmax < -FTINY) {
# Line 452 | Line 449 | init_frame_sample(void)                /* sample our initial frame *
449   }
450  
451  
452 < extern int
452 > int
453   getambcolor(            /* get ambient color for object if we can */
454                  COLOR   clr,
455                  int     obj
# Line 520 | Line 517 | getambcolor(           /* get ambient color for object if we ca
517   }
518  
519  
520 < extern double
520 > double
521   estimaterr(             /* estimate relative error from samples */
522                  COLOR   cs,
523                  COLOR   cs2,
# Line 546 | Line 543 | estimaterr(            /* estimate relative error from samples *
543   }
544  
545  
546 < extern double
546 > double
547   comperr(                /* estimate relative error in neighborhood */
548                  int     *neigh,
549                  int     nc,
# Line 582 | Line 579 | comperr(               /* estimate relative error in neighborhood *
579   }
580  
581  
582 < extern void
582 > void
583   comp_frame_error(void)          /* initialize frame error values */
584   {
585          uby8    *edone = NULL;
# Line 610 | Line 607 | comp_frame_error(void)         /* initialize frame error valu
607                   * by the returned ray value -- we take half of this.
608                   */
609                  edone = (uby8 *)calloc(hres*vres, sizeof(uby8));
610 <                for (y = vres; y--; )
614 <                    for (x = hres; x--; ) {
615 <                        n = fndx(x, y);
610 >                for (n = hres*vres; n--; ) {
611                          if ((abuffer[n] != ALOWQ) | (obuffer[n] == OVOID))
612                                  continue;
613                          if (!getambcolor(objamb, obuffer[n]))
# Line 629 | Line 624 | comp_frame_error(void)         /* initialize frame error valu
624                          else if (i >= ADISTANT/2) i = ADISTANT/2-1;
625                          abuffer[n] = i;
626                          edone[n] = 1;
627 <                    }
627 >                }
628          }
629                                          /* final statistical estimate */
630          for (y = vres; y--; )
# Line 661 | Line 656 | comp_frame_error(void)         /* initialize frame error valu
656   }
657  
658  
659 < extern void
659 > void
660   init_frame(void)                        /* render base (low quality) frame */
661   {
662          int     restart;
# Line 718 | Line 713 | init_frame(void)                       /* render base (low quality) frame
713   }
714  
715  
716 < extern void
716 > void
717   filter_frame(void)                      /* interpolation, motion-blur, and exposure */
718   {
719 <        double  expval = expspec_val(getexp(fcur));
720 <        int     x, y;
721 <        int     neigh[NPINTERP];
722 <        int     nc;
723 <        COLOR   cval;
724 <        double  w, wsum;
725 <        int     n;
719 >        const double    expval = expspec_val(getexp(fcur));
720 >        int             x, y;
721 >        int             neigh[NPINTERP];
722 >        int             nc;
723 >        COLOR           cval;
724 >        double          w, wsum;
725 >        int             n;
726  
727   #if 0
728          /* XXX TEMPORARY!! */
# Line 741 | Line 736 | filter_frame(void)                     /* interpolation, motion-blur, an
736                  free((void *)ebuf);
737          }
738   #endif
744
739          if (!silent) {
740                  printf("\tFiltering frame\n");
741                  fflush(stdout);
742          }
743                                          /* normalize samples */
744 <        for (y = vres; y--; )
751 <            for (x = hres; x--; ) {
752 <                n = fndx(x, y);
744 >        for (n = hres*vres; n--; ) {
745                  if (sbuffer[n] <= 1)
746                          continue;
747                  w = 1.0/(double)sbuffer[n];
748                  scalecolor(cbuffer[n], w);
749 <            }
749 >        }
750                                          /* interpolate samples */
751          for (y = vres; y--; )
752              for (x = hres; x--; ) {
# Line 861 | Line 853 | filter_frame(void)                     /* interpolation, motion-blur, an
853                          }
854                      }
855                                          /* compute final results */
856 <                for (y = vres; y--; )
865 <                    for (x = hres; x--; ) {
866 <                        n = fndx(x, y);
856 >                for (n = hres*vres; n--; ) {
857                          if (wbuffer[n] <= FTINY)
858                                  continue;
859 <                        w = 1./wbuffer[n];
859 >                        w = expval/wbuffer[n];
860                          scalecolor(outbuffer[n], w);
861 <                    }
862 <        } else
863 <                for (n = hres*vres; n--; )
864 <                        copycolor(outbuffer[n], cbuffer[n]);
861 >                }
862 >        } else {                        /* no blur -- just exposure */
863 >                memcpy(outbuffer, cbuffer, sizeof(COLOR)*hres*vres);
864 >                for (n = ((expval < 0.99) | (expval > 1.01))*hres*vres; n--; )
865 >                        scalecolor(outbuffer[n], expval);
866 >        }
867          /*
868             for (n = hres*vres; n--; )
869                     if (!sbuffer[n])
870                             setcolor(outbuffer[n], 0., 0., 0.);
871           */
880        /* adjust exposure */
881        if ((expval < 0.99) | (expval > 1.01))
882                for (n = hres*vres; n--; )
883                        scalecolor(outbuffer[n], expval);
872   #if 0
873          {
874                  float   *sbuf = (float *)malloc(sizeof(float)*hres*vres);
# Line 896 | Line 884 | filter_frame(void)                     /* interpolation, motion-blur, an
884   }
885  
886  
887 < extern void
887 > void
888   send_frame(void)                        /* send frame to destination */
889   {
890          char    fname[1024];
# Line 965 | Line 953 | send_frame(void)                       /* send frame to destination */
953          if (vdef(MNAME)) {              /* output motion buffer */
954                  unsigned short  *mbuffer = (unsigned short *)malloc(
955                                                  sizeof(unsigned short)*3*hres);
956 <                int             x;
956 >                int             x, n;
957                  if (mbuffer == NULL)
958 <                        error(SYSTEM, "out of memory in send_frame()");
958 >                        error(SYSTEM, "out of memory in send_frame");
959                  sprintf(fname, vval(MNAME), fcur);
960                  strcat(fname, ".mvo");
961                  fp = fopen(fname, "w");
# Line 983 | Line 971 | send_frame(void)                       /* send frame to destination */
971                  }
972                  for (y = vres; y--; ) {
973                          for (x = hres; x--; ) {
974 <                                mbuffer[3*x] = xmbuffer[fndx(x,y)] + 0x8000;
975 <                                mbuffer[3*x+1] = ymbuffer[fndx(x,y)] + 0x8000;
976 <                                mbuffer[3*x+2] = (oprev[fndx(x,y)]!=OVOID)*0x8000;
974 >                                n = fndx(x,y);
975 >                                mbuffer[3*x] = xmbuffer[n] + 0x8000;
976 >                                mbuffer[3*x+1] = ymbuffer[n] + 0x8000;
977 >                                mbuffer[3*x+2] = (oprev[n]!=OVOID)*0x8000;
978                          }
979                          if (fwrite(mbuffer, sizeof(*mbuffer),
980                                                  3*hres, fp) != 3*hres)
# Line 1002 | Line 991 | writerr:
991   }
992  
993  
994 < extern void
994 > void
995   free_frame(void)                        /* free frame allocation */
996   {
997          if (cbuffer == NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines