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.1 by greg, Sat Feb 22 02:07:30 2003 UTC vs.
Revision 3.17 by greg, Fri May 20 02:06:39 2011 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   */
11  
12 < /* ====================================================================
13 < * The Radiance Software License, Version 1.0
14 < *
15 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
16 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
17 < *
18 < * Redistribution and use in source and binary forms, with or without
19 < * modification, are permitted provided that the following conditions
20 < * are met:
21 < *
22 < * 1. Redistributions of source code must retain the above copyright
23 < *         notice, this list of conditions and the following disclaimer.
24 < *
25 < * 2. Redistributions in binary form must reproduce the above copyright
26 < *       notice, this list of conditions and the following disclaimer in
27 < *       the documentation and/or other materials provided with the
28 < *       distribution.
29 < *
30 < * 3. The end-user documentation included with the redistribution,
31 < *           if any, must include the following acknowledgment:
32 < *             "This product includes Radiance software
33 < *                 (http://radsite.lbl.gov/)
34 < *                 developed by the Lawrence Berkeley National Laboratory
35 < *               (http://www.lbl.gov/)."
36 < *       Alternately, this acknowledgment may appear in the software itself,
37 < *       if and wherever such third-party acknowledgments normally appear.
38 < *
39 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
40 < *       and "The Regents of the University of California" must
41 < *       not be used to endorse or promote products derived from this
42 < *       software without prior written permission. For written
43 < *       permission, please contact [email protected].
44 < *
45 < * 5. Products derived from this software may not be called "Radiance",
46 < *       nor may "Radiance" appear in their name, without prior written
47 < *       permission of Lawrence Berkeley National Laboratory.
48 < *
49 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
50 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
51 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
52 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
53 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
56 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
57 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
58 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
59 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 < * SUCH DAMAGE.
61 < * ====================================================================
62 < *
63 < * This software consists of voluntary contributions made by many
64 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
65 < * information on Lawrence Berkeley National Laboratory, please see
66 < * <http://www.lbl.gov/>.
67 < */
12 > #include "copyright.h"
13  
14 + #include <string.h>
15 +
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 81 | 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 98 | Line 47 | double         frm_stop;       /* when to stop rendering this frame
47   double          hlsmax;         /* maximum high-level saliency this frame */
48  
49  
50 < void
51 < write_map(mp, fn)               /* write out float map (debugging) */
52 < float   *mp;
53 < char    *fn;
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);
54 > static void init_frame_sample(void);
55 >
56 >
57 > #if 0
58 > extern void
59 > write_map(              /* write out float map (debugging) */
60 >        float   *mp,
61 >        char    *fn
62 > )
63   {
64          FILE    *fp = fopen(fn, "w");
65          COLOR   scanbuf[2048];
# Line 122 | Line 80 | char   *fn;
80          }
81          fclose(fp);
82   }
83 + #endif
84  
85  
86   static void
87 < next_frame()                    /* prepare next frame buffer */
87 > next_frame(void)                        /* prepare next frame buffer */
88   {
89          VIEW    *fv;
90          char    *err;
91                                          /* get previous view */
92          if (vw.type != 0)
93 <                copystruct(&vwprev, &vw);
93 >                vwprev = vw;
94          else if (fcur > 1 && (fv = getview(fcur-1)) != NULL) {
95 <                copystruct(&vwprev, fv);
95 >                vwprev = *fv;
96                  if (setview(&vwprev) != NULL)
97                          vwprev.type = 0;
98          }
# Line 142 | Line 101 | next_frame()                   /* prepare next frame buffer */
101                  sprintf(errmsg, "cannot get view for frame %d", fcur);
102                  error(USER, errmsg);
103          }
104 <        copystruct(&vw, fv);
104 >        vw = *fv;
105          if ((err = setview(&vw)) != NULL) {
106                  sprintf(errmsg, "view error at frame %d: %s", fcur, err);
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 158 | Line 118 | next_frame()                   /* prepare next frame buffer */
118                          pixaspect = 1.;
119                          /* fall through */
120                  case 3:
121 <                        if ((hres > 0 & vres > 0))
121 >                        if ((hres > 0) & (vres > 0))
122                                  break;
123                          /* fall through */
124                  default:
# Line 171 | 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);
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))
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 +                        oprev[n] = OVOID;
149 +                }
150                  frm_stop = getTime() + rtperfrm;
151          } else {
152                  COLOR   *cp;            /* else just swap buffers */
153                  float   *fp;
154                  OBJECT  *op;
155 <                BYTE    *bp;
155 >                uby8    *bp;
156                  cp = cprev; cprev = cbuffer; cbuffer = cp;
157                  fp = zprev; zprev = zbuffer; zbuffer = fp;
158                  op = oprev; oprev = obuffer; obuffer = op;
159                  bp = aprev; aprev = abuffer; abuffer = bp;
160 <                bzero(abuffer, sizeof(BYTE)*hres*vres);
161 <                bzero(sbuffer, sizeof(BYTE)*hres*vres);
160 >                memset(abuffer, '\0', sizeof(uby8)*hres*vres);
161 >                memset(sbuffer, '\0', sizeof(uby8)*hres*vres);
162                  frm_stop += rtperfrm;
163          }
164          cerrmap = NULL;
# Line 207 | Line 171 | next_frame()                   /* prepare next frame buffer */
171  
172  
173   static int
174 < sample_here(x, y)               /* 4x4 quincunx sample at this pixel? */
175 < register int    x, y;
174 > sample_here(            /* 4x4 quincunx sample at this pixel? */
175 >        register int    x,
176 >        register int    y
177 > )
178   {
179          if (y & 0x1)            /* every other row has samples */
180                  return(0);
# Line 218 | Line 184 | register int   x, y;
184   }
185  
186  
187 < void
188 < sample_pos(hv, x, y, sn)        /* compute jittered sample position */
189 < double  hv[2];
190 < int     x, y;
191 < int     sn;
187 > extern void
188 > sample_pos(     /* compute jittered sample position */
189 >        double  hv[2],
190 >        int     x,
191 >        int     y,
192 >        int     sn
193 > )
194   {
195          int     hl[2];
196  
# Line 233 | Line 201 | int    sn;
201   }
202  
203  
204 < double
205 < sample_wt(xo, yo)               /* compute interpolant sample weight */
206 < int     xo, yo;
204 > extern double
205 > sample_wt(              /* compute interpolant sample weight */
206 >        int     xo,
207 >        int yo
208 > )
209   {
210          static double   etab[400];
211 <        int     rad2 = xo*xo + yo*yo;
211 >        /* we can't use the name rad2 here, for some reason Visual C
212 >           thinks that is a constant (compiler bug?) */
213 >        int     rad_2 = xo*xo + yo*yo;
214          int     i;
215  
216          if (etab[0] <= FTINY)           /* initialize exponent table */
# Line 246 | Line 218 | int    xo, yo;
218                          etab[i] = exp(-0.1*i);
219  
220                                          /* look up Gaussian */
221 <        i = (int)((10.*3./(double)SAMPDIST2)*rad2 + .5);
221 >        i = (int)((10.*3./(double)SAMPDIST2)*rad_2 + .5);
222          if (i >= 400)
223                  return(0.0);
224          return(etab[i]);
# Line 254 | Line 226 | int    xo, yo;
226  
227  
228   static int
229 < offset_cmp(p1, p2)              /* compare offset distances */
230 < const void      *p1, *p2;
229 > offset_cmp(             /* compare offset distances */
230 >        const void      *p1,
231 >        const void      *p2
232 > )
233   {
234          return(*(const int *)p1 - *(const int *)p2);
235   }
236  
237  
238 < int
239 < getclosest(iarr, nc, x, y)      /* get nc closest neighbors on same object */
240 < int     *iarr;
241 < int     nc;
242 < int     x, y;
238 > extern int
239 > getclosest(     /* get nc closest neighbors on same object */
240 >        int     *iarr,
241 >        int     nc,
242 >        int     x,
243 >        int     y
244 > )
245   {
246   #define NSCHECK         ((2*SAMPDIST+1)*(2*SAMPDIST+1))
247          static int      hro, vro;
# Line 276 | Line 252 | int    x, y;
252                                          /* get our object number */
253          myobj = obuffer[fndx(x, y)];
254                                          /* special case for borders */
255 <        if ((x < SAMPDIST | x >= hres-SAMPDIST |
256 <                        y < SAMPDIST | y >= vres-SAMPDIST)) {
255 >        if ((x < SAMPDIST) | (x >= hres-SAMPDIST) |
256 >                        (y < SAMPDIST) | (y >= vres-SAMPDIST)) {
257                  int     tndx[NSCHECK][2];
258                  nf = 0;
259                  for (j = y - SAMPDIST; j <= y + SAMPDIST; j++) {
# Line 289 | Line 265 | int    x, y;
265                          i0 = fndx(i, j);
266                          if (!sbuffer[i0])
267                                  continue;
268 <                        if ((myobj != OVOID & obuffer[i0] != myobj))
268 >                        if ((myobj != OVOID) & (obuffer[i0] != myobj))
269                                  continue;
270                          tndx[nf][0] = (i-x)*(i-x) + (j-y)*(j-y);
271                          tndx[nf][1] = i0;
# Line 304 | Line 280 | int    x, y;
280                  return(nf);
281          }
282                                          /* initialize offset array */
283 <        if ((hres != hro | vres != vro)) {
283 >        if ((hres != hro) | (vres != vro)) {
284                  int     toffs[NSCHECK][2];
285                  i0 = fndx(SAMPDIST, SAMPDIST);
286                  nf = 0;
# Line 323 | Line 299 | int    x, y;
299          }
300                                          /* find up to nc neighbors */
301          i0 = fndx(x, y);
302 <        for (j = 0, nf = 0; (j < NSCHECK & nf < nc); j++) {
302 >        for (j = 0, nf = 0; (j < NSCHECK) & (nf < nc); j++) {
303                  i = i0 + ioffs[j];
304 <                if (sbuffer[i] && (myobj == OVOID | obuffer[i] == myobj))
304 >                if (sbuffer[i] && (myobj == OVOID) | (obuffer[i] == myobj))
305                          iarr[nf++] = i;
306          }
307                                          /* return number found */
# Line 335 | Line 311 | int    x, y;
311  
312  
313   static void
314 < setmotion(n, wpos)              /* compute motion vector for this pixel */
315 < register int    n;
316 < FVECT   wpos;
314 > setmotion(              /* compute motion vector for this pixel */
315 >                register int    n,
316 >                FVECT   wpos
317 > )
318   {
319          FVECT   ovp;
343        MAT4    xfm;
344        double  d;
320          int     moi;
321          int     xp, yp;
322                                          /* ID object and update maximum HLS */
# Line 361 | Line 336 | FVECT  wpos;
336          yp = (int)(ovp[1]*vres);
337          xmbuffer[n] = xp - (n % hres);
338          ymbuffer[n] = yp - (n / hres);
339 <        if ((xp < 0 | xp >= hres))
339 >        if ((xp < 0) | (xp >= hres))
340                  return;
341 <        if ((yp < 0 | yp >= vres))
341 >        if ((yp < 0) | (yp >= vres))
342                  return;
343          n = fndx(xp, yp);
344 <        if ((zprev[n] < 0.97*ovp[2] | zprev[n] > 1.03*ovp[2]))
344 >        if ((zprev[n] < 0.97*ovp[2]) | (zprev[n] > 1.03*ovp[2]))
345                  oprev[n] = OVOID;       /* assume it's a bad match */
346   }
347  
348  
349   static void
350 < init_frame_sample()             /* sample our initial frame */
350 > init_frame_sample(void)         /* sample our initial frame */
351   {
352          RAY     ir;
353          int     x, y;
# Line 399 | Line 374 | init_frame_sample()            /* sample our initial frame */
374                          continue;
375                  }
376                  if (!sample_here(x, y)) {       /* just cast */
377 <                        rayorigin(&ir, NULL, PRIMARY, 1.0);
377 >                        rayorigin(&ir, PRIMARY, NULL, NULL);
378                          if (!localhit(&ir, &thescene)) {
379 <                                if (ir.ro != &Aftplane)
380 <                                        sourcehit(&ir);
379 >                                if (ir.ro != &Aftplane && sourcehit(&ir)) {
380 >                                        rayshade(&ir, ir.ro->omod);
381 >                                        rayparticipate(&ir);
382 >                                }
383                                  copycolor(cbuffer[n], ir.rcol);
384                                  zbuffer[n] = ir.rot;
385                                  obuffer[n] = ir.robj;
# Line 417 | Line 394 | init_frame_sample()            /* sample our initial frame */
394                  }
395                  if (nprocs > 1) {               /* get sample */
396                          int     rval;
397 <                        rayorigin(&ir, NULL, PRIMARY, 1.0);
397 >                        rayorigin(&ir, PRIMARY, NULL, NULL);
398                          ir.rno = n;
399                          rval = ray_pqueue(&ir);
400                          if (!rval)
# Line 431 | Line 408 | init_frame_sample()            /* sample our initial frame */
408                  zbuffer[n] = ir.rot;
409                  obuffer[n] = ir.robj;
410                  sbuffer[n] = 1;
411 <                if (ir.rot >= FHUGE)
411 >                if (ir.rot >= 0.99*FHUGE)
412                          abuffer[n] = ADISTANT;
413                  else {
414                          abuffer[n] = ALOWQ;
# Line 459 | Line 436 | init_frame_sample()            /* sample our initial frame */
436                  n = fndx(x, y);
437                  if ((obj = obuffer[n]) == OVOID)
438                          continue;
439 <                if ((obuffer[n+1] != OVOID & obuffer[n+1] != obj)) {
439 >                if ((obuffer[n+1] != OVOID) & (obuffer[n+1] != obj)) {
440                          obuffer[n] = OVOID;
441                          obuffer[n+1] = OVOID;
442                  }
443 <                if ((obuffer[n+hres] != OVOID & obuffer[n+hres] != obj)) {
443 >                if ((obuffer[n+hres] != OVOID) & (obuffer[n+hres] != obj)) {
444                          obuffer[n] = OVOID;
445                          obuffer[n+hres] = OVOID;
446                  }
# Line 474 | Line 451 | init_frame_sample()            /* sample our initial frame */
451   }
452  
453  
454 < int
455 < getambcolor(clr, obj)           /* get ambient color for object if we can */
456 < COLOR   clr;
457 < int     obj;
454 > extern int
455 > getambcolor(            /* get ambient color for object if we can */
456 >                COLOR   clr,
457 >                int     obj
458 > )
459   {
460          register OBJREC *op;
461  
462          if (obj == OVOID)
463                  return(0);
464 <        op = objptr(obj);
465 <        if ((op->otype == OBJ_INSTANCE & op->omod == OVOID))
464 >        op = objptr(obj);               /* search for material */
465 >        if (op->omod == OVOID)
466                  return(0);
467 <                                        /* search for material */
468 <        do {
469 <                if (op->omod == OVOID || ofun[op->otype].flags & T_X)
492 <                        return(0);
493 <                op = objptr(op->omod);
494 <        } while (!ismaterial(op->otype));
467 >        op = findmaterial(objptr(op->omod));
468 >        if (op == NULL)
469 >                return(0);
470          /*
471           * Since this routine is called to compute the difference
472           * from rendering with and without interreflections,
# Line 505 | Line 480 | int    obj;
480                          if (lv[0] == op->oname[0] &&
481                                          !strcmp(lv+1, op->oname+1))
482                                  break;
483 <                if ((lv != NULL) != hirendparams.ambincl)
483 >                if ((lv != NULL) ^ hirendparams.ambincl)
484                          return(0);
485          }
486          switch (op->otype) {
# Line 544 | Line 519 | int    obj;
519   }
520  
521  
522 < double
523 < estimaterr(cs, cs2, ns, ns0)    /* estimate relative error from samples */
524 < COLOR   cs, cs2;
525 < int     ns;
522 > extern double
523 > estimaterr(             /* estimate relative error from samples */
524 >                COLOR   cs,
525 >                COLOR   cs2,
526 >                int     ns,
527 >                int ns0
528 > )
529   {
530          double  d, d2, brt;
531  
# Line 567 | Line 545 | int    ns;
545   }
546  
547  
548 < double
549 < comperr(neigh, nc, ns0)         /* estimate relative error in neighborhood */
550 < int     *neigh;
551 < int     nc;
552 < int     ns0;
548 > extern double
549 > comperr(                /* estimate relative error in neighborhood */
550 >                int     *neigh,
551 >                int     nc,
552 >                int     ns0
553 > )
554   {
555          COLOR   csum, csum2;
556          COLOR   ctmp;
# Line 581 | Line 560 | int    ns0;
560                                          /* add together samples */
561          setcolor(csum, 0., 0., 0.);
562          setcolor(csum2, 0., 0., 0.);
563 <        for (i = 0, ns = 0; (i < nc & ns < NSAMPOK); i++) {
563 >        for (i = 0, ns = 0; (i < nc) & (ns < NSAMPOK); i++) {
564                  n = neigh[i];
565                  addcolor(csum, cbuffer[n]);
566                  if (val2map != NULL) {
# Line 602 | Line 581 | int    ns0;
581   }
582  
583  
584 < void
585 < comp_frame_error()              /* initialize frame error values */
584 > extern void
585 > comp_frame_error(void)          /* initialize frame error values */
586   {
587 <        BYTE    *edone = NULL;
587 >        uby8    *edone = NULL;
588          COLOR   objamb;
589          double  eest;
590          int     neigh[NSAMPOK];
591          int     nc;
592 <        int     x, y, i, j;
592 >        int     x, y, i;
593          register int    n;
594  
595          if (!silent) {
# Line 629 | Line 608 | comp_frame_error()             /* initialize frame error values *
608                   * error should be less than the ambient value divided
609                   * by the returned ray value -- we take half of this.
610                   */
611 <                edone = (BYTE *)calloc(hres*vres, sizeof(BYTE));
611 >                edone = (uby8 *)calloc(hres*vres, sizeof(uby8));
612                  for (y = vres; y--; )
613                      for (x = hres; x--; ) {
614                          n = fndx(x, y);
615 <                        if ((abuffer[n] != ALOWQ | obuffer[n] == OVOID))
615 >                        if ((abuffer[n] != ALOWQ) | (obuffer[n] == OVOID))
616                                  continue;
617                          if (!getambcolor(objamb, obuffer[n]))
618                                  continue;
# Line 681 | Line 660 | comp_frame_error()             /* initialize frame error values *
660   }
661  
662  
663 < void
664 < init_frame()                    /* render base (low quality) frame */
663 > extern void
664 > init_frame(void)                        /* render base (low quality) frame */
665   {
666          int     restart;
688
667                                          /* allocate/swap buffers */
668          next_frame();
669                                          /* check rendering status */
670          restart = (!nobjects || vdef(MOVE));
671          if (!restart && curparams != &lorendparams && nprocs > 1)
672                  restart = -1;
695        if (restart > 0)
696                if (nprocs > 1)
697                        ray_pdone(1);
698                else
699                        ray_done(1);
673                                          /* post low quality parameters */
674          if (curparams != &lorendparams)
675                  ray_restore(curparams = &lorendparams);
# Line 728 | Line 701 | init_frame()                   /* render base (low quality) frame */
701          init_frame_sample();
702                                          /* initialize frame error */
703          comp_frame_error();
704 < return;
704 > #if 0
705   {
706          float   *ebuf = (float *)malloc(sizeof(float)*hres*vres);
707          char    fnm[256];
# Line 740 | Line 713 | return;
713          write_map(ebuf, fnm);
714          free((void *)ebuf);
715   }
716 + #endif
717   }
718  
719  
720 < void
721 < filter_frame()                  /* interpolation, motion-blur, and exposure */
720 > extern void
721 > filter_frame(void)                      /* interpolation, motion-blur, and exposure */
722   {
723          double  expval = expspec_val(getexp(fcur));
724          int     x, y;
# Line 755 | Line 729 | filter_frame()                 /* interpolation, motion-blur, and ex
729          register int    n;
730  
731   #if 0
732 < /* XXX TEMPORARY!! */
733 < conspicuity();
734 < write_map(cerrmap, "outcmap.pic");
735 < {
736 <        float   *ebuf = (float *)malloc(sizeof(float)*hres*vres);
737 <        for (n = hres*vres; n--; )
738 <                ebuf[n] = acctab[abuffer[n]];
739 <        write_map(ebuf, "outerr.pic");
740 <        free((void *)ebuf);
741 < }
732 >        /* XXX TEMPORARY!! */
733 >        conspicuity();
734 >        write_map(cerrmap, "outcmap.pic");
735 >        {
736 >                float   *ebuf = (float *)malloc(sizeof(float)*hres*vres);
737 >                for (n = hres*vres; n--; )
738 >                        ebuf[n] = acctab[abuffer[n]];
739 >                write_map(ebuf, "outerr.pic");
740 >                free((void *)ebuf);
741 >        }
742   #endif
743  
744          if (!silent) {
# Line 788 | Line 762 | write_map(cerrmap, "outcmap.pic");
762                          continue;
763                  nc = getclosest(neigh, NPINTERP, x, y);
764                  setcolor(cbuffer[n], 0., 0., 0.);
765 +                if (nc <= 0) {          /* no acceptable neighbors */
766 +                        if (y < vres-1)
767 +                                nc = fndx(x, y+1);
768 +                        else if (x < hres-1)
769 +                                nc = fndx(x+1, y);
770 +                        else
771 +                                continue;
772 +                        copycolor(cbuffer[n], cbuffer[nc]);
773 +                        continue;
774 +                }
775                  wsum = 0.;
776                  while (nc-- > 0) {
777                          copycolor(cval, cbuffer[neigh[nc]]);
# Line 797 | Line 781 | write_map(cerrmap, "outcmap.pic");
781                          addcolor(cbuffer[n], cval);
782                          wsum += w;
783                  }
784 <                if (wsum > FTINY) {
785 <                        w = 1.0/wsum;
802 <                        scalecolor(cbuffer[n], w);
803 <                }
784 >                w = 1.0/wsum;
785 >                scalecolor(cbuffer[n], w);
786              }
787                                          /* motion blur if requested */
788          if (mblur > .02) {
807                int     len;
789                  int     xs, ys, xl, yl;
790                  int     rise, run;
791                  long    rise2, run2;
792                  int     n2;
793                  int     cnt;
794                                          /* sum in motion streaks */
795 <                bzero(outbuffer, sizeof(COLOR)*hres*vres);
796 <                bzero(wbuffer, sizeof(float)*hres*vres);
795 >                memset(outbuffer, '\0', sizeof(COLOR)*hres*vres);
796 >                memset(wbuffer, '\0', sizeof(float)*hres*vres);
797                  for (y = vres; y--; )
798                      for (x = hres; x--; ) {
799                          n = fndx(x, y);
# Line 841 | Line 822 | write_map(cerrmap, "outcmap.pic");
822                                  scalecolor(cval, w);
823                                  while (cnt)
824                                          if (rise2 >= run2) {
825 <                                                if ((xl >= 0 & xl < hres &
826 <                                                        yl >= 0 & yl < vres)) {
825 >                                                if ((xl >= 0) & (xl < hres) &
826 >                                                    (yl >= 0) & (yl < vres)) {
827                                                          n2 = fndx(xl, yl);
828                                                          addcolor(outbuffer[n2],
829                                                                          cval);
# Line 862 | Line 843 | write_map(cerrmap, "outcmap.pic");
843                                  scalecolor(cval, w);
844                                  while (cnt)
845                                          if (run2 >= rise2) {
846 <                                                if ((xl >= 0 & xl < hres &
847 <                                                        yl >= 0 & yl < vres)) {
846 >                                                if ((xl >= 0) & (xl < hres) &
847 >                                                    (yl >= 0) & (yl < vres)) {
848                                                          n2 = fndx(xl, yl);
849                                                          addcolor(outbuffer[n2],
850                                                                          cval);
# Line 890 | Line 871 | write_map(cerrmap, "outcmap.pic");
871          } else
872                  for (n = hres*vres; n--; )
873                          copycolor(outbuffer[n], cbuffer[n]);
874 < /*
875 < for (n = hres*vres; n--; )
876 <        if (!sbuffer[n])
877 <                setcolor(outbuffer[n], 0., 0., 0.);
878 < */
879 <                                /* adjust exposure */
880 <        if ((expval < 0.99 | expval > 1.01))
874 >        /*
875 >           for (n = hres*vres; n--; )
876 >                   if (!sbuffer[n])
877 >                           setcolor(outbuffer[n], 0., 0., 0.);
878 >         */
879 >        /* adjust exposure */
880 >        if ((expval < 0.99) | (expval > 1.01))
881                  for (n = hres*vres; n--; )
882                          scalecolor(outbuffer[n], expval);
883 < return;
884 < {
885 <        float   *sbuf = (float *)malloc(sizeof(float)*hres*vres);
886 <        char    fnm[256];
887 <        sprintf(fnm, vval(BASENAME), fcur);
888 <        strcat(fnm, "_outsamp.pic");
889 <        for (n = hres*vres; n--; )
890 <                sbuf[n] = (float)sbuffer[n];
891 <        write_map(sbuf, fnm);
892 <        free((void *)sbuf);
883 > #if 0
884 >        {
885 >                float   *sbuf = (float *)malloc(sizeof(float)*hres*vres);
886 >                char    fnm[256];
887 >                sprintf(fnm, vval(BASENAME), fcur);
888 >                strcat(fnm, "_outsamp.pic");
889 >                for (n = hres*vres; n--; )
890 >                        sbuf[n] = (float)sbuffer[n];
891 >                write_map(sbuf, fnm);
892 >                free((void *)sbuf);
893 >        }
894 > #endif
895   }
913 }
896  
897  
898 < void
899 < send_frame()                    /* send frame to destination */
898 > extern void
899 > send_frame(void)                        /* send frame to destination */
900   {
901          char    pfname[1024];
902          double  d;
# Line 922 | Line 904 | send_frame()                   /* send frame to destination */
904          int     y;
905                                          /* open output picture */
906          sprintf(pfname, vval(BASENAME), fcur);
907 <        strcat(pfname, ".pic");
907 >        strcat(pfname, ".hdr");
908          fp = fopen(pfname, "w");
909          if (fp == NULL) {
910                  sprintf(errmsg, "cannot open output frame \"%s\"", pfname);
911                  error(SYSTEM, errmsg);
912          }
913 < #ifdef MSDOS
932 <        setmode(fileno(fp), O_BINARY);
933 < #endif
913 >        SET_FILE_BINARY(fp);
914          if (!silent) {
915                  printf("\tWriting to \"%s\"\n", pfname);
916                  fflush(stdout);
# Line 943 | Line 923 | send_frame()                   /* send frame to destination */
923          fputnow(fp);
924          fputs(VIEWSTR, fp); fprintview(&vw, fp); fputc('\n', fp);
925          d = expspec_val(getexp(fcur));
926 <        if ((d < 0.99 | d > 1.01))
926 >        if ((d < 0.99) | (d > 1.01))
927                  fputexpos(d, fp);
928          d = viewaspect(&vw) * hres / vres;
929 <        if ((d < 0.99 | d > 1.01))
929 >        if ((d < 0.99) | (d > 1.01))
930                  fputaspect(d, fp);
931          fputformat(COLRFMT, fp);
932          fputc('\n', fp);                /* end header */
# Line 968 | Line 948 | writerr:
948   }
949  
950  
951 < void
952 < free_frame()                    /* free frame allocation */
951 > extern void
952 > free_frame(void)                        /* free frame allocation */
953   {
954          if (cbuffer == NULL)
955                  return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines