--- ray/src/util/cmatrix.h 2014/01/20 22:18:29 2.3 +++ ray/src/util/cmatrix.h 2018/10/31 22:19:57 2.8 @@ -1,4 +1,4 @@ -/* RCSid $Id: cmatrix.h,v 2.3 2014/01/20 22:18:29 greg Exp $ */ +/* RCSid $Id: cmatrix.h,v 2.8 2018/10/31 22:19:57 greg Exp $ */ /* * Color matrix routine declarations. * @@ -8,6 +8,7 @@ #ifndef _RAD_CMATRIX_H_ #define _RAD_CMATRIX_H_ +#include #include "color.h" #ifdef __cplusplus @@ -15,8 +16,11 @@ extern "C" { #endif /* Data types for file loading */ -enum {DTfromHeader, DTascii, DTfloat, DTdouble, DTrgbe, DTxyze}; +enum {DTfromHeader=0, DTascii, DTrgbe, DTxyze, DTfloat, DTdouble, DTend}; +extern const char *cm_fmt_id[]; +extern const int cm_elem_size[]; + /* A color coefficient matrix -- vectors have ncols==1 */ typedef struct { int nrows, ncols; @@ -25,38 +29,38 @@ typedef struct { #define COLSPEC (sizeof(COLORV)==sizeof(float) ? "%f %f %f" : "%lf %lf %lf") -#define cm_lval(cm,r,c) ((cm)->cmem + 3*((r)*(cm)->ncols + (c))) +#define cm_lval(cm,r,c) ((cm)->cmem + 3*((size_t)(r)*(cm)->ncols + (c))) #define cv_lval(cm,i) ((cm)->cmem + 3*(i)) /* Allocate a color coefficient matrix */ -extern CMATRIX *cm_alloc(int nrows, int ncols); +extern CMATRIX *cm_alloc(int nrows, int ncols); /* Resize color coefficient matrix */ -extern CMATRIX *cm_resize(CMATRIX *cm, int nrows); +extern CMATRIX *cm_resize(CMATRIX *cm, int nrows); #define cm_free(cm) free(cm) -/* Load header to obtain data type */ -extern int getDTfromHeader(FILE *fp); +/* Load header to obtain/check data type and matrix dimensions */ +extern char *cm_getheader(int *dt, int *nr, int *nc, FILE *fp); -/* Allocate and load a matrix from the given file (or stdin if NULL) */ -extern CMATRIX *cm_load(const char *fname, int nrows, int ncols, int dtype); +/* Allocate and load a matrix from the given input (or stdin if NULL) */ +extern CMATRIX *cm_load(const char *inspec, int nrows, int ncols, int dtype); /* Extract a column vector from a matrix */ -extern CMATRIX *cm_column(const CMATRIX *cm, int c); +extern CMATRIX *cm_column(const CMATRIX *cm, int c); /* Scale a matrix by a single value */ -extern CMATRIX *cm_scale(const CMATRIX *cm1, const COLOR sca); +extern CMATRIX *cm_scale(const CMATRIX *cm1, const COLOR sca); /* Multiply two matrices (or a matrix and a vector) and allocate the result */ -extern CMATRIX *cm_multiply(const CMATRIX *cm1, const CMATRIX *cm2); +extern CMATRIX *cm_multiply(const CMATRIX *cm1, const CMATRIX *cm2); -/* print out matrix as ASCII text -- no header */ -extern void cm_print(const CMATRIX *cm, FILE *fp); +/* write out matrix to file (precede by resolution string if picture) */ +extern int cm_write(const CMATRIX *cm, int dtype, FILE *fp); /* Load and convert a matrix BTDF from the given XML file */ -extern CMATRIX *cm_loadBTDF(char *fname); +extern CMATRIX *cm_loadBTDF(char *fname); #ifdef __cplusplus }