| 27 |
|
|
| 28 |
|
int ign_header = 0; /* ignore header differences? */ |
| 29 |
|
|
| 30 |
+ |
int escape_newlines = 0; /* allow backslash to skip newlines */ |
| 31 |
+ |
|
| 32 |
|
double rel_min = 1e-5; /* positive for relative comparisons */ |
| 33 |
|
|
| 34 |
|
double rms_lim = 0.01; /* RMS difference limit */ |
| 37 |
|
|
| 38 |
|
int lin1cnt=0, lin2cnt=0; /* file line position */ |
| 39 |
|
|
| 40 |
+ |
int comment_c = '\0'; /* comment delimiter for text files */ |
| 41 |
+ |
|
| 42 |
|
const char nsuffix[10][3] = { /* 1st, 2nd, 3rd, etc. */ |
| 43 |
|
"th","st","nd","rd","th","th","th","th","th","th" |
| 44 |
|
}; |
| 51 |
|
"ascii", |
| 52 |
|
COLRFMT, |
| 53 |
|
CIEFMT, |
| 54 |
+ |
SPECFMT, |
| 55 |
|
DEPTH16FMT, |
| 56 |
|
NORMAL32FMT, |
| 57 |
|
"float", |
| 66 |
|
NULL /* terminator */ |
| 67 |
|
}; |
| 68 |
|
/* keep consistent with above */ |
| 69 |
< |
enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE, |
| 69 |
> |
enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE, TYP_SPEC, |
| 70 |
|
TYP_DEPTH, TYP_NORM, TYP_FLOAT, TYP_DOUBLE, |
| 71 |
|
TYP_RBFMESH, TYP_OCTREE, TYP_TMESH, |
| 72 |
|
TYP_ID8, TYP_ID16, TYP_ID24, TYP_BINARY}; |
| 116 |
|
{ |
| 117 |
|
fputs("Usage: ", stderr); |
| 118 |
|
fputs(progname, stderr); |
| 119 |
< |
fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", |
| 119 |
> |
fputs(" [-h][-c#][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", |
| 120 |
|
stderr); |
| 121 |
|
exit(2); |
| 122 |
|
} |
| 135 |
|
} |
| 136 |
|
while (fgets(bp->str + bp->len, bp->siz - bp->len, fp)) { |
| 137 |
|
bp->len += strlen(bp->str + bp->len); |
| 138 |
< |
if (bp->str[bp->len-1] == '\n') |
| 138 |
> |
if (bp->str[bp->len-1] == '\n') { |
| 139 |
> |
if (bp->len > 1 && bp->str[bp->len-2] == '\r') { |
| 140 |
> |
bp->str[--bp->len] = '\0'; |
| 141 |
> |
bp->str[bp->len-1] = '\n'; |
| 142 |
> |
} |
| 143 |
> |
if (escape_newlines && bp->len > 1 && |
| 144 |
> |
bp->str[bp->len-2] == '\\') { |
| 145 |
> |
bp->str[--bp->len] = '\0'; |
| 146 |
> |
bp->str[bp->len-1] = ' '; |
| 147 |
> |
continue; |
| 148 |
> |
} |
| 149 |
|
break; /* found EOL */ |
| 150 |
+ |
} |
| 151 |
|
if (bp->len < bp->siz - 4) |
| 152 |
|
continue; /* at EOF? */ |
| 153 |
|
if (bp->siz >= MAXBUF) { |
| 165 |
|
if (!bp->str) |
| 166 |
|
goto memerr; |
| 167 |
|
} |
| 168 |
+ |
if (comment_c) { /* elide comment? */ |
| 169 |
+ |
char *cp = sskip2(bp->str,0); |
| 170 |
+ |
if (*cp == comment_c) { |
| 171 |
+ |
*cp++ = '\n'; |
| 172 |
+ |
*cp = '\0'; |
| 173 |
+ |
bp->len = cp - bp->str; |
| 174 |
+ |
} |
| 175 |
+ |
} |
| 176 |
|
return(bp->len); |
| 177 |
|
memerr: |
| 178 |
|
fprintf(stderr, |
| 211 |
|
|
| 212 |
|
if (rel_min > 0) { /* doing relative differences? */ |
| 213 |
|
double av2 = .25*(r1*r1 + 2.*fabs(r1*r2) + r2*r2); |
| 214 |
< |
if (av2 > rel_min*rel_min) |
| 215 |
< |
diff2 /= av2; |
| 214 |
> |
if (av2 < rel_min*rel_min) |
| 215 |
> |
av2 = rel_min*rel_min; |
| 216 |
> |
diff2 /= av2; |
| 217 |
|
} |
| 218 |
|
if (max_lim >= 0 && diff2 > max_lim*max_lim) { |
| 219 |
|
if (report != REP_QUIET) |
| 245 |
|
return(real_check(colval(c1,p), colval(c2,p))); |
| 246 |
|
} |
| 247 |
|
|
| 248 |
+ |
/* Compare two color spectra for equivalence */ |
| 249 |
+ |
static int |
| 250 |
+ |
spec_check(COLORV *sc1, COLORV *sc2) |
| 251 |
+ |
{ |
| 252 |
+ |
int p, k; |
| 253 |
+ |
|
| 254 |
+ |
if (!real_check(scolor_mean(sc1), scolor_mean(sc2))) |
| 255 |
+ |
return(0); |
| 256 |
+ |
|
| 257 |
+ |
p = 0; /* find max. component */ |
| 258 |
+ |
for (k = NCSAMP; --k; ) |
| 259 |
+ |
if (sc1[k] > sc1[p]) |
| 260 |
+ |
p = k; |
| 261 |
+ |
|
| 262 |
+ |
return(real_check(sc1[p], sc2[p])); |
| 263 |
+ |
} |
| 264 |
+ |
|
| 265 |
|
/* Compare two normal directions for equivalence */ |
| 266 |
|
static int |
| 267 |
|
norm_check(FVECT nv1, FVECT nv2) |
| 268 |
|
{ |
| 269 |
< |
double max2 = nv1[2]*nv1[2]; |
| 269 |
> |
double max2 = nv1[2]*nv2[2]; |
| 270 |
|
int imax = 2; |
| 271 |
|
int i = 2; |
| 272 |
|
/* identify largest component */ |
| 273 |
|
while (i--) { |
| 274 |
< |
double tm2 = nv1[i]*nv1[i]; |
| 274 |
> |
double tm2 = nv1[i]*nv2[i]; |
| 275 |
|
if (tm2 > max2) { |
| 276 |
|
imax = i; |
| 277 |
|
max2 = tm2; |
| 359 |
|
static int |
| 360 |
|
setheadvar(char *val, void *p) |
| 361 |
|
{ |
| 362 |
+ |
char newval[128]; |
| 363 |
|
LUTAB *htp = (LUTAB *)p; |
| 364 |
|
LUENT *tep; |
| 365 |
|
char *key; |
| 402 |
|
return(-1); /* memory allocation error */ |
| 403 |
|
if (!tep->key) |
| 404 |
|
tep->key = strcpy(malloc(kln+1), key); |
| 405 |
< |
if (tep->data) |
| 405 |
> |
if (tep->data) { /* check for special cases */ |
| 406 |
> |
if (!strcmp(key, "EXPOSURE")) { |
| 407 |
> |
sprintf(newval, "%.6e", atof(tep->data)*atof(val)); |
| 408 |
> |
vln = strlen(val = newval); |
| 409 |
> |
} |
| 410 |
|
free(tep->data); |
| 411 |
+ |
} |
| 412 |
|
tep->data = strcpy(malloc(vln+1), val); |
| 413 |
|
return(1); |
| 414 |
|
} |
| 517 |
|
} |
| 518 |
|
if (c) |
| 519 |
|
return(TYP_BINARY); |
| 472 |
– |
SET_FILE_TEXT(fin); /* originally set to binary */ |
| 520 |
|
return(TYP_TEXT); |
| 521 |
|
badeof: |
| 522 |
|
if (report != REP_QUIET) { |
| 599 |
|
|
| 600 |
|
if (report >= REP_VERBOSE) { |
| 601 |
|
fputs(progname, stdout); |
| 602 |
< |
fputs(": comparing inputs as ASCII text\n", stdout); |
| 602 |
> |
fputs(": comparing inputs as ASCII text", stdout); |
| 603 |
> |
if (escape_newlines) |
| 604 |
> |
fputs(", allowing escaped newlines", stdout); |
| 605 |
> |
if (comment_c) { |
| 606 |
> |
fputs(", ignoring comments starting with '", stdout); |
| 607 |
> |
fputc(comment_c, stdout); |
| 608 |
> |
fputc('\'', stdout); |
| 609 |
> |
} |
| 610 |
> |
fputc('\n', stdout); |
| 611 |
|
} |
| 612 |
+ |
SET_FILE_TEXT(f1in); /* originally set to binary */ |
| 613 |
+ |
SET_FILE_TEXT(f2in); |
| 614 |
|
init_line(&l1buf); init_line(&l2buf); /* compare a line at a time */ |
| 615 |
|
while (read_line(&l1buf, f1in)) { |
| 616 |
|
lin1cnt++; |
| 633 |
|
/* compare non-empty lines */ |
| 634 |
|
if (!equiv_string(l1buf.str, l2buf.str)) { |
| 635 |
|
if (report != REP_QUIET) { |
| 636 |
< |
printf("%s: inputs '%s' and '%s' differ at line %d|%d\n", |
| 637 |
< |
progname, f1name, f2name, |
| 638 |
< |
lin1cnt, lin2cnt); |
| 636 |
> |
printf("%s: inputs '%s' and '%s' differ at line %d", |
| 637 |
> |
progname, f1name, f2name, lin1cnt); |
| 638 |
> |
if (lin1cnt != lin2cnt) |
| 639 |
> |
printf("|%d\n", lin2cnt); |
| 640 |
> |
else |
| 641 |
> |
putchar('\n'); |
| 642 |
|
if ( report >= REP_VERBOSE && |
| 643 |
|
(l1buf.len < 256) & |
| 644 |
|
(l2buf.len < 256) ) { |
| 668 |
|
return(good_RMS()); /* final check for reals */ |
| 669 |
|
} |
| 670 |
|
|
| 671 |
+ |
/* Set resolution based on NROWS, NCOLS in header */ |
| 672 |
+ |
static int |
| 673 |
+ |
set_resolu(RESOLU *rs, LUTAB *htp) |
| 674 |
+ |
{ |
| 675 |
+ |
const char *val; |
| 676 |
+ |
|
| 677 |
+ |
rs->rt = PIXSTANDARD; |
| 678 |
+ |
val = (const char *)lu_find(htp, "NROWS")->data; |
| 679 |
+ |
if (!val) return(0); |
| 680 |
+ |
rs->yr = atoi(val); |
| 681 |
+ |
if (rs->yr <= 0) return(-1); |
| 682 |
+ |
val = (const char *)lu_find(htp, "NCOLS")->data; |
| 683 |
+ |
if (!val) return(0); |
| 684 |
+ |
rs->xr = atoi(val); |
| 685 |
+ |
if (rs->xr <= 0) return(-1); |
| 686 |
+ |
return(1); |
| 687 |
+ |
} |
| 688 |
+ |
|
| 689 |
|
/* Check image/map resolutions */ |
| 690 |
|
static int |
| 691 |
|
check_resolu(const char *class, RESOLU *r1p, RESOLU *r2p) |
| 743 |
|
if (color_check(scan1[x], scan2[x])) |
| 744 |
|
continue; |
| 745 |
|
if (report != REP_QUIET) { |
| 746 |
< |
printf( |
| 669 |
< |
"%s: pixels at scanline %d offset %d differ\n", |
| 746 |
> |
printf("%s: pixels at scanline %d offset %d differ\n", |
| 747 |
|
progname, y, x); |
| 748 |
|
if (report >= REP_VERBOSE) { |
| 749 |
|
printf("%s: (R,G,B)=(%g,%g,%g)\n", |
| 766 |
|
return(good_RMS()); /* final check of RMS */ |
| 767 |
|
} |
| 768 |
|
|
| 769 |
+ |
/* Compare two inputs that are known to be spectral images */ |
| 770 |
+ |
static int |
| 771 |
+ |
compare_spec() |
| 772 |
+ |
{ |
| 773 |
+ |
static char NCstr[] = NCOMPSTR; |
| 774 |
+ |
RESOLU rs1, rs2; |
| 775 |
+ |
COLORV *scan1, *scan2; |
| 776 |
+ |
const char *val; |
| 777 |
+ |
int x, y; |
| 778 |
+ |
|
| 779 |
+ |
if (report >= REP_VERBOSE) { |
| 780 |
+ |
fputs(progname, stdout); |
| 781 |
+ |
fputs(": comparing inputs as spectral images\n", stdout); |
| 782 |
+ |
} |
| 783 |
+ |
if (!(set_resolu(&rs1, &hdr1) || fgetsresolu(&rs1, f1in))) |
| 784 |
+ |
return(0); |
| 785 |
+ |
if (!(set_resolu(&rs2, &hdr2) || fgetsresolu(&rs2, f2in))) |
| 786 |
+ |
return(0); |
| 787 |
+ |
if (!check_resolu("Spectral image", &rs1, &rs2)) |
| 788 |
+ |
return(0); |
| 789 |
+ |
NCstr[LNCOMPSTR-1] = '\0'; |
| 790 |
+ |
val = (const char *)lu_find(&hdr1, NCstr)->data; |
| 791 |
+ |
if (!val || (NCSAMP = atoi(val)) < 3) { |
| 792 |
+ |
if (report != REP_QUIET) { |
| 793 |
+ |
if (val) |
| 794 |
+ |
printf("%s: illegal # components (%d) for spectral image\n", |
| 795 |
+ |
progname, NCSAMP); |
| 796 |
+ |
else |
| 797 |
+ |
printf("%s: missing %s in header for spectral image\n", |
| 798 |
+ |
progname, NCstr); |
| 799 |
+ |
} |
| 800 |
+ |
return(0); |
| 801 |
+ |
} |
| 802 |
+ |
scan1 = (COLORV *)malloc(sizeof(COLORV)*NCSAMP*scanlen(&rs1)); |
| 803 |
+ |
scan2 = (COLORV *)malloc(sizeof(COLORV)*NCSAMP*scanlen(&rs2)); |
| 804 |
+ |
if (!scan1 | !scan2) { |
| 805 |
+ |
fprintf(stderr, "%s: out of memory in compare_hdr()\n", progname); |
| 806 |
+ |
exit(2); |
| 807 |
+ |
} |
| 808 |
+ |
for (y = 0; y < numscans(&rs1); y++) { |
| 809 |
+ |
if ((freadsscan(scan1, NCSAMP, scanlen(&rs1), f1in) < 0) | |
| 810 |
+ |
(freadsscan(scan2, NCSAMP, scanlen(&rs2), f2in) < 0)) { |
| 811 |
+ |
if (report != REP_QUIET) |
| 812 |
+ |
printf("%s: unexpected end-of-file\n", progname); |
| 813 |
+ |
free(scan1); |
| 814 |
+ |
free(scan2); |
| 815 |
+ |
return(0); |
| 816 |
+ |
} |
| 817 |
+ |
for (x = 0; x < scanlen(&rs1); x++) { |
| 818 |
+ |
if (spec_check(scan1+x*NCSAMP, scan2+x*NCSAMP)) |
| 819 |
+ |
continue; |
| 820 |
+ |
if (report != REP_QUIET) { |
| 821 |
+ |
int k; |
| 822 |
+ |
printf("%s: spectra at scanline %d offset %d differ\n", |
| 823 |
+ |
progname, y, x); |
| 824 |
+ |
if (report >= REP_VERBOSE) { |
| 825 |
+ |
printf("%s: spectrum =", f1name); |
| 826 |
+ |
for (k = 0; k < NCSAMP; k++) |
| 827 |
+ |
printf(" %g", scan1[x*NCSAMP+k]); |
| 828 |
+ |
fputc('\n', stdout); |
| 829 |
+ |
printf("%s: spectrum =", f2name); |
| 830 |
+ |
for (k = 0; k < NCSAMP; k++) |
| 831 |
+ |
printf(" %g", scan2[x*NCSAMP+k]); |
| 832 |
+ |
fputc('\n', stdout); |
| 833 |
+ |
} |
| 834 |
+ |
} |
| 835 |
+ |
free(scan1); |
| 836 |
+ |
free(scan2); |
| 837 |
+ |
return(0); |
| 838 |
+ |
} |
| 839 |
+ |
} |
| 840 |
+ |
free(scan1); |
| 841 |
+ |
free(scan2); |
| 842 |
+ |
return(good_RMS()); /* final check of RMS */ |
| 843 |
+ |
} |
| 844 |
+ |
|
| 845 |
|
/* Set reference depth based on header variable */ |
| 846 |
|
static int |
| 847 |
|
set_refdepth(DEPTHCODEC *dcp, LUTAB *htp) |
| 849 |
|
static char depthvar[] = DEPTHSTR; |
| 850 |
|
const char *drval; |
| 851 |
|
|
| 852 |
< |
depthvar[LDEPTHSTR] = '\0'; |
| 852 |
> |
depthvar[LDEPTHSTR-1] = '\0'; |
| 853 |
|
drval = (const char *)lu_find(htp, depthvar)->data; |
| 854 |
|
if (!drval) |
| 855 |
|
return(0); |
| 1046 |
|
case 'h': /* ignore header info. */ |
| 1047 |
|
ign_header = !ign_header; |
| 1048 |
|
continue; |
| 1049 |
+ |
case 'n': /* allow newline escapes */ |
| 1050 |
+ |
escape_newlines = !escape_newlines; |
| 1051 |
+ |
continue; |
| 1052 |
+ |
case 'c': /* ignore comments */ |
| 1053 |
+ |
comment_c = argv[a][2]; |
| 1054 |
+ |
continue; |
| 1055 |
|
case 's': /* silent operation */ |
| 1056 |
|
report = REP_QUIET; |
| 1057 |
|
continue; |
| 1112 |
|
return(2); |
| 1113 |
|
if (typ1 != typ2) { |
| 1114 |
|
if (report != REP_QUIET) |
| 1115 |
< |
printf("%s: '%s' is %s and '%s' is %s\n", |
| 1115 |
> |
printf("%s: '%s' format is %s and '%s' is %s\n", |
| 1116 |
|
progname, f1name, file_type[typ1], |
| 1117 |
|
f2name, file_type[typ2]); |
| 1118 |
|
return(1); |
| 1128 |
|
printf("%s: warning - unrecognized format\n", |
| 1129 |
|
progname); |
| 1130 |
|
} |
| 1131 |
< |
if (report >= REP_VERBOSE) |
| 1132 |
< |
printf("%s: input file type is %s\n", |
| 1133 |
< |
progname, file_type[typ1]); |
| 1134 |
< |
|
| 1131 |
> |
if (report >= REP_VERBOSE) { |
| 1132 |
> |
printf("%s: data format is %s\n", progname, file_type[typ1]); |
| 1133 |
> |
if ((typ1 == TYP_FLOAT) | (typ1 == TYP_DOUBLE)) { |
| 1134 |
> |
if (f1swap) |
| 1135 |
> |
printf("%s: input '%s' is byte-swapped\n", |
| 1136 |
> |
progname, f1name); |
| 1137 |
> |
if (f2swap) |
| 1138 |
> |
printf("%s: input '%s' is byte-swapped\n", |
| 1139 |
> |
progname, f2name); |
| 1140 |
> |
} |
| 1141 |
> |
} |
| 1142 |
|
switch (typ1) { /* compare based on type */ |
| 1143 |
|
case TYP_BINARY: |
| 1144 |
|
case TYP_TMESH: |
| 1155 |
|
case TYP_RGBE: |
| 1156 |
|
case TYP_XYZE: |
| 1157 |
|
return( !compare_hdr() ); |
| 1158 |
+ |
case TYP_SPEC: |
| 1159 |
+ |
return( !compare_spec() ); |
| 1160 |
|
case TYP_DEPTH: |
| 1161 |
|
return( !compare_depth() ); |
| 1162 |
|
case TYP_NORM: |