| 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 |
|
{ |
| 477 |
|
return(mop[mi].rmp->mtx[cur_col*in_ncomp + chan]); |
| 478 |
|
} |
| 479 |
|
|
| 480 |
+ |
/* Set up our operations and check consistency */ |
| 481 |
|
int |
| 482 |
|
initialize(RMATRIX *imp) |
| 483 |
|
{ |
| 525 |
|
return(1); |
| 526 |
|
} |
| 527 |
|
|
| 528 |
+ |
/* Copy input header information to output header, indented */ |
| 529 |
|
void |
| 530 |
|
output_headinfo(FILE *fp) |
| 531 |
|
{ |
| 549 |
|
} |
| 550 |
|
} |
| 551 |
|
|
| 552 |
+ |
/* Spawn the indicated number of children and return 1 in parent */ |
| 553 |
|
int |
| 554 |
|
spawned_children(int np) |
| 555 |
|
{ |
| 657 |
|
exit(1); |
| 658 |
|
} |
| 659 |
|
|
| 660 |
+ |
/* Run parental feeder loop */ |
| 661 |
|
int |
| 662 |
|
parent_loop(void) |
| 663 |
|
{ |
| 679 |
|
if (!rmx_load_row(mop[i].imx.mtx, &mop[i].imx, mop[i].infp)) { |
| 680 |
|
if (cur_row > in_nrows) /* unknown #input rows? */ |
| 681 |
|
break; |
| 682 |
< |
fprintf(stderr, "%s: parent_loop() load error at row %d\n", |
| 682 |
> |
fprintf(stderr, "%s: load error at row %d\n", |
| 683 |
|
mop[i].inspec, cur_row); |
| 684 |
|
return(0); |
| 685 |
|
} |
| 688 |
|
for (i = 0; i < nmats; i++) |
| 689 |
|
if (writebuf(wfd, mop[i].imx.mtx, rmx_array_size(&mop[i].imx)) |
| 690 |
|
!= rmx_array_size(&mop[i].imx)) { |
| 691 |
< |
fprintf(stderr, "%s: parent_loop() write error at row %d\n", |
| 691 |
> |
fprintf(stderr, "%s: write error at row %d\n", |
| 692 |
|
mop[i].inspec, cur_row); |
| 693 |
|
return(0); |
| 694 |
|
} |
| 697 |
|
free(cproc); cproc = NULL; nchildren = 0; |
| 698 |
|
if (i < 0) { |
| 699 |
|
if (!nowarn) |
| 700 |
< |
fputs("Warning: lost child in parent_loop()\n", stderr); |
| 700 |
> |
fputs("Warning: lost child process\n", stderr); |
| 701 |
|
return(1); |
| 702 |
|
} |
| 703 |
|
if (i > 0) { |
| 707 |
|
return(1); /* return success! */ |
| 708 |
|
} |
| 709 |
|
|
| 710 |
+ |
/* Main operation loop, may be run in each child */ |
| 711 |
|
int |
| 712 |
|
combine_input(void) |
| 713 |
|
{ |
| 744 |
|
if (!rmx_load_row(mop[i].imx.mtx, &mop[i].imx, mop[i].infp)) { |
| 745 |
|
if (cur_row > in_nrows) /* unknown #input rows? */ |
| 746 |
|
break; |
| 747 |
< |
fprintf(stderr, "%s: combine_input() load error at row %d\n", |
| 747 |
> |
fprintf(stderr, "%s: load error at row %d\n", |
| 748 |
|
mop[i].inspec, cur_row); |
| 749 |
|
return(0); |
| 750 |
|
} |
| 792 |
|
if (!rmx_write_data(res->rmp->mtx, res->rmp->ncomp, |
| 793 |
|
res->rmp->ncols, res->rmp->dtype, stdout) || |
| 794 |
|
(inchild >= 0 && fflush(stdout) == EOF)) { |
| 795 |
< |
fprintf(stderr, "Conversion/write error at row %d in combine_input()\n", |
| 795 |
> |
fprintf(stderr, "Conversion/write error at row %d\n", |
| 796 |
|
cur_row); |
| 797 |
|
return(0); |
| 798 |
|
} |
| 799 |
|
} |
| 800 |
|
return(inchild >= 0 || fflush(stdout) != EOF); |
| 801 |
|
multerror: |
| 802 |
< |
fputs("Unexpected matrix multiply error in combine_input()\n", stderr); |
| 802 |
> |
fputs("Unexpected matrix multiply error\n", stderr); |
| 803 |
|
return(0); |
| 804 |
|
} |
| 805 |
|
|
| 806 |
+ |
/* Run output process loop when #processes > 1 */ |
| 807 |
|
int |
| 808 |
|
output_loop(void) |
| 809 |
|
{ |
| 829 |
|
if (!rv) /* out of rows? */ |
| 830 |
|
break; |
| 831 |
|
if (rv != row_size) { |
| 832 |
< |
fputs("Read error in output_loop()\n", stderr); |
| 832 |
> |
fputs("Read error\n", stderr); |
| 833 |
|
return(0); |
| 834 |
|
} /* do final conversion */ |
| 835 |
|
if (!rmx_write_data(mop[nmats].rmp->mtx, mop[nmats].rmp->ncomp, |
| 836 |
|
mop[nmats].rmp->ncols, mop[nmats].rmp->dtype, stdout)) { |
| 837 |
< |
fputs("Conversion/write error in output_loop()\n", stderr); |
| 837 |
> |
fputs("Conversion/write error\n", stderr); |
| 838 |
|
return(0); |
| 839 |
|
} |
| 840 |
|
cur_child++; |
| 843 |
|
return(fflush(stdout) != EOF); |
| 844 |
|
} |
| 845 |
|
|
| 846 |
+ |
/* Check/convert floating-point arguments following this */ |
| 847 |
|
int |
| 848 |
|
get_factors(double da[], int n, char *av[]) |
| 849 |
|
{ |
| 854 |
|
return(ac); |
| 855 |
|
} |
| 856 |
|
|
| 857 |
+ |
/* Resize/reallocate the input array as requested */ |
| 858 |
|
void |
| 859 |
|
resize_inparr(int n2alloc) |
| 860 |
|
{ |
| 888 |
|
int stdin_used = 0; |
| 889 |
|
int nproc = 1; |
| 890 |
|
const char *mcat_spec = NULL; |
| 891 |
+ |
int transpose_mcat = 0; |
| 892 |
|
int n2comp = 0; |
| 893 |
|
uby8 comp_ndx[128]; |
| 894 |
|
int i; |
| 983 |
|
mop[nmats].preop.csym = NULL; |
| 984 |
|
break; |
| 985 |
|
case 'm': |
| 975 |
– |
mcat_last = 1; |
| 986 |
|
if (!n) goto userr; |
| 987 |
+ |
mcat_last = 1; |
| 988 |
+ |
transpose_mcat = (argv[i][2] == 't'); |
| 989 |
|
if (argv[++i][0] == '-' && !argv[i][1]) { |
| 990 |
|
if (stdin_used++) goto stdin_error; |
| 991 |
|
mcat_spec = stdin_name; |
| 1004 |
|
} |
| 1005 |
|
resize_inparr(nmats+1); /* extra matrix at end for result */ |
| 1006 |
|
mop[nmats].inspec = "trailing_ops"; |
| 1007 |
< |
/* load final concatenation matrix */ |
| 1008 |
< |
if (mcat_spec && !(mcat = rmx_load(mcat_spec, RMPnone))) { |
| 1009 |
< |
fprintf(stderr, "%s: error loading concatenation matrix: %s\n", |
| 1010 |
< |
argv[0], mcat_spec); |
| 1011 |
< |
return(1); |
| 1007 |
> |
|
| 1008 |
> |
if (mcat_spec) { /* load final concatenation matrix? */ |
| 1009 |
> |
mcat = rmx_load(mcat_spec); |
| 1010 |
> |
if (!mcat) { |
| 1011 |
> |
fprintf(stderr, "%s: error loading concatenation matrix: %s\n", |
| 1012 |
> |
argv[0], mcat_spec); |
| 1013 |
> |
return(1); |
| 1014 |
> |
} |
| 1015 |
> |
if (transpose_mcat && !rmx_transpose(mcat)) { |
| 1016 |
> |
fprintf(stderr, "%s: error transposing concatenation matrix: %s\n", |
| 1017 |
> |
argv[0], mcat_spec); |
| 1018 |
> |
return(1); |
| 1019 |
> |
} |
| 1020 |
|
} |
| 1021 |
|
/* get/check inputs, set constants */ |
| 1022 |
|
if (!initialize(&mop[nmats].imx)) |
| 1056 |
|
return(1); |
| 1057 |
|
mop[nmats].rmp->ncols = mcat->ncols; |
| 1058 |
|
} |
| 1059 |
+ |
#if DTrmx_native==DTfloat |
| 1060 |
+ |
if (outfmt == DTdouble) |
| 1061 |
+ |
fprintf(stderr, "%s: warning - writing float result as double\n", argv[0]); |
| 1062 |
+ |
#endif |
| 1063 |
|
newheader("RADIANCE", stdout); /* write output header */ |
| 1064 |
|
if (echoheader) |
| 1065 |
|
output_headinfo(stdout); |