--- ray/src/util/radcompare.c 2018/10/15 22:38:31 2.6 +++ ray/src/util/radcompare.c 2018/10/16 16:52:05 2.9 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: radcompare.c,v 2.6 2018/10/15 22:38:31 greg Exp $"; +static const char RCSid[] = "$Id: radcompare.c,v 2.9 2018/10/16 16:52:05 greg Exp $"; #endif /* * Compare Radiance files for significant differences @@ -82,7 +82,7 @@ FILE *f1in=NULL, *f2in=NULL; /* running real differences */ double diff2sum = 0; -int nsum = 0; +long nsum = 0; /* Report usage and exit */ static void @@ -92,7 +92,7 @@ usage() fputs(progname, stderr); fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", stderr); - exit(1); + exit(2); } /* Get type ID from name (or 0 if not found) */ @@ -134,6 +134,22 @@ real_check(double r1, double r2) return(1); } +/* Compare two color values for equivalence */ +static int +color_check(COLOR c1, COLOR c2) +{ + int p; + + if (!real_check(colval(c1,RED)+colval(c1,GRN)+colval(c1,BLU)*(1./3.), + colval(c2,RED)+colval(c2,GRN)+colval(c2,BLU))*(1./3.)) + return(0); + + p = (colval(c1,GRN) > colval(c1,RED)) ? GRN : RED; + if (colval(c1,BLU) > colval(c1,p)) p = BLU; + + return(real_check(colval(c1,p), colval(c2,p))); +} + /* Compare two strings for equivalence */ static int equiv_string(char *s1, char *s2) @@ -527,12 +543,7 @@ compare_hdr() return(0); } for (x = 0; x < scanlen(&rs1); x++) { - if (real_check(colval(scan1[x],RED), - colval(scan2[x],RED)) & - real_check(colval(scan1[x],GRN), - colval(scan2[x],GRN)) & - real_check(colval(scan1[x],BLU), - colval(scan2[x],BLU))) + if (color_check(scan1[x], scan2[x])) continue; if (report != REP_QUIET) { printf( @@ -568,7 +579,7 @@ compare_float() if (report >= REP_VERBOSE) { fputs(progname, stdout); - fputs(": comparing inputs as 32-bit IEEE float\n", stdout); + fputs(": comparing inputs as 32-bit IEEE floats\n", stdout); } while (getbinary(&f1, sizeof(f1), 1, f1in)) { if (!getbinary(&f2, sizeof(f2), 1, f2in)) @@ -598,7 +609,7 @@ compare_double() if (report >= REP_VERBOSE) { fputs(progname, stdout); - fputs(": comparing inputs as 64-bit IEEE double\n", stdout); + fputs(": comparing inputs as 64-bit IEEE doubles\n", stdout); } while (getbinary(&f1, sizeof(f1), 1, f1in)) { if (!getbinary(&f2, sizeof(f2), 1, f2in)) @@ -662,35 +673,34 @@ main(int argc, char *argv[]) } break; } - if (a != argc-2) + if (a != argc-2) /* make sure of two inputs */ usage(); - if (!f1name) f1name = argv[a]; - if (!f2name) f2name = argv[a+1]; - - if (!strcmp(f1name, f2name)) { /* inputs are same? */ + if (!strcmp(argv[a], argv[a+1])) { /* inputs are same? */ if (report >= REP_WARN) printf("%s: warning - identical inputs given\n", progname); return(0); } + if (!f1name) f1name = argv[a]; + if (!f2name) f2name = argv[a+1]; /* open inputs */ SET_FILE_BINARY(stdin); /* in case we're using it */ if (!f1in && !(f1in = fopen(f1name, "rb"))) { fprintf(stderr, "%s: cannot open for reading\n", f1name); - return(1); + return(2); } if (!strcmp(f2name, "-")) { f2in = stdin; f2name = stdin_name; } else if (!(f2in = fopen(f2name, "rb"))) { fprintf(stderr, "%s: cannot open for reading\n", f2name); - return(1); + return(2); } /* load headers */ if ((typ1 = identify_type(f1name, f1in, &hdr1)) < 0) - return(1); + return(2); if ((typ2 = identify_type(f2name, f2in, &hdr2)) < 0) - return(1); + return(2); if (typ1 != typ2) { if (report != REP_QUIET) printf("%s: '%s' is %s and '%s' is %s\n",