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.48 by greg, Fri Mar 11 02:28:51 2022 UTC vs.
Revision 2.51 by greg, Wed Mar 5 02:54:58 2025 UTC

# Line 47 | Line 47 | sum_images(const char *fspec, const CMATRIX *cv, FILE
47                          sprintf(errmsg, "cannot open picture '%s'", fname);
48                          error(SYSTEM, errmsg);
49                  }
50 + #ifdef getc_unlocked
51 +                flockfile(fp);
52 + #endif
53                  dt = DTfromHeader;
54                  if ((err = cm_getheader(&dt, NULL, NULL, NULL, NULL, fp)) != NULL)
55                          error(USER, err);
# Line 74 | Line 77 | sum_images(const char *fspec, const CMATRIX *cv, FILE
77                  }
78                                                          /* flat file check */
79                  if ((data_start = ftell(fp)) > 0 && fseek(fp, 0L, SEEK_END) == 0) {
80 <                        flat_file = (ftell(fp) == data_start + sizeof(COLR)*xr*yr);
80 >                        flat_file = (ftell(fp) >= data_start + sizeof(COLR)*xr*yr);
81                          if (fseek(fp, data_start, SEEK_SET) < 0) {
82                                  sprintf(errmsg, "cannot seek on picture '%s'", fname);
83                                  error(SYSTEM, errmsg);
# Line 107 | Line 110 | sum_images(const char *fspec, const CMATRIX *cv, FILE
110          return(i);
111   }
112  
113 + /* adjust matrix dimensions according to user size(s) */
114 + static int
115 + alt_dim(CMATRIX *cm, int nr, int nc)
116 + {
117 +        if ((nr <= 0) & (nc <= 0))
118 +                return(0);
119 +        if ((nr == cm->nrows) & (nc == cm->ncols))
120 +                return(0);
121 +        if (nr > 0) {
122 +                if (nc <= 0)
123 +                        nc = cm->nrows*cm->ncols/nr;
124 +                if (nr*nc != cm->nrows*cm->ncols) {
125 +                        fprintf(stderr, "Bad dimensions: %dx%d != %dx%d\n",
126 +                                        nr, nc, cm->nrows, cm->ncols);
127 +                        return(-1);
128 +                }
129 +        } else /* nc > 0 */ {
130 +                nr = cm->nrows*cm->ncols/nc;
131 +                if (nc*nr != cm->nrows*cm->ncols) {
132 +                        fprintf(stderr, "Bad dimensions: %d does not divide %dx%d evenly\n",
133 +                                        nc, cm->nrows, cm->ncols);
134 +                        return(-1);
135 +                }
136 +        }
137 +        cm->nrows = nr;
138 +        cm->ncols = nc;
139 +        return(1);
140 + }
141 +
142   /* check to see if a string contains a %d or %o specification */
143   static int
144   hasNumberFormat(const char *s)
# Line 296 | Line 328 | main(int argc, char *argv[])
328                          const char      *wtype = (outfmt==DTascii) ? "w" : "wb";
329                          for (i = 0; i < nsteps; i++) {
330                                  CMATRIX *rvec = cm_column(rmtx, i);
331 <                                if (yres > 0) {
332 <                                        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 <                                }
331 >                                if (alt_dim(rvec, yres, xres) < 0)
332 >                                        return(1);
333                                  sprintf(fnbuf, ofspec, i);
334                                  if ((ofp = fopen(fnbuf, wtype)) == NULL) {
335                                          fprintf(stderr,
# Line 358 | Line 371 | main(int argc, char *argv[])
371   #endif
372                          if (outfmt != DTascii)
373                                  SET_FILE_BINARY(ofp);
374 +                        if (alt_dim(rmtx, yres, xres) < 0)
375 +                                return(1);
376                          if (headout) {          /* header output */
377                                  newheader("RADIANCE", ofp);
378                                  printargs(argc, argv, ofp);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines