--- ray/src/util/rcrop.c 2022/03/21 20:19:19 1.12 +++ ray/src/util/rcrop.c 2023/11/21 02:06:14 1.14 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcrop.c,v 1.12 2022/03/21 20:19:19 greg Exp $"; +static const char RCSid[] = "$Id: rcrop.c,v 1.14 2023/11/21 02:06:14 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)) { @@ -98,9 +98,11 @@ binary_copyf(FILE *fp, int asize) /* check if fseek() useful */ if (skip_len > skip_thresh && fseek(fp, (rmin*width + cmin)*elsiz, SEEK_CUR) == 0) { + off_t curpos; buf = (char *)malloc(ncols*elsiz); if (!buf) goto memerr; +#ifdef NON_POSIX for (y = nrows; y-- > 0; ) { if (getbinary(buf, elsiz, ncols, fp) != ncols) goto readerr; @@ -112,6 +114,16 @@ binary_copyf(FILE *fp, int asize) return(0); } } +#else + curpos = ftello(fp); + for (y = nrows; y-- > 0; curpos += width*elsiz) { + if (pread(fileno(fp), buf, ncols*elsiz, + curpos) != ncols*elsiz) + goto readerr; + if (putbinary(buf, elsiz, ncols, stdout) != ncols) + goto writerr; + } +#endif free(buf); if (fflush(stdout) == EOF) goto writerr; @@ -309,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? */ @@ -339,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);