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

Comparing ray/src/util/dctimestep.c (file contents):
Revision 2.29 by greg, Mon Jan 20 22:18:29 2014 UTC vs.
Revision 2.31 by greg, Fri May 30 00:00:54 2014 UTC

# Line 26 | Line 26 | sum_images(const char *fspec, const CMATRIX *cv, FILE
26          int     i, y;
27  
28          if (cv->ncols != 1)
29 <                error(INTERNAL, "expected vector in sum_images()");
29 >                error(INTERNAL, "expected matrix in sum_images()");
30          for (i = 0; i < cv->nrows; i++) {
31                  const COLORV    *scv = cv_lval(cv,i);
32                  char            fname[1024];
33                  FILE            *fp;
34                  int             dt, xr, yr;
35                  COLORV          *psp;
36 +                char            *err;
37                                                          /* check for zero */
38                  if ((scv[RED] == 0) & (scv[GRN] == 0) & (scv[BLU] == 0) &&
39                                  (myDT != DTfromHeader) | (i < cv->nrows-1))
40                          continue;
41                                                          /* open next picture */
42                  sprintf(fname, fspec, i);
43 <                if ((fp = fopen(fname, "r")) == NULL) {
43 >                if ((fp = fopen(fname, "rb")) == NULL) {
44                          sprintf(errmsg, "cannot open picture '%s'", fname);
45                          error(SYSTEM, errmsg);
46                  }
47 <                SET_FILE_BINARY(fp);
48 <                dt = getDTfromHeader(fp);
47 >                dt = DTfromHeader;
48 >                if ((err = cm_getheader(&dt, NULL, NULL, fp)) != NULL)
49 >                        error(USER, err);
50                  if ((dt != DTrgbe) & (dt != DTxyze) ||
51                                  !fscnresolu(&xr, &yr, fp)) {
52                          sprintf(errmsg, "file '%s' not a picture", fname);
# Line 59 | Line 61 | sum_images(const char *fspec, const CMATRIX *cv, FILE
61                          pmat = cm_alloc(myYR, myXR);
62                          memset(pmat->cmem, 0, sizeof(COLOR)*myXR*myYR);
63                                                          /* finish header */
64 <                        fputformat(myDT==DTrgbe ? COLRFMT : CIEFMT, fout);
64 >                        fputformat((char *)cm_fmt_id[myDT], fout);
65                          fputc('\n', fout);
64                        fprtresolu(myXR, myYR, fout);
66                          fflush(fout);
67                  } else if ((dt != myDT) | (xr != myXR) | (yr != myYR)) {
68                          sprintf(errmsg, "picture '%s' format/size mismatch",
# Line 85 | Line 86 | sum_images(const char *fspec, const CMATRIX *cv, FILE
86                  fclose(fp);                             /* done this picture */
87          }
88          free(scanline);
89 <                                                        /* write scanlines */
90 <        for (y = 0; y < myYR; y++)
91 <                if (fwritescan((COLOR *)cm_lval(pmat, y, 0), myXR, fout) < 0)
91 <                        return(0);
92 <        cm_free(pmat);                                  /* all done */
93 <        return(fflush(fout) == 0);
89 >        i = cm_write(pmat, myDT, fout);                 /* write picture */
90 >        cm_free(pmat);                                  /* free data */
91 >        return(i);
92   }
93  
94   /* check to see if a string contains a %d or %o specification */
# Line 122 | Line 120 | int
120   main(int argc, char *argv[])
121   {
122          int             skyfmt = DTascii;
123 +        int             outfmt = DTascii;
124          int             nsteps = 1;
125          char            *ofspec = NULL;
126          FILE            *ofp = stdout;
# Line 135 | Line 134 | main(int argc, char *argv[])
134                  switch (argv[a][1]) {
135                  case 'n':
136                          nsteps = atoi(argv[++a]);
137 <                        if (nsteps <= 0)
137 >                        if (nsteps < 0)
138                                  goto userr;
139                          break;
141                case 'o':
142                        ofspec = argv[++a];
143                        break;
140                  case 'i':
141                          switch (argv[a][2]) {
142                          case 'f':
# Line 152 | Line 148 | main(int argc, char *argv[])
148                          case 'a':
149                                  skyfmt = DTascii;
150                                  break;
151 +                        case 'h':
152 +                                skyfmt = DTfromHeader;
153 +                                break;
154                          default:
155                                  goto userr;
156                          }
157                          break;
158 +                case 'o':
159 +                        switch (argv[a][2]) {
160 +                        case '\0':      /* output specification (not format) */
161 +                                ofspec = argv[++a];
162 +                                break;
163 +                        case 'f':
164 +                                outfmt = DTfloat;
165 +                                break;
166 +                        case 'd':
167 +                                outfmt = DTdouble;
168 +                                break;
169 +                        case 'a':
170 +                                outfmt = DTascii;
171 +                                break;
172 +                        default:
173 +                                goto userr;
174 +                        }
175 +                        break;
176                  default:
177                          goto userr;
178                  }
# Line 235 | Line 252 | main(int argc, char *argv[])
252                  CMATRIX *Vmat = cm_load(argv[a], 0, cmtx->nrows, DTfromHeader);
253                  CMATRIX *rmtx = cm_multiply(Vmat, cmtx);
254                  cm_free(Vmat);
255 <                if (ofspec != NULL)             /* multiple vector files? */
255 >                if (ofspec != NULL) {           /* multiple vector files? */
256 >                        const char      *wtype = (outfmt==DTascii) ? "w" : "wb";
257                          for (i = 0; i < nsteps; i++) {
258                                  CMATRIX *rvec = cm_column(rmtx, i);
259                                  sprintf(fnbuf, ofspec, i+1);
260 <                                if ((ofp = fopen(fnbuf, "w")) == NULL) {
260 >                                if ((ofp = fopen(fnbuf, wtype)) == NULL) {
261                                          fprintf(stderr,
262                                          "%s: cannot open '%s' for output\n",
263                                                          progname, fnbuf);
264                                          return(1);
265                                  }
266 <                                cm_print(rvec, ofp);
266 > #ifdef getc_unlocked
267 >                                flockfile(ofp);
268 > #endif
269 >                                cm_write(rvec, outfmt, ofp);
270                                  if (fclose(ofp) == EOF) {
271                                          fprintf(stderr,
272                                                  "%s: error writing to '%s'\n",
# Line 255 | Line 276 | main(int argc, char *argv[])
276                                  ofp = stdout;
277                                  cm_free(rvec);
278                          }
279 <                else
280 <                        cm_print(rmtx, ofp);
279 >                } else {
280 > #ifdef getc_unlocked
281 >                        flockfile(ofp);
282 > #endif
283 >                        if (outfmt != DTascii)
284 >                                SET_FILE_BINARY(ofp);
285 >                        if (rmtx->ncols > 1) {  /* header if actual matrix */
286 >                                newheader("RADIANCE", ofp);
287 >                                printargs(argc, argv, ofp);
288 >                                fputnow(ofp);
289 >                                fprintf(ofp, "NCOLS=%d\n", rmtx->ncols);
290 >                                fputs("NCOMP=3\n", ofp);
291 >                                fputformat((char *)cm_fmt_id[outfmt], ofp);
292 >                                fputc('\n', ofp);
293 >                        }
294 >                        cm_write(rmtx, outfmt, ofp);
295 >                }
296                  cm_free(rmtx);
297          }
298          if (fflush(ofp) == EOF) {               /* final clean-up */
# Line 266 | Line 302 | main(int argc, char *argv[])
302          cm_free(cmtx);
303          return(0);
304   userr:
305 <        fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d}] DCspec [skyf]\n",
305 >        fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d}][-o{f|d}] DCspec [skyf]\n",
306                                  progname);
307 <        fprintf(stderr, "   or: %s [-n nsteps][-o ospec][-i{f|d}] Vspec Tbsdf.xml Dmat.dat [skyf]\n",
307 >        fprintf(stderr, "   or: %s [-n nsteps][-o ospec][-i{f|d}][-o{f|d}] Vspec Tbsdf.xml Dmat.dat [skyf]\n",
308                                  progname);
309          return(1);
310   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines