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 */ |
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 |
|
/* keep consistent with above */ |
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}; |
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 */ |
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; |
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.)) |
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; |
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]*nv1[2]; |
228 |
+ |
int imax = 2; |
229 |
+ |
int i = 2; |
230 |
+ |
/* identify largest component */ |
231 |
+ |
while (i--) { |
232 |
+ |
double tm2 = nv1[i]*nv1[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) |
326 |
|
adv_linecnt(htp); /* side-effect is to count lines */ |
327 |
|
if (!isalpha(*val)) /* key must start line */ |
328 |
|
return(0); |
329 |
+ |
/* check if we need to swap binary data */ |
330 |
+ |
if ((n = isbigendian(val)) >= 0) { |
331 |
+ |
if (nativebigendian() == n) |
332 |
+ |
return(0); |
333 |
+ |
f1swap += (htp == &hdr1); |
334 |
+ |
f2swap += (htp == &hdr2); |
335 |
+ |
return(0); |
336 |
+ |
} |
337 |
|
key = val++; |
338 |
|
while (*val && !isspace(*val) & (*val != '=')) |
339 |
|
val++; |
608 |
|
return(good_RMS()); /* final check for reals */ |
609 |
|
} |
610 |
|
|
611 |
+ |
/* Check image/map resolutions */ |
612 |
+ |
static int |
613 |
+ |
check_resolu(const char *class, RESOLU *r1p, RESOLU *r2p) |
614 |
+ |
{ |
615 |
+ |
if (r1p->rt != r2p->rt) { |
616 |
+ |
if (report != REP_QUIET) |
617 |
+ |
printf( |
618 |
+ |
"%s: %ss '%s' and '%s' have different pixel ordering\n", |
619 |
+ |
progname, class, f1name, f2name); |
620 |
+ |
return(0); |
621 |
+ |
} |
622 |
+ |
if ((r1p->xr != r2p->xr) | (r1p->yr != r2p->yr)) { |
623 |
+ |
if (report != REP_QUIET) |
624 |
+ |
printf( |
625 |
+ |
"%s: %ss '%s' and '%s' are different sizes\n", |
626 |
+ |
progname, class, f1name, f2name); |
627 |
+ |
return(0); |
628 |
+ |
} |
629 |
+ |
return(1); |
630 |
+ |
} |
631 |
+ |
|
632 |
|
/* Compare two inputs that are known to be RGBE or XYZE images */ |
633 |
|
static int |
634 |
|
compare_hdr() |
643 |
|
} |
644 |
|
fgetsresolu(&rs1, f1in); |
645 |
|
fgetsresolu(&rs2, f2in); |
646 |
< |
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); |
646 |
> |
if (!check_resolu("HDR image", &rs1, &rs2)) |
647 |
|
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 |
– |
} |
648 |
|
scan1 = (COLOR *)malloc(scanlen(&rs1)*sizeof(COLOR)); |
649 |
|
scan2 = (COLOR *)malloc(scanlen(&rs2)*sizeof(COLOR)); |
650 |
|
if (!scan1 | !scan2) { |
689 |
|
return(good_RMS()); /* final check of RMS */ |
690 |
|
} |
691 |
|
|
692 |
+ |
/* Set reference depth based on header variable */ |
693 |
+ |
static int |
694 |
+ |
set_refdepth(DEPTHCODEC *dcp, LUTAB *htp) |
695 |
+ |
{ |
696 |
+ |
static char depthvar[] = DEPTHSTR; |
697 |
+ |
const char *drval; |
698 |
+ |
|
699 |
+ |
depthvar[LDEPTHSTR] = '\0'; |
700 |
+ |
drval = (const char *)lu_find(htp, depthvar)->data; |
701 |
+ |
if (!drval) |
702 |
+ |
return(0); |
703 |
+ |
dcp->refdepth = atof(drval); |
704 |
+ |
if (dcp->refdepth <= 0) { |
705 |
+ |
if (report != REP_QUIET) { |
706 |
+ |
fputs(dcp->inpname, stderr); |
707 |
+ |
fputs(": bad reference depth '", stderr); |
708 |
+ |
fputs(drval, stderr); |
709 |
+ |
fputs("'\n", stderr); |
710 |
+ |
} |
711 |
+ |
return(-1); |
712 |
+ |
} |
713 |
+ |
return(1); |
714 |
+ |
} |
715 |
+ |
|
716 |
+ |
/* Compare two encoded depth maps */ |
717 |
+ |
static int |
718 |
+ |
compare_depth() |
719 |
+ |
{ |
720 |
+ |
long nread = 0; |
721 |
+ |
DEPTHCODEC dc1, dc2; |
722 |
+ |
|
723 |
+ |
if (report >= REP_VERBOSE) { |
724 |
+ |
fputs(progname, stdout); |
725 |
+ |
fputs(": comparing inputs as depth maps\n", stdout); |
726 |
+ |
} |
727 |
+ |
set_dc_defaults(&dc1); |
728 |
+ |
dc1.hdrflags = HF_RESIN; |
729 |
+ |
dc1.finp = f1in; |
730 |
+ |
dc1.inpname = f1name; |
731 |
+ |
set_dc_defaults(&dc2); |
732 |
+ |
dc2.hdrflags = HF_RESIN; |
733 |
+ |
dc2.finp = f2in; |
734 |
+ |
dc2.inpname = f2name; |
735 |
+ |
if (report != REP_QUIET) { |
736 |
+ |
dc1.hdrflags |= HF_STDERR; |
737 |
+ |
dc2.hdrflags |= HF_STDERR; |
738 |
+ |
} |
739 |
+ |
if (!process_dc_header(&dc1, 0, NULL)) |
740 |
+ |
return(0); |
741 |
+ |
if (!process_dc_header(&dc2, 0, NULL)) |
742 |
+ |
return(0); |
743 |
+ |
if (!check_resolu("Depth map", &dc1.res, &dc2.res)) |
744 |
+ |
return(0); |
745 |
+ |
if (set_refdepth(&dc1, &hdr1) < 0) |
746 |
+ |
return(0); |
747 |
+ |
if (set_refdepth(&dc2, &hdr2) < 0) |
748 |
+ |
return(0); |
749 |
+ |
while (nread < dc1.res.xr*dc1.res.yr) { |
750 |
+ |
double d1 = decode_depth_next(&dc1); |
751 |
+ |
double d2 = decode_depth_next(&dc2); |
752 |
+ |
if ((d1 < 0) | (d2 < 0)) { |
753 |
+ |
if (report != REP_QUIET) |
754 |
+ |
printf("%s: unexpected end-of-file\n", |
755 |
+ |
progname); |
756 |
+ |
return(0); |
757 |
+ |
} |
758 |
+ |
++nread; |
759 |
+ |
if (real_check(d1, d2)) |
760 |
+ |
continue; |
761 |
+ |
if (report != REP_QUIET) |
762 |
+ |
printf("%s: %ld%s depth values differ\n", |
763 |
+ |
progname, nread, num_sfx(nread)); |
764 |
+ |
return(0); |
765 |
+ |
} |
766 |
+ |
return(good_RMS()); /* final check of RMS */ |
767 |
+ |
} |
768 |
+ |
|
769 |
+ |
/* Compare two encoded normal maps */ |
770 |
+ |
static int |
771 |
+ |
compare_norm() |
772 |
+ |
{ |
773 |
+ |
long nread = 0; |
774 |
+ |
NORMCODEC nc1, nc2; |
775 |
+ |
|
776 |
+ |
if (report >= REP_VERBOSE) { |
777 |
+ |
fputs(progname, stdout); |
778 |
+ |
fputs(": comparing inputs as normal maps\n", stdout); |
779 |
+ |
} |
780 |
+ |
set_nc_defaults(&nc1); |
781 |
+ |
nc1.hdrflags = HF_RESIN; |
782 |
+ |
nc1.finp = f1in; |
783 |
+ |
nc1.inpname = f1name; |
784 |
+ |
set_nc_defaults(&nc2); |
785 |
+ |
nc2.hdrflags = HF_RESIN; |
786 |
+ |
nc2.finp = f2in; |
787 |
+ |
nc2.inpname = f2name; |
788 |
+ |
if (report != REP_QUIET) { |
789 |
+ |
nc1.hdrflags |= HF_STDERR; |
790 |
+ |
nc2.hdrflags |= HF_STDERR; |
791 |
+ |
} |
792 |
+ |
if (!process_nc_header(&nc1, 0, NULL)) |
793 |
+ |
return(0); |
794 |
+ |
if (!process_nc_header(&nc2, 0, NULL)) |
795 |
+ |
return(0); |
796 |
+ |
if (!check_resolu("Normal map", &nc1.res, &nc2.res)) |
797 |
+ |
return(0); |
798 |
+ |
while (nread < nc1.res.xr*nc1.res.yr) { |
799 |
+ |
FVECT nv1, nv2; |
800 |
+ |
int rv1 = decode_normal_next(nv1, &nc1); |
801 |
+ |
int rv2 = decode_normal_next(nv2, &nc2); |
802 |
+ |
if ((rv1 < 0) | (rv2 < 0)) { |
803 |
+ |
if (report != REP_QUIET) |
804 |
+ |
printf("%s: unexpected end-of-file\n", |
805 |
+ |
progname); |
806 |
+ |
return(0); |
807 |
+ |
} |
808 |
+ |
++nread; |
809 |
+ |
if (rv1 == rv2 && (!rv1 || norm_check(nv1, nv2))) |
810 |
+ |
continue; |
811 |
+ |
if (report != REP_QUIET) |
812 |
+ |
printf("%s: %ld%s normal vectors differ\n", |
813 |
+ |
progname, nread, num_sfx(nread)); |
814 |
+ |
return(0); |
815 |
+ |
} |
816 |
+ |
return(good_RMS()); /* final check of RMS */ |
817 |
+ |
} |
818 |
+ |
|
819 |
|
/* Compare two inputs that are known to be 32-bit floating-point data */ |
820 |
|
static int |
821 |
|
compare_float() |
831 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
832 |
|
goto badeof; |
833 |
|
++nread; |
834 |
+ |
if (f1swap) swap32((char *)&f1, 1); |
835 |
+ |
if (f2swap) swap32((char *)&f2, 1); |
836 |
|
if (real_check(f1, f2)) |
837 |
|
continue; |
838 |
|
if (report != REP_QUIET) |
863 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
864 |
|
goto badeof; |
865 |
|
++nread; |
866 |
+ |
if (f1swap) swap64((char *)&f1, 1); |
867 |
+ |
if (f2swap) swap64((char *)&f2, 1); |
868 |
|
if (real_check(f1, f2)) |
869 |
|
continue; |
870 |
|
if (report != REP_QUIET) |
953 |
|
return(2); |
954 |
|
if (typ1 != typ2) { |
955 |
|
if (report != REP_QUIET) |
956 |
< |
printf("%s: '%s' is %s and '%s' is %s\n", |
956 |
> |
printf("%s: '%s' format is %s and '%s' is %s\n", |
957 |
|
progname, f1name, file_type[typ1], |
958 |
|
f2name, file_type[typ2]); |
959 |
|
return(1); |
961 |
|
ign_header |= !has_header(typ1); /* check headers if indicated */ |
962 |
|
if (!ign_header && !headers_match()) |
963 |
|
return(1); |
780 |
– |
lu_done(&hdr1); lu_done(&hdr2); /* done with header info. */ |
964 |
|
if (!ign_header & (report >= REP_WARN)) { |
965 |
|
if (lin1cnt != lin2cnt) |
966 |
|
printf("%s: warning - headers are different lengths\n", |
969 |
|
printf("%s: warning - unrecognized format\n", |
970 |
|
progname); |
971 |
|
} |
972 |
< |
if (report >= REP_VERBOSE) |
973 |
< |
printf("%s: input file type is %s\n", |
974 |
< |
progname, file_type[typ1]); |
975 |
< |
|
972 |
> |
if (report >= REP_VERBOSE) { |
973 |
> |
printf("%s: data format is %s\n", progname, file_type[typ1]); |
974 |
> |
if ((typ1 == TYP_FLOAT) | (typ1 == TYP_DOUBLE)) { |
975 |
> |
if (f1swap) |
976 |
> |
printf("%s: input '%s' is byte-swapped\n", |
977 |
> |
progname, f1name); |
978 |
> |
if (f2swap) |
979 |
> |
printf("%s: input '%s' is byte-swapped\n", |
980 |
> |
progname, f2name); |
981 |
> |
} |
982 |
> |
} |
983 |
|
switch (typ1) { /* compare based on type */ |
984 |
|
case TYP_BINARY: |
985 |
|
case TYP_TMESH: |
986 |
|
case TYP_OCTREE: |
987 |
|
case TYP_RBFMESH: |
988 |
+ |
case TYP_ID8: |
989 |
+ |
case TYP_ID16: |
990 |
+ |
case TYP_ID24: |
991 |
|
case TYP_UNKNOWN: |
992 |
|
return( !compare_binary() ); |
993 |
|
case TYP_TEXT: |
996 |
|
case TYP_RGBE: |
997 |
|
case TYP_XYZE: |
998 |
|
return( !compare_hdr() ); |
999 |
+ |
case TYP_DEPTH: |
1000 |
+ |
return( !compare_depth() ); |
1001 |
+ |
case TYP_NORM: |
1002 |
+ |
return( !compare_norm() ); |
1003 |
|
case TYP_FLOAT: |
1004 |
|
return( !compare_float() ); |
1005 |
|
case TYP_DOUBLE: |