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 */ |
35 |
|
|
36 |
|
int lin1cnt=0, lin2cnt=0; /* file line position */ |
37 |
|
|
38 |
+ |
const char nsuffix[10][3] = { /* 1st, 2nd, 3rd, etc. */ |
39 |
+ |
"th","st","nd","rd","th","th","th","th","th","th" |
40 |
+ |
}; |
41 |
+ |
#define num_sfx(n) nsuffix[(n)%10] |
42 |
+ |
|
43 |
|
/* file types */ |
44 |
|
const char *file_type[] = { |
45 |
|
"Unrecognized", |
47 |
|
"ascii", |
48 |
|
COLRFMT, |
49 |
|
CIEFMT, |
50 |
+ |
DEPTH16FMT, |
51 |
+ |
NORMAL32FMT, |
52 |
|
"float", |
53 |
|
"double", |
54 |
|
"BSDF_RBFmesh", |
55 |
|
"Radiance_octree", |
56 |
|
"Radiance_tmesh", |
57 |
+ |
"8-bit_indexed_name", |
58 |
+ |
"16-bit_indexed_name", |
59 |
+ |
"24-bit_indexed_name", |
60 |
|
"BINARY_unknown", |
61 |
|
NULL /* terminator */ |
62 |
|
}; |
63 |
< |
|
64 |
< |
enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE, TYP_FLOAT, |
65 |
< |
TYP_DOUBLE, TYP_RBFMESH, TYP_OCTREE, TYP_TMESH, TYP_BINARY}; |
63 |
> |
/* keep consistent with above */ |
64 |
> |
enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE, |
65 |
> |
TYP_DEPTH, TYP_NORM, TYP_FLOAT, TYP_DOUBLE, |
66 |
> |
TYP_RBFMESH, TYP_OCTREE, TYP_TMESH, |
67 |
> |
TYP_ID8, TYP_ID16, TYP_ID24, TYP_BINARY}; |
68 |
|
|
69 |
|
#define has_header(t) (!( 1L<<(t) & (1L<<TYP_TEXT | 1L<<TYP_BINARY) )) |
70 |
|
|
73 |
|
"SOFTWARE", |
74 |
|
"CAPDATE", |
75 |
|
"GMT", |
76 |
+ |
"FRAME", |
77 |
|
NULL /* terminator */ |
78 |
|
}; |
79 |
|
/* header variable settings */ |
84 |
|
#define adv_linecnt(htp) (lin1cnt += (htp == &hdr1), \ |
85 |
|
lin2cnt += (htp == &hdr2)) |
86 |
|
|
87 |
+ |
typedef struct { /* dynamic line buffer */ |
88 |
+ |
char *str; |
89 |
+ |
int len; |
90 |
+ |
int siz; |
91 |
+ |
} LINEBUF; |
92 |
+ |
|
93 |
+ |
#define init_line(bp) ((bp)->str = NULL, (bp)->siz = 0) |
94 |
+ |
/* 100 MByte limit on line buffer */ |
95 |
+ |
#define MAXBUF (100L<<20) |
96 |
+ |
|
97 |
|
/* input files */ |
98 |
|
char *progname = NULL; |
99 |
|
const char stdin_name[] = "<stdin>"; |
100 |
|
const char *f1name=NULL, *f2name=NULL; |
101 |
|
FILE *f1in=NULL, *f2in=NULL; |
102 |
+ |
int f1swap=0, f2swap=0; |
103 |
|
|
104 |
|
/* running real differences */ |
105 |
|
double diff2sum = 0; |
106 |
< |
int nsum = 0; |
106 |
> |
long nsum = 0; |
107 |
|
|
108 |
|
/* Report usage and exit */ |
109 |
|
static void |
113 |
|
fputs(progname, stderr); |
114 |
|
fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", |
115 |
|
stderr); |
116 |
< |
exit(1); |
116 |
> |
exit(2); |
117 |
|
} |
118 |
|
|
119 |
+ |
/* Read a text line, increasing buffer size as necessary */ |
120 |
+ |
static int |
121 |
+ |
read_line(LINEBUF *bp, FILE *fp) |
122 |
+ |
{ |
123 |
+ |
static int doneWarn = 0; |
124 |
+ |
|
125 |
+ |
bp->len = 0; |
126 |
+ |
if (!bp->str) { |
127 |
+ |
bp->str = (char *)malloc(bp->siz = 512); |
128 |
+ |
if (!bp->str) |
129 |
+ |
goto memerr; |
130 |
+ |
} |
131 |
+ |
while (fgets(bp->str + bp->len, bp->siz - bp->len, fp)) { |
132 |
+ |
bp->len += strlen(bp->str + bp->len); |
133 |
+ |
if (bp->str[bp->len-1] == '\n') |
134 |
+ |
break; /* found EOL */ |
135 |
+ |
if (bp->len < bp->siz - 4) |
136 |
+ |
continue; /* at EOF? */ |
137 |
+ |
if (bp->siz >= MAXBUF) { |
138 |
+ |
if ((report >= REP_WARN) & !doneWarn) { |
139 |
+ |
fprintf(stderr, |
140 |
+ |
"%s: warning - input line(s) past %ld MByte limit\n", |
141 |
+ |
progname, MAXBUF>>20); |
142 |
+ |
doneWarn++; |
143 |
+ |
} |
144 |
+ |
break; /* return MAXBUF partial line */ |
145 |
+ |
} |
146 |
+ |
if ((bp->siz += bp->siz/2) > MAXBUF) |
147 |
+ |
bp->siz = MAXBUF; |
148 |
+ |
bp->str = (char *)realloc(bp->str, bp->siz); |
149 |
+ |
if (!bp->str) |
150 |
+ |
goto memerr; |
151 |
+ |
} |
152 |
+ |
return(bp->len); |
153 |
+ |
memerr: |
154 |
+ |
fprintf(stderr, |
155 |
+ |
"%s: out of memory in read_line() allocating %d byte buffer\n", |
156 |
+ |
progname, bp->siz); |
157 |
+ |
exit(2); |
158 |
+ |
} |
159 |
+ |
|
160 |
+ |
/* Free line buffer */ |
161 |
+ |
static void |
162 |
+ |
free_line(LINEBUF *bp) |
163 |
+ |
{ |
164 |
+ |
if (bp->str) free(bp->str); |
165 |
+ |
init_line(bp); |
166 |
+ |
} |
167 |
+ |
|
168 |
|
/* Get type ID from name (or 0 if not found) */ |
169 |
|
static int |
170 |
|
xlate_type(const char *nm) |
193 |
|
if (max_lim >= 0 && diff2 > max_lim*max_lim) { |
194 |
|
if (report != REP_QUIET) |
195 |
|
printf( |
196 |
< |
"%s: %sdifference between %.8g and %.8g exceeds epsilon\n", |
196 |
> |
"%s: %sdifference between %.8g and %.8g exceeds epsilon of %.8g\n", |
197 |
|
progname, |
198 |
|
(rel_min > 0) ? "relative " : "", |
199 |
< |
r1, r2); |
199 |
> |
r1, r2, max_lim); |
200 |
|
return(0); |
201 |
|
} |
202 |
|
diff2sum += diff2; |
204 |
|
return(1); |
205 |
|
} |
206 |
|
|
207 |
+ |
/* Compare two color values for equivalence */ |
208 |
+ |
static int |
209 |
+ |
color_check(COLOR c1, COLOR c2) |
210 |
+ |
{ |
211 |
+ |
int p; |
212 |
+ |
|
213 |
+ |
if (!real_check((colval(c1,RED)+colval(c1,GRN)+colval(c1,BLU))*(1./3.), |
214 |
+ |
(colval(c2,RED)+colval(c2,GRN)+colval(c2,BLU))*(1./3.))) |
215 |
+ |
return(0); |
216 |
+ |
|
217 |
+ |
p = (colval(c1,GRN) > colval(c1,RED)) ? GRN : RED; |
218 |
+ |
if (colval(c1,BLU) > colval(c1,p)) p = BLU; |
219 |
+ |
|
220 |
+ |
return(real_check(colval(c1,p), colval(c2,p))); |
221 |
+ |
} |
222 |
+ |
|
223 |
+ |
/* Compare two normal directions for equivalence */ |
224 |
+ |
static int |
225 |
+ |
norm_check(FVECT nv1, FVECT nv2) |
226 |
+ |
{ |
227 |
+ |
double max2 = nv1[2]*nv2[2]; |
228 |
+ |
int imax = 2; |
229 |
+ |
int i = 2; |
230 |
+ |
/* identify largest component */ |
231 |
+ |
while (i--) { |
232 |
+ |
double tm2 = nv1[i]*nv2[i]; |
233 |
+ |
if (tm2 > max2) { |
234 |
+ |
imax = i; |
235 |
+ |
max2 = tm2; |
236 |
+ |
} |
237 |
+ |
} |
238 |
+ |
i = 3; /* compare smaller components */ |
239 |
+ |
while (i--) { |
240 |
+ |
if (i == imax) |
241 |
+ |
continue; |
242 |
+ |
if (!real_check(nv1[i], nv2[i])) |
243 |
+ |
return(0); |
244 |
+ |
} |
245 |
+ |
return(1); |
246 |
+ |
} |
247 |
+ |
|
248 |
|
/* Compare two strings for equivalence */ |
249 |
|
static int |
250 |
|
equiv_string(char *s1, char *s2) |
317 |
|
static int |
318 |
|
setheadvar(char *val, void *p) |
319 |
|
{ |
320 |
+ |
char newval[128]; |
321 |
|
LUTAB *htp = (LUTAB *)p; |
322 |
|
LUENT *tep; |
323 |
|
char *key; |
327 |
|
adv_linecnt(htp); /* side-effect is to count lines */ |
328 |
|
if (!isalpha(*val)) /* key must start line */ |
329 |
|
return(0); |
330 |
+ |
/* check if we need to swap binary data */ |
331 |
+ |
if ((n = isbigendian(val)) >= 0) { |
332 |
+ |
if (nativebigendian() == n) |
333 |
+ |
return(0); |
334 |
+ |
f1swap += (htp == &hdr1); |
335 |
+ |
f2swap += (htp == &hdr2); |
336 |
+ |
return(0); |
337 |
+ |
} |
338 |
|
key = val++; |
339 |
|
while (*val && !isspace(*val) & (*val != '=')) |
340 |
|
val++; |
348 |
|
val++; |
349 |
|
if (!*val) /* nothing set? */ |
350 |
|
return(0); |
226 |
– |
vln = strlen(val); /* eliminate space and newline at end */ |
227 |
– |
while (--vln > 0 && isspace(val[vln])) |
228 |
– |
; |
229 |
– |
val[++vln] = '\0'; |
351 |
|
/* check if key to ignore */ |
352 |
|
for (n = 0; hdr_ignkey[n]; n++) |
353 |
|
if (!strcmp(key, hdr_ignkey[n])) |
354 |
|
return(0); |
355 |
+ |
vln = strlen(val); /* eliminate space and newline at end */ |
356 |
+ |
while (isspace(val[--vln])) |
357 |
+ |
; |
358 |
+ |
val[++vln] = '\0'; |
359 |
|
if (!(tep = lu_find(htp, key))) |
360 |
|
return(-1); /* memory allocation error */ |
361 |
|
if (!tep->key) |
362 |
|
tep->key = strcpy(malloc(kln+1), key); |
363 |
< |
if (tep->data) |
363 |
> |
if (tep->data) { /* check for special cases */ |
364 |
> |
if (!strcmp(key, "EXPOSURE")) { |
365 |
> |
sprintf(newval, "%f", atof(tep->data)*atof(val)); |
366 |
> |
vln = strlen(val = newval); |
367 |
> |
} |
368 |
|
free(tep->data); |
369 |
+ |
} |
370 |
|
tep->data = strcpy(malloc(vln+1), val); |
371 |
|
return(1); |
372 |
|
} |
378 |
|
const LUENT *ep2 = lu_find((LUTAB *)p2, ep1->key); |
379 |
|
if (!ep2 || !ep2->data) { |
380 |
|
if (report != REP_QUIET) |
381 |
< |
printf("%s: Variable '%s' missing in '%s'\n", |
381 |
> |
printf("%s: variable '%s' missing in '%s'\n", |
382 |
|
progname, ep1->key, f2name); |
383 |
|
return(-1); |
384 |
|
} |
385 |
|
if (!equiv_string((char *)ep1->data, (char *)ep2->data)) { |
386 |
|
if (report != REP_QUIET) { |
387 |
< |
printf("%s: Header variable '%s' has different values\n", |
387 |
> |
printf("%s: header variable '%s' has different values\n", |
388 |
|
progname, ep1->key); |
389 |
|
if (report >= REP_VERBOSE) { |
390 |
|
printf("%s: %s=%s\n", f1name, |
400 |
|
|
401 |
|
/* Compare two sets of header variables */ |
402 |
|
static int |
403 |
< |
headers_match(LUTAB *hp1, LUTAB *hp2) |
403 |
> |
headers_match() |
404 |
|
{ |
405 |
< |
int ne = lu_doall(hp1, match_val, hp2); |
405 |
> |
int ne = lu_doall(&hdr1, match_val, &hdr2); |
406 |
|
if (ne < 0) |
407 |
|
return(0); /* something didn't match! */ |
408 |
|
/* non-fatal if second header has extra */ |
409 |
< |
if (report >= REP_WARN && (ne = lu_doall(hp2, NULL, NULL) - ne)) |
410 |
< |
printf("%s: '%s' has %d extra header setting(s)\n", |
409 |
> |
if (report >= REP_WARN && (ne = lu_doall(&hdr2, NULL, NULL) - ne)) |
410 |
> |
printf("%s: warning - '%s' has %d extra header setting(s)\n", |
411 |
|
progname, f2name, ne); |
412 |
|
return(1); /* good match */ |
413 |
|
} |
420 |
|
int c = 0; |
421 |
|
|
422 |
|
while ((c = getc(fin)) != EOF) { |
423 |
+ |
++n; |
424 |
|
if (!c | (c > 127)) |
425 |
|
break; /* non-ascii character */ |
426 |
< |
if (++n >= 10240) |
426 |
> |
if (n >= 10240) |
427 |
|
break; /* enough to be confident */ |
428 |
|
} |
429 |
|
if (!n) |
461 |
|
} |
462 |
|
if (getheader(fin, setheadvar, htp) < 0) { |
463 |
|
fputs(name, stderr); |
464 |
< |
fputs(": Unknown error reading header\n", stderr); |
464 |
> |
fputs(": unknown error reading header\n", stderr); |
465 |
|
return(-1); |
466 |
|
} |
467 |
|
adv_linecnt(htp); /* for trailing emtpy line */ |
480 |
|
badeof: |
481 |
|
if (report != REP_QUIET) { |
482 |
|
fputs(name, stdout); |
483 |
< |
fputs(": Unexpected end-of-file\n", stdout); |
483 |
> |
fputs(": unexpected end-of-file\n", stdout); |
484 |
|
} |
485 |
|
return(-1); |
486 |
|
} |
494 |
|
if (diff2sum/(double)nsum > rms_lim*rms_lim) { |
495 |
|
if (report != REP_QUIET) |
496 |
|
printf( |
497 |
< |
"%s: %sRMS difference between '%s' and '%s' of %.5g exceeds limit\n", |
497 |
> |
"%s: %sRMS difference between '%s' and '%s' of %.5g exceeds limit of %.5g\n", |
498 |
|
progname, |
499 |
|
(rel_min > 0) ? "relative " : "", |
500 |
|
f1name, f2name, |
501 |
< |
sqrt(diff2sum/(double)nsum)); |
501 |
> |
sqrt(diff2sum/(double)nsum), rms_lim); |
502 |
|
return(0); |
503 |
|
} |
504 |
|
if (report >= REP_VERBOSE) |
512 |
|
static int |
513 |
|
compare_binary() |
514 |
|
{ |
515 |
+ |
int c1=0, c2=0; |
516 |
+ |
|
517 |
|
if (report >= REP_VERBOSE) { |
518 |
|
fputs(progname, stdout); |
519 |
|
fputs(": comparing inputs as binary\n", stdout); |
520 |
|
} |
521 |
|
for ( ; ; ) { /* exact byte matching */ |
522 |
< |
int c1 = getc(f1in); |
523 |
< |
int c2 = getc(f2in); |
522 |
> |
c1 = getc(f1in); |
523 |
> |
c2 = getc(f2in); |
524 |
|
if (c1 == EOF) { |
525 |
|
if (c2 == EOF) |
526 |
|
return(1); /* success! */ |
527 |
|
if (report != REP_QUIET) { |
528 |
|
fputs(f1name, stdout); |
529 |
< |
fputs(": Unexpected end-of-file\n", stdout); |
529 |
> |
fputs(": unexpected end-of-file\n", stdout); |
530 |
|
} |
531 |
|
return(0); |
532 |
|
} |
533 |
|
if (c2 == EOF) { |
534 |
|
if (report != REP_QUIET) { |
535 |
|
fputs(f2name, stdout); |
536 |
< |
fputs(": Unexpected end-of-file\n", stdout); |
536 |
> |
fputs(": unexpected end-of-file\n", stdout); |
537 |
|
} |
538 |
|
return(0); |
539 |
|
} |
542 |
|
} |
543 |
|
if (report == REP_QUIET) |
544 |
|
return(0); |
545 |
< |
printf("%s: binary files '%s' and '%s' differ at offset %ld|%ld\n", |
545 |
> |
printf("%s: binary files '%s' and '%s' differ at byte offset %ld|%ld\n", |
546 |
|
progname, f1name, f2name, ftell(f1in), ftell(f2in)); |
547 |
+ |
if (report >= REP_VERBOSE) |
548 |
+ |
printf("%s: byte in '%s' is 0x%X, byte in '%s' is 0x%X\n", |
549 |
+ |
progname, f1name, c1, f2name, c2); |
550 |
|
return(0); |
551 |
|
} |
552 |
|
|
554 |
|
static int |
555 |
|
compare_text() |
556 |
|
{ |
557 |
< |
char l1buf[4096], l2buf[4096]; |
557 |
> |
LINEBUF l1buf, l2buf; |
558 |
|
|
559 |
|
if (report >= REP_VERBOSE) { |
560 |
|
fputs(progname, stdout); |
561 |
|
fputs(": comparing inputs as ASCII text\n", stdout); |
562 |
|
} |
563 |
< |
/* compare a line at a time */ |
564 |
< |
while (fgets(l1buf, sizeof(l1buf), f1in)) { |
563 |
> |
init_line(&l1buf); init_line(&l2buf); /* compare a line at a time */ |
564 |
> |
while (read_line(&l1buf, f1in)) { |
565 |
|
lin1cnt++; |
566 |
< |
if (!*sskip2(l1buf,0)) |
566 |
> |
if (!*sskip2(l1buf.str,0)) |
567 |
|
continue; /* ignore empty lines */ |
568 |
< |
while (fgets(l2buf, sizeof(l2buf), f2in)) { |
568 |
> |
|
569 |
> |
while (read_line(&l2buf, f2in)) { |
570 |
|
lin2cnt++; |
571 |
< |
if (*sskip2(l2buf,0)) |
571 |
> |
if (*sskip2(l2buf.str,0)) |
572 |
|
break; /* found other non-empty line */ |
573 |
|
} |
574 |
< |
if (feof(f2in)) { |
574 |
> |
if (!l2buf.len) { /* input 2 EOF? */ |
575 |
|
if (report != REP_QUIET) { |
576 |
|
fputs(f2name, stdout); |
577 |
< |
fputs(": Unexpected end-of-file\n", stdout); |
577 |
> |
fputs(": unexpected end-of-file\n", stdout); |
578 |
|
} |
579 |
+ |
free_line(&l1buf); free_line(&l2buf); |
580 |
|
return(0); |
581 |
|
} |
582 |
|
/* compare non-empty lines */ |
583 |
< |
if (!equiv_string(l1buf, l2buf)) { |
583 |
> |
if (!equiv_string(l1buf.str, l2buf.str)) { |
584 |
|
if (report != REP_QUIET) { |
585 |
|
printf("%s: inputs '%s' and '%s' differ at line %d|%d\n", |
586 |
|
progname, f1name, f2name, |
587 |
|
lin1cnt, lin2cnt); |
588 |
< |
if (report >= REP_VERBOSE) { |
588 |
> |
if ( report >= REP_VERBOSE && |
589 |
> |
(l1buf.len < 256) & |
590 |
> |
(l2buf.len < 256) ) { |
591 |
|
fputs("------------- Mismatch -------------\n", stdout); |
592 |
< |
printf("%s(%d):\t%s", f1name, |
593 |
< |
lin1cnt, l1buf); |
594 |
< |
printf("%s(%d):\t%s", f2name, |
595 |
< |
lin2cnt, l2buf); |
592 |
> |
printf("%s@%d:\t%s", f1name, |
593 |
> |
lin1cnt, l1buf.str); |
594 |
> |
printf("%s@%d:\t%s", f2name, |
595 |
> |
lin2cnt, l2buf.str); |
596 |
|
} |
597 |
|
} |
598 |
+ |
free_line(&l1buf); free_line(&l2buf); |
599 |
|
return(0); |
600 |
|
} |
601 |
|
} |
602 |
< |
/* check for EOF on input 2 */ |
603 |
< |
while (fgets(l2buf, sizeof(l2buf), f2in)) { |
604 |
< |
if (!*sskip2(l2buf,0)) |
602 |
> |
free_line(&l1buf); /* check for EOF on input 2 */ |
603 |
> |
while (read_line(&l2buf, f2in)) { |
604 |
> |
if (!*sskip2(l2buf.str,0)) |
605 |
|
continue; |
606 |
|
if (report != REP_QUIET) { |
607 |
|
fputs(f1name, stdout); |
608 |
< |
fputs(": Unexpected end-of-file\n", stdout); |
608 |
> |
fputs(": unexpected end-of-file\n", stdout); |
609 |
|
} |
610 |
+ |
free_line(&l2buf); |
611 |
|
return(0); |
612 |
|
} |
613 |
+ |
free_line(&l2buf); |
614 |
|
return(good_RMS()); /* final check for reals */ |
615 |
|
} |
616 |
|
|
617 |
+ |
/* Check image/map resolutions */ |
618 |
+ |
static int |
619 |
+ |
check_resolu(const char *class, RESOLU *r1p, RESOLU *r2p) |
620 |
+ |
{ |
621 |
+ |
if (r1p->rt != r2p->rt) { |
622 |
+ |
if (report != REP_QUIET) |
623 |
+ |
printf( |
624 |
+ |
"%s: %ss '%s' and '%s' have different pixel ordering\n", |
625 |
+ |
progname, class, f1name, f2name); |
626 |
+ |
return(0); |
627 |
+ |
} |
628 |
+ |
if ((r1p->xr != r2p->xr) | (r1p->yr != r2p->yr)) { |
629 |
+ |
if (report != REP_QUIET) |
630 |
+ |
printf( |
631 |
+ |
"%s: %ss '%s' and '%s' are different sizes\n", |
632 |
+ |
progname, class, f1name, f2name); |
633 |
+ |
return(0); |
634 |
+ |
} |
635 |
+ |
return(1); |
636 |
+ |
} |
637 |
+ |
|
638 |
|
/* Compare two inputs that are known to be RGBE or XYZE images */ |
639 |
|
static int |
640 |
|
compare_hdr() |
643 |
|
COLOR *scan1, *scan2; |
644 |
|
int x, y; |
645 |
|
|
646 |
+ |
if (report >= REP_VERBOSE) { |
647 |
+ |
fputs(progname, stdout); |
648 |
+ |
fputs(": comparing inputs as HDR images\n", stdout); |
649 |
+ |
} |
650 |
|
fgetsresolu(&rs1, f1in); |
651 |
|
fgetsresolu(&rs2, f2in); |
652 |
< |
if (rs1.rt != rs2.rt) { |
485 |
< |
if (report != REP_QUIET) |
486 |
< |
printf( |
487 |
< |
"%s: Images '%s' and '%s' have different pixel ordering\n", |
488 |
< |
progname, f1name, f2name); |
652 |
> |
if (!check_resolu("HDR image", &rs1, &rs2)) |
653 |
|
return(0); |
490 |
– |
} |
491 |
– |
if ((rs1.xr != rs2.xr) | (rs1.yr != rs2.yr)) { |
492 |
– |
if (report != REP_QUIET) |
493 |
– |
printf( |
494 |
– |
"%s: Images '%s' and '%s' are different sizes\n", |
495 |
– |
progname, f1name, f2name); |
496 |
– |
return(0); |
497 |
– |
} |
654 |
|
scan1 = (COLOR *)malloc(scanlen(&rs1)*sizeof(COLOR)); |
655 |
|
scan2 = (COLOR *)malloc(scanlen(&rs2)*sizeof(COLOR)); |
656 |
|
if (!scan1 | !scan2) { |
661 |
|
if ((freadscan(scan1, scanlen(&rs1), f1in) < 0) | |
662 |
|
(freadscan(scan2, scanlen(&rs2), f2in) < 0)) { |
663 |
|
if (report != REP_QUIET) |
664 |
< |
printf("%s: Unexpected end-of-file\n", |
664 |
> |
printf("%s: unexpected end-of-file\n", |
665 |
|
progname); |
666 |
|
free(scan1); |
667 |
|
free(scan2); |
668 |
|
return(0); |
669 |
|
} |
670 |
< |
for (x = scanlen(&rs1); x--; ) { |
671 |
< |
if (real_check(colval(scan1[x],RED), |
516 |
< |
colval(scan2[x],RED)) & |
517 |
< |
real_check(colval(scan1[x],GRN), |
518 |
< |
colval(scan2[x],GRN)) & |
519 |
< |
real_check(colval(scan1[x],BLU), |
520 |
< |
colval(scan2[x],BLU))) |
670 |
> |
for (x = 0; x < scanlen(&rs1); x++) { |
671 |
> |
if (color_check(scan1[x], scan2[x])) |
672 |
|
continue; |
673 |
|
if (report != REP_QUIET) { |
674 |
|
printf( |
695 |
|
return(good_RMS()); /* final check of RMS */ |
696 |
|
} |
697 |
|
|
698 |
< |
const char nsuffix[10][3] = { /* 1st, 2nd, 3rd, etc. */ |
699 |
< |
"th","st","nd","rd","th","th","th","th","th","th" |
700 |
< |
}; |
698 |
> |
/* Set reference depth based on header variable */ |
699 |
> |
static int |
700 |
> |
set_refdepth(DEPTHCODEC *dcp, LUTAB *htp) |
701 |
> |
{ |
702 |
> |
static char depthvar[] = DEPTHSTR; |
703 |
> |
const char *drval; |
704 |
|
|
705 |
+ |
depthvar[LDEPTHSTR-1] = '\0'; |
706 |
+ |
drval = (const char *)lu_find(htp, depthvar)->data; |
707 |
+ |
if (!drval) |
708 |
+ |
return(0); |
709 |
+ |
dcp->refdepth = atof(drval); |
710 |
+ |
if (dcp->refdepth <= 0) { |
711 |
+ |
if (report != REP_QUIET) { |
712 |
+ |
fputs(dcp->inpname, stderr); |
713 |
+ |
fputs(": bad reference depth '", stderr); |
714 |
+ |
fputs(drval, stderr); |
715 |
+ |
fputs("'\n", stderr); |
716 |
+ |
} |
717 |
+ |
return(-1); |
718 |
+ |
} |
719 |
+ |
return(1); |
720 |
+ |
} |
721 |
+ |
|
722 |
+ |
/* Compare two encoded depth maps */ |
723 |
+ |
static int |
724 |
+ |
compare_depth() |
725 |
+ |
{ |
726 |
+ |
long nread = 0; |
727 |
+ |
DEPTHCODEC dc1, dc2; |
728 |
+ |
|
729 |
+ |
if (report >= REP_VERBOSE) { |
730 |
+ |
fputs(progname, stdout); |
731 |
+ |
fputs(": comparing inputs as depth maps\n", stdout); |
732 |
+ |
} |
733 |
+ |
set_dc_defaults(&dc1); |
734 |
+ |
dc1.hdrflags = HF_RESIN; |
735 |
+ |
dc1.finp = f1in; |
736 |
+ |
dc1.inpname = f1name; |
737 |
+ |
set_dc_defaults(&dc2); |
738 |
+ |
dc2.hdrflags = HF_RESIN; |
739 |
+ |
dc2.finp = f2in; |
740 |
+ |
dc2.inpname = f2name; |
741 |
+ |
if (report != REP_QUIET) { |
742 |
+ |
dc1.hdrflags |= HF_STDERR; |
743 |
+ |
dc2.hdrflags |= HF_STDERR; |
744 |
+ |
} |
745 |
+ |
if (!process_dc_header(&dc1, 0, NULL)) |
746 |
+ |
return(0); |
747 |
+ |
if (!process_dc_header(&dc2, 0, NULL)) |
748 |
+ |
return(0); |
749 |
+ |
if (!check_resolu("Depth map", &dc1.res, &dc2.res)) |
750 |
+ |
return(0); |
751 |
+ |
if (set_refdepth(&dc1, &hdr1) < 0) |
752 |
+ |
return(0); |
753 |
+ |
if (set_refdepth(&dc2, &hdr2) < 0) |
754 |
+ |
return(0); |
755 |
+ |
while (nread < dc1.res.xr*dc1.res.yr) { |
756 |
+ |
double d1 = decode_depth_next(&dc1); |
757 |
+ |
double d2 = decode_depth_next(&dc2); |
758 |
+ |
if ((d1 < 0) | (d2 < 0)) { |
759 |
+ |
if (report != REP_QUIET) |
760 |
+ |
printf("%s: unexpected end-of-file\n", |
761 |
+ |
progname); |
762 |
+ |
return(0); |
763 |
+ |
} |
764 |
+ |
++nread; |
765 |
+ |
if (real_check(d1, d2)) |
766 |
+ |
continue; |
767 |
+ |
if (report != REP_QUIET) |
768 |
+ |
printf("%s: %ld%s depth values differ\n", |
769 |
+ |
progname, nread, num_sfx(nread)); |
770 |
+ |
return(0); |
771 |
+ |
} |
772 |
+ |
return(good_RMS()); /* final check of RMS */ |
773 |
+ |
} |
774 |
+ |
|
775 |
+ |
/* Compare two encoded normal maps */ |
776 |
+ |
static int |
777 |
+ |
compare_norm() |
778 |
+ |
{ |
779 |
+ |
long nread = 0; |
780 |
+ |
NORMCODEC nc1, nc2; |
781 |
+ |
|
782 |
+ |
if (report >= REP_VERBOSE) { |
783 |
+ |
fputs(progname, stdout); |
784 |
+ |
fputs(": comparing inputs as normal maps\n", stdout); |
785 |
+ |
} |
786 |
+ |
set_nc_defaults(&nc1); |
787 |
+ |
nc1.hdrflags = HF_RESIN; |
788 |
+ |
nc1.finp = f1in; |
789 |
+ |
nc1.inpname = f1name; |
790 |
+ |
set_nc_defaults(&nc2); |
791 |
+ |
nc2.hdrflags = HF_RESIN; |
792 |
+ |
nc2.finp = f2in; |
793 |
+ |
nc2.inpname = f2name; |
794 |
+ |
if (report != REP_QUIET) { |
795 |
+ |
nc1.hdrflags |= HF_STDERR; |
796 |
+ |
nc2.hdrflags |= HF_STDERR; |
797 |
+ |
} |
798 |
+ |
if (!process_nc_header(&nc1, 0, NULL)) |
799 |
+ |
return(0); |
800 |
+ |
if (!process_nc_header(&nc2, 0, NULL)) |
801 |
+ |
return(0); |
802 |
+ |
if (!check_resolu("Normal map", &nc1.res, &nc2.res)) |
803 |
+ |
return(0); |
804 |
+ |
while (nread < nc1.res.xr*nc1.res.yr) { |
805 |
+ |
FVECT nv1, nv2; |
806 |
+ |
int rv1 = decode_normal_next(nv1, &nc1); |
807 |
+ |
int rv2 = decode_normal_next(nv2, &nc2); |
808 |
+ |
if ((rv1 < 0) | (rv2 < 0)) { |
809 |
+ |
if (report != REP_QUIET) |
810 |
+ |
printf("%s: unexpected end-of-file\n", |
811 |
+ |
progname); |
812 |
+ |
return(0); |
813 |
+ |
} |
814 |
+ |
++nread; |
815 |
+ |
if (rv1 == rv2 && (!rv1 || norm_check(nv1, nv2))) |
816 |
+ |
continue; |
817 |
+ |
if (report != REP_QUIET) |
818 |
+ |
printf("%s: %ld%s normal vectors differ\n", |
819 |
+ |
progname, nread, num_sfx(nread)); |
820 |
+ |
return(0); |
821 |
+ |
} |
822 |
+ |
return(good_RMS()); /* final check of RMS */ |
823 |
+ |
} |
824 |
+ |
|
825 |
|
/* Compare two inputs that are known to be 32-bit floating-point data */ |
826 |
|
static int |
827 |
|
compare_float() |
829 |
|
long nread = 0; |
830 |
|
float f1, f2; |
831 |
|
|
832 |
+ |
if (report >= REP_VERBOSE) { |
833 |
+ |
fputs(progname, stdout); |
834 |
+ |
fputs(": comparing inputs as 32-bit IEEE floats\n", stdout); |
835 |
+ |
} |
836 |
|
while (getbinary(&f1, sizeof(f1), 1, f1in)) { |
837 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
838 |
|
goto badeof; |
839 |
|
++nread; |
840 |
+ |
if (f1swap) swap32((char *)&f1, 1); |
841 |
+ |
if (f2swap) swap32((char *)&f2, 1); |
842 |
|
if (real_check(f1, f2)) |
843 |
|
continue; |
844 |
|
if (report != REP_QUIET) |
845 |
|
printf("%s: %ld%s float values differ\n", |
846 |
< |
progname, nread, nsuffix[nread%10]); |
846 |
> |
progname, nread, num_sfx(nread)); |
847 |
|
return(0); |
848 |
|
} |
849 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
850 |
|
return(good_RMS()); /* final check of RMS */ |
851 |
|
badeof: |
852 |
|
if (report != REP_QUIET) |
853 |
< |
printf("%s: Unexpected end-of-file\n", progname); |
853 |
> |
printf("%s: unexpected end-of-file\n", progname); |
854 |
|
return(0); |
855 |
|
} |
856 |
|
|
861 |
|
long nread = 0; |
862 |
|
double f1, f2; |
863 |
|
|
864 |
+ |
if (report >= REP_VERBOSE) { |
865 |
+ |
fputs(progname, stdout); |
866 |
+ |
fputs(": comparing inputs as 64-bit IEEE doubles\n", stdout); |
867 |
+ |
} |
868 |
|
while (getbinary(&f1, sizeof(f1), 1, f1in)) { |
869 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
870 |
|
goto badeof; |
871 |
|
++nread; |
872 |
+ |
if (f1swap) swap64((char *)&f1, 1); |
873 |
+ |
if (f2swap) swap64((char *)&f2, 1); |
874 |
|
if (real_check(f1, f2)) |
875 |
|
continue; |
876 |
|
if (report != REP_QUIET) |
877 |
< |
printf("%s: %ld%s float values differ\n", |
878 |
< |
progname, nread, nsuffix[nread%10]); |
877 |
> |
printf("%s: %ld%s double values differ\n", |
878 |
> |
progname, nread, num_sfx(nread)); |
879 |
|
return(0); |
880 |
|
} |
881 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
882 |
|
return(good_RMS()); /* final check of RMS */ |
883 |
|
badeof: |
884 |
|
if (report != REP_QUIET) |
885 |
< |
printf("%s: Unexpected end-of-file\n", progname); |
885 |
> |
printf("%s: unexpected end-of-file\n", progname); |
886 |
|
return(0); |
887 |
|
} |
888 |
|
|
929 |
|
} |
930 |
|
break; |
931 |
|
} |
932 |
< |
if (a != argc-2) |
932 |
> |
if (a != argc-2) /* make sure of two inputs */ |
933 |
|
usage(); |
934 |
< |
if (!f1name) f1name = argv[a]; |
649 |
< |
if (!f2name) f2name = argv[a+1]; |
650 |
< |
|
651 |
< |
if (!strcmp(f1name, f2name)) { /* inputs are same? */ |
934 |
> |
if (!strcmp(argv[a], argv[a+1])) { /* inputs are same? */ |
935 |
|
if (report >= REP_WARN) |
936 |
|
printf("%s: warning - identical inputs given\n", |
937 |
|
progname); |
938 |
|
return(0); |
939 |
|
} |
940 |
+ |
if (!f1name) f1name = argv[a]; |
941 |
+ |
if (!f2name) f2name = argv[a+1]; |
942 |
|
/* open inputs */ |
943 |
|
SET_FILE_BINARY(stdin); /* in case we're using it */ |
944 |
|
if (!f1in && !(f1in = fopen(f1name, "rb"))) { |
945 |
|
fprintf(stderr, "%s: cannot open for reading\n", f1name); |
946 |
< |
return(1); |
946 |
> |
return(2); |
947 |
|
} |
948 |
|
if (!strcmp(f2name, "-")) { |
949 |
|
f2in = stdin; |
950 |
|
f2name = stdin_name; |
951 |
|
} else if (!(f2in = fopen(f2name, "rb"))) { |
952 |
|
fprintf(stderr, "%s: cannot open for reading\n", f2name); |
953 |
< |
return(1); |
953 |
> |
return(2); |
954 |
|
} |
955 |
|
/* load headers */ |
956 |
|
if ((typ1 = identify_type(f1name, f1in, &hdr1)) < 0) |
957 |
< |
return(1); |
957 |
> |
return(2); |
958 |
|
if ((typ2 = identify_type(f2name, f2in, &hdr2)) < 0) |
959 |
< |
return(1); |
959 |
> |
return(2); |
960 |
|
if (typ1 != typ2) { |
961 |
|
if (report != REP_QUIET) |
962 |
< |
printf("%s: '%s' is %s and '%s' is %s\n", |
962 |
> |
printf("%s: '%s' format is %s and '%s' is %s\n", |
963 |
|
progname, f1name, file_type[typ1], |
964 |
|
f2name, file_type[typ2]); |
965 |
|
return(1); |
966 |
|
} |
967 |
|
ign_header |= !has_header(typ1); /* check headers if indicated */ |
968 |
< |
if (!ign_header && !headers_match(&hdr1, &hdr2)) |
968 |
> |
if (!ign_header && !headers_match()) |
969 |
|
return(1); |
685 |
– |
lu_done(&hdr1); lu_done(&hdr2); |
970 |
|
if (!ign_header & (report >= REP_WARN)) { |
687 |
– |
if (typ1 == TYP_UNKNOWN) |
688 |
– |
printf("%s: warning - unrecognized format, comparing as binary\n", |
689 |
– |
progname); |
971 |
|
if (lin1cnt != lin2cnt) |
972 |
|
printf("%s: warning - headers are different lengths\n", |
973 |
|
progname); |
974 |
+ |
if (typ1 == TYP_UNKNOWN) |
975 |
+ |
printf("%s: warning - unrecognized format\n", |
976 |
+ |
progname); |
977 |
|
} |
978 |
< |
if (report >= REP_VERBOSE) |
979 |
< |
printf("%s: input file type is %s\n", |
980 |
< |
progname, file_type[typ1]); |
981 |
< |
|
978 |
> |
if (report >= REP_VERBOSE) { |
979 |
> |
printf("%s: data format is %s\n", progname, file_type[typ1]); |
980 |
> |
if ((typ1 == TYP_FLOAT) | (typ1 == TYP_DOUBLE)) { |
981 |
> |
if (f1swap) |
982 |
> |
printf("%s: input '%s' is byte-swapped\n", |
983 |
> |
progname, f1name); |
984 |
> |
if (f2swap) |
985 |
> |
printf("%s: input '%s' is byte-swapped\n", |
986 |
> |
progname, f2name); |
987 |
> |
} |
988 |
> |
} |
989 |
|
switch (typ1) { /* compare based on type */ |
990 |
|
case TYP_BINARY: |
991 |
|
case TYP_TMESH: |
992 |
|
case TYP_OCTREE: |
993 |
|
case TYP_RBFMESH: |
994 |
+ |
case TYP_ID8: |
995 |
+ |
case TYP_ID16: |
996 |
+ |
case TYP_ID24: |
997 |
|
case TYP_UNKNOWN: |
998 |
|
return( !compare_binary() ); |
999 |
|
case TYP_TEXT: |
1002 |
|
case TYP_RGBE: |
1003 |
|
case TYP_XYZE: |
1004 |
|
return( !compare_hdr() ); |
1005 |
+ |
case TYP_DEPTH: |
1006 |
+ |
return( !compare_depth() ); |
1007 |
+ |
case TYP_NORM: |
1008 |
+ |
return( !compare_norm() ); |
1009 |
|
case TYP_FLOAT: |
1010 |
|
return( !compare_float() ); |
1011 |
|
case TYP_DOUBLE: |