--- ray/src/util/cmatrix.c 2020/03/26 02:48:31 2.26 +++ ray/src/util/cmatrix.c 2020/03/30 20:41:47 2.28 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: cmatrix.c,v 2.26 2020/03/26 02:48:31 greg Exp $"; +static const char RCSid[] = "$Id: cmatrix.c,v 2.28 2020/03/30 20:41:47 greg Exp $"; #endif /* * Color matrix routines. @@ -181,10 +181,6 @@ cm_load_rgbe(FILE *fp, int nrows, int ncols, COLOR sca CMATRIX *cm; COLORV *mp; /* header already loaded */ - if ((nrows <= 0) | (ncols <= 0) && !fscnresolu(&ncols, &nrows, fp)) { - error(USER, "bad picture resolution string"); - return(NULL); - } cm = cm_alloc(nrows, ncols); if (!cm) return(NULL); @@ -242,9 +238,9 @@ cm_load(const char *inspec, int nrows, int ncols, int char *err = cm_getheader(&dtype, &nrows, &ncols, &swap, scale, fp); if (err) error(USER, err); - if (ncols <= 0) - error(USER, "unspecified number of columns"); } + if (ncols <= 0 && !fscnresolu(&ncols, &nrows, fp)) + error(USER, "unspecified number of columns"); switch (dtype) { case DTascii: case DTfloat: @@ -259,20 +255,19 @@ cm_load(const char *inspec, int nrows, int ncols, int } if (nrows <= 0) { /* don't know length? */ int guessrows = 147; /* usually big enough */ - if ((dtype != DTascii) & (fp != stdin) & (inspec[0] != '!')) { + if (cm_elem_size[dtype] && (fp != stdin) & (inspec[0] != '!')) { long startpos = ftell(fp); if (fseek(fp, 0L, SEEK_END) == 0) { + long rowsiz = (long)ncols*cm_elem_size[dtype]; long endpos = ftell(fp); - long elemsiz = 3*(dtype==DTfloat ? - sizeof(float) : sizeof(double)); - if ((endpos - startpos) % (ncols*elemsiz)) { + if ((endpos - startpos) % rowsiz) { sprintf(errmsg, "improper length for binary file '%s'", inspec); error(USER, errmsg); } - guessrows = (endpos - startpos)/(ncols*elemsiz); + guessrows = (endpos - startpos)/rowsiz; if (fseek(fp, startpos, SEEK_SET) < 0) { sprintf(errmsg, "fseek() error on file '%s'",