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.47 by greg, Fri Mar 11 02:27:02 2022 UTC vs.
Revision 2.53 by greg, Thu Mar 27 16:34:23 2025 UTC

# Line 20 | Line 20 | char   *progname;                      /* global argv[0] */
20   static int
21   sum_images(const char *fspec, const CMATRIX *cv, FILE *fout)
22   {
23 +        static int      runcnt = 0;
24          int     myDT = DTfromHeader;
25          COLR    *scanline = NULL;
26          CMATRIX *pmat = NULL;
# Line 28 | Line 29 | sum_images(const char *fspec, const CMATRIX *cv, FILE
29  
30          if (cv->ncols != 1)
31                  error(INTERNAL, "expected vector in sum_images()");
32 <        for (i = 0; i < cv->nrows; i++) {
33 <                const COLORV    *scv = cv_lval(cv,i);
32 >        for (i = cv->nrows; i-- > 0; ) {
33 >                const int       r = runcnt&1 ? i : cv->nrows-1 - i;
34 >                const COLORV    *scv = cv_lval(cv,r);
35                  int             flat_file = 0;
36                  char            fname[1024];
37                  FILE            *fp;
# Line 39 | Line 41 | sum_images(const char *fspec, const CMATRIX *cv, FILE
41                  char            *err;
42                                                          /* check for zero */
43                  if ((scv[RED] == 0) & (scv[GRN] == 0) & (scv[BLU] == 0) &&
44 <                                (myDT != DTfromHeader) | (i < cv->nrows-1))
44 >                                (myDT != DTfromHeader) | (i > 0))
45                          continue;
46                                                          /* open next picture */
47 <                sprintf(fname, fspec, i);
47 >                sprintf(fname, fspec, r);
48                  if ((fp = fopen(fname, "rb")) == NULL) {
49                          sprintf(errmsg, "cannot open picture '%s'", fname);
50                          error(SYSTEM, errmsg);
51                  }
52 + #ifdef getc_unlocked
53 +                flockfile(fp);
54 + #endif
55                  dt = DTfromHeader;
56                  if ((err = cm_getheader(&dt, NULL, NULL, NULL, NULL, fp)) != NULL)
57                          error(USER, err);
# Line 74 | Line 79 | sum_images(const char *fspec, const CMATRIX *cv, FILE
79                  }
80                                                          /* flat file check */
81                  if ((data_start = ftell(fp)) > 0 && fseek(fp, 0L, SEEK_END) == 0) {
82 <                        flat_file = (ftell(fp) == data_start + sizeof(COLR)*xr*yr);
82 >                        flat_file = (ftell(fp) >= data_start + sizeof(COLR)*xr*yr);
83                          if (fseek(fp, data_start, SEEK_SET) < 0) {
84                                  sprintf(errmsg, "cannot seek on picture '%s'", fname);
85                                  error(SYSTEM, errmsg);
# Line 104 | Line 109 | sum_images(const char *fspec, const CMATRIX *cv, FILE
109          free(scanline);
110          i = cm_write(pmat, myDT, fout);                 /* write picture */
111          cm_free(pmat);                                  /* free data */
112 +        ++runcnt;                                       /* for zig-zagging */
113          return(i);
114   }
115  
116 + /* adjust matrix dimensions according to user size(s) */
117 + static int
118 + alt_dim(CMATRIX *cm, int nr, int nc)
119 + {
120 +        if ((nr <= 0) & (nc <= 0))
121 +                return(0);
122 +        if ((nr == cm->nrows) & (nc == cm->ncols))
123 +                return(0);
124 +        if (nr > 0) {
125 +                if (nc <= 0)
126 +                        nc = cm->nrows*cm->ncols/nr;
127 +                if (nr*nc != cm->nrows*cm->ncols) {
128 +                        fprintf(stderr, "Bad dimensions: %dx%d != %dx%d\n",
129 +                                        nr, nc, cm->nrows, cm->ncols);
130 +                        return(-1);
131 +                }
132 +        } else /* nc > 0 */ {
133 +                nr = cm->nrows*cm->ncols/nc;
134 +                if (nc*nr != cm->nrows*cm->ncols) {
135 +                        fprintf(stderr, "Bad dimensions: %d does not divide %dx%d evenly\n",
136 +                                        nc, cm->nrows, cm->ncols);
137 +                        return(-1);
138 +                }
139 +        }
140 +        cm->nrows = nr;
141 +        cm->ncols = nc;
142 +        return(1);
143 + }
144 +
145   /* check to see if a string contains a %d or %o specification */
146   static int
147   hasNumberFormat(const char *s)
# Line 215 | Line 250 | main(int argc, char *argv[])
250                  nsteps = smtx->ncols;
251                                                  /* load BSDF */
252                  if (argv[a+1][0] != '!' &&
253 <                                (ccp = strrchr(argv[a+1], '.')) != NULL &&
253 >                                (ccp = strrchr(argv[a+1], '.')) > argv[a+1] &&
254                                  !strcasecmp(ccp+1, "XML"))
255                          Tmat = cm_loadBTDF(argv[a+1]);
256                  else
# Line 235 | Line 270 | main(int argc, char *argv[])
270          }
271                                                  /* prepare output stream */
272          if ((ofspec != NULL) & (nsteps == 1) && hasNumberFormat(ofspec)) {
273 <                sprintf(fnbuf, ofspec, 1);
273 >                sprintf(fnbuf, ofspec, 0);
274                  ofspec = fnbuf;
275          }
276          if (ofspec != NULL && !hasNumberFormat(ofspec)) {
# Line 246 | Line 281 | main(int argc, char *argv[])
281                  }
282                  ofspec = NULL;                  /* only need to open once */
283          }
284 <        if (hasNumberFormat(argv[a])) {         /* generating image(s) */
284 >        if (hasNumberFormat(argv[a])) {         /* loading image vector(s) */
285                  if (outfmt != DTrgbe) {
286                          error(WARNING, "changing output type to -oc");
287                          outfmt = DTrgbe;
# Line 288 | Line 323 | main(int argc, char *argv[])
323                          }
324                  else if (!sum_images(argv[a], cmtx, ofp))
325                          return(1);
326 <        } else {                                /* generating vector/matrix */
326 >        } else {                                /* loading view matrix */
327                  CMATRIX *Vmat = cm_load(argv[a], 0, cmtx->nrows, DTfromHeader);
328                  CMATRIX *rmtx = cm_multiply(Vmat, cmtx);
329                  cm_free(Vmat);
# Line 296 | Line 331 | main(int argc, char *argv[])
331                          const char      *wtype = (outfmt==DTascii) ? "w" : "wb";
332                          for (i = 0; i < nsteps; i++) {
333                                  CMATRIX *rvec = cm_column(rmtx, i);
334 <                                if (yres > 0) {
335 <                                        if (xres <= 0)
301 <                                                xres = rvec->nrows/yres;
302 <                                        if (xres*yres != rvec->nrows) {
303 <                                                fprintf(stderr, "Bad resolution: %d != %dx%d\n",
304 <                                                                rvec->nrows, xres, yres);
305 <                                                return(1);
306 <                                        }
307 <                                        rvec->nrows = yres;
308 <                                        rvec->ncols = xres;
309 <                                } else if (xres > 0) {
310 <                                        yres = rvec->nrows/xres;
311 <                                        if (xres*yres != rvec->nrows) {
312 <                                                fprintf(stderr,
313 <                                                        "Bad resolution: %d does not divide %d evenly\n",
314 <                                                                        xres, rvec->nrows);
315 <                                                return(1);
316 <                                        }
317 <                                        rvec->nrows = yres;
318 <                                        rvec->ncols = xres;
319 <                                }
334 >                                if (alt_dim(rvec, yres, xres) < 0)
335 >                                        return(1);
336                                  sprintf(fnbuf, ofspec, i);
337                                  if ((ofp = fopen(fnbuf, wtype)) == NULL) {
338                                          fprintf(stderr,
# Line 335 | Line 351 | main(int argc, char *argv[])
351                                          if ((outfmt != DTrgbe) & (outfmt != DTxyze)) {
352                                                  fprintf(ofp, "NROWS=%d\n", rvec->nrows);
353                                                  fprintf(ofp, "NCOLS=%d\n", rvec->ncols);
354 <                                                fputs("NCOMP=3\n", ofp);
354 >                                                fputncomp(3, ofp);
355                                          }
356                                          if ((outfmt == DTfloat) | (outfmt == DTdouble))
357                                                  fputendian(ofp);
# Line 358 | Line 374 | main(int argc, char *argv[])
374   #endif
375                          if (outfmt != DTascii)
376                                  SET_FILE_BINARY(ofp);
377 +                        if (alt_dim(rmtx, yres, xres) < 0)
378 +                                return(1);
379                          if (headout) {          /* header output */
380                                  newheader("RADIANCE", ofp);
381                                  printargs(argc, argv, ofp);
# Line 365 | Line 383 | main(int argc, char *argv[])
383                                  if ((outfmt != DTrgbe) & (outfmt != DTxyze)) {
384                                          fprintf(ofp, "NROWS=%d\n", rmtx->nrows);
385                                          fprintf(ofp, "NCOLS=%d\n", rmtx->ncols);
386 <                                        fputs("NCOMP=3\n", ofp);
386 >                                        fputncomp(3, ofp);
387                                  }
388                                  if ((outfmt == DTfloat) | (outfmt == DTdouble))
389                                          fputendian(ofp);
# Line 383 | Line 401 | main(int argc, char *argv[])
401          cm_free(cmtx);
402          return(0);
403   userr:
404 <        fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d|c}] DCspec [skyf]\n",
404 >        fprintf(stderr, "Usage: %s [-n nsteps][-o ospec][-x xr][-y yr][-i{f|d|h}][-o{f|d|c}] DCspec [skyf]\n",
405                                  progname);
406 <        fprintf(stderr, "   or: %s [-n nsteps][-o ospec][-i{f|d|h}][-o{f|d|c}] Vspec Tbsdf Dmat.dat [skyf]\n",
406 >        fprintf(stderr, "   or: %s [-n nsteps][-o ospec][-x xr][-y yr][-i{f|d|h}][-o{f|d|c}] Vspec Tbsdf Dmat.dat [skyf]\n",
407                                  progname);
408          return(1);
409   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines