--- ray/src/util/rcrop.c 2022/03/15 02:28:05 1.4 +++ ray/src/util/rcrop.c 2022/03/16 01:51:16 1.9 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcrop.c,v 1.4 2022/03/15 02:28:05 greg Exp $"; +static const char RCSid[] = "$Id: rcrop.c,v 1.9 2022/03/16 01:51:16 greg Exp $"; #endif /* * rcrop.c - crop a Radiance picture or matrix data @@ -18,7 +18,7 @@ char *progname; /* global argv[0] */ VIEW vw = STDVIEW; int gotvw = 0; -char fmt[MAXFMTLEN] = "Unknown"; +char fmt[MAXFMTLEN] = "ascii"; /* assumed when unspecified */ int ncomp = 0; RESOLU res; int rmin, cmin, nrows, ncols; @@ -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); @@ -257,7 +261,7 @@ main(int argc, char *argv[]) fputs(": illegal crop\n", stderr); return(1); } - printargs(argc, argv, stdout); + printargs(5, argv, stdout); if (gotvw) { /* adjust view? */ double p0[2], p1[2]; const char *err; @@ -267,10 +271,10 @@ main(int argc, char *argv[]) p1[0] = (cmin+ncols)/(double)res.xr; p1[1] = (rmin+nrows)/(double)res.yr; } else { - p0[1] = cmin/(double)res.xr; - p0[0] = rmin/(double)res.yr; - p1[1] = (cmin+ncols)/(double)res.xr; - p1[0] = (rmin+nrows)/(double)res.yr; + p0[0] = rmin/(double)res.xr; + p0[1] = cmin/(double)res.yr; + p1[0] = (rmin+nrows)/(double)res.xr; + p1[1] = (cmin+ncols)/(double)res.yr; } if (res.rt & XDECR) { p0[0] = 1. - p0[0]; @@ -316,6 +320,12 @@ 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; @@ -335,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);