--- ray/src/util/radcompare.c 2019/08/14 04:18:12 2.19 +++ ray/src/util/radcompare.c 2020/07/27 16:49:56 2.26 @@ -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.26 2020/07/27 16:49:56 greg Exp $"; #endif /* * Compare Radiance files for significant differences @@ -35,6 +35,8 @@ double max_lim = 0.25; /* difference limit if non-neg int lin1cnt=0, lin2cnt=0; /* file line position */ +int comment_c = '\0'; /* comment delimiter for text files */ + const char nsuffix[10][3] = { /* 1st, 2nd, 3rd, etc. */ "th","st","nd","rd","th","th","th","th","th","th" }; @@ -99,6 +101,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; @@ -110,7 +113,7 @@ usage() { fputs("Usage: ", stderr); fputs(progname, stderr); - fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", + fputs(" [-h][-c#][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", stderr); exit(2); } @@ -148,6 +151,14 @@ read_line(LINEBUF *bp, FILE *fp) if (!bp->str) goto memerr; } + if (comment_c) { /* elide comment? */ + char *cp = sskip2(bp->str,0); + if (*cp == comment_c) { + *cp++ = '\n'; + *cp = '\0'; + bp->len = cp - bp->str; + } + } return(bp->len); memerr: fprintf(stderr, @@ -223,12 +234,12 @@ color_check(COLOR c1, COLOR c2) static int norm_check(FVECT nv1, FVECT nv2) { - double max2 = nv1[2]*nv1[2]; + double max2 = nv1[2]*nv2[2]; int imax = 2; int i = 2; /* identify largest component */ while (i--) { - double tm2 = nv1[i]*nv1[i]; + double tm2 = nv1[i]*nv2[i]; if (tm2 > max2) { imax = i; max2 = tm2; @@ -316,6 +327,7 @@ equiv_string(char *s1, char *s2) static int setheadvar(char *val, void *p) { + char newval[128]; LUTAB *htp = (LUTAB *)p; LUENT *tep; char *key; @@ -325,6 +337,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++; @@ -350,8 +370,13 @@ setheadvar(char *val, void *p) return(-1); /* memory allocation error */ if (!tep->key) tep->key = strcpy(malloc(kln+1), key); - if (tep->data) + if (tep->data) { /* check for special cases */ + if (!strcmp(key, "EXPOSURE")) { + sprintf(newval, "%f", atof(tep->data)*atof(val)); + vln = strlen(val = newval); + } free(tep->data); + } tep->data = strcpy(malloc(vln+1), val); return(1); } @@ -460,7 +485,6 @@ identify_type(const char *name, FILE *fin, LUTAB *htp) } if (c) return(TYP_BINARY); - SET_FILE_TEXT(fin); /* originally set to binary */ return(TYP_TEXT); badeof: if (report != REP_QUIET) { @@ -543,8 +567,16 @@ compare_text() if (report >= REP_VERBOSE) { fputs(progname, stdout); - fputs(": comparing inputs as ASCII text\n", stdout); + fputs(": comparing inputs as ASCII text", stdout); + if (comment_c) { + fputs(", ignoring comments starting with '", stdout); + fputc(comment_c, stdout); + fputc('\'', stdout); + } + fputc('\n', stdout); } + SET_FILE_TEXT(f1in); /* originally set to binary */ + SET_FILE_TEXT(f2in); init_line(&l1buf); init_line(&l2buf); /* compare a line at a time */ while (read_line(&l1buf, f1in)) { lin1cnt++; @@ -687,7 +719,7 @@ set_refdepth(DEPTHCODEC *dcp, LUTAB *htp) static char depthvar[] = DEPTHSTR; const char *drval; - depthvar[LDEPTHSTR] = '\0'; + depthvar[LDEPTHSTR-1] = '\0'; drval = (const char *)lu_find(htp, depthvar)->data; if (!drval) return(0); @@ -822,6 +854,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 +886,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) @@ -880,6 +916,9 @@ main(int argc, char *argv[]) case 'h': /* ignore header info. */ ign_header = !ign_header; continue; + case 'c': /* ignore comments */ + comment_c = argv[a][2]; + continue; case 's': /* silent operation */ report = REP_QUIET; continue; @@ -940,7 +979,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 +995,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: