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.17 by greg, Wed Jun 5 17:30:56 2024 UTC

# Line 27 | Line 27 | headline(char *s, void *p)
27   {
28          if (formatval(fmt, s))
29                  return(0);
30 <        if (!strncmp(s, "NCOMP=", 6)) {
31 <                ncomp = atoi(s+6);
30 >        if (isncomp(s)) {
31 >                ncomp = ncompval(s);
32                  return(-(ncomp <= 0));
33          }
34          if (!strncmp(s, "NROWS=", 6)) {
# Line 97 | Line 97 | binary_copyf(FILE *fp, int asize)
97          int             y;
98                                          /* check if fseek() useful */
99          if (skip_len > skip_thresh &&
100 <                        fseek(fp, (rmin*width + cmin)*elsiz, SEEK_CUR) == 0) {
100 >                        fseek(fp, ((long)rmin*width + cmin)*elsiz, SEEK_CUR) == 0) {
101 >                int     fd;
102 >                off_t   curpos;
103                  buf = (char *)malloc(ncols*elsiz);
104                  if (!buf)
105                          goto memerr;
106 + #ifdef NON_POSIX
107                  for (y = nrows; y-- > 0; ) {
108                          if (getbinary(buf, elsiz, ncols, fp) != ncols)
109                                  goto readerr;
# Line 112 | Line 115 | binary_copyf(FILE *fp, int asize)
115                                  return(0);
116                          }
117                  }
118 <                free(buf);              /* success! */
119 <                return(1);
118 > #else
119 >                fd = fileno(fp);
120 >                curpos = ftello(fp);
121 >                for (y = nrows; y-- > 0; curpos += width*elsiz) {
122 >                        if (pread(fd, buf, ncols*elsiz,
123 >                                                curpos) != ncols*elsiz)
124 >                                goto readerr;
125 >                        if (putbinary(buf, elsiz, ncols, stdout) != ncols)
126 >                                goto writerr;
127 >                }
128 > #endif
129 >                free(buf);
130 >                if (fflush(stdout) == EOF)
131 >                        goto writerr;
132 >                return(1);              /* success! */
133          }                               /* else need to read it all... */
134          buf = (char *)malloc(width*elsiz);
135          if (!buf)
136                  goto memerr;
137                                          /* skip rows as requested */
138          if (skip_len > skip_thresh ||
139 <                        (rmin && fseek(fp, rmin*width*elsiz, SEEK_CUR) < 0))
139 >                        (rmin && fseek(fp, (long)rmin*width*elsiz, SEEK_CUR) < 0))
140                  for (y = 0; y < rmin; y++)
141                          if (getbinary(buf, elsiz, width, fp) != width)
142                                  goto readerr;
# Line 149 | Line 165 | memerr:
165  
166   /* Read (and copy) specified number of white-space-separated words */
167   static int
168 < readwords(FILE *finp, int nwords, FILE *fout)
168 > readwords(FILE *finp, long nwords, FILE *fout)
169   {
170          while (nwords-- > 0) {
171                  int     c;
# Line 178 | Line 194 | ascii_copyf(FILE *fp)
194          SET_FILE_TEXT(fp);              /* started as binary */
195          SET_FILE_TEXT(stdout);
196                                          /* skip rows as requested */
197 <        if (readwords(fp, rmin*width*ncomp, NULL) < 0)
197 >        if (readwords(fp, (long)rmin*width*ncomp, NULL) < 0)
198                  goto io_err;
199          for (y = 0; y < nrows; y++) {   /* copy part */
200                  if (readwords(fp, cmin*ncomp, NULL) < 0)
# Line 255 | Line 271 | main(int argc, char *argv[])
271          cmin = atoi(argv[2]);
272          nrows = atoi(argv[3]);
273          ncols = atoi(argv[4]);
274 <        if ((rmin < 0) | (cmin < 0) | (nrows < 0) | (ncols < 0))
274 >        if ((rmin < 0) | (cmin < 0))
275                  goto usage;
276          if (argc <= 5)
277                  SET_FILE_BINARY(fp);
# Line 287 | Line 303 | main(int argc, char *argv[])
303                  fputs(": missing input dimensions\n", stderr);
304                  return(1);
305          }
306 <        if (!nrows)
307 <                nrows = numscans(&res) - rmin;
308 <        if (!ncols)
309 <                ncols = scanlen(&res) - cmin;
306 >        if (nrows <= 0 )
307 >                nrows += numscans(&res) - rmin;
308 >        if (ncols <= 0)
309 >                ncols += scanlen(&res) - cmin;
310          if ((nrows <= 0) | (ncols <= 0) |
311                          (rmin+nrows > numscans(&res)) |
312                          (cmin+ncols > scanlen(&res))) {
# Line 307 | Line 323 | main(int argc, char *argv[])
323          if (gotdims)                    /* dimensions + format */
324                  printf("NROWS=%d\nNCOLS=%d\n", nrows, ncols);
325          if (ncomp)
326 <                printf("NCOMP=%d\n", ncomp);
326 >                fputncomp(ncomp, stdout);
327          fputformat(fmt, stdout);        /* will align bytes if it can */
328          fputc('\n', stdout);            /* end of new header */
329          if (!gotdims) {                 /* add resolution string? */
# Line 337 | Line 353 | main(int argc, char *argv[])
353                  asiz = -1;
354                  if (!ncomp) ncomp = 3;
355                  else ncomp *= (ncomp == 3);
356 +        } else if (!strcmp(fmt, SPECFMT)) {
357 +                asiz = ncomp+1;
358 +                ncomp = 1;              /* XXX assumes uncompressed */
359          } else if (strcasecmp(fmt, "ascii")) {
360                  fputs(progname, stderr);
361                  fputs(": unsupported format - ", stderr);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines