| 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}; |
| 79 |
|
"CAPDATE", |
| 80 |
|
"GMT", |
| 81 |
|
"FRAME", |
| 82 |
+ |
"TILED", |
| 83 |
|
NULL /* terminator */ |
| 84 |
|
}; |
| 85 |
|
/* header variable settings */ |
| 105 |
|
const char stdin_name[] = "<stdin>"; |
| 106 |
|
const char *f1name=NULL, *f2name=NULL; |
| 107 |
|
FILE *f1in=NULL, *f2in=NULL; |
| 108 |
+ |
int f1swap=0, f2swap=0; |
| 109 |
|
|
| 110 |
|
/* running real differences */ |
| 111 |
|
double diff2sum = 0; |
| 117 |
|
{ |
| 118 |
|
fputs("Usage: ", stderr); |
| 119 |
|
fputs(progname, stderr); |
| 120 |
< |
fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", |
| 120 |
> |
fputs(" [-h][-c#][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", |
| 121 |
|
stderr); |
| 122 |
|
exit(2); |
| 123 |
|
} |
| 136 |
|
} |
| 137 |
|
while (fgets(bp->str + bp->len, bp->siz - bp->len, fp)) { |
| 138 |
|
bp->len += strlen(bp->str + bp->len); |
| 139 |
< |
if (bp->str[bp->len-1] == '\n') |
| 139 |
> |
if (bp->str[bp->len-1] == '\n') { |
| 140 |
> |
if (bp->len > 1 && bp->str[bp->len-2] == '\r') { |
| 141 |
> |
bp->str[--bp->len] = '\0'; |
| 142 |
> |
bp->str[bp->len-1] = '\n'; |
| 143 |
> |
} |
| 144 |
> |
if (escape_newlines && bp->len > 1 && |
| 145 |
> |
bp->str[bp->len-2] == '\\') { |
| 146 |
> |
bp->str[--bp->len] = '\0'; |
| 147 |
> |
bp->str[bp->len-1] = ' '; |
| 148 |
> |
continue; |
| 149 |
> |
} |
| 150 |
|
break; /* found EOL */ |
| 151 |
+ |
} |
| 152 |
|
if (bp->len < bp->siz - 4) |
| 153 |
|
continue; /* at EOF? */ |
| 154 |
|
if (bp->siz >= MAXBUF) { |
| 166 |
|
if (!bp->str) |
| 167 |
|
goto memerr; |
| 168 |
|
} |
| 169 |
+ |
if (comment_c) { /* elide comment? */ |
| 170 |
+ |
char *cp = sskip2(bp->str,0); |
| 171 |
+ |
if (*cp == comment_c) { |
| 172 |
+ |
*cp++ = '\n'; |
| 173 |
+ |
*cp = '\0'; |
| 174 |
+ |
bp->len = cp - bp->str; |
| 175 |
+ |
} |
| 176 |
+ |
} |
| 177 |
|
return(bp->len); |
| 178 |
|
memerr: |
| 179 |
|
fprintf(stderr, |
| 212 |
|
|
| 213 |
|
if (rel_min > 0) { /* doing relative differences? */ |
| 214 |
|
double av2 = .25*(r1*r1 + 2.*fabs(r1*r2) + r2*r2); |
| 215 |
< |
if (av2 > rel_min*rel_min) |
| 216 |
< |
diff2 /= av2; |
| 215 |
> |
if (av2 < rel_min*rel_min) |
| 216 |
> |
av2 = rel_min*rel_min; |
| 217 |
> |
diff2 /= av2; |
| 218 |
|
} |
| 219 |
|
if (max_lim >= 0 && diff2 > max_lim*max_lim) { |
| 220 |
|
if (report != REP_QUIET) |
| 246 |
|
return(real_check(colval(c1,p), colval(c2,p))); |
| 247 |
|
} |
| 248 |
|
|
| 249 |
+ |
#if 1 |
| 250 |
+ |
/* Compare two color spectra for equivalence */ |
| 251 |
+ |
static int |
| 252 |
+ |
spec_check(COLORV *sc1, COLORV *sc2) |
| 253 |
+ |
{ |
| 254 |
+ |
int p, k; |
| 255 |
+ |
|
| 256 |
+ |
if (!real_check(scolor_mean(sc1), scolor_mean(sc2))) |
| 257 |
+ |
return(0); |
| 258 |
+ |
|
| 259 |
+ |
p = 0; /* find max. component */ |
| 260 |
+ |
for (k = NCSAMP; --k; ) |
| 261 |
+ |
if (sc1[k] > sc1[p]) |
| 262 |
+ |
p = k; |
| 263 |
+ |
|
| 264 |
+ |
return(real_check(sc1[p], sc2[p])); |
| 265 |
+ |
} |
| 266 |
+ |
#else |
| 267 |
+ |
/* Compare two color spectra for equivalence */ |
| 268 |
+ |
static int |
| 269 |
+ |
spec_check(COLORV *sc1, COLORV *sc2) |
| 270 |
+ |
{ |
| 271 |
+ |
COLOR c1, c2; |
| 272 |
+ |
int p; |
| 273 |
+ |
|
| 274 |
+ |
if (!real_check(scolor_mean(sc1), scolor_mean(sc2))) |
| 275 |
+ |
return(0); |
| 276 |
+ |
/* do comparisons in RGB space */ |
| 277 |
+ |
scolor_rgb(c1, sc1); |
| 278 |
+ |
scolor_rgb(c2, sc2); |
| 279 |
+ |
|
| 280 |
+ |
p = (colval(c1,GRN) > colval(c1,RED)) ? GRN : RED; |
| 281 |
+ |
if (colval(c1,BLU) > colval(c1,p)) p = BLU; |
| 282 |
+ |
|
| 283 |
+ |
return(real_check(colval(c1,p), colval(c2,p))); |
| 284 |
+ |
} |
| 285 |
+ |
#endif |
| 286 |
+ |
|
| 287 |
|
/* Compare two normal directions for equivalence */ |
| 288 |
|
static int |
| 289 |
|
norm_check(FVECT nv1, FVECT nv2) |
| 290 |
|
{ |
| 291 |
< |
double max2 = nv1[2]*nv1[2]; |
| 291 |
> |
double max2 = nv1[2]*nv2[2]; |
| 292 |
|
int imax = 2; |
| 293 |
|
int i = 2; |
| 294 |
|
/* identify largest component */ |
| 295 |
|
while (i--) { |
| 296 |
< |
double tm2 = nv1[i]*nv1[i]; |
| 296 |
> |
double tm2 = nv1[i]*nv2[i]; |
| 297 |
|
if (tm2 > max2) { |
| 298 |
|
imax = i; |
| 299 |
|
max2 = tm2; |
| 381 |
|
static int |
| 382 |
|
setheadvar(char *val, void *p) |
| 383 |
|
{ |
| 384 |
+ |
char newval[128]; |
| 385 |
|
LUTAB *htp = (LUTAB *)p; |
| 386 |
|
LUENT *tep; |
| 387 |
|
char *key; |
| 391 |
|
adv_linecnt(htp); /* side-effect is to count lines */ |
| 392 |
|
if (!isalpha(*val)) /* key must start line */ |
| 393 |
|
return(0); |
| 394 |
+ |
/* check if we need to swap binary data */ |
| 395 |
+ |
if ((n = isbigendian(val)) >= 0) { |
| 396 |
+ |
if (nativebigendian() == n) |
| 397 |
+ |
return(0); |
| 398 |
+ |
f1swap += (htp == &hdr1); |
| 399 |
+ |
f2swap += (htp == &hdr2); |
| 400 |
+ |
return(0); |
| 401 |
+ |
} |
| 402 |
|
key = val++; |
| 403 |
|
while (*val && !isspace(*val) & (*val != '=')) |
| 404 |
|
val++; |
| 424 |
|
return(-1); /* memory allocation error */ |
| 425 |
|
if (!tep->key) |
| 426 |
|
tep->key = strcpy(malloc(kln+1), key); |
| 427 |
< |
if (tep->data) |
| 427 |
> |
if (tep->data) { /* check for special cases */ |
| 428 |
> |
if (!strcmp(key, "EXPOSURE")) { |
| 429 |
> |
sprintf(newval, "%.6e", atof(tep->data)*atof(val)); |
| 430 |
> |
vln = strlen(val = newval); |
| 431 |
> |
} |
| 432 |
|
free(tep->data); |
| 433 |
+ |
} |
| 434 |
|
tep->data = strcpy(malloc(vln+1), val); |
| 435 |
|
return(1); |
| 436 |
|
} |
| 539 |
|
} |
| 540 |
|
if (c) |
| 541 |
|
return(TYP_BINARY); |
| 463 |
– |
SET_FILE_TEXT(fin); /* originally set to binary */ |
| 542 |
|
return(TYP_TEXT); |
| 543 |
|
badeof: |
| 544 |
|
if (report != REP_QUIET) { |
| 621 |
|
|
| 622 |
|
if (report >= REP_VERBOSE) { |
| 623 |
|
fputs(progname, stdout); |
| 624 |
< |
fputs(": comparing inputs as ASCII text\n", stdout); |
| 624 |
> |
fputs(": comparing inputs as ASCII text", stdout); |
| 625 |
> |
if (escape_newlines) |
| 626 |
> |
fputs(", allowing escaped newlines", stdout); |
| 627 |
> |
if (comment_c) { |
| 628 |
> |
fputs(", ignoring comments starting with '", stdout); |
| 629 |
> |
fputc(comment_c, stdout); |
| 630 |
> |
fputc('\'', stdout); |
| 631 |
> |
} |
| 632 |
> |
fputc('\n', stdout); |
| 633 |
|
} |
| 634 |
+ |
SET_FILE_TEXT(f1in); /* originally set to binary */ |
| 635 |
+ |
SET_FILE_TEXT(f2in); |
| 636 |
|
init_line(&l1buf); init_line(&l2buf); /* compare a line at a time */ |
| 637 |
|
while (read_line(&l1buf, f1in)) { |
| 638 |
|
lin1cnt++; |
| 655 |
|
/* compare non-empty lines */ |
| 656 |
|
if (!equiv_string(l1buf.str, l2buf.str)) { |
| 657 |
|
if (report != REP_QUIET) { |
| 658 |
< |
printf("%s: inputs '%s' and '%s' differ at line %d|%d\n", |
| 659 |
< |
progname, f1name, f2name, |
| 660 |
< |
lin1cnt, lin2cnt); |
| 658 |
> |
printf("%s: inputs '%s' and '%s' differ at line %d", |
| 659 |
> |
progname, f1name, f2name, lin1cnt); |
| 660 |
> |
if (lin1cnt != lin2cnt) |
| 661 |
> |
printf("|%d\n", lin2cnt); |
| 662 |
> |
else |
| 663 |
> |
putchar('\n'); |
| 664 |
|
if ( report >= REP_VERBOSE && |
| 665 |
|
(l1buf.len < 256) & |
| 666 |
|
(l2buf.len < 256) ) { |
| 690 |
|
return(good_RMS()); /* final check for reals */ |
| 691 |
|
} |
| 692 |
|
|
| 693 |
+ |
/* Set resolution based on NROWS, NCOLS in header */ |
| 694 |
+ |
static int |
| 695 |
+ |
set_resolu(RESOLU *rs, LUTAB *htp) |
| 696 |
+ |
{ |
| 697 |
+ |
const char *val; |
| 698 |
+ |
|
| 699 |
+ |
rs->rt = PIXSTANDARD; |
| 700 |
+ |
val = (const char *)lu_find(htp, "NROWS")->data; |
| 701 |
+ |
if (!val) return(0); |
| 702 |
+ |
rs->yr = atoi(val); |
| 703 |
+ |
if (rs->yr <= 0) return(-1); |
| 704 |
+ |
val = (const char *)lu_find(htp, "NCOLS")->data; |
| 705 |
+ |
if (!val) return(0); |
| 706 |
+ |
rs->xr = atoi(val); |
| 707 |
+ |
if (rs->xr <= 0) return(-1); |
| 708 |
+ |
return(1); |
| 709 |
+ |
} |
| 710 |
+ |
|
| 711 |
|
/* Check image/map resolutions */ |
| 712 |
|
static int |
| 713 |
|
check_resolu(const char *class, RESOLU *r1p, RESOLU *r2p) |
| 765 |
|
if (color_check(scan1[x], scan2[x])) |
| 766 |
|
continue; |
| 767 |
|
if (report != REP_QUIET) { |
| 768 |
< |
printf( |
| 660 |
< |
"%s: pixels at scanline %d offset %d differ\n", |
| 768 |
> |
printf("%s: pixels at scanline %d offset %d differ\n", |
| 769 |
|
progname, y, x); |
| 770 |
|
if (report >= REP_VERBOSE) { |
| 771 |
|
printf("%s: (R,G,B)=(%g,%g,%g)\n", |
| 788 |
|
return(good_RMS()); /* final check of RMS */ |
| 789 |
|
} |
| 790 |
|
|
| 791 |
+ |
/* Compare two inputs that are known to be spectral images */ |
| 792 |
+ |
static int |
| 793 |
+ |
compare_spec() |
| 794 |
+ |
{ |
| 795 |
+ |
static char NCstr[] = NCOMPSTR; |
| 796 |
+ |
RESOLU rs1, rs2; |
| 797 |
+ |
COLORV *scan1, *scan2; |
| 798 |
+ |
const char *val; |
| 799 |
+ |
int x, y; |
| 800 |
+ |
|
| 801 |
+ |
if (report >= REP_VERBOSE) { |
| 802 |
+ |
fputs(progname, stdout); |
| 803 |
+ |
fputs(": comparing inputs as spectral images\n", stdout); |
| 804 |
+ |
} |
| 805 |
+ |
if (!(set_resolu(&rs1, &hdr1) || fgetsresolu(&rs1, f1in))) |
| 806 |
+ |
return(0); |
| 807 |
+ |
if (!(set_resolu(&rs2, &hdr2) || fgetsresolu(&rs2, f2in))) |
| 808 |
+ |
return(0); |
| 809 |
+ |
if (!check_resolu("Spectral image", &rs1, &rs2)) |
| 810 |
+ |
return(0); |
| 811 |
+ |
NCstr[LNCOMPSTR-1] = '\0'; |
| 812 |
+ |
val = (const char *)lu_find(&hdr1, NCstr)->data; |
| 813 |
+ |
if (!val || (NCSAMP = atoi(val)) < 3) { |
| 814 |
+ |
if (report != REP_QUIET) { |
| 815 |
+ |
if (val) |
| 816 |
+ |
printf("%s: illegal # components (%d) for spectral image\n", |
| 817 |
+ |
progname, NCSAMP); |
| 818 |
+ |
else |
| 819 |
+ |
printf("%s: missing %s in header for spectral image\n", |
| 820 |
+ |
progname, NCstr); |
| 821 |
+ |
} |
| 822 |
+ |
return(0); |
| 823 |
+ |
} |
| 824 |
+ |
scan1 = (COLORV *)malloc(sizeof(COLORV)*NCSAMP*scanlen(&rs1)); |
| 825 |
+ |
scan2 = (COLORV *)malloc(sizeof(COLORV)*NCSAMP*scanlen(&rs2)); |
| 826 |
+ |
if (!scan1 | !scan2) { |
| 827 |
+ |
fprintf(stderr, "%s: out of memory in compare_hdr()\n", progname); |
| 828 |
+ |
exit(2); |
| 829 |
+ |
} |
| 830 |
+ |
for (y = 0; y < numscans(&rs1); y++) { |
| 831 |
+ |
if ((freadsscan(scan1, NCSAMP, scanlen(&rs1), f1in) < 0) | |
| 832 |
+ |
(freadsscan(scan2, NCSAMP, scanlen(&rs2), f2in) < 0)) { |
| 833 |
+ |
if (report != REP_QUIET) |
| 834 |
+ |
printf("%s: unexpected end-of-file\n", progname); |
| 835 |
+ |
free(scan1); |
| 836 |
+ |
free(scan2); |
| 837 |
+ |
return(0); |
| 838 |
+ |
} |
| 839 |
+ |
for (x = 0; x < scanlen(&rs1); x++) { |
| 840 |
+ |
if (spec_check(scan1+x*NCSAMP, scan2+x*NCSAMP)) |
| 841 |
+ |
continue; |
| 842 |
+ |
if (report != REP_QUIET) { |
| 843 |
+ |
int k; |
| 844 |
+ |
printf("%s: spectra at scanline %d offset %d differ\n", |
| 845 |
+ |
progname, y, x); |
| 846 |
+ |
if (report >= REP_VERBOSE) { |
| 847 |
+ |
printf("%s: spectrum =", f1name); |
| 848 |
+ |
for (k = 0; k < NCSAMP; k++) |
| 849 |
+ |
printf(" %g", scan1[x*NCSAMP+k]); |
| 850 |
+ |
fputc('\n', stdout); |
| 851 |
+ |
printf("%s: spectrum =", f2name); |
| 852 |
+ |
for (k = 0; k < NCSAMP; k++) |
| 853 |
+ |
printf(" %g", scan2[x*NCSAMP+k]); |
| 854 |
+ |
fputc('\n', stdout); |
| 855 |
+ |
} |
| 856 |
+ |
} |
| 857 |
+ |
free(scan1); |
| 858 |
+ |
free(scan2); |
| 859 |
+ |
return(0); |
| 860 |
+ |
} |
| 861 |
+ |
} |
| 862 |
+ |
free(scan1); |
| 863 |
+ |
free(scan2); |
| 864 |
+ |
return(good_RMS()); /* final check of RMS */ |
| 865 |
+ |
} |
| 866 |
+ |
|
| 867 |
|
/* Set reference depth based on header variable */ |
| 868 |
|
static int |
| 869 |
|
set_refdepth(DEPTHCODEC *dcp, LUTAB *htp) |
| 871 |
|
static char depthvar[] = DEPTHSTR; |
| 872 |
|
const char *drval; |
| 873 |
|
|
| 874 |
< |
depthvar[LDEPTHSTR] = '\0'; |
| 874 |
> |
depthvar[LDEPTHSTR-1] = '\0'; |
| 875 |
|
drval = (const char *)lu_find(htp, depthvar)->data; |
| 876 |
|
if (!drval) |
| 877 |
|
return(0); |
| 1006 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
| 1007 |
|
goto badeof; |
| 1008 |
|
++nread; |
| 1009 |
+ |
if (f1swap) swap32((char *)&f1, 1); |
| 1010 |
+ |
if (f2swap) swap32((char *)&f2, 1); |
| 1011 |
|
if (real_check(f1, f2)) |
| 1012 |
|
continue; |
| 1013 |
|
if (report != REP_QUIET) |
| 1038 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
| 1039 |
|
goto badeof; |
| 1040 |
|
++nread; |
| 1041 |
+ |
if (f1swap) swap64((char *)&f1, 1); |
| 1042 |
+ |
if (f2swap) swap64((char *)&f2, 1); |
| 1043 |
|
if (real_check(f1, f2)) |
| 1044 |
|
continue; |
| 1045 |
|
if (report != REP_QUIET) |
| 1068 |
|
case 'h': /* ignore header info. */ |
| 1069 |
|
ign_header = !ign_header; |
| 1070 |
|
continue; |
| 1071 |
+ |
case 'n': /* allow newline escapes */ |
| 1072 |
+ |
escape_newlines = !escape_newlines; |
| 1073 |
+ |
continue; |
| 1074 |
+ |
case 'c': /* ignore comments */ |
| 1075 |
+ |
comment_c = argv[a][2]; |
| 1076 |
+ |
continue; |
| 1077 |
|
case 's': /* silent operation */ |
| 1078 |
|
report = REP_QUIET; |
| 1079 |
|
continue; |
| 1134 |
|
return(2); |
| 1135 |
|
if (typ1 != typ2) { |
| 1136 |
|
if (report != REP_QUIET) |
| 1137 |
< |
printf("%s: '%s' is %s and '%s' is %s\n", |
| 1137 |
> |
printf("%s: '%s' format is %s and '%s' is %s\n", |
| 1138 |
|
progname, f1name, file_type[typ1], |
| 1139 |
|
f2name, file_type[typ2]); |
| 1140 |
|
return(1); |
| 1150 |
|
printf("%s: warning - unrecognized format\n", |
| 1151 |
|
progname); |
| 1152 |
|
} |
| 1153 |
< |
if (report >= REP_VERBOSE) |
| 1154 |
< |
printf("%s: input file type is %s\n", |
| 1155 |
< |
progname, file_type[typ1]); |
| 1156 |
< |
|
| 1153 |
> |
if (report >= REP_VERBOSE) { |
| 1154 |
> |
printf("%s: data format is %s\n", progname, file_type[typ1]); |
| 1155 |
> |
if ((typ1 == TYP_FLOAT) | (typ1 == TYP_DOUBLE)) { |
| 1156 |
> |
if (f1swap) |
| 1157 |
> |
printf("%s: input '%s' is byte-swapped\n", |
| 1158 |
> |
progname, f1name); |
| 1159 |
> |
if (f2swap) |
| 1160 |
> |
printf("%s: input '%s' is byte-swapped\n", |
| 1161 |
> |
progname, f2name); |
| 1162 |
> |
} |
| 1163 |
> |
} |
| 1164 |
|
switch (typ1) { /* compare based on type */ |
| 1165 |
|
case TYP_BINARY: |
| 1166 |
|
case TYP_TMESH: |
| 1177 |
|
case TYP_RGBE: |
| 1178 |
|
case TYP_XYZE: |
| 1179 |
|
return( !compare_hdr() ); |
| 1180 |
+ |
case TYP_SPEC: |
| 1181 |
+ |
return( !compare_spec() ); |
| 1182 |
|
case TYP_DEPTH: |
| 1183 |
|
return( !compare_depth() ); |
| 1184 |
|
case TYP_NORM: |