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]*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++; |
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 |
|
} |
475 |
|
} |
476 |
|
if (c) |
477 |
|
return(TYP_BINARY); |
428 |
– |
SET_FILE_TEXT(fin); /* originally set to binary */ |
478 |
|
return(TYP_TEXT); |
479 |
|
badeof: |
480 |
|
if (report != REP_QUIET) { |
559 |
|
fputs(progname, stdout); |
560 |
|
fputs(": comparing inputs as ASCII text\n", stdout); |
561 |
|
} |
562 |
+ |
SET_FILE_TEXT(f1in); /* originally set to binary */ |
563 |
+ |
SET_FILE_TEXT(f2in); |
564 |
|
init_line(&l1buf); init_line(&l2buf); /* compare a line at a time */ |
565 |
|
while (read_line(&l1buf, f1in)) { |
566 |
|
lin1cnt++; |
615 |
|
return(good_RMS()); /* final check for reals */ |
616 |
|
} |
617 |
|
|
618 |
+ |
/* Check image/map resolutions */ |
619 |
+ |
static int |
620 |
+ |
check_resolu(const char *class, RESOLU *r1p, RESOLU *r2p) |
621 |
+ |
{ |
622 |
+ |
if (r1p->rt != r2p->rt) { |
623 |
+ |
if (report != REP_QUIET) |
624 |
+ |
printf( |
625 |
+ |
"%s: %ss '%s' and '%s' have different pixel ordering\n", |
626 |
+ |
progname, class, f1name, f2name); |
627 |
+ |
return(0); |
628 |
+ |
} |
629 |
+ |
if ((r1p->xr != r2p->xr) | (r1p->yr != r2p->yr)) { |
630 |
+ |
if (report != REP_QUIET) |
631 |
+ |
printf( |
632 |
+ |
"%s: %ss '%s' and '%s' are different sizes\n", |
633 |
+ |
progname, class, f1name, f2name); |
634 |
+ |
return(0); |
635 |
+ |
} |
636 |
+ |
return(1); |
637 |
+ |
} |
638 |
+ |
|
639 |
|
/* Compare two inputs that are known to be RGBE or XYZE images */ |
640 |
|
static int |
641 |
|
compare_hdr() |
650 |
|
} |
651 |
|
fgetsresolu(&rs1, f1in); |
652 |
|
fgetsresolu(&rs2, f2in); |
653 |
< |
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); |
653 |
> |
if (!check_resolu("HDR image", &rs1, &rs2)) |
654 |
|
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 |
– |
} |
655 |
|
scan1 = (COLOR *)malloc(scanlen(&rs1)*sizeof(COLOR)); |
656 |
|
scan2 = (COLOR *)malloc(scanlen(&rs2)*sizeof(COLOR)); |
657 |
|
if (!scan1 | !scan2) { |
696 |
|
return(good_RMS()); /* final check of RMS */ |
697 |
|
} |
698 |
|
|
699 |
+ |
/* Set reference depth based on header variable */ |
700 |
+ |
static int |
701 |
+ |
set_refdepth(DEPTHCODEC *dcp, LUTAB *htp) |
702 |
+ |
{ |
703 |
+ |
static char depthvar[] = DEPTHSTR; |
704 |
+ |
const char *drval; |
705 |
+ |
|
706 |
+ |
depthvar[LDEPTHSTR-1] = '\0'; |
707 |
+ |
drval = (const char *)lu_find(htp, depthvar)->data; |
708 |
+ |
if (!drval) |
709 |
+ |
return(0); |
710 |
+ |
dcp->refdepth = atof(drval); |
711 |
+ |
if (dcp->refdepth <= 0) { |
712 |
+ |
if (report != REP_QUIET) { |
713 |
+ |
fputs(dcp->inpname, stderr); |
714 |
+ |
fputs(": bad reference depth '", stderr); |
715 |
+ |
fputs(drval, stderr); |
716 |
+ |
fputs("'\n", stderr); |
717 |
+ |
} |
718 |
+ |
return(-1); |
719 |
+ |
} |
720 |
+ |
return(1); |
721 |
+ |
} |
722 |
+ |
|
723 |
+ |
/* Compare two encoded depth maps */ |
724 |
+ |
static int |
725 |
+ |
compare_depth() |
726 |
+ |
{ |
727 |
+ |
long nread = 0; |
728 |
+ |
DEPTHCODEC dc1, dc2; |
729 |
+ |
|
730 |
+ |
if (report >= REP_VERBOSE) { |
731 |
+ |
fputs(progname, stdout); |
732 |
+ |
fputs(": comparing inputs as depth maps\n", stdout); |
733 |
+ |
} |
734 |
+ |
set_dc_defaults(&dc1); |
735 |
+ |
dc1.hdrflags = HF_RESIN; |
736 |
+ |
dc1.finp = f1in; |
737 |
+ |
dc1.inpname = f1name; |
738 |
+ |
set_dc_defaults(&dc2); |
739 |
+ |
dc2.hdrflags = HF_RESIN; |
740 |
+ |
dc2.finp = f2in; |
741 |
+ |
dc2.inpname = f2name; |
742 |
+ |
if (report != REP_QUIET) { |
743 |
+ |
dc1.hdrflags |= HF_STDERR; |
744 |
+ |
dc2.hdrflags |= HF_STDERR; |
745 |
+ |
} |
746 |
+ |
if (!process_dc_header(&dc1, 0, NULL)) |
747 |
+ |
return(0); |
748 |
+ |
if (!process_dc_header(&dc2, 0, NULL)) |
749 |
+ |
return(0); |
750 |
+ |
if (!check_resolu("Depth map", &dc1.res, &dc2.res)) |
751 |
+ |
return(0); |
752 |
+ |
if (set_refdepth(&dc1, &hdr1) < 0) |
753 |
+ |
return(0); |
754 |
+ |
if (set_refdepth(&dc2, &hdr2) < 0) |
755 |
+ |
return(0); |
756 |
+ |
while (nread < dc1.res.xr*dc1.res.yr) { |
757 |
+ |
double d1 = decode_depth_next(&dc1); |
758 |
+ |
double d2 = decode_depth_next(&dc2); |
759 |
+ |
if ((d1 < 0) | (d2 < 0)) { |
760 |
+ |
if (report != REP_QUIET) |
761 |
+ |
printf("%s: unexpected end-of-file\n", |
762 |
+ |
progname); |
763 |
+ |
return(0); |
764 |
+ |
} |
765 |
+ |
++nread; |
766 |
+ |
if (real_check(d1, d2)) |
767 |
+ |
continue; |
768 |
+ |
if (report != REP_QUIET) |
769 |
+ |
printf("%s: %ld%s depth values differ\n", |
770 |
+ |
progname, nread, num_sfx(nread)); |
771 |
+ |
return(0); |
772 |
+ |
} |
773 |
+ |
return(good_RMS()); /* final check of RMS */ |
774 |
+ |
} |
775 |
+ |
|
776 |
+ |
/* Compare two encoded normal maps */ |
777 |
+ |
static int |
778 |
+ |
compare_norm() |
779 |
+ |
{ |
780 |
+ |
long nread = 0; |
781 |
+ |
NORMCODEC nc1, nc2; |
782 |
+ |
|
783 |
+ |
if (report >= REP_VERBOSE) { |
784 |
+ |
fputs(progname, stdout); |
785 |
+ |
fputs(": comparing inputs as normal maps\n", stdout); |
786 |
+ |
} |
787 |
+ |
set_nc_defaults(&nc1); |
788 |
+ |
nc1.hdrflags = HF_RESIN; |
789 |
+ |
nc1.finp = f1in; |
790 |
+ |
nc1.inpname = f1name; |
791 |
+ |
set_nc_defaults(&nc2); |
792 |
+ |
nc2.hdrflags = HF_RESIN; |
793 |
+ |
nc2.finp = f2in; |
794 |
+ |
nc2.inpname = f2name; |
795 |
+ |
if (report != REP_QUIET) { |
796 |
+ |
nc1.hdrflags |= HF_STDERR; |
797 |
+ |
nc2.hdrflags |= HF_STDERR; |
798 |
+ |
} |
799 |
+ |
if (!process_nc_header(&nc1, 0, NULL)) |
800 |
+ |
return(0); |
801 |
+ |
if (!process_nc_header(&nc2, 0, NULL)) |
802 |
+ |
return(0); |
803 |
+ |
if (!check_resolu("Normal map", &nc1.res, &nc2.res)) |
804 |
+ |
return(0); |
805 |
+ |
while (nread < nc1.res.xr*nc1.res.yr) { |
806 |
+ |
FVECT nv1, nv2; |
807 |
+ |
int rv1 = decode_normal_next(nv1, &nc1); |
808 |
+ |
int rv2 = decode_normal_next(nv2, &nc2); |
809 |
+ |
if ((rv1 < 0) | (rv2 < 0)) { |
810 |
+ |
if (report != REP_QUIET) |
811 |
+ |
printf("%s: unexpected end-of-file\n", |
812 |
+ |
progname); |
813 |
+ |
return(0); |
814 |
+ |
} |
815 |
+ |
++nread; |
816 |
+ |
if (rv1 == rv2 && (!rv1 || norm_check(nv1, nv2))) |
817 |
+ |
continue; |
818 |
+ |
if (report != REP_QUIET) |
819 |
+ |
printf("%s: %ld%s normal vectors differ\n", |
820 |
+ |
progname, nread, num_sfx(nread)); |
821 |
+ |
return(0); |
822 |
+ |
} |
823 |
+ |
return(good_RMS()); /* final check of RMS */ |
824 |
+ |
} |
825 |
+ |
|
826 |
|
/* Compare two inputs that are known to be 32-bit floating-point data */ |
827 |
|
static int |
828 |
|
compare_float() |
838 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
839 |
|
goto badeof; |
840 |
|
++nread; |
841 |
+ |
if (f1swap) swap32((char *)&f1, 1); |
842 |
+ |
if (f2swap) swap32((char *)&f2, 1); |
843 |
|
if (real_check(f1, f2)) |
844 |
|
continue; |
845 |
|
if (report != REP_QUIET) |
870 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
871 |
|
goto badeof; |
872 |
|
++nread; |
873 |
+ |
if (f1swap) swap64((char *)&f1, 1); |
874 |
+ |
if (f2swap) swap64((char *)&f2, 1); |
875 |
|
if (real_check(f1, f2)) |
876 |
|
continue; |
877 |
|
if (report != REP_QUIET) |
960 |
|
return(2); |
961 |
|
if (typ1 != typ2) { |
962 |
|
if (report != REP_QUIET) |
963 |
< |
printf("%s: '%s' is %s and '%s' is %s\n", |
963 |
> |
printf("%s: '%s' format is %s and '%s' is %s\n", |
964 |
|
progname, f1name, file_type[typ1], |
965 |
|
f2name, file_type[typ2]); |
966 |
|
return(1); |
968 |
|
ign_header |= !has_header(typ1); /* check headers if indicated */ |
969 |
|
if (!ign_header && !headers_match()) |
970 |
|
return(1); |
780 |
– |
lu_done(&hdr1); lu_done(&hdr2); |
971 |
|
if (!ign_header & (report >= REP_WARN)) { |
782 |
– |
if (typ1 == TYP_UNKNOWN) |
783 |
– |
printf("%s: warning - unrecognized format, comparing as binary\n", |
784 |
– |
progname); |
972 |
|
if (lin1cnt != lin2cnt) |
973 |
|
printf("%s: warning - headers are different lengths\n", |
974 |
|
progname); |
975 |
+ |
if (typ1 == TYP_UNKNOWN) |
976 |
+ |
printf("%s: warning - unrecognized format\n", |
977 |
+ |
progname); |
978 |
|
} |
979 |
< |
if (report >= REP_VERBOSE) |
980 |
< |
printf("%s: input file type is %s\n", |
981 |
< |
progname, file_type[typ1]); |
982 |
< |
|
979 |
> |
if (report >= REP_VERBOSE) { |
980 |
> |
printf("%s: data format is %s\n", progname, file_type[typ1]); |
981 |
> |
if ((typ1 == TYP_FLOAT) | (typ1 == TYP_DOUBLE)) { |
982 |
> |
if (f1swap) |
983 |
> |
printf("%s: input '%s' is byte-swapped\n", |
984 |
> |
progname, f1name); |
985 |
> |
if (f2swap) |
986 |
> |
printf("%s: input '%s' is byte-swapped\n", |
987 |
> |
progname, f2name); |
988 |
> |
} |
989 |
> |
} |
990 |
|
switch (typ1) { /* compare based on type */ |
991 |
|
case TYP_BINARY: |
992 |
|
case TYP_TMESH: |
993 |
|
case TYP_OCTREE: |
994 |
|
case TYP_RBFMESH: |
995 |
+ |
case TYP_ID8: |
996 |
+ |
case TYP_ID16: |
997 |
+ |
case TYP_ID24: |
998 |
|
case TYP_UNKNOWN: |
999 |
|
return( !compare_binary() ); |
1000 |
|
case TYP_TEXT: |
1003 |
|
case TYP_RGBE: |
1004 |
|
case TYP_XYZE: |
1005 |
|
return( !compare_hdr() ); |
1006 |
+ |
case TYP_DEPTH: |
1007 |
+ |
return( !compare_depth() ); |
1008 |
+ |
case TYP_NORM: |
1009 |
+ |
return( !compare_norm() ); |
1010 |
|
case TYP_FLOAT: |
1011 |
|
return( !compare_float() ); |
1012 |
|
case TYP_DOUBLE: |