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.17 by greg, Fri May 20 02:06:39 2011 UTC vs.
Revision 3.20 by greg, Tue Oct 2 21:56:20 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 <                        oprev[n] = OVOID;
148 >                        oprev[n] = OVOID;
149                  }
150                  frm_stop = getTime() + rtperfrm;
151          } else {
# Line 172 | Line 172 | next_frame(void)                       /* prepare next frame buffer */
172  
173   static int
174   sample_here(            /* 4x4 quincunx sample at this pixel? */
175 <        register int    x,
176 <        register int    y
175 >        int     x,
176 >        int     y
177   )
178   {
179          if (y & 0x1)            /* every other row has samples */
# Line 184 | 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 201 | 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 235 | 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 248 | Line 248 | getclosest(    /* get nc closest neighbors on same object
248          static int      ioffs[NSCHECK];
249          OBJECT  myobj;
250          int     i0, nf;
251 <        register int    i, j;
251 >        int     i, j;
252                                          /* get our object number */
253          myobj = obuffer[fndx(x, y)];
254                                          /* special case for borders */
# Line 312 | Line 312 | getclosest(    /* get nc closest neighbors on same object
312  
313   static void
314   setmotion(              /* compute motion vector for this pixel */
315 <                register int    n,
315 >                int     n,
316                  FVECT   wpos
317   )
318   {
# Line 351 | Line 351 | init_frame_sample(void)                /* sample our initial frame *
351   {
352          RAY     ir;
353          int     x, y;
354 <        register int    n;
354 >        int     n;
355  
356          if (!silent) {
357                  printf("\tComputing initial samples...");
# Line 362 | 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;
366 <                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 451 | 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
457   )
458   {
459 <        register OBJREC *op;
459 >        OBJREC  *op;
460  
461          if (obj == OVOID)
462                  return(0);
# Line 519 | 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 545 | 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 556 | Line 555 | comperr(               /* estimate relative error in neighborhood *
555          COLOR   ctmp;
556          int     i;
557          int     ns;
558 <        register int    n;
558 >        int     n;
559                                          /* add together samples */
560          setcolor(csum, 0., 0., 0.);
561          setcolor(csum2, 0., 0., 0.);
# Line 581 | 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 590 | Line 589 | comp_frame_error(void)         /* initialize frame error valu
589          int     neigh[NSAMPOK];
590          int     nc;
591          int     x, y, i;
592 <        register int    n;
592 >        int     n;
593  
594          if (!silent) {
595                  printf("\tComputing error map\n");
# Line 609 | 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--; )
613 <                    for (x = hres; x--; ) {
614 <                        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 628 | 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 660 | 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 705 | Line 702 | init_frame(void)                       /* render base (low quality) frame
702   {
703          float   *ebuf = (float *)malloc(sizeof(float)*hres*vres);
704          char    fnm[256];
705 <        register int    n;
705 >        int     n;
706          for (n = hres*vres; n--; )
707                  ebuf[n] = acctab[abuffer[n]];
708          sprintf(fnm, vval(BASENAME), fcur);
# Line 717 | 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 <        register 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 740 | Line 737 | filter_frame(void)                     /* interpolation, motion-blur, an
737                  free((void *)ebuf);
738          }
739   #endif
743
740          if (!silent) {
741                  printf("\tFiltering frame\n");
742                  fflush(stdout);
743          }
744                                          /* normalize samples */
745 <        for (y = vres; y--; )
750 <            for (x = hres; x--; ) {
751 <                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 860 | Line 854 | filter_frame(void)                     /* interpolation, motion-blur, an
854                          }
855                      }
856                                          /* compute final results */
857 <                for (y = vres; y--; )
864 <                    for (x = hres; x--; ) {
865 <                        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           */
879        /* adjust exposure */
880        if ((expval < 0.99) | (expval > 1.01))
881                for (n = hres*vres; n--; )
882                        scalecolor(outbuffer[n], expval);
873   #if 0
874          {
875                  float   *sbuf = (float *)malloc(sizeof(float)*hres*vres);
# Line 895 | 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    pfname[1024];
891 >        char    fname[1024];
892          double  d;
893          FILE    *fp;
894          int     y;
895                                          /* open output picture */
896 <        sprintf(pfname, vval(BASENAME), fcur);
897 <        strcat(pfname, ".hdr");
898 <        fp = fopen(pfname, "w");
896 >        sprintf(fname, vval(BASENAME), fcur);
897 >        strcat(fname, ".hdr");
898 >        fp = fopen(fname, "w");
899          if (fp == NULL) {
900 <                sprintf(errmsg, "cannot open output frame \"%s\"", pfname);
900 >                sprintf(errmsg, "cannot open output frame \"%s\"", fname);
901                  error(SYSTEM, errmsg);
902          }
903          SET_FILE_BINARY(fp);
904          if (!silent) {
905 <                printf("\tWriting to \"%s\"\n", pfname);
905 >                printf("\tWriting to \"%s\"\n", fname);
906                  fflush(stdout);
907          }
908                                          /* write header */
# Line 941 | Line 931 | send_frame(void)                       /* send frame to destination */
931                          goto writerr;
932          if (fclose(fp) == EOF)
933                  goto writerr;
934 +        if (vdef(ZNAME)) {              /* output z-buffer */
935 +                sprintf(fname, vval(ZNAME), fcur);
936 +                strcat(fname, ".zbf");
937 +                fp = fopen(fname, "w");
938 +                if (fp == NULL) {
939 +                        sprintf(errmsg, "cannot open z-file \"%s\"\n", fname);
940 +                        error(SYSTEM, errmsg);
941 +                }
942 +                SET_FILE_BINARY(fp);
943 +                if (!silent) {
944 +                        printf("\tWriting depths to \"%s\"\n", fname);
945 +                        fflush(stdout);
946 +                }
947 +                for (y = vres; y--; )
948 +                        if (fwrite(zbuffer+y*hres, sizeof(float),
949 +                                                hres, fp) != hres)
950 +                                goto writerr;
951 +                if (fclose(fp) == EOF)
952 +                        goto writerr;
953 +        }
954 +        if (vdef(MNAME)) {              /* output motion buffer */
955 +                unsigned short  *mbuffer = (unsigned short *)malloc(
956 +                                                sizeof(unsigned short)*3*hres);
957 +                int             x, n;
958 +                if (mbuffer == NULL)
959 +                        error(SYSTEM, "out of memory in send_frame");
960 +                sprintf(fname, vval(MNAME), fcur);
961 +                strcat(fname, ".mvo");
962 +                fp = fopen(fname, "w");
963 +                if (fp == NULL) {
964 +                        sprintf(errmsg, "cannot open motion file \"%s\"\n",
965 +                                                        fname);
966 +                        error(SYSTEM, errmsg);
967 +                }
968 +                SET_FILE_BINARY(fp);
969 +                if (!silent) {
970 +                        printf("\tWriting motion vectors to \"%s\"\n", fname);
971 +                        fflush(stdout);
972 +                }
973 +                for (y = vres; y--; ) {
974 +                        for (x = hres; x--; ) {
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)
982 +                                goto writerr;
983 +                }
984 +                free((void *)mbuffer);
985 +                if (fclose(fp) == EOF)
986 +                        goto writerr;
987 +        }
988          return;                         /* all is well */
989   writerr:
990 <        sprintf(errmsg, "error writing frame \"%s\"", pfname);
990 >        sprintf(errmsg, "error writing file \"%s\"", fname);
991          error(SYSTEM, errmsg);
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