| 62 |
|
int nchildren = 0; /* # of child processes */ |
| 63 |
|
int inchild = -1; /* our child ID (-1: parent) */ |
| 64 |
|
|
| 65 |
< |
static int checksymbolic(ROPMAT *rop); |
| 65 |
> |
extern int checksymbolic(ROPMAT *rop); |
| 66 |
|
|
| 67 |
< |
static int |
| 67 |
> |
int |
| 68 |
|
split_input(ROPMAT *rop) |
| 69 |
|
{ |
| 70 |
|
if (rop->rmp == &rop->imx && !(rop->rmp = rmx_copy(&rop->imx))) { |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
/* Check/set transform based on a reference input file */ |
| 79 |
< |
static int |
| 79 |
> |
int |
| 80 |
|
checkreffile(ROPMAT *rop) |
| 81 |
|
{ |
| 82 |
|
static const char *curRF = NULL; |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
/* Compute conversion row from spectrum to one channel of RGB */ |
| 142 |
< |
static void |
| 142 |
> |
void |
| 143 |
|
rgbrow(ROPMAT *rop, int r, int p) |
| 144 |
|
{ |
| 145 |
|
const int nc = rop->imx.ncomp; |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
/* Compute conversion row from spectrum to one channel of XYZ */ |
| 159 |
< |
static void |
| 159 |
> |
void |
| 160 |
|
xyzrow(ROPMAT *rop, int r, int p) |
| 161 |
|
{ |
| 162 |
|
const int nc = rop->imx.ncomp; |
| 173 |
|
} |
| 174 |
|
|
| 175 |
|
/* Use the spectral sensitivity function to compute matrix coefficients */ |
| 176 |
< |
static void |
| 176 |
> |
void |
| 177 |
|
sensrow(ROPMAT *rop, int r, double (*sf)(SCOLOR sc, int ncs, const float wlpt[4])) |
| 178 |
|
{ |
| 179 |
|
const int nc = rop->imx.ncomp; |
| 188 |
|
} |
| 189 |
|
|
| 190 |
|
/* Check/set symbolic transform */ |
| 191 |
< |
static int |
| 191 |
> |
int |
| 192 |
|
checksymbolic(ROPMAT *rop) |
| 193 |
|
{ |
| 194 |
|
const int nc = rop->imx.ncomp; |
| 302 |
|
return(1); |
| 303 |
|
} |
| 304 |
|
|
| 305 |
< |
static int |
| 305 |
> |
int |
| 306 |
|
get_component_xfm(ROPMAT *rop) |
| 307 |
|
{ |
| 308 |
|
int i, j; |
| 385 |
|
return(1); |
| 386 |
|
} |
| 387 |
|
|
| 388 |
< |
static int |
| 388 |
> |
int |
| 389 |
|
apply_op(RMATRIX *dst, const RMATRIX *src, const RUNARYOP *ro) |
| 390 |
|
{ |
| 391 |
|
if (ro->clen > 0) { |
| 404 |
|
return(1); |
| 405 |
|
} |
| 406 |
|
|
| 407 |
< |
static int |
| 407 |
> |
int |
| 408 |
|
open_input(ROPMAT *rop) |
| 409 |
|
{ |
| 410 |
|
int outtype; |
| 426 |
|
} |
| 427 |
|
|
| 428 |
|
/* Return nominal wavelength associated with input component (return nm) */ |
| 429 |
< |
static double |
| 429 |
> |
double |
| 430 |
|
l_wavelength(char *nam) |
| 431 |
|
{ |
| 432 |
|
double comp = argument(1); |
| 450 |
|
} |
| 451 |
|
|
| 452 |
|
/* Return ith input with optional channel selector */ |
| 453 |
< |
static double |
| 453 |
> |
double |
| 454 |
|
l_chanin(char *nam) |
| 455 |
|
{ |
| 456 |
|
double inp = argument(1); |
| 475 |
|
return(mop[mi].rmp->mtx[cur_col*in_ncomp + chan]); |
| 476 |
|
} |
| 477 |
|
|
| 478 |
< |
static int |
| 478 |
> |
int |
| 479 |
|
initialize(RMATRIX *imp) |
| 480 |
|
{ |
| 481 |
|
int i; |
| 522 |
|
return(1); |
| 523 |
|
} |
| 524 |
|
|
| 525 |
< |
static void |
| 525 |
> |
void |
| 526 |
|
output_headinfo(FILE *fp) |
| 527 |
|
{ |
| 528 |
|
int i; |
| 545 |
|
} |
| 546 |
|
} |
| 547 |
|
|
| 548 |
< |
static int |
| 549 |
< |
output_loop(void) |
| 550 |
< |
{ |
| 551 |
< |
const size_t row_size = rmx_array_size(mop[nmats].rmp); |
| 552 |
< |
int i = nmats; |
| 553 |
< |
int cur_child = 0; |
| 554 |
< |
|
| 555 |
< |
if (mop[nmats].rmp != &mop[nmats].imx) /* output is split? */ |
| 556 |
< |
rmx_reset(&mop[nmats].imx); |
| 557 |
< |
while (i-- > 0) { /* close input matrices */ |
| 558 |
< |
fclose(mop[i].infp); /* ! pclose() */ |
| 559 |
< |
mop[i].infp = NULL; |
| 560 |
< |
rmx_reset(&mop[i].imx); |
| 561 |
< |
if (mop[i].rmp != &mop[i].imx) { |
| 562 |
< |
rmx_free(mop[i].rmp); |
| 563 |
< |
mop[i].rmp = &mop[i].imx; |
| 564 |
< |
} |
| 565 |
< |
} |
| 566 |
< |
#ifdef getc_unlocked |
| 567 |
< |
flockfile(stdout); /* we own this, now */ |
| 568 |
< |
#endif |
| 569 |
< |
for ( ; ; ) { /* loop until no more */ |
| 570 |
< |
ssize_t rv; |
| 571 |
< |
rv = readbuf(cproc[cur_child].r, mop[nmats].rmp->mtx, row_size); |
| 572 |
< |
if (!rv) /* out of rows? */ |
| 573 |
< |
break; |
| 574 |
< |
if (rv != row_size) { |
| 575 |
< |
fputs("Read error in output loop\n", stderr); |
| 576 |
< |
return(0); |
| 577 |
< |
} /* do final conversion */ |
| 578 |
< |
if (!rmx_write_data(mop[nmats].rmp->mtx, mop[nmats].rmp->ncomp, |
| 579 |
< |
mop[nmats].rmp->ncols, mop[nmats].rmp->dtype, stdout)) { |
| 580 |
< |
fputs("Conversion/write error in output loop\n", stderr); |
| 581 |
< |
return(0); |
| 582 |
< |
} |
| 583 |
< |
cur_child++; |
| 584 |
< |
cur_child *= (cur_child < inchild); |
| 585 |
< |
} |
| 586 |
< |
return(fflush(stdout) != EOF); |
| 587 |
< |
} |
| 588 |
< |
|
| 589 |
< |
static int |
| 548 |
> |
int |
| 549 |
|
spawned_children(int np) |
| 550 |
|
{ |
| 551 |
|
int i, rv; |
| 622 |
|
while (i-- > 0) /* only parent writes siblings */ |
| 623 |
|
close(cproc[i].w); |
| 624 |
|
|
| 625 |
< |
if (inchild == nchildren-1) /* last child sequences output */ |
| 626 |
< |
exit(output_loop() ? 0 : 1); |
| 625 |
> |
if (inchild == nchildren-1) |
| 626 |
> |
return(-1); /* output process return value */ |
| 627 |
|
|
| 628 |
|
i = inchild; /* won't read from siblings */ |
| 629 |
|
while (i-- > 0) |
| 647 |
|
exit(1); |
| 648 |
|
} |
| 649 |
|
|
| 650 |
< |
static int |
| 650 |
> |
int |
| 651 |
|
parent_loop(void) |
| 652 |
|
{ |
| 653 |
|
int i; |
| 695 |
|
exit(1); |
| 696 |
|
} |
| 697 |
|
|
| 698 |
< |
static int |
| 698 |
> |
int |
| 699 |
|
combine_input(void) |
| 700 |
|
{ |
| 701 |
|
const int row0 = (inchild >= 0)*inchild; |
| 790 |
|
return(0); |
| 791 |
|
} |
| 792 |
|
|
| 793 |
< |
static int |
| 793 |
> |
int |
| 794 |
> |
output_loop(void) |
| 795 |
> |
{ |
| 796 |
> |
const size_t row_size = rmx_array_size(mop[nmats].rmp); |
| 797 |
> |
int i = nmats; |
| 798 |
> |
int cur_child = 0; |
| 799 |
> |
|
| 800 |
> |
if (mop[nmats].rmp != &mop[nmats].imx) /* output is split? */ |
| 801 |
> |
rmx_reset(&mop[nmats].imx); |
| 802 |
> |
while (i-- > 0) { /* close input matrices */ |
| 803 |
> |
fclose(mop[i].infp); /* ! pclose() */ |
| 804 |
> |
mop[i].infp = NULL; |
| 805 |
> |
rmx_reset(&mop[i].imx); |
| 806 |
> |
if (mop[i].rmp != &mop[i].imx) { |
| 807 |
> |
rmx_free(mop[i].rmp); |
| 808 |
> |
mop[i].rmp = &mop[i].imx; |
| 809 |
> |
} |
| 810 |
> |
} |
| 811 |
> |
#ifdef getc_unlocked |
| 812 |
> |
flockfile(stdout); /* we own this, now */ |
| 813 |
> |
#endif |
| 814 |
> |
for ( ; ; ) { /* loop until no more */ |
| 815 |
> |
ssize_t rv; |
| 816 |
> |
rv = readbuf(cproc[cur_child].r, mop[nmats].rmp->mtx, row_size); |
| 817 |
> |
if (!rv) /* out of rows? */ |
| 818 |
> |
break; |
| 819 |
> |
if (rv != row_size) { |
| 820 |
> |
fputs("Read error in output loop\n", stderr); |
| 821 |
> |
return(0); |
| 822 |
> |
} /* do final conversion */ |
| 823 |
> |
if (!rmx_write_data(mop[nmats].rmp->mtx, mop[nmats].rmp->ncomp, |
| 824 |
> |
mop[nmats].rmp->ncols, mop[nmats].rmp->dtype, stdout)) { |
| 825 |
> |
fputs("Conversion/write error in output loop\n", stderr); |
| 826 |
> |
return(0); |
| 827 |
> |
} |
| 828 |
> |
cur_child++; |
| 829 |
> |
cur_child *= (cur_child < inchild); |
| 830 |
> |
} |
| 831 |
> |
return(fflush(stdout) != EOF); |
| 832 |
> |
} |
| 833 |
> |
|
| 834 |
> |
int |
| 835 |
|
get_factors(double da[], int n, char *av[]) |
| 836 |
|
{ |
| 837 |
|
int ac; |
| 841 |
|
return(ac); |
| 842 |
|
} |
| 843 |
|
|
| 844 |
< |
static void |
| 844 |
> |
void |
| 845 |
|
resize_inparr(int n2alloc) |
| 846 |
|
{ |
| 847 |
|
int i; |
| 1044 |
|
return(1); |
| 1045 |
|
} |
| 1046 |
|
doptimize(1); /* optimize definitions */ |
| 1047 |
< |
if (spawned_children(nproc)) /* running in parent process? */ |
| 1047 |
> |
i = spawned_children(nproc); /* create multiple processes if requested */ |
| 1048 |
> |
if (i > 0) /* running in parent process? */ |
| 1049 |
|
return(parent_loop() ? 0 : 1); |
| 1050 |
< |
/* process & write rows */ |
| 1050 |
> |
if (i < 0) /* running in output process? */ |
| 1051 |
> |
return(output_loop() ? 0 : 1); |
| 1052 |
> |
/* else we are a worker process */ |
| 1053 |
|
return(combine_input() ? 0 : 1); |
| 1054 |
|
stdin_error: |
| 1055 |
|
fprintf(stderr, "%s: %s used for more than one input\n", |