ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/radcompare.c
(Generate patch)

Comparing ray/src/util/radcompare.c (file contents):
Revision 2.6 by greg, Mon Oct 15 22:38:31 2018 UTC vs.
Revision 2.30 by greg, Tue May 24 22:34:18 2022 UTC

# Line 8 | Line 8 | static const char RCSid[] = "$Id$";
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 */
# Line 25 | Line 27 | int    report = REP_WARN;      /* reporting level */
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 */
# Line 33 | Line 37 | double max_lim = 0.25;         /* difference limit if non-neg
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                  };
# Line 45 | Line 51 | const char     *file_type[] = {
51                          "ascii",
52                          COLRFMT,
53                          CIEFMT,
54 +                        DEPTH16FMT,
55 +                        NORMAL32FMT,
56                          "float",
57                          "double",
58                          "BSDF_RBFmesh",
59                          "Radiance_octree",
60                          "Radiance_tmesh",
61 +                        "8-bit_indexed_name",
62 +                        "16-bit_indexed_name",
63 +                        "24-bit_indexed_name",
64                          "BINARY_unknown",
65                          NULL    /* terminator */
66                  };
67                                  /* keep consistent with above */
68 < enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE, TYP_FLOAT,
69 <                TYP_DOUBLE, TYP_RBFMESH, TYP_OCTREE, TYP_TMESH, TYP_BINARY};
68 > enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE,
69 >                TYP_DEPTH, TYP_NORM, TYP_FLOAT, TYP_DOUBLE,
70 >                TYP_RBFMESH, TYP_OCTREE, TYP_TMESH,
71 >                TYP_ID8, TYP_ID16, TYP_ID24, TYP_BINARY};
72                  
73   #define has_header(t)   (!( 1L<<(t) & (1L<<TYP_TEXT | 1L<<TYP_BINARY) ))
74  
75                                  /* header variables to always ignore */
76   const char      *hdr_ignkey[] = {
77 +                        "FORMAT",
78                          "SOFTWARE",
79                          "CAPDATE",
80                          "GMT",
81 +                        "FRAME",
82                          NULL    /* terminator */
83                  };
84                                  /* header variable settings */
# Line 74 | Line 89 | LUTAB  hdr2 = LU_SINIT(free,free);
89   #define adv_linecnt(htp)        (lin1cnt += (htp == &hdr1), \
90                                          lin2cnt += (htp == &hdr2))
91  
92 + typedef struct {                /* dynamic line buffer */
93 +        char    *str;
94 +        int     len;
95 +        int     siz;
96 + } LINEBUF;
97 +
98 + #define init_line(bp)   ((bp)->str = NULL, (bp)->siz = 0)
99 +                                /* 100 MByte limit on line buffer */
100 + #define MAXBUF          (100L<<20)
101 +
102                                  /* input files */
103   char            *progname = NULL;
104   const char      stdin_name[] = "<stdin>";
105   const char      *f1name=NULL, *f2name=NULL;
106   FILE            *f1in=NULL, *f2in=NULL;
107 + int             f1swap=0, f2swap=0;
108  
109                                  /* running real differences */
110   double  diff2sum = 0;
111 < int     nsum = 0;
111 > long    nsum = 0;
112  
113   /* Report usage and exit */
114   static void
# Line 90 | Line 116 | usage()
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(1);
121 >        exit(2);
122   }
123  
124 + /* Read a text line, increasing buffer size as necessary */
125 + static int
126 + read_line(LINEBUF *bp, FILE *fp)
127 + {
128 +        static int      doneWarn = 0;
129 +
130 +        bp->len = 0;
131 +        if (!bp->str) {
132 +                bp->str = (char *)malloc(bp->siz = 512);
133 +                if (!bp->str)
134 +                        goto memerr;
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') {
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) {
154 +                        if ((report >= REP_WARN) & !doneWarn) {
155 +                                fprintf(stderr,
156 +                        "%s: warning - input line(s) past %ld MByte limit\n",
157 +                                        progname, MAXBUF>>20);
158 +                                doneWarn++;
159 +                        }
160 +                        break;          /* return MAXBUF partial line */
161 +                }
162 +                if ((bp->siz += bp->siz/2) > MAXBUF)
163 +                        bp->siz = MAXBUF;
164 +                bp->str = (char *)realloc(bp->str, bp->siz);
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,
179 +                "%s: out of memory in read_line() allocating %d byte buffer\n",
180 +                        progname, bp->siz);
181 +        exit(2);
182 + }
183 +
184 + /* Free line buffer */
185 + static void
186 + free_line(LINEBUF *bp)
187 + {
188 +        if (bp->str) free(bp->str);
189 +        init_line(bp);
190 + }
191 +
192   /* Get type ID from name (or 0 if not found) */
193   static int
194   xlate_type(const char *nm)
# Line 117 | Line 211 | real_check(double r1, double r2)
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)
# Line 134 | Line 229 | real_check(double r1, double r2)
229          return(1);
230   }
231  
232 + /* Compare two color values for equivalence */
233 + static int
234 + color_check(COLOR c1, COLOR c2)
235 + {
236 +        int     p;
237 +
238 +        if (!real_check((colval(c1,RED)+colval(c1,GRN)+colval(c1,BLU))*(1./3.),
239 +                        (colval(c2,RED)+colval(c2,GRN)+colval(c2,BLU))*(1./3.)))
240 +                return(0);
241 +
242 +        p = (colval(c1,GRN) > colval(c1,RED)) ? GRN : RED;
243 +        if (colval(c1,BLU) > colval(c1,p)) p = BLU;
244 +        
245 +        return(real_check(colval(c1,p), colval(c2,p)));
246 + }
247 +
248 + /* Compare two normal directions for equivalence */
249 + static int
250 + norm_check(FVECT nv1, FVECT nv2)
251 + {
252 +        double  max2 = nv1[2]*nv2[2];
253 +        int     imax = 2;
254 +        int     i = 2;
255 +                                        /* identify largest component */
256 +        while (i--) {
257 +                double  tm2 = nv1[i]*nv2[i];
258 +                if (tm2 > max2) {
259 +                        imax = i;
260 +                        max2 = tm2;
261 +                }
262 +        }
263 +        i = 3;                          /* compare smaller components */
264 +        while (i--) {
265 +                if (i == imax)
266 +                        continue;
267 +                if (!real_check(nv1[i], nv2[i]))
268 +                        return(0);
269 +        }
270 +        return(1);
271 + }
272 +
273   /* Compare two strings for equivalence */
274   static int
275   equiv_string(char *s1, char *s2)
# Line 206 | Line 342 | equiv_string(char *s1, char *s2)
342   static int
343   setheadvar(char *val, void *p)
344   {
345 +        char    newval[128];
346          LUTAB   *htp = (LUTAB *)p;
347          LUENT   *tep;
348          char    *key;
# Line 215 | Line 352 | setheadvar(char *val, void *p)
352          adv_linecnt(htp);       /* side-effect is to count lines */
353          if (!isalpha(*val))     /* key must start line */
354                  return(0);
355 +                                /* check if we need to swap binary data */
356 +        if ((n = isbigendian(val)) >= 0) {
357 +                if (nativebigendian() == n)
358 +                        return(0);
359 +                f1swap += (htp == &hdr1);
360 +                f2swap += (htp == &hdr2);
361 +                return(0);
362 +        }
363          key = val++;
364          while (*val && !isspace(*val) & (*val != '='))
365                  val++;
# Line 240 | Line 385 | setheadvar(char *val, void *p)
385                  return(-1);     /* memory allocation error */
386          if (!tep->key)
387                  tep->key = strcpy(malloc(kln+1), key);
388 <        if (tep->data)
388 >        if (tep->data) {        /* check for special cases */
389 >                if (!strcmp(key, "EXPOSURE")) {
390 >                        sprintf(newval, "%.6e", atof(tep->data)*atof(val));
391 >                        vln = strlen(val = newval);
392 >                }
393                  free(tep->data);
394 +        }
395          tep->data = strcpy(malloc(vln+1), val);
396          return(1);
397   }
# Line 275 | Line 425 | match_val(const LUENT *ep1, void *p2)
425  
426   /* Compare two sets of header variables */
427   static int
428 < headers_match(LUTAB *hp1, LUTAB *hp2)
428 > headers_match()
429   {
430 <        int     ne = lu_doall(hp1, match_val, hp2);
430 >        int     ne = lu_doall(&hdr1, match_val, &hdr2);
431          if (ne < 0)
432                  return(0);      /* something didn't match! */
433                                  /* non-fatal if second header has extra */
434 <        if (report >= REP_WARN && (ne = lu_doall(hp2, NULL, NULL) - ne))
434 >        if (report >= REP_WARN && (ne = lu_doall(&hdr2, NULL, NULL) - ne))
435                  printf("%s: warning - '%s' has %d extra header setting(s)\n",
436                                          progname, f2name, ne);
437          return(1);              /* good match */
# Line 350 | Line 500 | identify_type(const char *name, FILE *fin, LUTAB *htp)
500          }
501          if (c)
502                  return(TYP_BINARY);
353        SET_FILE_TEXT(fin);                     /* originally set to binary */
503          return(TYP_TEXT);
504   badeof:
505          if (report != REP_QUIET) {
# Line 429 | Line 578 | compare_binary()
578   static int
579   compare_text()
580   {
581 <        char    l1buf[4096], l2buf[4096];
581 >        LINEBUF l1buf, l2buf;
582  
583          if (report >= REP_VERBOSE) {
584                  fputs(progname, stdout);
585 <                fputs(": comparing inputs as ASCII text\n", stdout);
585 >                fputs(": comparing inputs as ASCII text", stdout);
586 >                if (escape_newlines)
587 >                        fputs(", allowing escaped newlines", stdout);
588 >                if (comment_c) {
589 >                        fputs(", ignoring comments starting with '", stdout);
590 >                        fputc(comment_c, stdout);
591 >                        fputc('\'', stdout);
592 >                }
593 >                fputc('\n', stdout);
594          }
595 <                                                /* compare a line at a time */
596 <        while (fgets(l1buf, sizeof(l1buf), f1in)) {
595 >        SET_FILE_TEXT(f1in);                    /* originally set to binary */
596 >        SET_FILE_TEXT(f2in);
597 >        init_line(&l1buf); init_line(&l2buf);   /* compare a line at a time */
598 >        while (read_line(&l1buf, f1in)) {
599                  lin1cnt++;
600 <                if (!*sskip2(l1buf,0))
600 >                if (!*sskip2(l1buf.str,0))
601                          continue;               /* ignore empty lines */
602 <                while (fgets(l2buf, sizeof(l2buf), f2in)) {
602 >
603 >                while (read_line(&l2buf, f2in)) {
604                          lin2cnt++;
605 <                        if (*sskip2(l2buf,0))
605 >                        if (*sskip2(l2buf.str,0))
606                                  break;          /* found other non-empty line */
607                  }
608 <                if (feof(f2in)) {
608 >                if (!l2buf.len) {               /* input 2 EOF? */
609                          if (report != REP_QUIET) {
610                                  fputs(f2name, stdout);
611                                  fputs(": unexpected end-of-file\n", stdout);
612                          }
613 +                        free_line(&l1buf); free_line(&l2buf);
614                          return(0);
615                  }
616                                                  /* compare non-empty lines */
617 <                if (!equiv_string(l1buf, l2buf)) {
617 >                if (!equiv_string(l1buf.str, l2buf.str)) {
618                          if (report != REP_QUIET) {
619                                  printf("%s: inputs '%s' and '%s' differ at line %d|%d\n",
620                                                  progname, f1name, f2name,
621                                                  lin1cnt, lin2cnt);
622 <                                if (report >= REP_VERBOSE) {
622 >                                if ( report >= REP_VERBOSE &&
623 >                                                (l1buf.len < 256) &
624 >                                                (l2buf.len < 256) ) {
625                                          fputs("------------- Mismatch -------------\n", stdout);
626                                          printf("%s@%d:\t%s", f1name,
627 <                                                        lin1cnt, l1buf);
627 >                                                        lin1cnt, l1buf.str);
628                                          printf("%s@%d:\t%s", f2name,
629 <                                                        lin2cnt, l2buf);
629 >                                                        lin2cnt, l2buf.str);
630                                  }
631                          }
632 +                        free_line(&l1buf); free_line(&l2buf);
633                          return(0);
634                  }
635          }
636 <                                                /* check for EOF on input 2 */
637 <        while (fgets(l2buf, sizeof(l2buf), f2in)) {
638 <                if (!*sskip2(l2buf,0))
636 >        free_line(&l1buf);                      /* check for EOF on input 2 */
637 >        while (read_line(&l2buf, f2in)) {
638 >                if (!*sskip2(l2buf.str,0))
639                          continue;
640                  if (report != REP_QUIET) {
641                          fputs(f1name, stdout);
642                          fputs(": unexpected end-of-file\n", stdout);
643                  }
644 +                free_line(&l2buf);
645                  return(0);
646          }
647 +        free_line(&l2buf);
648          return(good_RMS());                     /* final check for reals */
649   }
650  
651 + /* Check image/map resolutions */
652 + static int
653 + check_resolu(const char *class, RESOLU *r1p, RESOLU *r2p)
654 + {
655 +        if (r1p->rt != r2p->rt) {
656 +                if (report != REP_QUIET)
657 +                        printf(
658 +                        "%s: %ss '%s' and '%s' have different pixel ordering\n",
659 +                                        progname, class, f1name, f2name);
660 +                return(0);
661 +        }
662 +        if ((r1p->xr != r2p->xr) | (r1p->yr != r2p->yr)) {
663 +                if (report != REP_QUIET)
664 +                        printf(
665 +                        "%s: %ss '%s' and '%s' are different sizes\n",
666 +                                        progname, class, f1name, f2name);
667 +                return(0);
668 +        }
669 +        return(1);
670 + }
671 +
672   /* Compare two inputs that are known to be RGBE or XYZE images */
673   static int
674   compare_hdr()
# Line 496 | Line 683 | compare_hdr()
683          }
684          fgetsresolu(&rs1, f1in);
685          fgetsresolu(&rs2, f2in);
686 <        if (rs1.rt != rs2.rt) {
500 <                if (report != REP_QUIET)
501 <                        printf(
502 <                        "%s: Images '%s' and '%s' have different pixel ordering\n",
503 <                                        progname, f1name, f2name);
686 >        if (!check_resolu("HDR image", &rs1, &rs2))
687                  return(0);
505        }
506        if ((rs1.xr != rs2.xr) | (rs1.yr != rs2.yr)) {
507                if (report != REP_QUIET)
508                        printf(
509                        "%s: Images '%s' and '%s' are different sizes\n",
510                                        progname, f1name, f2name);
511                return(0);
512        }
688          scan1 = (COLOR *)malloc(scanlen(&rs1)*sizeof(COLOR));
689          scan2 = (COLOR *)malloc(scanlen(&rs2)*sizeof(COLOR));
690          if (!scan1 | !scan2) {
# Line 527 | Line 702 | compare_hdr()
702                          return(0);
703                  }
704                  for (x = 0; x < scanlen(&rs1); x++) {
705 <                        if (real_check(colval(scan1[x],RED),
531 <                                                colval(scan2[x],RED)) &
532 <                                        real_check(colval(scan1[x],GRN),
533 <                                                colval(scan2[x],GRN)) &
534 <                                        real_check(colval(scan1[x],BLU),
535 <                                                colval(scan2[x],BLU)))
705 >                        if (color_check(scan1[x], scan2[x]))
706                                  continue;
707                          if (report != REP_QUIET) {
708                                  printf(
# Line 559 | Line 729 | compare_hdr()
729          return(good_RMS());                     /* final check of RMS */
730   }
731  
732 + /* Set reference depth based on header variable */
733 + static int
734 + set_refdepth(DEPTHCODEC *dcp, LUTAB *htp)
735 + {
736 +        static char     depthvar[] = DEPTHSTR;
737 +        const char      *drval;
738 +
739 +        depthvar[LDEPTHSTR-1] = '\0';
740 +        drval = (const char *)lu_find(htp, depthvar)->data;
741 +        if (!drval)
742 +                return(0);
743 +        dcp->refdepth = atof(drval);
744 +        if (dcp->refdepth <= 0) {
745 +                if (report != REP_QUIET) {
746 +                        fputs(dcp->inpname, stderr);
747 +                        fputs(": bad reference depth '", stderr);
748 +                        fputs(drval, stderr);
749 +                        fputs("'\n", stderr);
750 +                }
751 +                return(-1);
752 +        }
753 +        return(1);
754 + }
755 +
756 + /* Compare two encoded depth maps */
757 + static int
758 + compare_depth()
759 + {
760 +        long            nread = 0;
761 +        DEPTHCODEC      dc1, dc2;
762 +
763 +        if (report >= REP_VERBOSE) {
764 +                fputs(progname, stdout);
765 +                fputs(": comparing inputs as depth maps\n", stdout);
766 +        }
767 +        set_dc_defaults(&dc1);
768 +        dc1.hdrflags = HF_RESIN;
769 +        dc1.finp = f1in;
770 +        dc1.inpname = f1name;
771 +        set_dc_defaults(&dc2);
772 +        dc2.hdrflags = HF_RESIN;
773 +        dc2.finp = f2in;
774 +        dc2.inpname = f2name;
775 +        if (report != REP_QUIET) {
776 +                dc1.hdrflags |= HF_STDERR;
777 +                dc2.hdrflags |= HF_STDERR;
778 +        }
779 +        if (!process_dc_header(&dc1, 0, NULL))
780 +                return(0);
781 +        if (!process_dc_header(&dc2, 0, NULL))
782 +                return(0);
783 +        if (!check_resolu("Depth map", &dc1.res, &dc2.res))
784 +                return(0);
785 +        if (set_refdepth(&dc1, &hdr1) < 0)
786 +                return(0);
787 +        if (set_refdepth(&dc2, &hdr2) < 0)
788 +                return(0);
789 +        while (nread < dc1.res.xr*dc1.res.yr) {
790 +                double  d1 = decode_depth_next(&dc1);
791 +                double  d2 = decode_depth_next(&dc2);
792 +                if ((d1 < 0) | (d2 < 0)) {
793 +                        if (report != REP_QUIET)
794 +                                printf("%s: unexpected end-of-file\n",
795 +                                                progname);
796 +                        return(0);
797 +                }
798 +                ++nread;
799 +                if (real_check(d1, d2))
800 +                        continue;
801 +                if (report != REP_QUIET)
802 +                        printf("%s: %ld%s depth values differ\n",
803 +                                        progname, nread, num_sfx(nread));
804 +                return(0);
805 +        }
806 +        return(good_RMS());             /* final check of RMS */
807 + }
808 +
809 + /* Compare two encoded normal maps */
810 + static int
811 + compare_norm()
812 + {
813 +        long            nread = 0;
814 +        NORMCODEC       nc1, nc2;
815 +
816 +        if (report >= REP_VERBOSE) {
817 +                fputs(progname, stdout);
818 +                fputs(": comparing inputs as normal maps\n", stdout);
819 +        }
820 +        set_nc_defaults(&nc1);
821 +        nc1.hdrflags = HF_RESIN;
822 +        nc1.finp = f1in;
823 +        nc1.inpname = f1name;
824 +        set_nc_defaults(&nc2);
825 +        nc2.hdrflags = HF_RESIN;
826 +        nc2.finp = f2in;
827 +        nc2.inpname = f2name;
828 +        if (report != REP_QUIET) {
829 +                nc1.hdrflags |= HF_STDERR;
830 +                nc2.hdrflags |= HF_STDERR;
831 +        }
832 +        if (!process_nc_header(&nc1, 0, NULL))
833 +                return(0);
834 +        if (!process_nc_header(&nc2, 0, NULL))
835 +                return(0);
836 +        if (!check_resolu("Normal map", &nc1.res, &nc2.res))
837 +                return(0);
838 +        while (nread < nc1.res.xr*nc1.res.yr) {
839 +                FVECT   nv1, nv2;
840 +                int     rv1 = decode_normal_next(nv1, &nc1);
841 +                int     rv2 = decode_normal_next(nv2, &nc2);
842 +                if ((rv1 < 0) | (rv2 < 0)) {
843 +                        if (report != REP_QUIET)
844 +                                printf("%s: unexpected end-of-file\n",
845 +                                                progname);
846 +                        return(0);
847 +                }
848 +                ++nread;
849 +                if (rv1 == rv2 && (!rv1 || norm_check(nv1, nv2)))
850 +                        continue;
851 +                if (report != REP_QUIET)
852 +                        printf("%s: %ld%s normal vectors differ\n",
853 +                                        progname, nread, num_sfx(nread));
854 +                return(0);
855 +        }
856 +        return(good_RMS());             /* final check of RMS */
857 + }
858 +
859   /* Compare two inputs that are known to be 32-bit floating-point data */
860   static int
861   compare_float()
# Line 568 | Line 865 | compare_float()
865  
866          if (report >= REP_VERBOSE) {
867                  fputs(progname, stdout);
868 <                fputs(": comparing inputs as 32-bit IEEE float\n", stdout);
868 >                fputs(": comparing inputs as 32-bit IEEE floats\n", stdout);
869          }
870          while (getbinary(&f1, sizeof(f1), 1, f1in)) {
871                  if (!getbinary(&f2, sizeof(f2), 1, f2in))
872                          goto badeof;
873                  ++nread;
874 +                if (f1swap) swap32((char *)&f1, 1);
875 +                if (f2swap) swap32((char *)&f2, 1);
876                  if (real_check(f1, f2))
877                          continue;
878                  if (report != REP_QUIET)
# Line 598 | Line 897 | compare_double()
897  
898          if (report >= REP_VERBOSE) {
899                  fputs(progname, stdout);
900 <                fputs(": comparing inputs as 64-bit IEEE double\n", stdout);
900 >                fputs(": comparing inputs as 64-bit IEEE doubles\n", stdout);
901          }
902          while (getbinary(&f1, sizeof(f1), 1, f1in)) {
903                  if (!getbinary(&f2, sizeof(f2), 1, f2in))
904                          goto badeof;
905                  ++nread;
906 +                if (f1swap) swap64((char *)&f1, 1);
907 +                if (f2swap) swap64((char *)&f2, 1);
908                  if (real_check(f1, f2))
909                          continue;
910                  if (report != REP_QUIET)
# Line 632 | Line 933 | main(int argc, char *argv[])
933                  case 'h':                       /* ignore header info. */
934                          ign_header = !ign_header;
935                          continue;
936 +                case 'n':                       /* allow newline escapes */
937 +                        escape_newlines = !escape_newlines;
938 +                        continue;
939 +                case 'c':                       /* ignore comments */
940 +                        comment_c = argv[a][2];
941 +                        continue;
942                  case 's':                       /* silent operation */
943                          report = REP_QUIET;
944                          continue;
# Line 662 | Line 969 | main(int argc, char *argv[])
969                  }
970                  break;
971          }
972 <        if (a != argc-2)
972 >        if (a != argc-2)                        /* make sure of two inputs */
973                  usage();
974 <        if (!f1name) f1name = argv[a];
668 <        if (!f2name) f2name = argv[a+1];
669 <
670 <        if (!strcmp(f1name, f2name)) {          /* inputs are same? */
974 >        if (!strcmp(argv[a], argv[a+1])) {      /* inputs are same? */
975                  if (report >= REP_WARN)
976                          printf("%s: warning - identical inputs given\n",
977                                          progname);
978                  return(0);
979          }
980 +        if (!f1name) f1name = argv[a];
981 +        if (!f2name) f2name = argv[a+1];
982                                                  /* open inputs */
983          SET_FILE_BINARY(stdin);                 /* in case we're using it */
984          if (!f1in && !(f1in = fopen(f1name, "rb"))) {
985                  fprintf(stderr, "%s: cannot open for reading\n", f1name);
986 <                return(1);
986 >                return(2);
987          }
988          if (!strcmp(f2name, "-")) {
989                  f2in = stdin;
990                  f2name = stdin_name;
991          } else if (!(f2in = fopen(f2name, "rb"))) {
992                  fprintf(stderr, "%s: cannot open for reading\n", f2name);
993 <                return(1);
993 >                return(2);
994          }
995                                                  /* load headers */
996          if ((typ1 = identify_type(f1name, f1in, &hdr1)) < 0)
997 <                return(1);
997 >                return(2);
998          if ((typ2 = identify_type(f2name, f2in, &hdr2)) < 0)
999 <                return(1);
999 >                return(2);
1000          if (typ1 != typ2) {
1001                  if (report != REP_QUIET)
1002 <                        printf("%s: '%s' is %s and '%s' is %s\n",
1002 >                        printf("%s: '%s' format is %s and '%s' is %s\n",
1003                                          progname, f1name, file_type[typ1],
1004                                          f2name, file_type[typ2]);
1005                  return(1);
1006          }
1007          ign_header |= !has_header(typ1);        /* check headers if indicated */
1008 <        if (!ign_header && !headers_match(&hdr1, &hdr2))
1008 >        if (!ign_header && !headers_match())
1009                  return(1);
704        lu_done(&hdr1); lu_done(&hdr2);
1010          if (!ign_header & (report >= REP_WARN)) {
706                if (typ1 == TYP_UNKNOWN)
707                        printf("%s: warning - unrecognized format, comparing as binary\n",
708                                        progname);
1011                  if (lin1cnt != lin2cnt)
1012                          printf("%s: warning - headers are different lengths\n",
1013                                          progname);
1014 +                if (typ1 == TYP_UNKNOWN)
1015 +                        printf("%s: warning - unrecognized format\n",
1016 +                                        progname);
1017          }
1018 <        if (report >= REP_VERBOSE)
1019 <                printf("%s: input file type is %s\n",
1020 <                                progname, file_type[typ1]);
1021 <
1018 >        if (report >= REP_VERBOSE) {
1019 >                printf("%s: data format is %s\n", progname, file_type[typ1]);
1020 >                if ((typ1 == TYP_FLOAT) | (typ1 == TYP_DOUBLE)) {
1021 >                        if (f1swap)
1022 >                                printf("%s: input '%s' is byte-swapped\n",
1023 >                                                progname, f1name);
1024 >                        if (f2swap)
1025 >                                printf("%s: input '%s' is byte-swapped\n",
1026 >                                                progname, f2name);
1027 >                }
1028 >        }
1029          switch (typ1) {                         /* compare based on type */
1030          case TYP_BINARY:
1031          case TYP_TMESH:
1032          case TYP_OCTREE:
1033          case TYP_RBFMESH:
1034 +        case TYP_ID8:
1035 +        case TYP_ID16:
1036 +        case TYP_ID24:
1037          case TYP_UNKNOWN:
1038                  return( !compare_binary() );
1039          case TYP_TEXT:
# Line 727 | Line 1042 | main(int argc, char *argv[])
1042          case TYP_RGBE:
1043          case TYP_XYZE:
1044                  return( !compare_hdr() );
1045 +        case TYP_DEPTH:
1046 +                return( !compare_depth() );
1047 +        case TYP_NORM:
1048 +                return( !compare_norm() );
1049          case TYP_FLOAT:
1050                  return( !compare_float() );
1051          case TYP_DOUBLE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines