| 21 |
|
#define M_PI 3.14159265358979323846 |
| 22 |
|
#endif |
| 23 |
|
|
| 24 |
– |
#define MAXCOMP MAXCSAMP /* #components we support */ |
| 25 |
– |
|
| 24 |
|
/* Unary matrix operation(s) */ |
| 25 |
|
typedef struct { |
| 26 |
|
double cmat[MAXCOMP*MAXCOMP]; /* component transformation */ |
| 62 |
|
|
| 63 |
|
extern int checksymbolic(ROPMAT *rop); |
| 64 |
|
|
| 65 |
+ |
/* Split input matrices to allow for certain operations */ |
| 66 |
|
int |
| 67 |
|
split_input(ROPMAT *rop) |
| 68 |
|
{ |
| 195 |
|
double cf = 1; |
| 196 |
|
int i, j; |
| 197 |
|
/* check suffix => reference file */ |
| 198 |
< |
if (strchr(rop->preop.csym, '.') > rop->preop.csym) |
| 198 |
> |
if (strchr(rop->preop.csym, '.') != NULL) |
| 199 |
|
return(checkreffile(rop)); |
| 200 |
|
|
| 201 |
|
if (nc < 3) { |
| 301 |
|
return(1); |
| 302 |
|
} |
| 303 |
|
|
| 304 |
+ |
/* Set up color transform for matrix */ |
| 305 |
|
int |
| 306 |
|
get_component_xfm(ROPMAT *rop) |
| 307 |
|
{ |
| 385 |
|
return(1); |
| 386 |
|
} |
| 387 |
|
|
| 388 |
+ |
/* Apply the given color transform and/or scaling operation */ |
| 389 |
|
int |
| 390 |
|
apply_op(RMATRIX *dst, const RMATRIX *src, const RUNARYOP *ro) |
| 391 |
|
{ |
| 405 |
|
return(1); |
| 406 |
|
} |
| 407 |
|
|
| 408 |
+ |
/* Open the associated input file and load/check header */ |
| 409 |
|
int |
| 410 |
|
open_input(ROPMAT *rop) |
| 411 |
|
{ |
| 419 |
|
rop->infp = popen(rop->inspec+1, "r"); |
| 420 |
|
else |
| 421 |
|
rop->infp = fopen(rop->inspec, "rb"); |
| 422 |
< |
|
| 422 |
> |
|
| 423 |
> |
if (!rop->infp) { |
| 424 |
> |
fprintf(stderr, "Cannot open for reading: %s\n", |
| 425 |
> |
rop->inspec); |
| 426 |
> |
return(0); |
| 427 |
> |
} |
| 428 |
|
if (!rmx_load_header(&rop->imx, rop->infp)) { |
| 429 |
|
fprintf(stderr, "Bad header from: %s\n", rop->inspec); |
| 430 |
|
return(0); |
| 482 |
|
return(mop[mi].rmp->mtx[cur_col*in_ncomp + chan]); |
| 483 |
|
} |
| 484 |
|
|
| 485 |
+ |
/* Set up our operations and check consistency */ |
| 486 |
|
int |
| 487 |
|
initialize(RMATRIX *imp) |
| 488 |
|
{ |
| 530 |
|
return(1); |
| 531 |
|
} |
| 532 |
|
|
| 533 |
+ |
/* Copy input header information to output header, indented */ |
| 534 |
|
void |
| 535 |
|
output_headinfo(FILE *fp) |
| 536 |
|
{ |
| 554 |
|
} |
| 555 |
|
} |
| 556 |
|
|
| 557 |
+ |
/* Spawn the indicated number of children and return 1 in parent */ |
| 558 |
|
int |
| 559 |
|
spawned_children(int np) |
| 560 |
|
{ |
| 662 |
|
exit(1); |
| 663 |
|
} |
| 664 |
|
|
| 665 |
+ |
/* Run parental feeder loop */ |
| 666 |
|
int |
| 667 |
|
parent_loop(void) |
| 668 |
|
{ |
| 684 |
|
if (!rmx_load_row(mop[i].imx.mtx, &mop[i].imx, mop[i].infp)) { |
| 685 |
|
if (cur_row > in_nrows) /* unknown #input rows? */ |
| 686 |
|
break; |
| 687 |
< |
fprintf(stderr, "%s: parent_loop() load error at row %d\n", |
| 687 |
> |
fprintf(stderr, "%s: load error at row %d\n", |
| 688 |
|
mop[i].inspec, cur_row); |
| 689 |
|
return(0); |
| 690 |
|
} |
| 693 |
|
for (i = 0; i < nmats; i++) |
| 694 |
|
if (writebuf(wfd, mop[i].imx.mtx, rmx_array_size(&mop[i].imx)) |
| 695 |
|
!= rmx_array_size(&mop[i].imx)) { |
| 696 |
< |
fprintf(stderr, "%s: parent_loop() write error at row %d\n", |
| 696 |
> |
fprintf(stderr, "%s: write error at row %d\n", |
| 697 |
|
mop[i].inspec, cur_row); |
| 698 |
|
return(0); |
| 699 |
|
} |
| 702 |
|
free(cproc); cproc = NULL; nchildren = 0; |
| 703 |
|
if (i < 0) { |
| 704 |
|
if (!nowarn) |
| 705 |
< |
fputs("Warning: lost child in parent_loop()\n", stderr); |
| 705 |
> |
fputs("Warning: lost child process\n", stderr); |
| 706 |
|
return(1); |
| 707 |
|
} |
| 708 |
|
if (i > 0) { |
| 712 |
|
return(1); /* return success! */ |
| 713 |
|
} |
| 714 |
|
|
| 715 |
+ |
/* Main operation loop, may be run in each child */ |
| 716 |
|
int |
| 717 |
|
combine_input(void) |
| 718 |
|
{ |
| 749 |
|
if (!rmx_load_row(mop[i].imx.mtx, &mop[i].imx, mop[i].infp)) { |
| 750 |
|
if (cur_row > in_nrows) /* unknown #input rows? */ |
| 751 |
|
break; |
| 752 |
< |
fprintf(stderr, "%s: combine_input() load error at row %d\n", |
| 752 |
> |
fprintf(stderr, "%s: load error at row %d\n", |
| 753 |
|
mop[i].inspec, cur_row); |
| 754 |
|
return(0); |
| 755 |
|
} |
| 797 |
|
if (!rmx_write_data(res->rmp->mtx, res->rmp->ncomp, |
| 798 |
|
res->rmp->ncols, res->rmp->dtype, stdout) || |
| 799 |
|
(inchild >= 0 && fflush(stdout) == EOF)) { |
| 800 |
< |
fprintf(stderr, "Conversion/write error at row %d in combine_input()\n", |
| 800 |
> |
fprintf(stderr, "Conversion/write error at row %d\n", |
| 801 |
|
cur_row); |
| 802 |
|
return(0); |
| 803 |
|
} |
| 804 |
|
} |
| 805 |
|
return(inchild >= 0 || fflush(stdout) != EOF); |
| 806 |
|
multerror: |
| 807 |
< |
fputs("Unexpected matrix multiply error in combine_input()\n", stderr); |
| 807 |
> |
fputs("Unexpected matrix multiply error\n", stderr); |
| 808 |
|
return(0); |
| 809 |
|
} |
| 810 |
|
|
| 811 |
+ |
/* Run output process loop when #processes > 1 */ |
| 812 |
|
int |
| 813 |
|
output_loop(void) |
| 814 |
|
{ |
| 834 |
|
if (!rv) /* out of rows? */ |
| 835 |
|
break; |
| 836 |
|
if (rv != row_size) { |
| 837 |
< |
fputs("Read error in output_loop()\n", stderr); |
| 837 |
> |
fputs("Read error\n", stderr); |
| 838 |
|
return(0); |
| 839 |
|
} /* do final conversion */ |
| 840 |
|
if (!rmx_write_data(mop[nmats].rmp->mtx, mop[nmats].rmp->ncomp, |
| 841 |
|
mop[nmats].rmp->ncols, mop[nmats].rmp->dtype, stdout)) { |
| 842 |
< |
fputs("Conversion/write error in output_loop()\n", stderr); |
| 842 |
> |
fputs("Conversion/write error\n", stderr); |
| 843 |
|
return(0); |
| 844 |
|
} |
| 845 |
|
cur_child++; |
| 848 |
|
return(fflush(stdout) != EOF); |
| 849 |
|
} |
| 850 |
|
|
| 851 |
+ |
/* Check/convert floating-point arguments following this */ |
| 852 |
|
int |
| 853 |
|
get_factors(double da[], int n, char *av[]) |
| 854 |
|
{ |
| 859 |
|
return(ac); |
| 860 |
|
} |
| 861 |
|
|
| 862 |
+ |
/* Resize/reallocate the input array as requested */ |
| 863 |
|
void |
| 864 |
|
resize_inparr(int n2alloc) |
| 865 |
|
{ |
| 893 |
|
int stdin_used = 0; |
| 894 |
|
int nproc = 1; |
| 895 |
|
const char *mcat_spec = NULL; |
| 896 |
+ |
int transpose_mcat = 0; |
| 897 |
|
int n2comp = 0; |
| 898 |
|
uby8 comp_ndx[128]; |
| 899 |
|
int i; |
| 988 |
|
mop[nmats].preop.csym = NULL; |
| 989 |
|
break; |
| 990 |
|
case 'm': |
| 975 |
– |
mcat_last = 1; |
| 991 |
|
if (!n) goto userr; |
| 992 |
+ |
mcat_last = 1; |
| 993 |
+ |
transpose_mcat = (argv[i][2] == 't'); |
| 994 |
|
if (argv[++i][0] == '-' && !argv[i][1]) { |
| 995 |
|
if (stdin_used++) goto stdin_error; |
| 996 |
|
mcat_spec = stdin_name; |
| 1009 |
|
} |
| 1010 |
|
resize_inparr(nmats+1); /* extra matrix at end for result */ |
| 1011 |
|
mop[nmats].inspec = "trailing_ops"; |
| 1012 |
< |
/* load final concatenation matrix */ |
| 1013 |
< |
if (mcat_spec && !(mcat = rmx_load(mcat_spec, RMPnone))) { |
| 1014 |
< |
fprintf(stderr, "%s: error loading concatenation matrix: %s\n", |
| 1015 |
< |
argv[0], mcat_spec); |
| 1016 |
< |
return(1); |
| 1012 |
> |
|
| 1013 |
> |
if (mcat_spec) { /* load final concatenation matrix? */ |
| 1014 |
> |
mcat = rmx_load(mcat_spec); |
| 1015 |
> |
if (!mcat) { |
| 1016 |
> |
fprintf(stderr, "%s: error loading concatenation matrix: %s\n", |
| 1017 |
> |
argv[0], mcat_spec); |
| 1018 |
> |
return(1); |
| 1019 |
> |
} |
| 1020 |
> |
if (transpose_mcat && !rmx_transpose(mcat)) { |
| 1021 |
> |
fprintf(stderr, "%s: error transposing concatenation matrix: %s\n", |
| 1022 |
> |
argv[0], mcat_spec); |
| 1023 |
> |
return(1); |
| 1024 |
> |
} |
| 1025 |
|
} |
| 1026 |
|
/* get/check inputs, set constants */ |
| 1027 |
|
if (!initialize(&mop[nmats].imx)) |
| 1061 |
|
return(1); |
| 1062 |
|
mop[nmats].rmp->ncols = mcat->ncols; |
| 1063 |
|
} |
| 1064 |
+ |
#if DTrmx_native==DTfloat |
| 1065 |
+ |
if (outfmt == DTdouble) |
| 1066 |
+ |
fprintf(stderr, "%s: warning - writing float result as double\n", argv[0]); |
| 1067 |
+ |
#endif |
| 1068 |
|
newheader("RADIANCE", stdout); /* write output header */ |
| 1069 |
|
if (echoheader) |
| 1070 |
|
output_headinfo(stdout); |