--- ray/src/util/rcrop.c 2022/03/15 01:44:27 1.3 +++ ray/src/util/rcrop.c 2022/03/15 20:21:18 1.7 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcrop.c,v 1.3 2022/03/15 01:44:27 greg Exp $"; +static const char RCSid[] = "$Id: rcrop.c,v 1.7 2022/03/15 20:21:18 greg Exp $"; #endif /* * rcrop.c - crop a Radiance picture or matrix data @@ -79,11 +79,11 @@ colr_copyf(FILE *fp) return(1); writerr: fputs(progname, stderr); - fputs(": error writing scanline\n", stderr); + fputs(": error writing picture\n", stderr); return(0); readerr: fputs(progname, stderr); - fputs(": error reading scanline\n", stderr); + fputs(": error reading picture\n", stderr); return(0); } @@ -234,6 +234,10 @@ main(int argc, char *argv[]) fputs(": cannot open for writing\n", stderr); return(1); } +#ifdef getc_unlocked /* avoid stupid semaphores */ + flockfile(fp); + flockfile(stdout); +#endif /* process information header */ if (getheader(fp, headline, NULL) < 0) { fputs(progname, stderr); @@ -258,7 +262,7 @@ main(int argc, char *argv[]) return(1); } printargs(argc, argv, stdout); - if (gotvw) { + if (gotvw) { /* adjust view? */ double p0[2], p1[2]; const char *err; if (res.rt & YMAJOR) { @@ -287,10 +291,11 @@ main(int argc, char *argv[]) fputs(err, stderr); fputc('\n', stderr); return(1); + } else { + fputs(VIEWSTR, stdout); + fprintview(&vw, stdout); + fputc('\n', stdout); } - fputs(VIEWSTR, stdout); - fprintview(&vw, stdout); - fputc('\n', stdout); } if (gotdims) printf("NROWS=%d\nNCOLS=%d\n", nrows, ncols); @@ -315,9 +320,16 @@ main(int argc, char *argv[]) asiz = sizeof(float); } else if (!strcmp(fmt, "double")) { asiz = sizeof(double); + } else if (!strcmp(fmt, "32-bit_encoded_normal")) { + asiz = 4; + ncomp = 1; + } else if (!strcmp(fmt, "16-bit_encoded_depth")) { + asiz = 2; + ncomp = 1; } else if (globmatch(PICFMT, fmt)) { asiz = -1; if (!ncomp) ncomp = 3; + else ncomp *= (ncomp == 3); } else if (strcasecmp(fmt, "ascii")) { fputs(progname, stderr); fputs(": unsupported format - ", stderr); @@ -333,6 +345,11 @@ main(int argc, char *argv[]) if (!(asiz < 0 ? colr_copyf(fp) : !asiz ? ascii_copyf(fp) : binary_copyf(fp, asiz))) return(1); + /* need to consume the rest? */ + if (fp == stdin && rmin+nrows < numscans(&res) && + fseek(fp, 0L, SEEK_END) < 0) + while (getc(fp) != EOF) + ; return(0); usage: fputs("Usage: ", stderr);