--- ray/src/util/radcompare.c 2019/08/14 04:18:12 2.19 +++ ray/src/util/radcompare.c 2019/08/15 17:28:45 2.21 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: radcompare.c,v 2.19 2019/08/14 04:18:12 greg Exp $"; +static const char RCSid[] = "$Id: radcompare.c,v 2.21 2019/08/15 17:28:45 greg Exp $"; #endif /* * Compare Radiance files for significant differences @@ -99,6 +99,7 @@ char *progname = NULL; const char stdin_name[] = ""; const char *f1name=NULL, *f2name=NULL; FILE *f1in=NULL, *f2in=NULL; +int f1swap=0, f2swap=0; /* running real differences */ double diff2sum = 0; @@ -325,6 +326,14 @@ setheadvar(char *val, void *p) adv_linecnt(htp); /* side-effect is to count lines */ if (!isalpha(*val)) /* key must start line */ return(0); + /* check if we need to swap binary data */ + if ((n = isbigendian(val)) >= 0) { + if (nativebigendian() == n) + return(0); + f1swap += (htp == &hdr1); + f2swap += (htp == &hdr2); + return(0); + } key = val++; while (*val && !isspace(*val) & (*val != '=')) val++; @@ -822,6 +831,8 @@ compare_float() if (!getbinary(&f2, sizeof(f2), 1, f2in)) goto badeof; ++nread; + if (f1swap) swap32((char *)&f1, 1); + if (f2swap) swap32((char *)&f2, 1); if (real_check(f1, f2)) continue; if (report != REP_QUIET) @@ -852,6 +863,8 @@ compare_double() if (!getbinary(&f2, sizeof(f2), 1, f2in)) goto badeof; ++nread; + if (f1swap) swap64((char *)&f1, 1); + if (f2swap) swap64((char *)&f2, 1); if (real_check(f1, f2)) continue; if (report != REP_QUIET) @@ -940,7 +953,7 @@ main(int argc, char *argv[]) return(2); if (typ1 != typ2) { if (report != REP_QUIET) - printf("%s: '%s' is %s and '%s' is %s\n", + printf("%s: '%s' format is %s and '%s' is %s\n", progname, f1name, file_type[typ1], f2name, file_type[typ2]); return(1); @@ -956,10 +969,17 @@ main(int argc, char *argv[]) printf("%s: warning - unrecognized format\n", progname); } - if (report >= REP_VERBOSE) - printf("%s: input file type is %s\n", - progname, file_type[typ1]); - + if (report >= REP_VERBOSE) { + printf("%s: data format is %s\n", progname, file_type[typ1]); + if ((typ1 == TYP_FLOAT) | (typ1 == TYP_DOUBLE)) { + if (f1swap) + printf("%s: input '%s' is byte-swapped\n", + progname, f1name); + if (f2swap) + printf("%s: input '%s' is byte-swapped\n", + progname, f2name); + } + } switch (typ1) { /* compare based on type */ case TYP_BINARY: case TYP_TMESH: