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.11 by greg, Wed Mar 16 16:48:39 2022 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 27 | Line 25 | headline(char *s, void *p)
25   {
26          if (formatval(fmt, s))
27                  return(0);
28 <        if (!strncmp(s, "NCOMP=", 6)) {
29 <                ncomp = atoi(s+6);
28 >        if (isncomp(s)) {
29 >                ncomp = ncompval(s);
30                  return(-(ncomp <= 0));
31          }
32          if (!strncmp(s, "NROWS=", 6)) {
# Line 97 | Line 95 | binary_copyf(FILE *fp, int asize)
95          int             y;
96                                          /* check if fseek() useful */
97          if (skip_len > skip_thresh &&
98 <                        fseek(fp, (rmin*width + cmin)*elsiz, SEEK_CUR) == 0) {
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)
103                          goto memerr;
104 + #ifdef NON_POSIX
105                  for (y = nrows; y-- > 0; ) {
106                          if (getbinary(buf, elsiz, ncols, fp) != ncols)
107                                  goto readerr;
# Line 112 | Line 113 | binary_copyf(FILE *fp, int asize)
113                                  return(0);
114                          }
115                  }
116 <                free(buf);              /* success! */
117 <                return(1);
116 > #else
117 >                fd = fileno(fp);
118 >                curpos = ftello(fp);
119 >                for (y = nrows; y-- > 0; curpos += width*elsiz) {
120 >                        if (pread(fd, buf, ncols*elsiz,
121 >                                                curpos) != ncols*elsiz)
122 >                                goto readerr;
123 >                        if (putbinary(buf, elsiz, ncols, stdout) != ncols)
124 >                                goto writerr;
125 >                }
126 > #endif
127 >                free(buf);
128 >                if (fflush(stdout) == EOF)
129 >                        goto writerr;
130 >                return(1);              /* success! */
131          }                               /* else need to read it all... */
132          buf = (char *)malloc(width*elsiz);
133          if (!buf)
134                  goto memerr;
135                                          /* skip rows as requested */
136          if (skip_len > skip_thresh ||
137 <                        (rmin && fseek(fp, rmin*width*elsiz, SEEK_CUR) < 0))
137 >                        (rmin && fseek(fp, (long)rmin*width*elsiz, SEEK_CUR) < 0))
138                  for (y = 0; y < rmin; y++)
139                          if (getbinary(buf, elsiz, width, fp) != width)
140                                  goto readerr;
# Line 149 | Line 163 | memerr:
163  
164   /* Read (and copy) specified number of white-space-separated words */
165   static int
166 < readwords(FILE *finp, int nwords, FILE *fout)
166 > readwords(FILE *finp, long nwords, FILE *fout)
167   {
168          while (nwords-- > 0) {
169                  int     c;
# Line 178 | Line 192 | ascii_copyf(FILE *fp)
192          SET_FILE_TEXT(fp);              /* started as binary */
193          SET_FILE_TEXT(stdout);
194                                          /* skip rows as requested */
195 <        if (readwords(fp, rmin*width*ncomp, NULL) < 0)
195 >        if (readwords(fp, (long)rmin*width*ncomp, NULL) < 0)
196                  goto io_err;
197          for (y = 0; y < nrows; y++) {   /* copy part */
198                  if (readwords(fp, cmin*ncomp, NULL) < 0)
# Line 243 | 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 255 | 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 287 | 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))) {
# Line 307 | Line 321 | main(int argc, char *argv[])
321          if (gotdims)                    /* dimensions + format */
322                  printf("NROWS=%d\nNCOLS=%d\n", nrows, ncols);
323          if (ncomp)
324 <                printf("NCOMP=%d\n", ncomp);
324 >                fputncomp(ncomp, stdout);
325          fputformat(fmt, stdout);        /* will align bytes if it can */
326          fputc('\n', stdout);            /* end of new header */
327          if (!gotdims) {                 /* add resolution string? */
# Line 337 | Line 351 | main(int argc, char *argv[])
351                  asiz = -1;
352                  if (!ncomp) ncomp = 3;
353                  else ncomp *= (ncomp == 3);
354 +        } else if (!strcmp(fmt, SPECFMT)) {
355 +                asiz = ncomp+1;
356 +                ncomp = 1;              /* XXX assumes uncompressed */
357          } else if (strcasecmp(fmt, "ascii")) {
358                  fputs(progname, stderr);
359                  fputs(": unsupported format - ", stderr);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines