--- ray/src/util/rcrop.c 2022/03/16 15:50:24 1.10 +++ ray/src/util/rcrop.c 2022/04/07 16:58:30 1.13 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcrop.c,v 1.10 2022/03/16 15:50:24 greg Exp $"; +static const char RCSid[] = "$Id: rcrop.c,v 1.13 2022/04/07 16:58:30 greg Exp $"; #endif /* * rcrop.c - crop a Radiance picture or matrix data @@ -12,8 +12,6 @@ static const char RCSid[] = "$Id: rcrop.c,v 1.10 2022/ #include "fvect.h" #include "view.h" -#define MAXWORD 64 /* maximum word (number) length */ - char *progname; /* global argv[0] */ VIEW vw = STDVIEW; @@ -100,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; @@ -114,8 +114,20 @@ binary_copyf(FILE *fp, int asize) return(0); } } - free(buf); /* success! */ - return(1); +#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; + return(1); /* success! */ } /* else need to read it all... */ buf = (char *)malloc(width*elsiz); if (!buf) @@ -226,14 +238,15 @@ adjust_view(void) p1[1] = 1. - p1[1]; } err = cropview(&vw, p0[0], p0[1], p1[0], p1[1]); - if (err) { - fputs(progname, stderr); - fputs(": view error - ", stderr); - fputs(err, stderr); - fputc('\n', stderr); - return(0); - } - return(1); + + if (!err) + return(1); /* success! */ + + fputs(progname, stderr); + fputs(": view error - ", stderr); + fputs(err, stderr); + fputc('\n', stderr); + return(0); /* something went wrong */ }