| 8 |
|
*/ |
| 9 |
|
|
| 10 |
|
#include <stdlib.h> |
| 11 |
– |
#include <math.h> |
| 11 |
|
#include <ctype.h> |
| 12 |
+ |
#include "rtmath.h" |
| 13 |
|
#include "platform.h" |
| 14 |
|
#include "rtio.h" |
| 15 |
|
#include "resolu.h" |
| 16 |
|
#include "color.h" |
| 17 |
+ |
#include "depthcodec.h" |
| 18 |
+ |
#include "normcodec.h" |
| 19 |
|
#include "lookup.h" |
| 20 |
|
/* Reporting levels */ |
| 21 |
|
#define REP_QUIET 0 /* no reporting */ |
| 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", |
| 58 |
|
"double", |
| 59 |
|
"BSDF_RBFmesh", |
| 60 |
|
"Radiance_octree", |
| 61 |
|
"Radiance_tmesh", |
| 62 |
+ |
"8-bit_indexed_name", |
| 63 |
+ |
"16-bit_indexed_name", |
| 64 |
+ |
"24-bit_indexed_name", |
| 65 |
|
"BINARY_unknown", |
| 66 |
|
NULL /* terminator */ |
| 67 |
|
}; |
| 68 |
|
/* keep consistent with above */ |
| 69 |
< |
enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE, TYP_FLOAT, |
| 70 |
< |
TYP_DOUBLE, TYP_RBFMESH, TYP_OCTREE, TYP_TMESH, TYP_BINARY}; |
| 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}; |
| 73 |
|
|
| 74 |
|
#define has_header(t) (!( 1L<<(t) & (1L<<TYP_TEXT | 1L<<TYP_BINARY) )) |
| 75 |
|
|
| 78 |
|
"SOFTWARE", |
| 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) |
| 236 |
|
{ |
| 237 |
|
int p; |
| 238 |
|
|
| 239 |
< |
if (!real_check(colval(c1,RED)+colval(c1,GRN)+colval(c1,BLU)*(1./3.), |
| 240 |
< |
colval(c2,RED)+colval(c2,GRN)+colval(c2,BLU))*(1./3.)) |
| 239 |
> |
if (!real_check((colval(c1,RED)+colval(c1,GRN)+colval(c1,BLU))*(1./3.), |
| 240 |
> |
(colval(c2,RED)+colval(c2,GRN)+colval(c2,BLU))*(1./3.))) |
| 241 |
|
return(0); |
| 242 |
|
|
| 243 |
|
p = (colval(c1,GRN) > colval(c1,RED)) ? GRN : RED; |
| 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]*nv2[2]; |
| 292 |
+ |
int imax = 2; |
| 293 |
+ |
int i = 2; |
| 294 |
+ |
/* identify largest component */ |
| 295 |
+ |
while (i--) { |
| 296 |
+ |
double tm2 = nv1[i]*nv2[i]; |
| 297 |
+ |
if (tm2 > max2) { |
| 298 |
+ |
imax = i; |
| 299 |
+ |
max2 = tm2; |
| 300 |
+ |
} |
| 301 |
+ |
} |
| 302 |
+ |
i = 3; /* compare smaller components */ |
| 303 |
+ |
while (i--) { |
| 304 |
+ |
if (i == imax) |
| 305 |
+ |
continue; |
| 306 |
+ |
if (!real_check(nv1[i], nv2[i])) |
| 307 |
+ |
return(0); |
| 308 |
+ |
} |
| 309 |
+ |
return(1); |
| 310 |
+ |
} |
| 311 |
+ |
|
| 312 |
|
/* Compare two strings for equivalence */ |
| 313 |
|
static int |
| 314 |
|
equiv_string(char *s1, char *s2) |
| 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); |
| 428 |
– |
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) |
| 714 |
+ |
{ |
| 715 |
+ |
if (r1p->rt != r2p->rt) { |
| 716 |
+ |
if (report != REP_QUIET) |
| 717 |
+ |
printf( |
| 718 |
+ |
"%s: %ss '%s' and '%s' have different pixel ordering\n", |
| 719 |
+ |
progname, class, f1name, f2name); |
| 720 |
+ |
return(0); |
| 721 |
+ |
} |
| 722 |
+ |
if ((r1p->xr != r2p->xr) | (r1p->yr != r2p->yr)) { |
| 723 |
+ |
if (report != REP_QUIET) |
| 724 |
+ |
printf( |
| 725 |
+ |
"%s: %ss '%s' and '%s' are different sizes\n", |
| 726 |
+ |
progname, class, f1name, f2name); |
| 727 |
+ |
return(0); |
| 728 |
+ |
} |
| 729 |
+ |
return(1); |
| 730 |
+ |
} |
| 731 |
+ |
|
| 732 |
|
/* Compare two inputs that are known to be RGBE or XYZE images */ |
| 733 |
|
static int |
| 734 |
|
compare_hdr() |
| 743 |
|
} |
| 744 |
|
fgetsresolu(&rs1, f1in); |
| 745 |
|
fgetsresolu(&rs2, f2in); |
| 746 |
< |
if (rs1.rt != rs2.rt) { |
| 582 |
< |
if (report != REP_QUIET) |
| 583 |
< |
printf( |
| 584 |
< |
"%s: Images '%s' and '%s' have different pixel ordering\n", |
| 585 |
< |
progname, f1name, f2name); |
| 746 |
> |
if (!check_resolu("HDR image", &rs1, &rs2)) |
| 747 |
|
return(0); |
| 587 |
– |
} |
| 588 |
– |
if ((rs1.xr != rs2.xr) | (rs1.yr != rs2.yr)) { |
| 589 |
– |
if (report != REP_QUIET) |
| 590 |
– |
printf( |
| 591 |
– |
"%s: Images '%s' and '%s' are different sizes\n", |
| 592 |
– |
progname, f1name, f2name); |
| 593 |
– |
return(0); |
| 594 |
– |
} |
| 748 |
|
scan1 = (COLOR *)malloc(scanlen(&rs1)*sizeof(COLOR)); |
| 749 |
|
scan2 = (COLOR *)malloc(scanlen(&rs2)*sizeof(COLOR)); |
| 750 |
|
if (!scan1 | !scan2) { |
| 765 |
|
if (color_check(scan1[x], scan2[x])) |
| 766 |
|
continue; |
| 767 |
|
if (report != REP_QUIET) { |
| 768 |
< |
printf( |
| 616 |
< |
"%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) |
| 870 |
+ |
{ |
| 871 |
+ |
static char depthvar[] = DEPTHSTR; |
| 872 |
+ |
const char *drval; |
| 873 |
+ |
|
| 874 |
+ |
depthvar[LDEPTHSTR-1] = '\0'; |
| 875 |
+ |
drval = (const char *)lu_find(htp, depthvar)->data; |
| 876 |
+ |
if (!drval) |
| 877 |
+ |
return(0); |
| 878 |
+ |
dcp->refdepth = atof(drval); |
| 879 |
+ |
if (dcp->refdepth <= 0) { |
| 880 |
+ |
if (report != REP_QUIET) { |
| 881 |
+ |
fputs(dcp->inpname, stderr); |
| 882 |
+ |
fputs(": bad reference depth '", stderr); |
| 883 |
+ |
fputs(drval, stderr); |
| 884 |
+ |
fputs("'\n", stderr); |
| 885 |
+ |
} |
| 886 |
+ |
return(-1); |
| 887 |
+ |
} |
| 888 |
+ |
return(1); |
| 889 |
+ |
} |
| 890 |
+ |
|
| 891 |
+ |
/* Compare two encoded depth maps */ |
| 892 |
+ |
static int |
| 893 |
+ |
compare_depth() |
| 894 |
+ |
{ |
| 895 |
+ |
long nread = 0; |
| 896 |
+ |
DEPTHCODEC dc1, dc2; |
| 897 |
+ |
|
| 898 |
+ |
if (report >= REP_VERBOSE) { |
| 899 |
+ |
fputs(progname, stdout); |
| 900 |
+ |
fputs(": comparing inputs as depth maps\n", stdout); |
| 901 |
+ |
} |
| 902 |
+ |
set_dc_defaults(&dc1); |
| 903 |
+ |
dc1.hdrflags = HF_RESIN; |
| 904 |
+ |
dc1.finp = f1in; |
| 905 |
+ |
dc1.inpname = f1name; |
| 906 |
+ |
set_dc_defaults(&dc2); |
| 907 |
+ |
dc2.hdrflags = HF_RESIN; |
| 908 |
+ |
dc2.finp = f2in; |
| 909 |
+ |
dc2.inpname = f2name; |
| 910 |
+ |
if (report != REP_QUIET) { |
| 911 |
+ |
dc1.hdrflags |= HF_STDERR; |
| 912 |
+ |
dc2.hdrflags |= HF_STDERR; |
| 913 |
+ |
} |
| 914 |
+ |
if (!process_dc_header(&dc1, 0, NULL)) |
| 915 |
+ |
return(0); |
| 916 |
+ |
if (!process_dc_header(&dc2, 0, NULL)) |
| 917 |
+ |
return(0); |
| 918 |
+ |
if (!check_resolu("Depth map", &dc1.res, &dc2.res)) |
| 919 |
+ |
return(0); |
| 920 |
+ |
if (set_refdepth(&dc1, &hdr1) < 0) |
| 921 |
+ |
return(0); |
| 922 |
+ |
if (set_refdepth(&dc2, &hdr2) < 0) |
| 923 |
+ |
return(0); |
| 924 |
+ |
while (nread < dc1.res.xr*dc1.res.yr) { |
| 925 |
+ |
double d1 = decode_depth_next(&dc1); |
| 926 |
+ |
double d2 = decode_depth_next(&dc2); |
| 927 |
+ |
if ((d1 < 0) | (d2 < 0)) { |
| 928 |
+ |
if (report != REP_QUIET) |
| 929 |
+ |
printf("%s: unexpected end-of-file\n", |
| 930 |
+ |
progname); |
| 931 |
+ |
return(0); |
| 932 |
+ |
} |
| 933 |
+ |
++nread; |
| 934 |
+ |
if (real_check(d1, d2)) |
| 935 |
+ |
continue; |
| 936 |
+ |
if (report != REP_QUIET) |
| 937 |
+ |
printf("%s: %ld%s depth values differ\n", |
| 938 |
+ |
progname, nread, num_sfx(nread)); |
| 939 |
+ |
return(0); |
| 940 |
+ |
} |
| 941 |
+ |
return(good_RMS()); /* final check of RMS */ |
| 942 |
+ |
} |
| 943 |
+ |
|
| 944 |
+ |
/* Compare two encoded normal maps */ |
| 945 |
+ |
static int |
| 946 |
+ |
compare_norm() |
| 947 |
+ |
{ |
| 948 |
+ |
long nread = 0; |
| 949 |
+ |
NORMCODEC nc1, nc2; |
| 950 |
+ |
|
| 951 |
+ |
if (report >= REP_VERBOSE) { |
| 952 |
+ |
fputs(progname, stdout); |
| 953 |
+ |
fputs(": comparing inputs as normal maps\n", stdout); |
| 954 |
+ |
} |
| 955 |
+ |
set_nc_defaults(&nc1); |
| 956 |
+ |
nc1.hdrflags = HF_RESIN; |
| 957 |
+ |
nc1.finp = f1in; |
| 958 |
+ |
nc1.inpname = f1name; |
| 959 |
+ |
set_nc_defaults(&nc2); |
| 960 |
+ |
nc2.hdrflags = HF_RESIN; |
| 961 |
+ |
nc2.finp = f2in; |
| 962 |
+ |
nc2.inpname = f2name; |
| 963 |
+ |
if (report != REP_QUIET) { |
| 964 |
+ |
nc1.hdrflags |= HF_STDERR; |
| 965 |
+ |
nc2.hdrflags |= HF_STDERR; |
| 966 |
+ |
} |
| 967 |
+ |
if (!process_nc_header(&nc1, 0, NULL)) |
| 968 |
+ |
return(0); |
| 969 |
+ |
if (!process_nc_header(&nc2, 0, NULL)) |
| 970 |
+ |
return(0); |
| 971 |
+ |
if (!check_resolu("Normal map", &nc1.res, &nc2.res)) |
| 972 |
+ |
return(0); |
| 973 |
+ |
while (nread < nc1.res.xr*nc1.res.yr) { |
| 974 |
+ |
FVECT nv1, nv2; |
| 975 |
+ |
int rv1 = decode_normal_next(nv1, &nc1); |
| 976 |
+ |
int rv2 = decode_normal_next(nv2, &nc2); |
| 977 |
+ |
if ((rv1 < 0) | (rv2 < 0)) { |
| 978 |
+ |
if (report != REP_QUIET) |
| 979 |
+ |
printf("%s: unexpected end-of-file\n", |
| 980 |
+ |
progname); |
| 981 |
+ |
return(0); |
| 982 |
+ |
} |
| 983 |
+ |
++nread; |
| 984 |
+ |
if (rv1 == rv2 && (!rv1 || norm_check(nv1, nv2))) |
| 985 |
+ |
continue; |
| 986 |
+ |
if (report != REP_QUIET) |
| 987 |
+ |
printf("%s: %ld%s normal vectors differ\n", |
| 988 |
+ |
progname, nread, num_sfx(nread)); |
| 989 |
+ |
return(0); |
| 990 |
+ |
} |
| 991 |
+ |
return(good_RMS()); /* final check of RMS */ |
| 992 |
+ |
} |
| 993 |
+ |
|
| 994 |
|
/* Compare two inputs that are known to be 32-bit floating-point data */ |
| 995 |
|
static int |
| 996 |
|
compare_float() |
| 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); |
| 1142 |
|
ign_header |= !has_header(typ1); /* check headers if indicated */ |
| 1143 |
|
if (!ign_header && !headers_match()) |
| 1144 |
|
return(1); |
| 780 |
– |
lu_done(&hdr1); lu_done(&hdr2); |
| 1145 |
|
if (!ign_header & (report >= REP_WARN)) { |
| 782 |
– |
if (typ1 == TYP_UNKNOWN) |
| 783 |
– |
printf("%s: warning - unrecognized format, comparing as binary\n", |
| 784 |
– |
progname); |
| 1146 |
|
if (lin1cnt != lin2cnt) |
| 1147 |
|
printf("%s: warning - headers are different lengths\n", |
| 1148 |
|
progname); |
| 1149 |
+ |
if (typ1 == TYP_UNKNOWN) |
| 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: |
| 1167 |
|
case TYP_OCTREE: |
| 1168 |
|
case TYP_RBFMESH: |
| 1169 |
+ |
case TYP_ID8: |
| 1170 |
+ |
case TYP_ID16: |
| 1171 |
+ |
case TYP_ID24: |
| 1172 |
|
case TYP_UNKNOWN: |
| 1173 |
|
return( !compare_binary() ); |
| 1174 |
|
case TYP_TEXT: |
| 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: |
| 1185 |
+ |
return( !compare_norm() ); |
| 1186 |
|
case TYP_FLOAT: |
| 1187 |
|
return( !compare_float() ); |
| 1188 |
|
case TYP_DOUBLE: |