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.2 by greg, Sun Jun 10 05:25:42 2012 UTC vs.
Revision 2.10 by greg, Fri May 30 16:05:52 2014 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 92 | Line 112 | printheader(FILE *fout, const char *info)
112          printargs(gargc-1, gargv, fout);        /* add our command */
113          fprintf(fout, "SOFTWARE= %s\n", VersionID);
114          fputnow(fout);
115 +        fputs("NCOMP=3\n", fout);               /* always RGB */
116          if (info != NULL)                       /* add extra info if given */
117                  fputs(info, fout);
118          fputformat(formstr(outfmt), fout);
# Line 112 | Line 133 | printresolu(FILE *fout, int xr, int yr)
133   STREAMOUT *
134   getostream(const char *ospec, const char *mname, int bn, int noopen)
135   {
115        /* static const DCOLOR  nocontrib = BLKCOLOR; */
136          static STREAMOUT        stdos;
137 +        char                    info[1024];
138          int                     ofl;
139          char                    oname[1024];
140          LUENT                   *lep;
141          STREAMOUT               *sop;
142          
143          if (ospec == NULL) {                    /* use stdout? */
144 <                if (!noopen && !using_stdout) {
144 >                if (!noopen & !using_stdout) {
145                          if (outfmt != 'a')
146                                  SET_FILE_BINARY(stdout);
147 <                        if (header)
148 <                                printheader(stdout, NULL);
147 >                        if (header) {
148 >                                sprintf(info, "NCOLS=%d\nNCOMP=3\n",
149 >                                                stdos.reclen);
150 >                                printheader(stdout, info);
151 >                        }
152                          printresolu(stdout, xres, yres);
153                          if (waitflush > 0)
154                                  fflush(stdout);
# Line 163 | Line 187 | getostream(const char *ospec, const char *mname, int b
187                  }
188          }
189          if (!noopen && sop->ofp == NULL) {      /* open output stream */
166                long            i;
190                  if (oname[0] == '!')            /* output to command */
191                          sop->ofp = popen(oname+1, "w");
192                  else                            /* else open file */
# Line 176 | Line 199 | getostream(const char *ospec, const char *mname, int b
199                  flockfile(sop->ofp);            /* avoid lock/unlock overhead */
200   #endif
201                  if (header) {
179                        char    info[512];
202                          char    *cp = info;
203                          if (ofl & OF_MODIFIER || sop->reclen == 1) {
204                                  sprintf(cp, "MODIFIER=%s\n", mname);
# Line 186 | Line 208 | getostream(const char *ospec, const char *mname, int b
208                                  sprintf(cp, "BIN=%d\n", bn);
209                                  while (*cp) ++cp;
210                          }
211 <                        *cp = '\0';
211 >                        sprintf(cp, "NCOLS=%d\nNCOMP=3\n", sop->reclen);
212                          printheader(sop->ofp, info);
213                  }
214                  if (accumulate > 0) {           /* global resolution */
215                          sop->xr = xres; sop->yr = yres;
216                  }
217                  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
218                  if (waitflush > 0)
219                          fflush(sop->ofp);
220          }
# Line 309 | Line 320 | mod_output(MODCONT *mp)
320  
321          put_contrib(mp->cbin[0], sop->ofp);
322          if (mp->nbins > 3 &&    /* minor optimization */
323 <                        sop == getostream(mp->outspec, mp->modname, 1, 0))
323 >                        sop == getostream(mp->outspec, mp->modname, 1, 0)) {
324                  for (j = 1; j < mp->nbins; j++)
325                          put_contrib(mp->cbin[j], sop->ofp);
326 <        else
326 >        } else {
327                  for (j = 1; j < mp->nbins; j++) {
328                          sop = getostream(mp->outspec, mp->modname, j, 0);
329                          put_contrib(mp->cbin[j], sop->ofp);
330                  }
331 +        }
332   }
333  
334  
# Line 343 | Line 355 | void
355   end_record()
356   {
357          --waitflush;
358 <        lu_doall(&ofiletab, puteol, NULL);
358 >        lu_doall(&ofiletab, &puteol, NULL);
359          if (using_stdout & (outfmt == 'a'))
360                  putc('\n', stdout);
361          if (!waitflush) {
# Line 493 | Line 505 | reload_output()
505                          *(STREAMOUT *)oent->data = sout;
506                  }
507          }
508 <        lu_doall(&ofiletab, myclose, NULL);     /* close all files */
508 >        lu_doall(&ofiletab, &myclose, NULL);    /* close all files */
509   }
510  
511  
# Line 649 | Line 661 | recover_output()
661          }
662                                                  /* seek on all files */
663          nvals = lastout * outvsiz;
664 <        lu_doall(&ofiletab, myseeko, &nvals);
664 >        lu_doall(&ofiletab, &myseeko, &nvals);
665                                                  /* skip repeated input */
666 +        lastout *= accumulate;
667          for (nvals = 0; nvals < lastout; nvals++) {
668                  FVECT   vdummy;
669                  if (getvec(vdummy) < 0 || getvec(vdummy) < 0)
670                          error(USER, "unexpected EOF on input");
671          }
672 <        lastray = lastdone = lastout * accumulate;
672 >        lastray = lastdone = (RNUMBER)lastout;
673          if (raysleft)
674                  raysleft -= lastray;
675   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines