1 |
/* RCSid $Id: cmatrix.h,v 2.2 2014/01/20 21:30:34 greg Exp $ */ |
2 |
/* |
3 |
* Color matrix routine declarations. |
4 |
* |
5 |
* G. Ward |
6 |
*/ |
7 |
|
8 |
#ifndef _RAD_CMATRIX_H_ |
9 |
#define _RAD_CMATRIX_H_ |
10 |
|
11 |
#include "color.h" |
12 |
|
13 |
#ifdef __cplusplus |
14 |
extern "C" { |
15 |
#endif |
16 |
|
17 |
/* Data types for file loading */ |
18 |
enum {DTfromHeader, DTascii, DTfloat, DTdouble, DTrgbe, DTxyze}; |
19 |
|
20 |
/* A color coefficient matrix -- vectors have ncols==1 */ |
21 |
typedef struct { |
22 |
int nrows, ncols; |
23 |
COLORV cmem[3]; /* extends struct */ |
24 |
} CMATRIX; |
25 |
|
26 |
#define COLSPEC (sizeof(COLORV)==sizeof(float) ? "%f %f %f" : "%lf %lf %lf") |
27 |
|
28 |
#define cm_lval(cm,r,c) ((cm)->cmem + 3*((r)*(cm)->ncols + (c))) |
29 |
|
30 |
#define cv_lval(cm,i) ((cm)->cmem + 3*(i)) |
31 |
|
32 |
/* Allocate a color coefficient matrix */ |
33 |
extern CMATRIX *cm_alloc(int nrows, int ncols); |
34 |
|
35 |
/* Resize color coefficient matrix */ |
36 |
extern CMATRIX *cm_resize(CMATRIX *cm, int nrows); |
37 |
|
38 |
#define cm_free(cm) free(cm) |
39 |
|
40 |
/* Load header to obtain data type */ |
41 |
extern int getDTfromHeader(FILE *fp); |
42 |
|
43 |
/* Allocate and load a matrix from the given file (or stdin if NULL) */ |
44 |
extern CMATRIX *cm_load(const char *fname, int nrows, int ncols, int dtype); |
45 |
|
46 |
/* Extract a column vector from a matrix */ |
47 |
extern CMATRIX *cm_column(const CMATRIX *cm, int c); |
48 |
|
49 |
/* Scale a matrix by a single value */ |
50 |
extern CMATRIX *cm_scale(const CMATRIX *cm1, const COLOR sca); |
51 |
|
52 |
/* Multiply two matrices (or a matrix and a vector) and allocate the result */ |
53 |
extern CMATRIX *cm_multiply(const CMATRIX *cm1, const CMATRIX *cm2); |
54 |
|
55 |
/* print out matrix as ASCII text -- no header */ |
56 |
extern void cm_print(const CMATRIX *cm, FILE *fp); |
57 |
|
58 |
/* Load and convert a matrix BTDF from the given XML file */ |
59 |
extern CMATRIX *cm_loadBTDF(char *fname); |
60 |
|
61 |
#ifdef __cplusplus |
62 |
} |
63 |
#endif |
64 |
#endif /* _RAD_CMATRIX_H_ */ |