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.8 by schorsch, Fri Mar 26 21:36:20 2004 UTC vs.
Revision 3.19 by greg, Sun Sep 30 19:18:41 2012 UTC

# Line 4 | Line 4 | static const char      RCSid[] = "$Id$";
4   /*
5   *  ranimove1.c
6   *
7 < *  Basic frame rendering routines for ranimate(1).
7 > *  Basic frame rendering routines for ranimove(1).
8   *
9   *  Created by Gregory Ward on Wed Jan 08 2003.
10   */
# Line 30 | Line 30 | float          *zbuffer;       /* depth at each pixel */
30   OBJECT          *obuffer;       /* object id at each pixel */
31   short           *xmbuffer;      /* x motion at each pixel */
32   short           *ymbuffer;      /* y motion at each pixel */
33 < BYTE            *abuffer;       /* accuracy at each pixel */
34 < BYTE            *sbuffer;       /* sample count per pixel */
33 > uby8            *abuffer;       /* accuracy at each pixel */
34 > uby8            *sbuffer;       /* sample count per pixel */
35  
36   VIEW            vwprev;         /* last frame's view */
37   COLOR           *cprev;         /* last frame colors */
38   float           *zprev;         /* last frame depth */
39   OBJECT          *oprev;         /* last frame objects */
40 < BYTE            *aprev;         /* last frame accuracy */
40 > uby8            *aprev;         /* last frame accuracy */
41  
42   float           *cerrmap;       /* conspicuous error map */
43   COLOR           *val2map;       /* value-squared map for variance */
# Line 54 | Line 54 | static void setmotion(int      n, FVECT        wpos);
54   static void init_frame_sample(void);
55  
56  
57 < extern void
57 > #if 0
58 > void
59   write_map(              /* write out float map (debugging) */
60          float   *mp,
61          char    *fn
# Line 79 | Line 80 | write_map(             /* write out float map (debugging) */
80          }
81          fclose(fp);
82   }
83 + #endif
84  
85  
86   static void
# Line 105 | Line 107 | next_frame(void)                       /* prepare next frame buffer */
107                  error(USER, errmsg);
108          }
109          if (cbuffer == NULL) {
110 +                int     n;
111                                          /* compute resolution and allocate */
112                  switch (sscanf(vval(RESOLUTION), "%d %d %lf",
113                                  &hres, &vres, &pixaspect)) {
# Line 128 | Line 131 | next_frame(void)                       /* prepare next frame buffer */
131                  obuffer = (OBJECT *)malloc(sizeof(OBJECT)*hres*vres);
132                  xmbuffer = (short *)malloc(sizeof(short)*hres*vres);
133                  ymbuffer = (short *)malloc(sizeof(short)*hres*vres);
134 <                abuffer = (BYTE *)calloc(hres*vres, sizeof(BYTE));
135 <                sbuffer = (BYTE *)calloc(hres*vres, sizeof(BYTE));
134 >                abuffer = (uby8 *)calloc(hres*vres, sizeof(uby8));
135 >                sbuffer = (uby8 *)calloc(hres*vres, sizeof(uby8));
136                  cprev = (COLOR *)malloc(sizeof(COLOR)*hres*vres);
137                  zprev = (float *)malloc(sizeof(float)*hres*vres);
138                  oprev = (OBJECT *)malloc(sizeof(OBJECT)*hres*vres);
139 <                aprev = (BYTE *)malloc(sizeof(BYTE)*hres*vres);
139 >                aprev = (uby8 *)malloc(sizeof(uby8)*hres*vres);
140                  if ((cbuffer==NULL) | (zbuffer==NULL) | (obuffer==NULL) |
141                                  (xmbuffer==NULL) | (ymbuffer==NULL) |
142                                  (abuffer==NULL) | (sbuffer==NULL) |
143                                  (cprev==NULL) | (zprev == NULL) |
144                                  (oprev==NULL) | (aprev==NULL))
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;
150 +                }
151                  frm_stop = getTime() + rtperfrm;
152          } else {
153                  COLOR   *cp;            /* else just swap buffers */
154                  float   *fp;
155                  OBJECT  *op;
156 <                BYTE    *bp;
156 >                uby8    *bp;
157                  cp = cprev; cprev = cbuffer; cbuffer = cp;
158                  fp = zprev; zprev = zbuffer; zbuffer = fp;
159                  op = oprev; oprev = obuffer; obuffer = op;
160                  bp = aprev; aprev = abuffer; abuffer = bp;
161 <                memset(abuffer, '\0', sizeof(BYTE)*hres*vres);
162 <                memset(sbuffer, '\0', sizeof(BYTE)*hres*vres);
161 >                memset(abuffer, '\0', sizeof(uby8)*hres*vres);
162 >                memset(sbuffer, '\0', sizeof(uby8)*hres*vres);
163                  frm_stop += rtperfrm;
164          }
165          cerrmap = NULL;
# Line 165 | Line 173 | next_frame(void)                       /* prepare next frame buffer */
173  
174   static int
175   sample_here(            /* 4x4 quincunx sample at this pixel? */
176 <        register int    x,
177 <        register int    y
176 >        int     x,
177 >        int     y
178   )
179   {
180          if (y & 0x1)            /* every other row has samples */
# Line 177 | Line 185 | sample_here(           /* 4x4 quincunx sample at this pixel? */
185   }
186  
187  
188 < extern void
188 > void
189   sample_pos(     /* compute jittered sample position */
190          double  hv[2],
191          int     x,
# Line 194 | Line 202 | sample_pos(    /* compute jittered sample position */
202   }
203  
204  
205 < extern double
205 > double
206   sample_wt(              /* compute interpolant sample weight */
207          int     xo,
208          int yo
# Line 228 | Line 236 | offset_cmp(            /* compare offset distances */
236   }
237  
238  
239 < extern int
239 > int
240   getclosest(     /* get nc closest neighbors on same object */
241          int     *iarr,
242          int     nc,
# Line 241 | Line 249 | getclosest(    /* get nc closest neighbors on same object
249          static int      ioffs[NSCHECK];
250          OBJECT  myobj;
251          int     i0, nf;
252 <        register int    i, j;
252 >        int     i, j;
253                                          /* get our object number */
254          myobj = obuffer[fndx(x, y)];
255                                          /* special case for borders */
# Line 305 | Line 313 | getclosest(    /* get nc closest neighbors on same object
313  
314   static void
315   setmotion(              /* compute motion vector for this pixel */
316 <                register int    n,
316 >                int     n,
317                  FVECT   wpos
318   )
319   {
# Line 344 | Line 352 | init_frame_sample(void)                /* sample our initial frame *
352   {
353          RAY     ir;
354          int     x, y;
355 <        register int    n;
355 >        int     n;
356  
357          if (!silent) {
358                  printf("\tComputing initial samples...");
# Line 367 | Line 375 | init_frame_sample(void)                /* sample our initial frame *
375                          continue;
376                  }
377                  if (!sample_here(x, y)) {       /* just cast */
378 <                        rayorigin(&ir, NULL, PRIMARY, 1.0);
378 >                        rayorigin(&ir, PRIMARY, NULL, NULL);
379                          if (!localhit(&ir, &thescene)) {
380 <                                if (ir.ro != &Aftplane)
381 <                                        sourcehit(&ir);
380 >                                if (ir.ro != &Aftplane && sourcehit(&ir)) {
381 >                                        rayshade(&ir, ir.ro->omod);
382 >                                        rayparticipate(&ir);
383 >                                }
384                                  copycolor(cbuffer[n], ir.rcol);
385                                  zbuffer[n] = ir.rot;
386                                  obuffer[n] = ir.robj;
# Line 385 | Line 395 | init_frame_sample(void)                /* sample our initial frame *
395                  }
396                  if (nprocs > 1) {               /* get sample */
397                          int     rval;
398 <                        rayorigin(&ir, NULL, PRIMARY, 1.0);
398 >                        rayorigin(&ir, PRIMARY, NULL, NULL);
399                          ir.rno = n;
400                          rval = ray_pqueue(&ir);
401                          if (!rval)
# Line 399 | Line 409 | init_frame_sample(void)                /* sample our initial frame *
409                  zbuffer[n] = ir.rot;
410                  obuffer[n] = ir.robj;
411                  sbuffer[n] = 1;
412 <                if (ir.rot >= FHUGE)
412 >                if (ir.rot >= 0.99*FHUGE)
413                          abuffer[n] = ADISTANT;
414                  else {
415                          abuffer[n] = ALOWQ;
# Line 442 | Line 452 | init_frame_sample(void)                /* sample our initial frame *
452   }
453  
454  
455 < extern int
455 > int
456   getambcolor(            /* get ambient color for object if we can */
457                  COLOR   clr,
458                  int     obj
459   )
460   {
461 <        register OBJREC *op;
461 >        OBJREC  *op;
462  
463          if (obj == OVOID)
464                  return(0);
465 <        op = objptr(obj);
466 <        if ((op->otype == OBJ_INSTANCE) & (op->omod == OVOID))
465 >        op = objptr(obj);               /* search for material */
466 >        if (op->omod == OVOID)
467                  return(0);
468 <                                        /* search for material */
469 <        do {
470 <                if (op->omod == OVOID || ofun[op->otype].flags & T_X)
461 <                        return(0);
462 <                op = objptr(op->omod);
463 <        } while (!ismaterial(op->otype));
468 >        op = findmaterial(objptr(op->omod));
469 >        if (op == NULL)
470 >                return(0);
471          /*
472           * Since this routine is called to compute the difference
473           * from rendering with and without interreflections,
# Line 474 | Line 481 | getambcolor(           /* get ambient color for object if we ca
481                          if (lv[0] == op->oname[0] &&
482                                          !strcmp(lv+1, op->oname+1))
483                                  break;
484 <                if ((lv != NULL) != hirendparams.ambincl)
484 >                if ((lv != NULL) ^ hirendparams.ambincl)
485                          return(0);
486          }
487          switch (op->otype) {
# Line 513 | Line 520 | getambcolor(           /* get ambient color for object if we ca
520   }
521  
522  
523 < extern double
523 > double
524   estimaterr(             /* estimate relative error from samples */
525                  COLOR   cs,
526                  COLOR   cs2,
# Line 539 | Line 546 | estimaterr(            /* estimate relative error from samples *
546   }
547  
548  
549 < extern double
549 > double
550   comperr(                /* estimate relative error in neighborhood */
551                  int     *neigh,
552                  int     nc,
# Line 550 | Line 557 | comperr(               /* estimate relative error in neighborhood *
557          COLOR   ctmp;
558          int     i;
559          int     ns;
560 <        register int    n;
560 >        int     n;
561                                          /* add together samples */
562          setcolor(csum, 0., 0., 0.);
563          setcolor(csum2, 0., 0., 0.);
# Line 575 | Line 582 | comperr(               /* estimate relative error in neighborhood *
582   }
583  
584  
585 < extern void
585 > void
586   comp_frame_error(void)          /* initialize frame error values */
587   {
588 <        BYTE    *edone = NULL;
588 >        uby8    *edone = NULL;
589          COLOR   objamb;
590          double  eest;
591          int     neigh[NSAMPOK];
592          int     nc;
593          int     x, y, i;
594 <        register int    n;
594 >        int     n;
595  
596          if (!silent) {
597                  printf("\tComputing error map\n");
# Line 602 | Line 609 | comp_frame_error(void)         /* initialize frame error valu
609                   * error should be less than the ambient value divided
610                   * by the returned ray value -- we take half of this.
611                   */
612 <                edone = (BYTE *)calloc(hres*vres, sizeof(BYTE));
613 <                for (y = vres; y--; )
607 <                    for (x = hres; x--; ) {
608 <                        n = fndx(x, y);
612 >                edone = (uby8 *)calloc(hres*vres, sizeof(uby8));
613 >                for (n = hres*vres; n--; ) {
614                          if ((abuffer[n] != ALOWQ) | (obuffer[n] == OVOID))
615                                  continue;
616                          if (!getambcolor(objamb, obuffer[n]))
# Line 622 | Line 627 | comp_frame_error(void)         /* initialize frame error valu
627                          else if (i >= ADISTANT/2) i = ADISTANT/2-1;
628                          abuffer[n] = i;
629                          edone[n] = 1;
630 <                    }
630 >                }
631          }
632                                          /* final statistical estimate */
633          for (y = vres; y--; )
# Line 654 | Line 659 | comp_frame_error(void)         /* initialize frame error valu
659   }
660  
661  
662 < extern void
662 > void
663   init_frame(void)                        /* render base (low quality) frame */
664   {
665          int     restart;
661
666                                          /* allocate/swap buffers */
667          next_frame();
668                                          /* check rendering status */
669          restart = (!nobjects || vdef(MOVE));
670          if (!restart && curparams != &lorendparams && nprocs > 1)
671                  restart = -1;
668        if (restart > 0) {
669                if (nprocs > 1)
670                        ray_pdone(1);
671                else
672                        ray_done(1);
673        }
672                                          /* post low quality parameters */
673          if (curparams != &lorendparams)
674                  ray_restore(curparams = &lorendparams);
# Line 702 | Line 700 | init_frame(void)                       /* render base (low quality) frame
700          init_frame_sample();
701                                          /* initialize frame error */
702          comp_frame_error();
703 < return;
703 > #if 0
704   {
705          float   *ebuf = (float *)malloc(sizeof(float)*hres*vres);
706          char    fnm[256];
707 <        register int    n;
707 >        int     n;
708          for (n = hres*vres; n--; )
709                  ebuf[n] = acctab[abuffer[n]];
710          sprintf(fnm, vval(BASENAME), fcur);
# Line 714 | Line 712 | return;
712          write_map(ebuf, fnm);
713          free((void *)ebuf);
714   }
715 + #endif
716   }
717  
718  
719 < extern void
719 > void
720   filter_frame(void)                      /* interpolation, motion-blur, and exposure */
721   {
722 <        double  expval = expspec_val(getexp(fcur));
723 <        int     x, y;
724 <        int     neigh[NPINTERP];
725 <        int     nc;
726 <        COLOR   cval;
727 <        double  w, wsum;
728 <        register int    n;
722 >        const double    expval = expspec_val(getexp(fcur));
723 >        int             x, y;
724 >        int             neigh[NPINTERP];
725 >        int             nc;
726 >        COLOR           cval;
727 >        double          w, wsum;
728 >        int             n;
729  
730   #if 0
731          /* XXX TEMPORARY!! */
# Line 745 | Line 744 | filter_frame(void)                     /* interpolation, motion-blur, an
744                  printf("\tFiltering frame\n");
745                  fflush(stdout);
746          }
747 <        /* normalize samples */
748 <        for (y = vres; y--; ) {
749 <                for (x = hres; x--; ) {
750 <                        n = fndx(x, y);
751 <                        if (sbuffer[n] <= 1)
752 <                                continue;
754 <                        w = 1.0/(double)sbuffer[n];
755 <                        scalecolor(cbuffer[n], w);
756 <                }
747 >                                        /* normalize samples */
748 >        for (n = hres*vres; n--; ) {
749 >                if (sbuffer[n] <= 1)
750 >                        continue;
751 >                w = 1.0/(double)sbuffer[n];
752 >                scalecolor(cbuffer[n], w);
753          }
754 <        /* interpolate samples */
755 <        for (y = vres; y--; ) {
756 <                for (x = hres; x--; ) {
757 <                        n = fndx(x, y);
758 <                        if (sbuffer[n])
754 >                                        /* interpolate samples */
755 >        for (y = vres; y--; )
756 >            for (x = hres; x--; ) {
757 >                n = fndx(x, y);
758 >                if (sbuffer[n])
759 >                        continue;
760 >                nc = getclosest(neigh, NPINTERP, x, y);
761 >                setcolor(cbuffer[n], 0., 0., 0.);
762 >                if (nc <= 0) {          /* no acceptable neighbors */
763 >                        if (y < vres-1)
764 >                                nc = fndx(x, y+1);
765 >                        else if (x < hres-1)
766 >                                nc = fndx(x+1, y);
767 >                        else
768                                  continue;
769 <                        nc = getclosest(neigh, NPINTERP, x, y);
770 <                        setcolor(cbuffer[n], 0., 0., 0.);
766 <                        wsum = 0.;
767 <                        while (nc-- > 0) {
768 <                                copycolor(cval, cbuffer[neigh[nc]]);
769 <                                w = sample_wt((neigh[nc]%hres) - x,
770 <                                                (neigh[nc]/hres) - y);
771 <                                scalecolor(cval, w);
772 <                                addcolor(cbuffer[n], cval);
773 <                                wsum += w;
774 <                        }
775 <                        if (wsum > FTINY) {
776 <                                w = 1.0/wsum;
777 <                                scalecolor(cbuffer[n], w);
778 <                        }
769 >                        copycolor(cbuffer[n], cbuffer[nc]);
770 >                        continue;
771                  }
772 <        }
773 <        /* motion blur if requested */
772 >                wsum = 0.;
773 >                while (nc-- > 0) {
774 >                        copycolor(cval, cbuffer[neigh[nc]]);
775 >                        w = sample_wt((neigh[nc]%hres) - x,
776 >                                        (neigh[nc]/hres) - y);
777 >                        scalecolor(cval, w);
778 >                        addcolor(cbuffer[n], cval);
779 >                        wsum += w;
780 >                }
781 >                w = 1.0/wsum;
782 >                scalecolor(cbuffer[n], w);
783 >            }
784 >                                        /* motion blur if requested */
785          if (mblur > .02) {
786 <            int xs, ys, xl, yl;
787 <            int rise, run;
788 <            long        rise2, run2;
789 <            int n2;
790 <            int cnt;
791 <            /* sum in motion streaks */
792 <            memset(outbuffer, '\0', sizeof(COLOR)*hres*vres);
793 <            memset(wbuffer, '\0', sizeof(float)*hres*vres);
794 <            for (y = vres; y--; ) {
795 <                for (x = hres; x--; ) {
786 >                int     xs, ys, xl, yl;
787 >                int     rise, run;
788 >                long    rise2, run2;
789 >                int     n2;
790 >                int     cnt;
791 >                                        /* sum in motion streaks */
792 >                memset(outbuffer, '\0', sizeof(COLOR)*hres*vres);
793 >                memset(wbuffer, '\0', sizeof(float)*hres*vres);
794 >                for (y = vres; y--; )
795 >                    for (x = hres; x--; ) {
796                          n = fndx(x, y);
797                          if (xmbuffer[n] == MO_UNK) {
798                                  run = rise = 0;
# Line 810 | Line 813 | filter_frame(void)                     /* interpolation, motion-blur, an
813                          else ys = 1;
814                          rise2 = run2 = 0L;
815                          if (rise > run) {
816 <                            cnt = rise + 1;
817 <                            w = 1./cnt;
818 <                            copycolor(cval, cbuffer[n]);
819 <                            scalecolor(cval, w);
820 <                            while (cnt) {
821 <                                if (rise2 >= run2) {
822 <                                    if ((xl >= 0) & (xl < hres) &
816 >                                cnt = rise + 1;
817 >                                w = 1./cnt;
818 >                                copycolor(cval, cbuffer[n]);
819 >                                scalecolor(cval, w);
820 >                                while (cnt)
821 >                                        if (rise2 >= run2) {
822 >                                                if ((xl >= 0) & (xl < hres) &
823                                                      (yl >= 0) & (yl < vres)) {
824 <                                            n2 = fndx(xl, yl);
825 <                                            addcolor(outbuffer[n2], cval);
826 <                                            wbuffer[n2] += w;
827 <                                    }
828 <                                    yl += ys;
829 <                                    run2 += run;
830 <                                    cnt--;
831 <                                } else {
832 <                                        xl += xs;
833 <                                        rise2 += rise;
834 <                                }
835 <                            }
824 >                                                        n2 = fndx(xl, yl);
825 >                                                        addcolor(outbuffer[n2],
826 >                                                                        cval);
827 >                                                        wbuffer[n2] += w;
828 >                                                }
829 >                                                yl += ys;
830 >                                                run2 += run;
831 >                                                cnt--;
832 >                                        } else {
833 >                                                xl += xs;
834 >                                                rise2 += rise;
835 >                                        }
836                          } else {
837                                  cnt = run + 1;
838                                  w = 1./cnt;
839                                  copycolor(cval, cbuffer[n]);
840                                  scalecolor(cval, w);
841 <                                while (cnt) {
842 <                                    if (run2 >= rise2) {
843 <                                        if ((xl >= 0) & (xl < hres) &
841 >                                while (cnt)
842 >                                        if (run2 >= rise2) {
843 >                                                if ((xl >= 0) & (xl < hres) &
844                                                      (yl >= 0) & (yl < vres)) {
845 <                                                n2 = fndx(xl, yl);
846 <                                                addcolor(outbuffer[n2],
847 <                                                                cval);
848 <                                                wbuffer[n2] += w;
845 >                                                        n2 = fndx(xl, yl);
846 >                                                        addcolor(outbuffer[n2],
847 >                                                                        cval);
848 >                                                        wbuffer[n2] += w;
849 >                                                }
850 >                                                xl += xs;
851 >                                                rise2 += rise;
852 >                                                cnt--;
853 >                                        } else {
854 >                                                yl += ys;
855 >                                                run2 += run;
856                                          }
847                                        xl += xs;
848                                        rise2 += rise;
849                                        cnt--;
850                                    } else {
851                                            yl += ys;
852                                            run2 += run;
853                                    }
854                                }
857                          }
858 <                }
859 <                /* compute final results */
858 <                for (y = vres; y--; ) {
859 <                        for (x = hres; x--; ) {
860 <                                n = fndx(x, y);
861 <                                if (wbuffer[n] <= FTINY)
862 <                                        continue;
863 <                                w = 1./wbuffer[n];
864 <                                scalecolor(outbuffer[n], w);
865 <                        }
866 <                }
867 <            }
868 <        } else {
858 >                    }
859 >                                        /* compute final results */
860                  for (n = hres*vres; n--; ) {
861 <                        copycolor(outbuffer[n], cbuffer[n]);
861 >                        if (wbuffer[n] <= FTINY)
862 >                                continue;
863 >                        w = expval/wbuffer[n];
864 >                        scalecolor(outbuffer[n], w);
865                  }
866 +        } else {                        /* no blur -- just exposure */
867 +                memcpy(outbuffer, cbuffer, sizeof(COLOR)*hres*vres);
868 +                for (n = ((expval < 0.99) | (expval > 1.01))*hres*vres; n--; )
869 +                        scalecolor(outbuffer[n], expval);
870          }
871          /*
872             for (n = hres*vres; n--; )
873 <           if (!sbuffer[n])
874 <           setcolor(outbuffer[n], 0., 0., 0.);
873 >                   if (!sbuffer[n])
874 >                           setcolor(outbuffer[n], 0., 0., 0.);
875           */
876 <        /* adjust exposure */
879 <        if ((expval < 0.99) | (expval > 1.01))
880 <                for (n = hres*vres; n--; )
881 <                        scalecolor(outbuffer[n], expval);
882 <        return;
876 > #if 0
877          {
878                  float   *sbuf = (float *)malloc(sizeof(float)*hres*vres);
879                  char    fnm[256];
# Line 890 | Line 884 | filter_frame(void)                     /* interpolation, motion-blur, an
884                  write_map(sbuf, fnm);
885                  free((void *)sbuf);
886          }
887 + #endif
888   }
889  
890  
891 < extern void
891 > void
892   send_frame(void)                        /* send frame to destination */
893   {
894 <        char    pfname[1024];
894 >        char    fname[1024];
895          double  d;
896          FILE    *fp;
897          int     y;
898                                          /* open output picture */
899 <        sprintf(pfname, vval(BASENAME), fcur);
900 <        strcat(pfname, ".pic");
901 <        fp = fopen(pfname, "w");
899 >        sprintf(fname, vval(BASENAME), fcur);
900 >        strcat(fname, ".hdr");
901 >        fp = fopen(fname, "w");
902          if (fp == NULL) {
903 <                sprintf(errmsg, "cannot open output frame \"%s\"", pfname);
903 >                sprintf(errmsg, "cannot open output frame \"%s\"", fname);
904                  error(SYSTEM, errmsg);
905          }
906          SET_FILE_BINARY(fp);
907          if (!silent) {
908 <                printf("\tWriting to \"%s\"\n", pfname);
908 >                printf("\tWriting to \"%s\"\n", fname);
909                  fflush(stdout);
910          }
911                                          /* write header */
# Line 939 | Line 934 | send_frame(void)                       /* send frame to destination */
934                          goto writerr;
935          if (fclose(fp) == EOF)
936                  goto writerr;
937 +        if (vdef(ZNAME)) {              /* output z-buffer */
938 +                sprintf(fname, vval(ZNAME), fcur);
939 +                strcat(fname, ".zbf");
940 +                fp = fopen(fname, "w");
941 +                if (fp == NULL) {
942 +                        sprintf(errmsg, "cannot open z-file \"%s\"\n", fname);
943 +                        error(SYSTEM, errmsg);
944 +                }
945 +                SET_FILE_BINARY(fp);
946 +                if (!silent) {
947 +                        printf("\tWriting depths to \"%s\"\n", fname);
948 +                        fflush(stdout);
949 +                }
950 +                for (y = vres; y--; )
951 +                        if (fwrite(zbuffer+y*hres, sizeof(float),
952 +                                                hres, fp) != hres)
953 +                                goto writerr;
954 +                if (fclose(fp) == EOF)
955 +                        goto writerr;
956 +        }
957 +        if (vdef(MNAME)) {              /* output motion buffer */
958 +                unsigned short  *mbuffer = (unsigned short *)malloc(
959 +                                                sizeof(unsigned short)*3*hres);
960 +                int             x;
961 +                if (mbuffer == NULL)
962 +                        error(SYSTEM, "out of memory in send_frame()");
963 +                sprintf(fname, vval(MNAME), fcur);
964 +                strcat(fname, ".mvo");
965 +                fp = fopen(fname, "w");
966 +                if (fp == NULL) {
967 +                        sprintf(errmsg, "cannot open motion file \"%s\"\n",
968 +                                                        fname);
969 +                        error(SYSTEM, errmsg);
970 +                }
971 +                SET_FILE_BINARY(fp);
972 +                if (!silent) {
973 +                        printf("\tWriting motion vectors to \"%s\"\n", fname);
974 +                        fflush(stdout);
975 +                }
976 +                for (y = vres; y--; ) {
977 +                        for (x = hres; x--; ) {
978 +                                mbuffer[3*x] = xmbuffer[fndx(x,y)] + 0x8000;
979 +                                mbuffer[3*x+1] = ymbuffer[fndx(x,y)] + 0x8000;
980 +                                mbuffer[3*x+2] = (oprev[fndx(x,y)]!=OVOID)*0x8000;
981 +                        }
982 +                        if (fwrite(mbuffer, sizeof(*mbuffer),
983 +                                                3*hres, fp) != 3*hres)
984 +                                goto writerr;
985 +                }
986 +                free((void *)mbuffer);
987 +                if (fclose(fp) == EOF)
988 +                        goto writerr;
989 +        }
990          return;                         /* all is well */
991   writerr:
992 <        sprintf(errmsg, "error writing frame \"%s\"", pfname);
992 >        sprintf(errmsg, "error writing file \"%s\"", fname);
993          error(SYSTEM, errmsg);
994   }
995  
996  
997 < extern void
997 > void
998   free_frame(void)                        /* free frame allocation */
999   {
1000          if (cbuffer == NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines