9 |
|
#include <math.h> |
10 |
|
#include "platform.h" |
11 |
|
#include "rtio.h" |
12 |
– |
#include "resolu.h" |
12 |
|
#include "rmatrix.h" |
13 |
|
#include "calcomp.h" |
14 |
|
#include "paths.h" |
185 |
|
{ |
186 |
|
const int nc = rop->imx.ncomp; |
187 |
|
const int dt = rop->imx.dtype; |
188 |
+ |
double cf = 1; |
189 |
|
int i, j; |
190 |
|
/* check suffix => reference file */ |
191 |
|
if (strchr(rop->preop.csym, '.') > rop->preop.csym) |
206 |
|
int comp = 0; |
207 |
|
switch (rop->preop.csym[j]) { |
208 |
|
case 'B': |
209 |
+ |
case 'b': |
210 |
|
++comp; |
211 |
|
/* fall through */ |
212 |
|
case 'G': |
213 |
+ |
case 'g': |
214 |
|
++comp; |
215 |
|
/* fall through */ |
216 |
|
case 'R': |
217 |
+ |
case 'r': |
218 |
+ |
if (rop->preop.csym[j] <= 'Z') |
219 |
+ |
cf = 1./WHTEFFICACY; |
220 |
|
if (dt == DTxyze) { |
221 |
|
for (i = 3; i--; ) |
222 |
< |
rop->preop.cmat[j*nc+i] = 1./WHTEFFICACY * |
218 |
< |
xyz2rgbmat[comp][i]; |
222 |
> |
rop->preop.cmat[j*nc+i] = cf*xyz2rgbmat[comp][i]; |
223 |
|
} else if (nc == 3) |
224 |
|
rop->preop.cmat[j*nc+comp] = 1.; |
225 |
|
else |
226 |
|
rgbrow(rop, j, comp); |
227 |
|
break; |
228 |
|
case 'Z': |
229 |
+ |
case 'z': |
230 |
|
++comp; |
231 |
|
/* fall through */ |
232 |
|
case 'Y': |
233 |
+ |
case 'y': |
234 |
|
++comp; |
235 |
|
/* fall through */ |
236 |
|
case 'X': |
237 |
+ |
case 'x': |
238 |
+ |
if ((rop->preop.csym[j] <= 'Z') & (dt != DTxyze)) |
239 |
+ |
cf = WHTEFFICACY; |
240 |
|
if (dt == DTxyze) { |
241 |
|
rop->preop.cmat[j*nc+comp] = 1.; |
242 |
|
} else if (nc == 3) { |
248 |
|
else |
249 |
|
xyzrow(rop, j, comp); |
250 |
|
|
251 |
< |
for (i = nc*(dt != DTxyze); i--; ) |
252 |
< |
rop->preop.cmat[j*nc+i] *= WHTEFFICACY; |
251 |
> |
for (i = nc*(cf != 1); i--; ) |
252 |
> |
rop->preop.cmat[j*nc+i] *= cf; |
253 |
|
break; |
254 |
|
case 'S': /* scotopic (il)luminance */ |
255 |
+ |
cf = WHTSCOTOPIC; |
256 |
+ |
/* fall through */ |
257 |
+ |
case 's': |
258 |
|
sensrow(rop, j, scolor2scotopic); |
259 |
< |
for (i = nc; i--; ) |
260 |
< |
rop->preop.cmat[j*nc+i] *= WHTSCOTOPIC; |
259 |
> |
for (i = nc*(cf != 1); i--; ) |
260 |
> |
rop->preop.cmat[j*nc+i] *= cf; |
261 |
|
break; |
262 |
|
case 'M': /* melanopic (il)luminance */ |
263 |
+ |
cf = WHTMELANOPIC; |
264 |
+ |
/* fall through */ |
265 |
+ |
case 'm': |
266 |
|
sensrow(rop, j, scolor2melanopic); |
267 |
< |
for (i = nc; i--; ) |
268 |
< |
rop->preop.cmat[j*nc+i] *= WHTMELANOPIC; |
267 |
> |
for (i = nc*(cf != 1); i--; ) |
268 |
> |
rop->preop.cmat[j*nc+i] *= cf; |
269 |
|
break; |
270 |
|
case 'A': /* average component */ |
271 |
+ |
case 'a': |
272 |
|
for (i = nc; i--; ) |
273 |
|
rop->preop.cmat[j*nc+i] = 1./(double)nc; |
274 |
|
break; |
283 |
|
memcpy(rop->rmp->wlpart, WLPART, sizeof(rop->rmp->wlpart)); |
284 |
|
rop->rmp->ncomp = rop->preop.clen / nc; |
285 |
|
/* decide on output type */ |
286 |
< |
if (!strcmp(rop->preop.csym, "XYZ")) { |
286 |
> |
if (!strcasecmp(rop->preop.csym, "XYZ")) { |
287 |
|
if (dt <= DTspec) |
288 |
|
rop->rmp->dtype = DTxyze; |
289 |
< |
} else if (!strcmp(rop->preop.csym, "RGB")) { |
289 |
> |
} else if (!strcasecmp(rop->preop.csym, "RGB")) { |
290 |
|
if (dt <= DTspec) |
291 |
|
rop->rmp->dtype = DTrgbe; |
292 |
|
} else if (rop->rmp->dtype == DTspec) |
591 |
|
RMATRIX *mres = NULL; |
592 |
|
for (i = 0; i < nmats; i++) { |
593 |
|
if (!rmx_load_row(mop[i].imx.mtx, &mop[i].imx, mop[i].infp)) { |
594 |
< |
if (in_nrows <= 0) /* normal end? */ |
594 |
> |
if (cur_row > in_nrows) /* unknown #input rows? */ |
595 |
|
goto loop_exit; |
596 |
|
fprintf(stderr, "%s: read error at row %d\n", |
597 |
|
mop[i].inspec, cur_row); |
679 |
|
{ |
680 |
|
int i; |
681 |
|
|
682 |
< |
for (i = nmats; i > n2alloc; i--) { |
682 |
> |
if (n2alloc == nall) |
683 |
> |
return; |
684 |
> |
for (i = nall; i > n2alloc; i--) { |
685 |
|
rmx_reset(&mop[i].imx); |
686 |
|
if (mop[i].rmp != &mop[i].imx) |
687 |
|
rmx_free(mop[i].rmp); |
691 |
|
fputs("Out of memory in resize_inparr()\n", stderr); |
692 |
|
exit(1); |
693 |
|
} |
694 |
< |
if (n2alloc > nmats) |
695 |
< |
memset(mop+nmats, 0, (n2alloc-nmats)*sizeof(ROPMAT)); |
694 |
> |
if (n2alloc > nall) |
695 |
> |
memset(mop+nall, 0, (n2alloc-nall)*sizeof(ROPMAT)); |
696 |
|
nall = n2alloc; |
697 |
|
} |
698 |
|
|
869 |
|
fprintf(stderr, "%s: unsupported output format\n", argv[0]); |
870 |
|
return(1); |
871 |
|
} |
872 |
+ |
doptimize(1); /* optimize definitions */ |
873 |
|
/* process & write rows */ |
874 |
|
return(combine_input(&mop[nmats], stdout) ? 0 : 1); |
875 |
|
stdin_error: |