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 |
+ |
#if 1 |
249 |
+ |
/* Compare two color spectra for equivalence */ |
250 |
+ |
static int |
251 |
+ |
spec_check(COLORV *sc1, COLORV *sc2) |
252 |
+ |
{ |
253 |
+ |
int p, k; |
254 |
+ |
|
255 |
+ |
if (!real_check(scolor_mean(sc1), scolor_mean(sc2))) |
256 |
+ |
return(0); |
257 |
+ |
|
258 |
+ |
p = 0; /* find max. component */ |
259 |
+ |
for (k = NCSAMP; --k; ) |
260 |
+ |
if (sc1[k] > sc1[p]) |
261 |
+ |
p = k; |
262 |
+ |
|
263 |
+ |
return(real_check(sc1[p], sc2[p])); |
264 |
+ |
} |
265 |
+ |
#else |
266 |
+ |
/* Compare two color spectra for equivalence */ |
267 |
+ |
static int |
268 |
+ |
spec_check(COLORV *sc1, COLORV *sc2) |
269 |
+ |
{ |
270 |
+ |
COLOR c1, c2; |
271 |
+ |
int p; |
272 |
+ |
|
273 |
+ |
if (!real_check(scolor_mean(sc1), scolor_mean(sc2))) |
274 |
+ |
return(0); |
275 |
+ |
/* do comparisons in RGB space */ |
276 |
+ |
scolor_rgb(c1, sc1); |
277 |
+ |
scolor_rgb(c2, sc2); |
278 |
+ |
|
279 |
+ |
p = (colval(c1,GRN) > colval(c1,RED)) ? GRN : RED; |
280 |
+ |
if (colval(c1,BLU) > colval(c1,p)) p = BLU; |
281 |
+ |
|
282 |
+ |
return(real_check(colval(c1,p), colval(c2,p))); |
283 |
+ |
} |
284 |
+ |
#endif |
285 |
+ |
|
286 |
|
/* Compare two normal directions for equivalence */ |
287 |
|
static int |
288 |
|
norm_check(FVECT nv1, FVECT nv2) |
380 |
|
static int |
381 |
|
setheadvar(char *val, void *p) |
382 |
|
{ |
383 |
+ |
char newval[128]; |
384 |
|
LUTAB *htp = (LUTAB *)p; |
385 |
|
LUENT *tep; |
386 |
|
char *key; |
423 |
|
return(-1); /* memory allocation error */ |
424 |
|
if (!tep->key) |
425 |
|
tep->key = strcpy(malloc(kln+1), key); |
426 |
< |
if (tep->data) |
426 |
> |
if (tep->data) { /* check for special cases */ |
427 |
> |
if (!strcmp(key, "EXPOSURE")) { |
428 |
> |
sprintf(newval, "%.6e", atof(tep->data)*atof(val)); |
429 |
> |
vln = strlen(val = newval); |
430 |
> |
} |
431 |
|
free(tep->data); |
432 |
+ |
} |
433 |
|
tep->data = strcpy(malloc(vln+1), val); |
434 |
|
return(1); |
435 |
|
} |
538 |
|
} |
539 |
|
if (c) |
540 |
|
return(TYP_BINARY); |
472 |
– |
SET_FILE_TEXT(fin); /* originally set to binary */ |
541 |
|
return(TYP_TEXT); |
542 |
|
badeof: |
543 |
|
if (report != REP_QUIET) { |
620 |
|
|
621 |
|
if (report >= REP_VERBOSE) { |
622 |
|
fputs(progname, stdout); |
623 |
< |
fputs(": comparing inputs as ASCII text\n", stdout); |
623 |
> |
fputs(": comparing inputs as ASCII text", stdout); |
624 |
> |
if (escape_newlines) |
625 |
> |
fputs(", allowing escaped newlines", stdout); |
626 |
> |
if (comment_c) { |
627 |
> |
fputs(", ignoring comments starting with '", stdout); |
628 |
> |
fputc(comment_c, stdout); |
629 |
> |
fputc('\'', stdout); |
630 |
> |
} |
631 |
> |
fputc('\n', stdout); |
632 |
|
} |
633 |
+ |
SET_FILE_TEXT(f1in); /* originally set to binary */ |
634 |
+ |
SET_FILE_TEXT(f2in); |
635 |
|
init_line(&l1buf); init_line(&l2buf); /* compare a line at a time */ |
636 |
|
while (read_line(&l1buf, f1in)) { |
637 |
|
lin1cnt++; |
654 |
|
/* compare non-empty lines */ |
655 |
|
if (!equiv_string(l1buf.str, l2buf.str)) { |
656 |
|
if (report != REP_QUIET) { |
657 |
< |
printf("%s: inputs '%s' and '%s' differ at line %d|%d\n", |
658 |
< |
progname, f1name, f2name, |
659 |
< |
lin1cnt, lin2cnt); |
657 |
> |
printf("%s: inputs '%s' and '%s' differ at line %d", |
658 |
> |
progname, f1name, f2name, lin1cnt); |
659 |
> |
if (lin1cnt != lin2cnt) |
660 |
> |
printf("|%d\n", lin2cnt); |
661 |
> |
else |
662 |
> |
putchar('\n'); |
663 |
|
if ( report >= REP_VERBOSE && |
664 |
|
(l1buf.len < 256) & |
665 |
|
(l2buf.len < 256) ) { |
689 |
|
return(good_RMS()); /* final check for reals */ |
690 |
|
} |
691 |
|
|
692 |
+ |
/* Set resolution based on NROWS, NCOLS in header */ |
693 |
+ |
static int |
694 |
+ |
set_resolu(RESOLU *rs, LUTAB *htp) |
695 |
+ |
{ |
696 |
+ |
const char *val; |
697 |
+ |
|
698 |
+ |
rs->rt = PIXSTANDARD; |
699 |
+ |
val = (const char *)lu_find(htp, "NROWS")->data; |
700 |
+ |
if (!val) return(0); |
701 |
+ |
rs->yr = atoi(val); |
702 |
+ |
if (rs->yr <= 0) return(-1); |
703 |
+ |
val = (const char *)lu_find(htp, "NCOLS")->data; |
704 |
+ |
if (!val) return(0); |
705 |
+ |
rs->xr = atoi(val); |
706 |
+ |
if (rs->xr <= 0) return(-1); |
707 |
+ |
return(1); |
708 |
+ |
} |
709 |
+ |
|
710 |
|
/* Check image/map resolutions */ |
711 |
|
static int |
712 |
|
check_resolu(const char *class, RESOLU *r1p, RESOLU *r2p) |
764 |
|
if (color_check(scan1[x], scan2[x])) |
765 |
|
continue; |
766 |
|
if (report != REP_QUIET) { |
767 |
< |
printf( |
669 |
< |
"%s: pixels at scanline %d offset %d differ\n", |
767 |
> |
printf("%s: pixels at scanline %d offset %d differ\n", |
768 |
|
progname, y, x); |
769 |
|
if (report >= REP_VERBOSE) { |
770 |
|
printf("%s: (R,G,B)=(%g,%g,%g)\n", |
787 |
|
return(good_RMS()); /* final check of RMS */ |
788 |
|
} |
789 |
|
|
790 |
+ |
/* Compare two inputs that are known to be spectral images */ |
791 |
+ |
static int |
792 |
+ |
compare_spec() |
793 |
+ |
{ |
794 |
+ |
static char NCstr[] = NCOMPSTR; |
795 |
+ |
RESOLU rs1, rs2; |
796 |
+ |
COLORV *scan1, *scan2; |
797 |
+ |
const char *val; |
798 |
+ |
int x, y; |
799 |
+ |
|
800 |
+ |
if (report >= REP_VERBOSE) { |
801 |
+ |
fputs(progname, stdout); |
802 |
+ |
fputs(": comparing inputs as spectral images\n", stdout); |
803 |
+ |
} |
804 |
+ |
if (!(set_resolu(&rs1, &hdr1) || fgetsresolu(&rs1, f1in))) |
805 |
+ |
return(0); |
806 |
+ |
if (!(set_resolu(&rs2, &hdr2) || fgetsresolu(&rs2, f2in))) |
807 |
+ |
return(0); |
808 |
+ |
if (!check_resolu("Spectral image", &rs1, &rs2)) |
809 |
+ |
return(0); |
810 |
+ |
NCstr[LNCOMPSTR-1] = '\0'; |
811 |
+ |
val = (const char *)lu_find(&hdr1, NCstr)->data; |
812 |
+ |
if (!val || (NCSAMP = atoi(val)) < 3) { |
813 |
+ |
if (report != REP_QUIET) { |
814 |
+ |
if (val) |
815 |
+ |
printf("%s: illegal # components (%d) for spectral image\n", |
816 |
+ |
progname, NCSAMP); |
817 |
+ |
else |
818 |
+ |
printf("%s: missing %s in header for spectral image\n", |
819 |
+ |
progname, NCstr); |
820 |
+ |
} |
821 |
+ |
return(0); |
822 |
+ |
} |
823 |
+ |
scan1 = (COLORV *)malloc(sizeof(COLORV)*NCSAMP*scanlen(&rs1)); |
824 |
+ |
scan2 = (COLORV *)malloc(sizeof(COLORV)*NCSAMP*scanlen(&rs2)); |
825 |
+ |
if (!scan1 | !scan2) { |
826 |
+ |
fprintf(stderr, "%s: out of memory in compare_hdr()\n", progname); |
827 |
+ |
exit(2); |
828 |
+ |
} |
829 |
+ |
for (y = 0; y < numscans(&rs1); y++) { |
830 |
+ |
if ((freadsscan(scan1, NCSAMP, scanlen(&rs1), f1in) < 0) | |
831 |
+ |
(freadsscan(scan2, NCSAMP, scanlen(&rs2), f2in) < 0)) { |
832 |
+ |
if (report != REP_QUIET) |
833 |
+ |
printf("%s: unexpected end-of-file\n", progname); |
834 |
+ |
free(scan1); |
835 |
+ |
free(scan2); |
836 |
+ |
return(0); |
837 |
+ |
} |
838 |
+ |
for (x = 0; x < scanlen(&rs1); x++) { |
839 |
+ |
if (spec_check(scan1+x*NCSAMP, scan2+x*NCSAMP)) |
840 |
+ |
continue; |
841 |
+ |
if (report != REP_QUIET) { |
842 |
+ |
int k; |
843 |
+ |
printf("%s: spectra at scanline %d offset %d differ\n", |
844 |
+ |
progname, y, x); |
845 |
+ |
if (report >= REP_VERBOSE) { |
846 |
+ |
printf("%s: spectrum =", f1name); |
847 |
+ |
for (k = 0; k < NCSAMP; k++) |
848 |
+ |
printf(" %g", scan1[x*NCSAMP+k]); |
849 |
+ |
fputc('\n', stdout); |
850 |
+ |
printf("%s: spectrum =", f2name); |
851 |
+ |
for (k = 0; k < NCSAMP; k++) |
852 |
+ |
printf(" %g", scan2[x*NCSAMP+k]); |
853 |
+ |
fputc('\n', stdout); |
854 |
+ |
} |
855 |
+ |
} |
856 |
+ |
free(scan1); |
857 |
+ |
free(scan2); |
858 |
+ |
return(0); |
859 |
+ |
} |
860 |
+ |
} |
861 |
+ |
free(scan1); |
862 |
+ |
free(scan2); |
863 |
+ |
return(good_RMS()); /* final check of RMS */ |
864 |
+ |
} |
865 |
+ |
|
866 |
|
/* Set reference depth based on header variable */ |
867 |
|
static int |
868 |
|
set_refdepth(DEPTHCODEC *dcp, LUTAB *htp) |
1067 |
|
case 'h': /* ignore header info. */ |
1068 |
|
ign_header = !ign_header; |
1069 |
|
continue; |
1070 |
+ |
case 'n': /* allow newline escapes */ |
1071 |
+ |
escape_newlines = !escape_newlines; |
1072 |
+ |
continue; |
1073 |
+ |
case 'c': /* ignore comments */ |
1074 |
+ |
comment_c = argv[a][2]; |
1075 |
+ |
continue; |
1076 |
|
case 's': /* silent operation */ |
1077 |
|
report = REP_QUIET; |
1078 |
|
continue; |
1176 |
|
case TYP_RGBE: |
1177 |
|
case TYP_XYZE: |
1178 |
|
return( !compare_hdr() ); |
1179 |
+ |
case TYP_SPEC: |
1180 |
+ |
return( !compare_spec() ); |
1181 |
|
case TYP_DEPTH: |
1182 |
|
return( !compare_depth() ); |
1183 |
|
case TYP_NORM: |