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.11 by greg, Fri Jun 13 01:16:41 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);
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 >                                sprintf(cp, "NCOLS=%d\nNCOMP=3\n",
156 >                                                stdos.reclen);
157 >                                printheader(stdout, info);
158 >                        }
159                          printresolu(stdout, xres, yres);
160                          if (waitflush > 0)
161                                  fflush(stdout);
# Line 163 | Line 194 | getostream(const char *ospec, const char *mname, int b
194                  }
195          }
196          if (!noopen && sop->ofp == NULL) {      /* open output stream */
166                long            i;
197                  if (oname[0] == '!')            /* output to command */
198                          sop->ofp = popen(oname+1, "w");
199                  else                            /* else open file */
# Line 175 | Line 205 | getostream(const char *ospec, const char *mname, int b
205   #ifdef getc_unlocked
206                  flockfile(sop->ofp);            /* avoid lock/unlock overhead */
207   #endif
208 +                if (accumulate > 0) {           /* global resolution */
209 +                        sop->xr = xres; sop->yr = yres;
210 +                }
211                  if (header) {
212 <                        char    info[512];
180 <                        char    *cp = info;
212 >                        cp = info;
213                          if (ofl & OF_MODIFIER || sop->reclen == 1) {
214                                  sprintf(cp, "MODIFIER=%s\n", mname);
215                                  while (*cp) ++cp;
# Line 186 | Line 218 | getostream(const char *ospec, const char *mname, int b
218                                  sprintf(cp, "BIN=%d\n", bn);
219                                  while (*cp) ++cp;
220                          }
221 <                        *cp = '\0';
221 >                        if (sop->yr > 0) {
222 >                                sprintf(cp, "NROWS=%d\n", sop->yr *
223 >                                                (sop->xr + !sop->xr) );
224 >                                while (*cp) ++cp;
225 >                        }
226 >                        sprintf(cp, "NCOLS=%d\nNCOMP=3\n", sop->reclen);
227                          printheader(sop->ofp, info);
228                  }
192                if (accumulate > 0) {           /* global resolution */
193                        sop->xr = xres; sop->yr = yres;
194                }
229                  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
230                  if (waitflush > 0)
231                          fflush(sop->ofp);
232          }
# Line 256 | Line 279 | static void
279   put_contrib(const DCOLOR cnt, FILE *fout)
280   {
281          double  sf = 1;
282 <        float   fv[3];
282 >        COLOR   fv;
283          COLR    cv;
284  
285          if (accumulate > 1)
# Line 272 | Line 295 | put_contrib(const DCOLOR cnt, FILE *fout)
295                  break;
296          case 'f':
297                  if (accumulate > 1) {
298 <                        fv[0] = sf*cnt[0]; fv[1] = sf*cnt[1]; fv[2] = sf*cnt[2];
298 >                        copycolor(fv, cnt);
299 >                        scalecolor(fv, sf);
300                  } else
301                          copycolor(fv, cnt);
302                  fwrite(fv, sizeof(float), 3, fout);
303                  break;
304          case 'd':
305                  if (accumulate > 1) {
306 <                        double  dv[3];
307 <                        dv[0] = sf*cnt[0]; dv[1] = sf*cnt[1]; dv[2] = sf*cnt[2];
306 >                        DCOLOR  dv;
307 >                        copycolor(dv, cnt);
308 >                        scalecolor(dv, sf);
309                          fwrite(dv, sizeof(double), 3, fout);
310                  } else
311                          fwrite(cnt, sizeof(double), 3, fout);
# Line 302 | Line 327 | put_contrib(const DCOLOR cnt, FILE *fout)
327   void
328   mod_output(MODCONT *mp)
329   {
330 <        STREAMOUT       *sop = getostream(mp->outspec, mp->modname, 0,0);
330 >        STREAMOUT       *sop = getostream(mp->outspec, mp->modname, 0, 0);
331          int             j;
332  
333          put_contrib(mp->cbin[0], sop->ofp);
334          if (mp->nbins > 3 &&    /* minor optimization */
335 <                        sop == getostream(mp->outspec, mp->modname, 1,0))
335 >                        sop == getostream(mp->outspec, mp->modname, 1, 0)) {
336                  for (j = 1; j < mp->nbins; j++)
337                          put_contrib(mp->cbin[j], sop->ofp);
338 <        else
338 >        } else {
339                  for (j = 1; j < mp->nbins; j++) {
340 <                        sop = getostream(mp->outspec, mp->modname,j,0);
340 >                        sop = getostream(mp->outspec, mp->modname, j, 0);
341                          put_contrib(mp->cbin[j], sop->ofp);
342                  }
343 +        }
344   }
345  
346  
# Line 341 | Line 367 | void
367   end_record()
368   {
369          --waitflush;
370 <        lu_doall(&ofiletab, puteol, NULL);
370 >        lu_doall(&ofiletab, &puteol, NULL);
371          if (using_stdout & (outfmt == 'a'))
372                  putc('\n', stdout);
373          if (!waitflush) {
# Line 491 | Line 517 | reload_output()
517                          *(STREAMOUT *)oent->data = sout;
518                  }
519          }
520 <        lu_doall(&ofiletab, myclose, NULL);     /* close all files */
520 >        lu_doall(&ofiletab, &myclose, NULL);    /* close all files */
521   }
522  
523  
# Line 647 | Line 673 | recover_output()
673          }
674                                                  /* seek on all files */
675          nvals = lastout * outvsiz;
676 <        lu_doall(&ofiletab, myseeko, &nvals);
676 >        lu_doall(&ofiletab, &myseeko, &nvals);
677                                                  /* skip repeated input */
678 +        lastout *= accumulate;
679          for (nvals = 0; nvals < lastout; nvals++) {
680                  FVECT   vdummy;
681                  if (getvec(vdummy) < 0 || getvec(vdummy) < 0)
682                          error(USER, "unexpected EOF on input");
683          }
684 <        lastray = lastdone = lastout * accumulate;
684 >        lastray = lastdone = (RNUMBER)lastout;
685          if (raysleft)
686                  raysleft -= lastray;
687   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines