7 |
|
|
8 |
|
#include <errno.h> |
9 |
|
#include "rtio.h" |
10 |
– |
#include "resolu.h" |
10 |
|
#include "rmatrix.h" |
11 |
|
#include "platform.h" |
12 |
|
|
13 |
< |
#define MAXCOMP MAXCSAMP /* #components we support */ |
13 |
> |
/* Preferred BSDF component: |
14 |
> |
none, transmission, reflection front (normal side), reflection back */ |
15 |
> |
typedef enum {RMPnone=-1, RMPtrans=0, RMPreflF, RMPreflB} RMPref; |
16 |
|
|
17 |
|
/* Unary matrix operation(s) */ |
18 |
|
typedef struct { |
36 |
|
int verbose = 0; /* verbose reporting? */ |
37 |
|
|
38 |
|
/* Load matrix */ |
39 |
< |
static int |
39 |
> |
int |
40 |
|
loadmatrix(ROPMAT *rop) |
41 |
|
{ |
42 |
< |
if (rop->mtx != NULL) /* already loaded? */ |
42 |
> |
if (rop->mtx) /* already loaded? */ |
43 |
|
return(0); |
44 |
+ |
/* check for BSDF input */ |
45 |
+ |
if ((rop->inspec[0] != '!') & (rop->rmp != RMPnone)) { |
46 |
+ |
const char *sp = strrchr(rop->inspec, '.'); |
47 |
+ |
if (sp > rop->inspec && !strcasecmp(sp+1, "XML")) { |
48 |
+ |
CMATRIX *cm = rop->rmp==RMPtrans ? cm_loadBTDF(rop->inspec) : |
49 |
+ |
cm_loadBRDF(rop->inspec, rop->rmp==RMPreflB) ; |
50 |
+ |
if (!cm) |
51 |
+ |
return(-1); |
52 |
+ |
rop->mtx = rmx_from_cmatrix(cm); |
53 |
+ |
cm_free(cm); |
54 |
+ |
if (!rop->mtx) |
55 |
+ |
return(-1); |
56 |
+ |
rop->mtx->dtype = DTascii; |
57 |
+ |
return(1); /* loaded BSDF XML file */ |
58 |
+ |
} |
59 |
+ |
} /* else load regular matrix */ |
60 |
+ |
rop->mtx = rmx_load(rop->inspec); |
61 |
|
|
62 |
< |
rop->mtx = rmx_load(rop->inspec, rop->rmp); |
45 |
< |
|
46 |
< |
return(!rop->mtx ? -1 : 1); |
62 |
> |
return(rop->mtx ? 1 : -1); |
63 |
|
} |
64 |
|
|
65 |
< |
static int checksymbolic(ROPMAT *rop); |
65 |
> |
extern int checksymbolic(ROPMAT *rop); |
66 |
|
|
67 |
|
/* Check/set transform based on a reference input file */ |
68 |
< |
static int |
68 |
> |
int |
69 |
|
checkreffile(ROPMAT *rop) |
70 |
|
{ |
71 |
|
static const char *curRF = NULL; |
124 |
|
} |
125 |
|
|
126 |
|
/* Compute conversion row from spectrum to one channel of RGB */ |
127 |
< |
static void |
127 |
> |
void |
128 |
|
rgbrow(ROPMAT *rop, int r, int p) |
129 |
|
{ |
130 |
|
const int nc = rop->mtx->ncomp; |
141 |
|
} |
142 |
|
|
143 |
|
/* Compute conversion row from spectrum to one channel of XYZ */ |
144 |
< |
static void |
144 |
> |
void |
145 |
|
xyzrow(ROPMAT *rop, int r, int p) |
146 |
|
{ |
147 |
|
const int nc = rop->mtx->ncomp; |
158 |
|
} |
159 |
|
|
160 |
|
/* Use the spectral sensitivity function to compute matrix coefficients */ |
161 |
< |
static void |
162 |
< |
sensrow(ROPMAT *rop, int r, double (*sf)(SCOLOR sc, int ncs, const float wlpt[4])) |
161 |
> |
void |
162 |
> |
sensrow(ROPMAT *rop, int r, double (*sf)(const SCOLOR sc, int ncs, const float wlpt[4])) |
163 |
|
{ |
164 |
|
const int nc = rop->mtx->ncomp; |
165 |
|
int i; |
173 |
|
} |
174 |
|
|
175 |
|
/* Check/set symbolic transform */ |
176 |
< |
static int |
176 |
> |
int |
177 |
|
checksymbolic(ROPMAT *rop) |
178 |
|
{ |
179 |
|
const int nc = rop->mtx->ncomp; |
272 |
|
} |
273 |
|
} |
274 |
|
/* return recommended output type */ |
275 |
< |
if (!strcmp(rop->preop.csym, "XYZ")) { |
275 |
> |
if (!strcasecmp(rop->preop.csym, "XYZ")) { |
276 |
|
if (dt <= DTspec) |
277 |
|
return(DTxyze); |
278 |
< |
} else if (!strcmp(rop->preop.csym, "RGB")) { |
278 |
> |
} else if (!strcasecmp(rop->preop.csym, "RGB")) { |
279 |
|
if (dt <= DTspec) |
280 |
|
return(DTrgbe); |
281 |
|
} else if (dt == DTspec) |
284 |
|
} |
285 |
|
|
286 |
|
/* Get matrix and perform unary operations */ |
287 |
< |
static RMATRIX * |
287 |
> |
RMATRIX * |
288 |
|
loadop(ROPMAT *rop) |
289 |
|
{ |
290 |
|
int outtype = 0; |
360 |
|
} |
361 |
|
} |
362 |
|
if (rop->preop.transpose) { /* transpose matrix? */ |
363 |
< |
mres = rmx_transpose(rop->mtx); |
348 |
< |
if (mres == NULL) { |
363 |
> |
if (!rmx_transpose(rop->mtx)) { |
364 |
|
fputs(rop->inspec, stderr); |
365 |
|
fputs(": transpose failed\n", stderr); |
366 |
|
goto failure; |
369 |
|
fputs(rop->inspec, stderr); |
370 |
|
fputs(": transposed rows and columns\n", stderr); |
371 |
|
} |
357 |
– |
rmx_free(rop->mtx); |
358 |
– |
rop->mtx = mres; |
372 |
|
} |
373 |
|
mres = rop->mtx; |
374 |
|
rop->mtx = NULL; |
381 |
|
} |
382 |
|
|
383 |
|
/* Execute binary operation, free matrix arguments and return new result */ |
384 |
< |
static RMATRIX * |
384 |
> |
RMATRIX * |
385 |
|
binaryop(const char *inspec, RMATRIX *mleft, int op, RMATRIX *mright) |
386 |
|
{ |
387 |
|
RMATRIX *mres = NULL; |
458 |
|
} |
459 |
|
|
460 |
|
/* Perform matrix operations from left to right */ |
461 |
< |
static RMATRIX * |
461 |
> |
RMATRIX * |
462 |
|
op_left2right(ROPMAT *mop) |
463 |
|
{ |
464 |
|
RMATRIX *mleft = loadop(mop); |
474 |
|
} |
475 |
|
|
476 |
|
/* Perform matrix operations from right to left */ |
477 |
< |
static RMATRIX * |
477 |
> |
RMATRIX * |
478 |
|
op_right2left(ROPMAT *mop) |
479 |
|
{ |
480 |
|
RMATRIX *mright; |
503 |
|
: (mop)->mtx->ncols) |
504 |
|
|
505 |
|
/* Should we prefer concatenating from rightmost matrix towards left? */ |
506 |
< |
static int |
506 |
> |
int |
507 |
|
prefer_right2left(ROPMAT *mop) |
508 |
|
{ |
509 |
|
int mri = 0; |
530 |
|
return(t_ncols(mop+mri) < t_nrows(mop)); |
531 |
|
} |
532 |
|
|
533 |
< |
static int |
533 |
> |
int |
534 |
|
get_factors(double da[], int n, char *av[]) |
535 |
|
{ |
536 |
|
int ac; |
540 |
|
return(ac); |
541 |
|
} |
542 |
|
|
543 |
< |
static ROPMAT * |
543 |
> |
ROPMAT * |
544 |
|
resize_moparr(ROPMAT *mop, int n2alloc) |
545 |
|
{ |
546 |
|
int nmats = 0; |
548 |
|
|
549 |
|
while (mop[nmats++].binop) |
550 |
|
; |
551 |
< |
for (i = nmats; i > n2alloc; i--) |
551 |
> |
for (i = nmats; i >= n2alloc; i--) |
552 |
|
rmx_free(mop[i].mtx); |
553 |
|
mop = (ROPMAT *)realloc(mop, n2alloc*sizeof(ROPMAT)); |
554 |
|
if (mop == NULL) { |
695 |
|
mres = loadop(mop+nmats); |
696 |
|
if (mres == NULL) |
697 |
|
return(1); |
698 |
< |
if (outfmt == DTfromHeader) /* check data type */ |
698 |
> |
if ((outfmt == DTfromHeader) & (mres->dtype < DTspec)) |
699 |
|
outfmt = mres->dtype; |
700 |
< |
if (outfmt == DTrgbe) { |
700 |
> |
if (outfmt == DTrgbe) { /* check data type */ |
701 |
|
if (mres->ncomp > 3) |
702 |
|
outfmt = DTspec; |
703 |
|
else if (mres->dtype == DTxyze) |
704 |
|
outfmt = DTxyze; |
705 |
|
} |
706 |
+ |
#if DTrmx_native==DTfloat |
707 |
+ |
if (outfmt == DTdouble) |
708 |
+ |
fprintf(stderr, |
709 |
+ |
"%s: warning - writing float result as double\n", |
710 |
+ |
argv[0]); |
711 |
+ |
#endif |
712 |
|
newheader("RADIANCE", stdout); /* write result to stdout */ |
713 |
|
printargs(argc, argv, stdout); |
714 |
|
return(rmx_write(mres, outfmt, stdout) ? 0 : 1); |