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.13 by greg, Thu Jul 24 16:28:17 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 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 */
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 +        char                    *cp;
143          
144          if (ospec == NULL) {                    /* use stdout? */
145 <                if (!noopen && !using_stdout) {
145 >                if (!noopen & !using_stdout) {
146                          if (outfmt != 'a')
147                                  SET_FILE_BINARY(stdout);
148 <                        if (header)
149 <                                printheader(stdout, NULL);
150 <                        printresolu(stdout, xres, yres);
148 >                        if (header) {
149 >                                cp = info;
150 >                                if (yres > 0) {
151 >                                        sprintf(cp, "NROWS=%d\n", yres *
152 >                                                        (xres + !xres) );
153 >                                        while (*cp) ++cp;
154 >                                }
155 >                                if ((xres <= 0) | (stdos.reclen > 1))
156 >                                        sprintf(cp, "NCOLS=%d\n", stdos.reclen);
157 >                                printheader(stdout, info);
158 >                        }
159 >                        if (stdos.reclen == 1)
160 >                                printresolu(stdout, xres, yres);
161                          if (waitflush > 0)
162                                  fflush(stdout);
163                          stdos.xr = xres; stdos.yr = yres;
# Line 163 | Line 195 | getostream(const char *ospec, const char *mname, int b
195                  }
196          }
197          if (!noopen && sop->ofp == NULL) {      /* open output stream */
166                long            i;
198                  if (oname[0] == '!')            /* output to command */
199                          sop->ofp = popen(oname+1, "w");
200                  else                            /* else open file */
# Line 175 | Line 206 | getostream(const char *ospec, const char *mname, int b
206   #ifdef getc_unlocked
207                  flockfile(sop->ofp);            /* avoid lock/unlock overhead */
208   #endif
209 +                if (accumulate > 0) {           /* global resolution */
210 +                        sop->xr = xres; sop->yr = yres;
211 +                }
212                  if (header) {
213 <                        char    info[512];
180 <                        char    *cp = info;
213 >                        cp = info;
214                          if (ofl & OF_MODIFIER || sop->reclen == 1) {
215                                  sprintf(cp, "MODIFIER=%s\n", mname);
216                                  while (*cp) ++cp;
# Line 186 | Line 219 | getostream(const char *ospec, const char *mname, int b
219                                  sprintf(cp, "BIN=%d\n", bn);
220                                  while (*cp) ++cp;
221                          }
222 <                        *cp = '\0';
222 >                        if (sop->yr > 0) {
223 >                                sprintf(cp, "NROWS=%d\n", sop->yr *
224 >                                                (sop->xr + !sop->xr) );
225 >                                while (*cp) ++cp;
226 >                        }
227 >                        if ((sop->xr <= 0) | (sop->reclen > 1))
228 >                                sprintf(cp, "NCOLS=%d\n", sop->reclen);
229                          printheader(sop->ofp, info);
230                  }
231 <                if (accumulate > 0) {           /* global resolution */
232 <                        sop->xr = xres; sop->yr = yres;
194 <                }
195 <                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
231 >                if (sop->reclen == 1)
232 >                        printresolu(sop->ofp, sop->xr, sop->yr);
233                  if (waitflush > 0)
234                          fflush(sop->ofp);
235          }
# Line 256 | Line 282 | static void
282   put_contrib(const DCOLOR cnt, FILE *fout)
283   {
284          double  sf = 1;
285 <        float   fv[3];
285 >        COLOR   fv;
286          COLR    cv;
287  
288          if (accumulate > 1)
# Line 272 | Line 298 | put_contrib(const DCOLOR cnt, FILE *fout)
298                  break;
299          case 'f':
300                  if (accumulate > 1) {
301 <                        fv[0] = sf*cnt[0]; fv[1] = sf*cnt[1]; fv[2] = sf*cnt[2];
301 >                        copycolor(fv, cnt);
302 >                        scalecolor(fv, sf);
303                  } else
304                          copycolor(fv, cnt);
305                  fwrite(fv, sizeof(float), 3, fout);
306                  break;
307          case 'd':
308                  if (accumulate > 1) {
309 <                        double  dv[3];
310 <                        dv[0] = sf*cnt[0]; dv[1] = sf*cnt[1]; dv[2] = sf*cnt[2];
309 >                        DCOLOR  dv;
310 >                        copycolor(dv, cnt);
311 >                        scalecolor(dv, sf);
312                          fwrite(dv, sizeof(double), 3, fout);
313                  } else
314                          fwrite(cnt, sizeof(double), 3, fout);
# Line 302 | Line 330 | put_contrib(const DCOLOR cnt, FILE *fout)
330   void
331   mod_output(MODCONT *mp)
332   {
333 <        STREAMOUT       *sop = getostream(mp->outspec, mp->modname, 0,0);
333 >        STREAMOUT       *sop = getostream(mp->outspec, mp->modname, 0, 0);
334          int             j;
335  
336          put_contrib(mp->cbin[0], sop->ofp);
337          if (mp->nbins > 3 &&    /* minor optimization */
338 <                        sop == getostream(mp->outspec, mp->modname, 1,0))
338 >                        sop == getostream(mp->outspec, mp->modname, 1, 0)) {
339                  for (j = 1; j < mp->nbins; j++)
340                          put_contrib(mp->cbin[j], sop->ofp);
341 <        else
341 >        } else {
342                  for (j = 1; j < mp->nbins; j++) {
343 <                        sop = getostream(mp->outspec, mp->modname,j,0);
343 >                        sop = getostream(mp->outspec, mp->modname, j, 0);
344                          put_contrib(mp->cbin[j], sop->ofp);
345                  }
346 +        }
347   }
348  
349  
# Line 341 | Line 370 | void
370   end_record()
371   {
372          --waitflush;
373 <        lu_doall(&ofiletab, puteol, NULL);
373 >        lu_doall(&ofiletab, &puteol, NULL);
374          if (using_stdout & (outfmt == 'a'))
375                  putc('\n', stdout);
376          if (!waitflush) {
# Line 491 | Line 520 | reload_output()
520                          *(STREAMOUT *)oent->data = sout;
521                  }
522          }
523 <        lu_doall(&ofiletab, myclose, NULL);     /* close all files */
523 >        lu_doall(&ofiletab, &myclose, NULL);    /* close all files */
524   }
525  
526  
# Line 647 | Line 676 | recover_output()
676          }
677                                                  /* seek on all files */
678          nvals = lastout * outvsiz;
679 <        lu_doall(&ofiletab, myseeko, &nvals);
679 >        lu_doall(&ofiletab, &myseeko, &nvals);
680                                                  /* skip repeated input */
681 +        lastout *= accumulate;
682          for (nvals = 0; nvals < lastout; nvals++) {
683                  FVECT   vdummy;
684                  if (getvec(vdummy) < 0 || getvec(vdummy) < 0)
685                          error(USER, "unexpected EOF on input");
686          }
687 <        lastray = lastdone = lastout * accumulate;
687 >        lastray = lastdone = (RNUMBER)lastout;
688          if (raysleft)
689                  raysleft -= lastray;
690   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines