ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rc2.c
(Generate patch)

Comparing ray/src/rt/rc2.c (file contents):
Revision 2.1 by greg, Sat Jun 9 07:16:47 2012 UTC vs.
Revision 2.8 by greg, Wed Aug 7 05:10:09 2013 UTC

# Line 8 | Line 8 | static const char RCSid[] = "$Id$";
8  
9   #include "rcontrib.h"
10   #include "resolu.h"
11 < #include "platform.h"
11 > #include <ctype.h>
12  
13 + /* Close output stream and free record */
14 + static void
15 + closestream(void *p)
16 + {
17 +        STREAMOUT       *sop = (STREAMOUT *)p;
18 +        
19 +        if (sop->ofp != NULL) {
20 +                int     status = 0;
21 +                if (sop->outpipe)
22 +                        status = pclose(sop->ofp);
23 +                else if (sop->ofp != stdout)
24 +                        status = fclose(sop->ofp);
25 +                if (status)
26 +                        error(SYSTEM, "error closing output stream");
27 +        }
28 +        free(p);
29 + }
30 +
31 + LUTAB   ofiletab = LU_SINIT(free,closestream);  /* output file table */
32 +
33   #define OF_MODIFIER     01
34   #define OF_BIN          02
35  
# Line 83 | Line 103 | printheader(FILE *fout, const char *info)
103                  if (octname[strlen(octname)-1] != '\n')
104                          fputc('\n', fout);
105          } else {
106 <                FILE    *fin = fopen(octname, "r");
106 >                FILE    *fin = fopen(octname, (outfmt=='a') ? "r" : "rb");
107                  if (fin == NULL)
108                          quit(1);
109 <                checkheader(fin, "ignore", fout);
109 >                checkheader(fin, OCTFMT, fout);
110                  fclose(fin);
111          }
112          printargs(gargc-1, gargv, fout);        /* add our command */
# Line 120 | Line 140 | getostream(const char *ospec, const char *mname, int b
140          STREAMOUT               *sop;
141          
142          if (ospec == NULL) {                    /* use stdout? */
143 <                if (!noopen && !using_stdout) {
143 >                if (!noopen & !using_stdout) {
144                          if (outfmt != 'a')
145                                  SET_FILE_BINARY(stdout);
146                          if (header)
# Line 163 | Line 183 | getostream(const char *ospec, const char *mname, int b
183                  }
184          }
185          if (!noopen && sop->ofp == NULL) {      /* open output stream */
166                long            i;
186                  if (oname[0] == '!')            /* output to command */
187                          sop->ofp = popen(oname+1, "w");
188                  else                            /* else open file */
# Line 193 | Line 212 | getostream(const char *ospec, const char *mname, int b
212                          sop->xr = xres; sop->yr = yres;
213                  }
214                  printresolu(sop->ofp, sop->xr, sop->yr);
196 #if 0
197                                                /* play catch-up */
198                for (i = accumulate > 0 ? lastdone/accumulate : 0; i--; ) {
199                        int     j = sop->reclen;
200                        if (j <= 0) j = 1;
201                        while (j--)
202                                put_contrib(nocontrib, sop->ofp);
203                        if (outfmt == 'a')
204                                putc('\n', sop->ofp);
205                }
206 #endif
215                  if (waitflush > 0)
216                          fflush(sop->ofp);
217          }
# Line 256 | Line 264 | static void
264   put_contrib(const DCOLOR cnt, FILE *fout)
265   {
266          double  sf = 1;
267 <        float   fv[3];
267 >        COLOR   fv;
268          COLR    cv;
269  
270          if (accumulate > 1)
# Line 272 | Line 280 | put_contrib(const DCOLOR cnt, FILE *fout)
280                  break;
281          case 'f':
282                  if (accumulate > 1) {
283 <                        fv[0] = sf*cnt[0]; fv[1] = sf*cnt[1]; fv[2] = sf*cnt[2];
283 >                        copycolor(fv, cnt);
284 >                        scalecolor(fv, sf);
285                  } else
286                          copycolor(fv, cnt);
287                  fwrite(fv, sizeof(float), 3, fout);
288                  break;
289          case 'd':
290                  if (accumulate > 1) {
291 <                        double  dv[3];
292 <                        dv[0] = sf*cnt[0]; dv[1] = sf*cnt[1]; dv[2] = sf*cnt[2];
291 >                        DCOLOR  dv;
292 >                        copycolor(dv, cnt);
293 >                        scalecolor(dv, sf);
294                          fwrite(dv, sizeof(double), 3, fout);
295                  } else
296                          fwrite(cnt, sizeof(double), 3, fout);
# Line 302 | Line 312 | put_contrib(const DCOLOR cnt, FILE *fout)
312   void
313   mod_output(MODCONT *mp)
314   {
315 <        STREAMOUT       *sop = getostream(mp->outspec, mp->modname, 0,0);
315 >        STREAMOUT       *sop = getostream(mp->outspec, mp->modname, 0, 0);
316          int             j;
317  
318          put_contrib(mp->cbin[0], sop->ofp);
319          if (mp->nbins > 3 &&    /* minor optimization */
320 <                        sop == getostream(mp->outspec, mp->modname, 1,0))
320 >                        sop == getostream(mp->outspec, mp->modname, 1, 0)) {
321                  for (j = 1; j < mp->nbins; j++)
322                          put_contrib(mp->cbin[j], sop->ofp);
323 <        else
323 >        } else {
324                  for (j = 1; j < mp->nbins; j++) {
325 <                        sop = getostream(mp->outspec, mp->modname,j,0);
325 >                        sop = getostream(mp->outspec, mp->modname, j, 0);
326                          put_contrib(mp->cbin[j], sop->ofp);
327                  }
328 +        }
329   }
330  
331  
# Line 341 | Line 352 | void
352   end_record()
353   {
354          --waitflush;
355 <        lu_doall(&ofiletab, puteol, NULL);
355 >        lu_doall(&ofiletab, &puteol, NULL);
356          if (using_stdout & (outfmt == 'a'))
357                  putc('\n', stdout);
358          if (!waitflush) {
# Line 491 | Line 502 | reload_output()
502                          *(STREAMOUT *)oent->data = sout;
503                  }
504          }
505 <        lu_doall(&ofiletab, myclose, NULL);     /* close all files */
505 >        lu_doall(&ofiletab, &myclose, NULL);    /* close all files */
506   }
507  
508  
# Line 647 | Line 658 | recover_output()
658          }
659                                                  /* seek on all files */
660          nvals = lastout * outvsiz;
661 <        lu_doall(&ofiletab, myseeko, &nvals);
661 >        lu_doall(&ofiletab, &myseeko, &nvals);
662                                                  /* skip repeated input */
663 +        lastout *= accumulate;
664          for (nvals = 0; nvals < lastout; nvals++) {
665                  FVECT   vdummy;
666                  if (getvec(vdummy) < 0 || getvec(vdummy) < 0)
667                          error(USER, "unexpected EOF on input");
668          }
669 <        lastray = lastdone = lastout * accumulate;
669 >        lastray = lastdone = (RNUMBER)lastout;
670          if (raysleft)
671                  raysleft -= lastray;
672   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines