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.7 by schorsch, Tue Oct 21 19:19:29 2003 UTC vs.
Revision 3.21 by greg, Fri Oct 5 00:59:38 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 16 | Line 16 | static const char      RCSid[] = "$Id$";
16   #include "platform.h"
17   #include "ranimove.h"
18   #include "otypes.h"
19 + #include "source.h"
20   #include "random.h"
21  
22   double          acctab[256];    /* accuracy value table */
# Line 29 | 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 > COLOR           *outbuffer;     /* output buffer (may equal cbuffer) */
36  
37   VIEW            vwprev;         /* last frame's view */
38   COLOR           *cprev;         /* last frame colors */
39   float           *zprev;         /* last frame depth */
40   OBJECT          *oprev;         /* last frame objects */
41 < BYTE            *aprev;         /* last frame accuracy */
41 > uby8            *aprev;         /* last frame accuracy */
42  
43   float           *cerrmap;       /* conspicuous error map */
44   COLOR           *val2map;       /* value-squared map for variance */
# Line 46 | Line 48 | double         frm_stop;       /* when to stop rendering this frame
48   double          hlsmax;         /* maximum high-level saliency this frame */
49  
50  
51 + static void next_frame(void);
52 + static int sample_here(int x, int y);
53 + static int offset_cmp(const void *p1, const void *p2);
54 + static void setmotion(int n, FVECT wpos);
55 + static void init_frame_sample(void);
56 +
57 +
58 + #if 0
59   void
60 < write_map(mp, fn)               /* write out float map (debugging) */
61 < float   *mp;
62 < char    *fn;
60 > write_map(              /* write out float map (debugging) */
61 >        float   *mp,
62 >        char    *fn
63 > )
64   {
65          FILE    *fp = fopen(fn, "w");
66          COLOR   scanbuf[2048];
# Line 70 | Line 81 | char   *fn;
81          }
82          fclose(fp);
83   }
84 + #endif
85  
86  
87   static void
88 < next_frame()                    /* prepare next frame buffer */
88 > next_frame(void)                        /* prepare next frame buffer */
89   {
90          VIEW    *fv;
91          char    *err;
# Line 96 | Line 108 | next_frame()                   /* prepare next frame buffer */
108                  error(USER, errmsg);
109          }
110          if (cbuffer == NULL) {
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 119 | Line 131 | next_frame()                   /* 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 (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 {
136 <                COLOR   *cp;            /* else just swap buffers */
156 >        } else {                        /* else just swap buffers */
157                  float   *fp;
158                  OBJECT  *op;
159 <                BYTE    *bp;
160 <                cp = cprev; cprev = cbuffer; cbuffer = cp;
159 >                uby8    *bp;
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(BYTE)*hres*vres);
171 <                memset(sbuffer, '\0', sizeof(BYTE)*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 155 | Line 181 | next_frame()                   /* prepare next frame buffer */
181  
182  
183   static int
184 < sample_here(x, y)               /* 4x4 quincunx sample at this pixel? */
185 < register int    x, y;
184 > sample_here(            /* 4x4 quincunx sample at this pixel? */
185 >        int     x,
186 >        int     y
187 > )
188   {
189          if (y & 0x1)            /* every other row has samples */
190                  return(0);
# Line 167 | Line 195 | register int   x, y;
195  
196  
197   void
198 < sample_pos(hv, x, y, sn)        /* compute jittered sample position */
199 < double  hv[2];
200 < int     x, y;
201 < int     sn;
198 > sample_pos(     /* compute jittered sample position */
199 >        double  hv[2],
200 >        int     x,
201 >        int     y,
202 >        int     sn
203 > )
204   {
205          int     hl[2];
206  
# Line 182 | Line 212 | int    sn;
212  
213  
214   double
215 < sample_wt(xo, yo)               /* compute interpolant sample weight */
216 < int     xo, yo;
215 > sample_wt(              /* compute interpolant sample weight */
216 >        int     xo,
217 >        int yo
218 > )
219   {
220          static double   etab[400];
221          /* we can't use the name rad2 here, for some reason Visual C
# Line 204 | Line 236 | int    xo, yo;
236  
237  
238   static int
239 < offset_cmp(p1, p2)              /* compare offset distances */
240 < const void      *p1, *p2;
239 > offset_cmp(             /* compare offset distances */
240 >        const void      *p1,
241 >        const void      *p2
242 > )
243   {
244          return(*(const int *)p1 - *(const int *)p2);
245   }
246  
247  
248   int
249 < getclosest(iarr, nc, x, y)      /* get nc closest neighbors on same object */
250 < int     *iarr;
251 < int     nc;
252 < int     x, y;
249 > getclosest(     /* get nc closest neighbors on same object */
250 >        int     *iarr,
251 >        int     nc,
252 >        int     x,
253 >        int     y
254 > )
255   {
256   #define NSCHECK         ((2*SAMPDIST+1)*(2*SAMPDIST+1))
257          static int      hro, vro;
258          static int      ioffs[NSCHECK];
259          OBJECT  myobj;
260          int     i0, nf;
261 <        register int    i, j;
261 >        int     i, j;
262                                          /* get our object number */
263          myobj = obuffer[fndx(x, y)];
264                                          /* special case for borders */
# Line 285 | Line 321 | int    x, y;
321  
322  
323   static void
324 < setmotion(n, wpos)              /* compute motion vector for this pixel */
325 < register int    n;
326 < FVECT   wpos;
324 > setmotion(              /* compute motion vector for this pixel */
325 >                int     n,
326 >                FVECT   wpos
327 > )
328   {
329          FVECT   ovp;
293        MAT4    xfm;
294        double  d;
330          int     moi;
331          int     xp, yp;
332                                          /* ID object and update maximum HLS */
# Line 322 | Line 357 | FVECT  wpos;
357  
358  
359   static void
360 < init_frame_sample()             /* sample our initial frame */
360 > init_frame_sample(void)         /* sample our initial frame */
361   {
362          RAY     ir;
363          int     x, y;
364 <        register int    n;
364 >        int     n;
365  
366          if (!silent) {
367                  printf("\tComputing initial samples...");
# Line 337 | Line 372 | init_frame_sample()            /* sample our initial frame */
372              for (x = hres; x--; ) {
373                  double  hv[2];
374                  n = fndx(x, y);
375 <                xmbuffer[n] = MO_UNK;
341 <                ymbuffer[n] = MO_UNK;
375 >                xmbuffer[n] = ymbuffer[n] = MO_UNK;
376                  sample_pos(hv, x, y, 0);
377                  ir.rmax = viewray(ir.rorg, ir.rdir, &vw, hv[0], hv[1]);
378                  if (ir.rmax < -FTINY) {
# Line 349 | Line 383 | init_frame_sample()            /* sample our initial frame */
383                          continue;
384                  }
385                  if (!sample_here(x, y)) {       /* just cast */
386 <                        rayorigin(&ir, NULL, PRIMARY, 1.0);
386 >                        rayorigin(&ir, PRIMARY, NULL, NULL);
387                          if (!localhit(&ir, &thescene)) {
388 <                                if (ir.ro != &Aftplane)
389 <                                        sourcehit(&ir);
388 >                                if (ir.ro != &Aftplane && sourcehit(&ir)) {
389 >                                        rayshade(&ir, ir.ro->omod);
390 >                                        rayparticipate(&ir);
391 >                                }
392                                  copycolor(cbuffer[n], ir.rcol);
393                                  zbuffer[n] = ir.rot;
394                                  obuffer[n] = ir.robj;
# Line 367 | Line 403 | init_frame_sample()            /* sample our initial frame */
403                  }
404                  if (nprocs > 1) {               /* get sample */
405                          int     rval;
406 <                        rayorigin(&ir, NULL, PRIMARY, 1.0);
406 >                        rayorigin(&ir, PRIMARY, NULL, NULL);
407                          ir.rno = n;
408                          rval = ray_pqueue(&ir);
409                          if (!rval)
# Line 381 | Line 417 | init_frame_sample()            /* sample our initial frame */
417                  zbuffer[n] = ir.rot;
418                  obuffer[n] = ir.robj;
419                  sbuffer[n] = 1;
420 <                if (ir.rot >= FHUGE)
420 >                if (ir.rot >= 0.99*FHUGE)
421                          abuffer[n] = ADISTANT;
422                  else {
423                          abuffer[n] = ALOWQ;
# Line 425 | Line 461 | init_frame_sample()            /* sample our initial frame */
461  
462  
463   int
464 < getambcolor(clr, obj)           /* get ambient color for object if we can */
465 < COLOR   clr;
466 < int     obj;
464 > getambcolor(            /* get ambient color for object if we can */
465 >                COLOR   clr,
466 >                int     obj
467 > )
468   {
469 <        register OBJREC *op;
469 >        OBJREC  *op;
470  
471          if (obj == OVOID)
472                  return(0);
473 <        op = objptr(obj);
474 <        if ((op->otype == OBJ_INSTANCE) & (op->omod == OVOID))
473 >        op = objptr(obj);               /* search for material */
474 >        if (op->omod == OVOID)
475                  return(0);
476 <                                        /* search for material */
477 <        do {
478 <                if (op->omod == OVOID || ofun[op->otype].flags & T_X)
442 <                        return(0);
443 <                op = objptr(op->omod);
444 <        } while (!ismaterial(op->otype));
476 >        op = findmaterial(objptr(op->omod));
477 >        if (op == NULL)
478 >                return(0);
479          /*
480           * Since this routine is called to compute the difference
481           * from rendering with and without interreflections,
# Line 455 | Line 489 | int    obj;
489                          if (lv[0] == op->oname[0] &&
490                                          !strcmp(lv+1, op->oname+1))
491                                  break;
492 <                if ((lv != NULL) != hirendparams.ambincl)
492 >                if ((lv != NULL) ^ hirendparams.ambincl)
493                          return(0);
494          }
495          switch (op->otype) {
# Line 495 | Line 529 | int    obj;
529  
530  
531   double
532 < estimaterr(cs, cs2, ns, ns0)    /* estimate relative error from samples */
533 < COLOR   cs, cs2;
534 < int     ns;
532 > estimaterr(             /* estimate relative error from samples */
533 >                COLOR   cs,
534 >                COLOR   cs2,
535 >                int     ns,
536 >                int ns0
537 > )
538   {
539          double  d, d2, brt;
540  
# Line 518 | Line 555 | int    ns;
555  
556  
557   double
558 < comperr(neigh, nc, ns0)         /* estimate relative error in neighborhood */
559 < int     *neigh;
560 < int     nc;
561 < int     ns0;
558 > comperr(                /* estimate relative error in neighborhood */
559 >                int     *neigh,
560 >                int     nc,
561 >                int     ns0
562 > )
563   {
564          COLOR   csum, csum2;
565          COLOR   ctmp;
566          int     i;
567          int     ns;
568 <        register int    n;
568 >        int     n;
569                                          /* add together samples */
570          setcolor(csum, 0., 0., 0.);
571          setcolor(csum2, 0., 0., 0.);
# Line 541 | Line 579 | int    ns0;
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),
546 <                        colval(cbuffer[n],GRN)*colval(cbuffer[n],GRN),
547 <                        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 553 | Line 589 | int    ns0;
589  
590  
591   void
592 < comp_frame_error()              /* initialize frame error values */
592 > comp_frame_error(void)          /* initialize frame error values */
593   {
594 <        BYTE    *edone = NULL;
594 >        uby8    *edone = NULL;
595          COLOR   objamb;
596          double  eest;
597          int     neigh[NSAMPOK];
598          int     nc;
599 <        int     x, y, i, j;
600 <        register int    n;
599 >        int     x, y, i;
600 >        int     n;
601  
602          if (!silent) {
603                  printf("\tComputing error map\n");
# Line 579 | Line 615 | comp_frame_error()             /* initialize frame error values *
615                   * error should be less than the ambient value divided
616                   * by the returned ray value -- we take half of this.
617                   */
618 <                edone = (BYTE *)calloc(hres*vres, sizeof(BYTE));
619 <                for (y = vres; y--; )
584 <                    for (x = hres; x--; ) {
585 <                        n = fndx(x, y);
618 >                edone = (uby8 *)calloc(hres*vres, sizeof(uby8));
619 >                for (n = hres*vres; n--; ) {
620                          if ((abuffer[n] != ALOWQ) | (obuffer[n] == OVOID))
621                                  continue;
622                          if (!getambcolor(objamb, obuffer[n]))
# Line 599 | Line 633 | comp_frame_error()             /* initialize frame error values *
633                          else if (i >= ADISTANT/2) i = ADISTANT/2-1;
634                          abuffer[n] = i;
635                          edone[n] = 1;
636 <                    }
636 >                }
637          }
638                                          /* final statistical estimate */
639          for (y = vres; y--; )
# Line 632 | Line 666 | comp_frame_error()             /* initialize frame error values *
666  
667  
668   void
669 < init_frame()                    /* render base (low quality) frame */
669 > init_frame(void)                        /* render base (low quality) frame */
670   {
671          int     restart;
638
672                                          /* allocate/swap buffers */
673          next_frame();
674                                          /* check rendering status */
675          restart = (!nobjects || vdef(MOVE));
676          if (!restart && curparams != &lorendparams && nprocs > 1)
677                  restart = -1;
645        if (restart > 0) {
646                if (nprocs > 1)
647                        ray_pdone(1);
648                else
649                        ray_done(1);
650        }
678                                          /* post low quality parameters */
679          if (curparams != &lorendparams)
680                  ray_restore(curparams = &lorendparams);
# Line 679 | Line 706 | init_frame()                   /* render base (low quality) frame */
706          init_frame_sample();
707                                          /* initialize frame error */
708          comp_frame_error();
709 < return;
709 > #if 0
710   {
711          float   *ebuf = (float *)malloc(sizeof(float)*hres*vres);
712          char    fnm[256];
713 <        register int    n;
713 >        int     n;
714          for (n = hres*vres; n--; )
715                  ebuf[n] = acctab[abuffer[n]];
716          sprintf(fnm, vval(BASENAME), fcur);
# Line 691 | Line 718 | return;
718          write_map(ebuf, fnm);
719          free((void *)ebuf);
720   }
721 + #endif
722   }
723  
724  
725   void
726 < filter_frame()                  /* interpolation, motion-blur, and exposure */
726 > filter_frame(void)                      /* interpolation, motion-blur, and exposure */
727   {
728 <        double  expval = expspec_val(getexp(fcur));
729 <        int     x, y;
730 <        int     neigh[NPINTERP];
731 <        int     nc;
732 <        COLOR   cval;
733 <        double  w, wsum;
734 <        register int    n;
728 >        const double    expval = expspec_val(getexp(fcur));
729 >        int             x, y;
730 >        int             neigh[NPINTERP];
731 >        int             nc;
732 >        COLOR           cval;
733 >        double          w, wsum;
734 >        int             n;
735  
736   #if 0
737 < /* XXX TEMPORARY!! */
738 < conspicuity();
739 < write_map(cerrmap, "outcmap.pic");
740 < {
741 <        float   *ebuf = (float *)malloc(sizeof(float)*hres*vres);
742 <        for (n = hres*vres; n--; )
743 <                ebuf[n] = acctab[abuffer[n]];
744 <        write_map(ebuf, "outerr.pic");
745 <        free((void *)ebuf);
746 < }
737 >        /* XXX TEMPORARY!! */
738 >        conspicuity();
739 >        write_map(cerrmap, "outcmap.pic");
740 >        {
741 >                float   *ebuf = (float *)malloc(sizeof(float)*hres*vres);
742 >                for (n = hres*vres; n--; )
743 >                        ebuf[n] = acctab[abuffer[n]];
744 >                write_map(ebuf, "outerr.pic");
745 >                free((void *)ebuf);
746 >        }
747   #endif
720
748          if (!silent) {
749                  printf("\tFiltering frame\n");
750                  fflush(stdout);
751          }
752                                          /* normalize samples */
753 <        for (y = vres; y--; )
727 <            for (x = hres; x--; ) {
728 <                n = fndx(x, y);
753 >        for (n = hres*vres; n--; ) {
754                  if (sbuffer[n] <= 1)
755                          continue;
756                  w = 1.0/(double)sbuffer[n];
757                  scalecolor(cbuffer[n], w);
758 <            }
758 >        }
759                                          /* interpolate samples */
760          for (y = vres; y--; )
761              for (x = hres; x--; ) {
# Line 739 | Line 764 | write_map(cerrmap, "outcmap.pic");
764                          continue;
765                  nc = getclosest(neigh, NPINTERP, x, y);
766                  setcolor(cbuffer[n], 0., 0., 0.);
767 +                if (nc <= 0) {          /* no acceptable neighbors */
768 +                        if (y < vres-1)
769 +                                nc = fndx(x, y+1);
770 +                        else if (x < hres-1)
771 +                                nc = fndx(x+1, y);
772 +                        else
773 +                                continue;
774 +                        copycolor(cbuffer[n], cbuffer[nc]);
775 +                        continue;
776 +                }
777                  wsum = 0.;
778                  while (nc-- > 0) {
779                          copycolor(cval, cbuffer[neigh[nc]]);
# Line 748 | Line 783 | write_map(cerrmap, "outcmap.pic");
783                          addcolor(cbuffer[n], cval);
784                          wsum += w;
785                  }
786 <                if (wsum > FTINY) {
787 <                        w = 1.0/wsum;
753 <                        scalecolor(cbuffer[n], w);
754 <                }
786 >                w = 1.0/wsum;
787 >                scalecolor(cbuffer[n], w);
788              }
789                                          /* motion blur if requested */
790 <        if (mblur > .02) {
758 <                int     len;
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 778 | Line 812 | write_map(cerrmap, "outcmap.pic");
812                                  wbuffer[n] += 1.;
813                                  continue;
814                          }
815 <                        xl = x - run/4;
782 <                        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 793 | Line 826 | write_map(cerrmap, "outcmap.pic");
826                                  while (cnt)
827                                          if (rise2 >= run2) {
828                                                  if ((xl >= 0) & (xl < hres) &
829 <                                                        (yl >= 0) & (yl < vres)) {
829 >                                                    (yl >= 0) & (yl < vres)) {
830                                                          n2 = fndx(xl, yl);
831                                                          addcolor(outbuffer[n2],
832                                                                          cval);
# Line 814 | Line 847 | write_map(cerrmap, "outcmap.pic");
847                                  while (cnt)
848                                          if (run2 >= rise2) {
849                                                  if ((xl >= 0) & (xl < hres) &
850 <                                                        (yl >= 0) & (yl < vres)) {
850 >                                                    (yl >= 0) & (yl < vres)) {
851                                                          n2 = fndx(xl, yl);
852                                                          addcolor(outbuffer[n2],
853                                                                          cval);
# Line 830 | Line 863 | write_map(cerrmap, "outcmap.pic");
863                          }
864                      }
865                                          /* compute final results */
833                for (y = vres; y--; )
834                    for (x = hres; x--; ) {
835                        n = fndx(x, y);
836                        if (wbuffer[n] <= FTINY)
837                                continue;
838                        w = 1./wbuffer[n];
839                        scalecolor(outbuffer[n], w);
840                    }
841        } else
866                  for (n = hres*vres; n--; )
867 <                        copycolor(outbuffer[n], cbuffer[n]);
868 < /*
869 < for (n = hres*vres; n--; )
870 <        if (!sbuffer[n])
871 <                setcolor(outbuffer[n], 0., 0., 0.);
872 < */
873 <                                /* adjust exposure */
874 <        if ((expval < 0.99) | (expval > 1.01))
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])
883 >                           setcolor(outbuffer[n], 0., 0., 0.);
884 >         */
885 > #if 0
886 >        {
887 >                float   *sbuf = (float *)malloc(sizeof(float)*hres*vres);
888 >                char    fnm[256];
889 >                sprintf(fnm, vval(BASENAME), fcur);
890 >                strcat(fnm, "_outsamp.pic");
891                  for (n = hres*vres; n--; )
892 <                        scalecolor(outbuffer[n], expval);
893 < return;
894 < {
895 <        float   *sbuf = (float *)malloc(sizeof(float)*hres*vres);
896 <        char    fnm[256];
857 <        sprintf(fnm, vval(BASENAME), fcur);
858 <        strcat(fnm, "_outsamp.pic");
859 <        for (n = hres*vres; n--; )
860 <                sbuf[n] = (float)sbuffer[n];
861 <        write_map(sbuf, fnm);
862 <        free((void *)sbuf);
892 >                        sbuf[n] = (float)sbuffer[n];
893 >                write_map(sbuf, fnm);
894 >                free((void *)sbuf);
895 >        }
896 > #endif
897   }
864 }
898  
899  
900   void
901 < send_frame()                    /* send frame to destination */
901 > send_frame(void)                        /* send frame to destination */
902   {
903 <        char    pfname[1024];
903 >        char    fname[1024];
904          double  d;
905          FILE    *fp;
906          int     y;
907                                          /* open output picture */
908 <        sprintf(pfname, vval(BASENAME), fcur);
909 <        strcat(pfname, ".pic");
910 <        fp = fopen(pfname, "w");
908 >        sprintf(fname, vval(BASENAME), fcur);
909 >        strcat(fname, ".hdr");
910 >        fp = fopen(fname, "w");
911          if (fp == NULL) {
912 <                sprintf(errmsg, "cannot open output frame \"%s\"", pfname);
912 >                sprintf(errmsg, "cannot open output frame \"%s\"", fname);
913                  error(SYSTEM, errmsg);
914          }
915          SET_FILE_BINARY(fp);
916          if (!silent) {
917 <                printf("\tWriting to \"%s\"\n", pfname);
917 >                printf("\tWriting to \"%s\"\n", fname);
918                  fflush(stdout);
919          }
920                                          /* write header */
# Line 910 | Line 943 | send_frame()                   /* send frame to destination */
943                          goto writerr;
944          if (fclose(fp) == EOF)
945                  goto writerr;
946 +        if (vdef(ZNAME)) {              /* output z-buffer */
947 +                sprintf(fname, vval(ZNAME), fcur);
948 +                strcat(fname, ".zbf");
949 +                fp = fopen(fname, "w");
950 +                if (fp == NULL) {
951 +                        sprintf(errmsg, "cannot open z-file \"%s\"\n", fname);
952 +                        error(SYSTEM, errmsg);
953 +                }
954 +                SET_FILE_BINARY(fp);
955 +                if (!silent) {
956 +                        printf("\tWriting depths to \"%s\"\n", fname);
957 +                        fflush(stdout);
958 +                }
959 +                for (y = vres; y--; )
960 +                        if (fwrite(zbuffer+y*hres, sizeof(float),
961 +                                                hres, fp) != hres)
962 +                                goto writerr;
963 +                if (fclose(fp) == EOF)
964 +                        goto writerr;
965 +        }
966 +        if (vdef(MNAME)) {              /* output motion buffer */
967 +                unsigned short  *mbuffer = (unsigned short *)malloc(
968 +                                                sizeof(unsigned short)*3*hres);
969 +                int             x, n;
970 +                if (mbuffer == NULL)
971 +                        error(SYSTEM, "out of memory in send_frame");
972 +                sprintf(fname, vval(MNAME), fcur);
973 +                strcat(fname, ".mvo");
974 +                fp = fopen(fname, "w");
975 +                if (fp == NULL) {
976 +                        sprintf(errmsg, "cannot open motion file \"%s\"\n",
977 +                                                        fname);
978 +                        error(SYSTEM, errmsg);
979 +                }
980 +                SET_FILE_BINARY(fp);
981 +                if (!silent) {
982 +                        printf("\tWriting motion vectors to \"%s\"\n", fname);
983 +                        fflush(stdout);
984 +                }
985 +                for (y = vres; y--; ) {
986 +                        for (x = hres; x--; ) {
987 +                                n = fndx(x,y);
988 +                                mbuffer[3*x] = xmbuffer[n] + 0x8000;
989 +                                mbuffer[3*x+1] = ymbuffer[n] + 0x8000;
990 +                                mbuffer[3*x+2] = (oprev[n]!=OVOID)*0x8000;
991 +                        }
992 +                        if (fwrite(mbuffer, sizeof(*mbuffer),
993 +                                                3*hres, fp) != 3*hres)
994 +                                goto writerr;
995 +                }
996 +                free((void *)mbuffer);
997 +                if (fclose(fp) == EOF)
998 +                        goto writerr;
999 +        }
1000          return;                         /* all is well */
1001   writerr:
1002 <        sprintf(errmsg, "error writing frame \"%s\"", pfname);
1002 >        sprintf(errmsg, "error writing file \"%s\"", fname);
1003          error(SYSTEM, errmsg);
1004   }
1005  
1006  
1007   void
1008 < free_frame()                    /* free frame allocation */
1008 > 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