--- ray/src/util/rcrop.c 2022/04/07 16:58:30 1.13 +++ ray/src/util/rcrop.c 2024/05/17 20:50:57 1.16 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcrop.c,v 1.13 2022/04/07 16:58:30 greg Exp $"; +static const char RCSid[] = "$Id: rcrop.c,v 1.16 2024/05/17 20:50:57 greg Exp $"; #endif /* * rcrop.c - crop a Radiance picture or matrix data @@ -27,8 +27,8 @@ headline(char *s, void *p) { if (formatval(fmt, s)) return(0); - if (!strncmp(s, "NCOMP=", 6)) { - ncomp = atoi(s+6); + if (isncomp(s)) { + ncomp = ncompval(s); return(-(ncomp <= 0)); } if (!strncmp(s, "NROWS=", 6)) { @@ -97,7 +97,7 @@ binary_copyf(FILE *fp, int asize) int y; /* check if fseek() useful */ if (skip_len > skip_thresh && - fseek(fp, (rmin*width + cmin)*elsiz, SEEK_CUR) == 0) { + fseek(fp, ((long)rmin*width + cmin)*elsiz, SEEK_CUR) == 0) { off_t curpos; buf = (char *)malloc(ncols*elsiz); if (!buf) @@ -134,7 +134,7 @@ binary_copyf(FILE *fp, int asize) goto memerr; /* skip rows as requested */ if (skip_len > skip_thresh || - (rmin && fseek(fp, rmin*width*elsiz, SEEK_CUR) < 0)) + (rmin && fseek(fp, (long)rmin*width*elsiz, SEEK_CUR) < 0)) for (y = 0; y < rmin; y++) if (getbinary(buf, elsiz, width, fp) != width) goto readerr; @@ -163,7 +163,7 @@ memerr: /* Read (and copy) specified number of white-space-separated words */ static int -readwords(FILE *finp, int nwords, FILE *fout) +readwords(FILE *finp, long nwords, FILE *fout) { while (nwords-- > 0) { int c; @@ -192,7 +192,7 @@ ascii_copyf(FILE *fp) SET_FILE_TEXT(fp); /* started as binary */ SET_FILE_TEXT(stdout); /* skip rows as requested */ - if (readwords(fp, rmin*width*ncomp, NULL) < 0) + if (readwords(fp, (long)rmin*width*ncomp, NULL) < 0) goto io_err; for (y = 0; y < nrows; y++) { /* copy part */ if (readwords(fp, cmin*ncomp, NULL) < 0) @@ -269,7 +269,7 @@ main(int argc, char *argv[]) cmin = atoi(argv[2]); nrows = atoi(argv[3]); ncols = atoi(argv[4]); - if ((rmin < 0) | (cmin < 0) | (nrows < 0) | (ncols < 0)) + if ((rmin < 0) | (cmin < 0)) goto usage; if (argc <= 5) SET_FILE_BINARY(fp); @@ -301,10 +301,10 @@ main(int argc, char *argv[]) fputs(": missing input dimensions\n", stderr); return(1); } - if (!nrows) - nrows = numscans(&res) - rmin; - if (!ncols) - ncols = scanlen(&res) - cmin; + if (nrows <= 0 ) + nrows += numscans(&res) - rmin; + if (ncols <= 0) + ncols += scanlen(&res) - cmin; if ((nrows <= 0) | (ncols <= 0) | (rmin+nrows > numscans(&res)) | (cmin+ncols > scanlen(&res))) { @@ -321,7 +321,7 @@ main(int argc, char *argv[]) if (gotdims) /* dimensions + format */ printf("NROWS=%d\nNCOLS=%d\n", nrows, ncols); if (ncomp) - printf("NCOMP=%d\n", ncomp); + fputncomp(ncomp, stdout); fputformat(fmt, stdout); /* will align bytes if it can */ fputc('\n', stdout); /* end of new header */ if (!gotdims) { /* add resolution string? */ @@ -351,6 +351,9 @@ main(int argc, char *argv[]) asiz = -1; if (!ncomp) ncomp = 3; else ncomp *= (ncomp == 3); + } else if (!strcmp(fmt, SPECFMT)) { + asiz = ncomp+1; + ncomp = 1; /* XXX assumes uncompressed */ } else if (strcasecmp(fmt, "ascii")) { fputs(progname, stderr); fputs(": unsupported format - ", stderr);