1 |
/* RCSid $Id: cmatrix.h,v 2.15 2025/04/04 18:06:48 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 <sys/types.h> |
12 |
#include "color.h" |
13 |
|
14 |
#ifdef __cplusplus |
15 |
extern "C" { |
16 |
#endif |
17 |
|
18 |
/* Data types for file loading (used to be an enum) */ |
19 |
#define DTfromHeader 0 |
20 |
#define DTrgbe 1 |
21 |
#define DTxyze 2 |
22 |
#define DTspec 3 |
23 |
#define DTfloat 4 |
24 |
#define DTascii 5 |
25 |
#define DTdouble 6 |
26 |
#define DTend 7 |
27 |
|
28 |
/* Defined in cmconst.c */ |
29 |
extern const char stdin_name[]; |
30 |
extern const char *cm_fmt_id[]; |
31 |
extern const int cm_elem_size[]; |
32 |
|
33 |
/* A color coefficient matrix -- vectors have ncols==1 */ |
34 |
typedef struct { |
35 |
int nrows, ncols; |
36 |
COLORV cmem[3]; /* extends struct */ |
37 |
} CMATRIX; |
38 |
|
39 |
#define COLSPEC (sizeof(COLORV)==sizeof(float) ? "%f %f %f" : "%lf %lf %lf") |
40 |
|
41 |
#define cm_lval(cm,r,c) ((cm)->cmem + 3*((size_t)(r)*(cm)->ncols + (c))) |
42 |
|
43 |
#define cv_lval(cm,i) ((cm)->cmem + 3*(i)) |
44 |
|
45 |
/* Allocate a color coefficient matrix */ |
46 |
extern CMATRIX *cm_alloc(int nrows, int ncols); |
47 |
|
48 |
/* Resize color coefficient matrix */ |
49 |
extern CMATRIX *cm_resize(CMATRIX *cm, int nrows); |
50 |
|
51 |
#define cm_free(cm) free(cm) |
52 |
|
53 |
/* Load header to obtain/check data type and matrix dimensions */ |
54 |
extern char *cm_getheader(int *dt, int *nr, int *nc, |
55 |
int *swp, COLOR scale, FILE *fp); |
56 |
|
57 |
/* Allocate and load a matrix from the given input (or stdin if NULL) */ |
58 |
extern CMATRIX *cm_load(const char *inspec, int nrows, int ncols, int dtype); |
59 |
|
60 |
/* Extract a column vector from a matrix */ |
61 |
extern CMATRIX *cm_column(const CMATRIX *cm, int c); |
62 |
|
63 |
/* Multiply two matrices (or a matrix and a vector) and allocate the result */ |
64 |
extern CMATRIX *cm_multiply(const CMATRIX *cm1, const CMATRIX *cm2); |
65 |
|
66 |
/* write out matrix to file (precede by resolution string if picture) */ |
67 |
extern int cm_write(const CMATRIX *cm, int dtype, FILE *fp); |
68 |
|
69 |
/* Load and convert a matrix BTDF from the given XML file */ |
70 |
extern CMATRIX *cm_loadBTDF(const char *fname); |
71 |
|
72 |
/* Load and convert a matrix BRDF from the given XML file */ |
73 |
extern CMATRIX *cm_loadBRDF(const char *fname, int backside); |
74 |
|
75 |
#ifdef __cplusplus |
76 |
} |
77 |
#endif |
78 |
#endif /* _RAD_CMATRIX_H_ */ |