--- ray/src/util/radcompare.c 2020/07/27 16:49:56 2.26 +++ ray/src/util/radcompare.c 2022/05/24 22:34:18 2.30 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: radcompare.c,v 2.26 2020/07/27 16:49:56 greg Exp $"; +static const char RCSid[] = "$Id: radcompare.c,v 2.30 2022/05/24 22:34:18 greg Exp $"; #endif /* * Compare Radiance files for significant differences @@ -27,6 +27,8 @@ int report = REP_WARN; /* reporting level */ int ign_header = 0; /* ignore header differences? */ +int escape_newlines = 0; /* allow backslash to skip newlines */ + double rel_min = 1e-5; /* positive for relative comparisons */ double rms_lim = 0.01; /* RMS difference limit */ @@ -72,6 +74,7 @@ enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_ /* header variables to always ignore */ const char *hdr_ignkey[] = { + "FORMAT", "SOFTWARE", "CAPDATE", "GMT", @@ -132,8 +135,19 @@ read_line(LINEBUF *bp, FILE *fp) } while (fgets(bp->str + bp->len, bp->siz - bp->len, fp)) { bp->len += strlen(bp->str + bp->len); - if (bp->str[bp->len-1] == '\n') + if (bp->str[bp->len-1] == '\n') { + if (bp->len > 1 && bp->str[bp->len-2] == '\r') { + bp->str[--bp->len] = '\0'; + bp->str[bp->len-1] = '\n'; + } + if (escape_newlines && bp->len > 1 && + bp->str[bp->len-2] == '\\') { + bp->str[--bp->len] = '\0'; + bp->str[bp->len-1] = ' '; + continue; + } break; /* found EOL */ + } if (bp->len < bp->siz - 4) continue; /* at EOF? */ if (bp->siz >= MAXBUF) { @@ -197,8 +211,9 @@ real_check(double r1, double r2) if (rel_min > 0) { /* doing relative differences? */ double av2 = .25*(r1*r1 + 2.*fabs(r1*r2) + r2*r2); - if (av2 > rel_min*rel_min) - diff2 /= av2; + if (av2 < rel_min*rel_min) + av2 = rel_min*rel_min; + diff2 /= av2; } if (max_lim >= 0 && diff2 > max_lim*max_lim) { if (report != REP_QUIET) @@ -372,7 +387,7 @@ setheadvar(char *val, void *p) tep->key = strcpy(malloc(kln+1), key); if (tep->data) { /* check for special cases */ if (!strcmp(key, "EXPOSURE")) { - sprintf(newval, "%f", atof(tep->data)*atof(val)); + sprintf(newval, "%.6e", atof(tep->data)*atof(val)); vln = strlen(val = newval); } free(tep->data); @@ -568,6 +583,8 @@ compare_text() if (report >= REP_VERBOSE) { fputs(progname, stdout); fputs(": comparing inputs as ASCII text", stdout); + if (escape_newlines) + fputs(", allowing escaped newlines", stdout); if (comment_c) { fputs(", ignoring comments starting with '", stdout); fputc(comment_c, stdout); @@ -915,6 +932,9 @@ main(int argc, char *argv[]) switch (argv[a][1]) { case 'h': /* ignore header info. */ ign_header = !ign_header; + continue; + case 'n': /* allow newline escapes */ + escape_newlines = !escape_newlines; continue; case 'c': /* ignore comments */ comment_c = argv[a][2];