--- ray/src/util/rmatrix.c 2014/08/28 05:59:42 2.9 +++ ray/src/util/rmatrix.c 2015/01/23 01:14:20 2.12 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rmatrix.c,v 2.9 2014/08/28 05:59:42 greg Exp $"; +static const char RCSid[] = "$Id: rmatrix.c,v 2.12 2015/01/23 01:14:20 greg Exp $"; #endif /* * General matrix operations. @@ -246,6 +246,7 @@ rmx_load(const char *fname) case DTascii: if (!rmx_load_ascii(dnew, fp)) goto loaderr; + dnew->dtype = DTascii; /* should leave double? */ break; case DTfloat: if (!rmx_load_float(dnew, fp)) @@ -356,7 +357,7 @@ rmx_write_rgbe(const RMATRIX *rm, FILE *fp) } /* Write matrix to file type indicated by dtype */ -long +int rmx_write(const RMATRIX *rm, int dtype, FILE *fp) { RMATRIX *mydm = NULL; @@ -409,7 +410,7 @@ rmx_write(const RMATRIX *rm, int dtype, FILE *fp) } ok &= (fflush(fp) == 0); rmx_free(mydm); - return(ftell(fp) * ok); /* return # bytes written */ + return(ok); } /* Allocate and assign square identity matrix with n components */ @@ -417,16 +418,14 @@ RMATRIX * rmx_identity(const int dim, const int n) { RMATRIX *rid = rmx_alloc(dim, dim, n); - int i; + int i, k; if (rid == NULL) return(NULL); - memset(rid->mtx, 0, sizeof(rid->mtx[0])*dim*dim); + memset(rid->mtx, 0, sizeof(rid->mtx[0])*n*dim*dim); for (i = dim; i--; ) - rmx_lval(rid,i,i,0) = 1; - for (i = n; --i; ) - memcpy(rid->mtx+i*(dim*dim), rid->mtx, - sizeof(rid->mtx[0])*dim*dim); + for (k = n; k--; ) + rmx_lval(rid,i,i,k) = 1; return(rid); }