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

Comparing ray/src/util/rcrop.c (file contents):
Revision 1.15 by greg, Thu May 16 18:59:19 2024 UTC vs.
Revision 1.18 by greg, Tue Jun 3 21:31:51 2025 UTC

# Line 12 | Line 12 | static const char RCSid[] = "$Id$";
12   #include "fvect.h"
13   #include "view.h"
14  
15 char    *progname;              /* global argv[0] */
16
15   VIEW    vw = STDVIEW;
16   int     gotvw = 0;
17   char    fmt[MAXFMTLEN] = "ascii";       /* assumed when unspecified */
# Line 98 | Line 96 | binary_copyf(FILE *fp, int asize)
96                                          /* check if fseek() useful */
97          if (skip_len > skip_thresh &&
98                          fseek(fp, ((long)rmin*width + cmin)*elsiz, SEEK_CUR) == 0) {
99 +                int     fd;
100                  off_t   curpos;
101                  buf = (char *)malloc(ncols*elsiz);
102                  if (!buf)
# Line 115 | Line 114 | binary_copyf(FILE *fp, int asize)
114                          }
115                  }
116   #else
117 +                fd = fileno(fp);
118                  curpos = ftello(fp);
119                  for (y = nrows; y-- > 0; curpos += width*elsiz) {
120 <                        if (pread(fileno(fp), buf, ncols*elsiz,
120 >                        if (pread(fd, buf, ncols*elsiz,
121                                                  curpos) != ncols*elsiz)
122                                  goto readerr;
123                          if (putbinary(buf, elsiz, ncols, stdout) != ncols)
# Line 257 | Line 257 | main(int argc, char *argv[])
257          FILE    *fp = stdin;
258          int     asiz = 0;
259          int     gotdims;
260 <
261 <        progname = argv[0];
260 >                                /* set global progname */
261 >        fixargv0(argv[0]);
262                                  /* get input and output */
263          if ((argc < 5) | (argc > 7))
264                  goto usage;
# Line 269 | Line 269 | main(int argc, char *argv[])
269          cmin = atoi(argv[2]);
270          nrows = atoi(argv[3]);
271          ncols = atoi(argv[4]);
272 <        if ((rmin < 0) | (cmin < 0) | (nrows < 0) | (ncols < 0))
272 >        if ((rmin < 0) | (cmin < 0))
273                  goto usage;
274          if (argc <= 5)
275                  SET_FILE_BINARY(fp);
# Line 301 | Line 301 | main(int argc, char *argv[])
301                  fputs(": missing input dimensions\n", stderr);
302                  return(1);
303          }
304 <        if (!nrows)
305 <                nrows = numscans(&res) - rmin;
306 <        if (!ncols)
307 <                ncols = scanlen(&res) - cmin;
304 >        if (nrows <= 0 )
305 >                nrows += numscans(&res) - rmin;
306 >        if (ncols <= 0)
307 >                ncols += scanlen(&res) - cmin;
308          if ((nrows <= 0) | (ncols <= 0) |
309                          (rmin+nrows > numscans(&res)) |
310                          (cmin+ncols > scanlen(&res))) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines