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.1 by greg, Mon Oct 15 17:52:52 2018 UTC vs.
Revision 2.19 by greg, Wed Aug 14 04:18:12 2019 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 33 | Line 35 | double max_lim = 0.25;         /* difference limit if non-neg
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",
# Line 40 | Line 47 | const char     *file_type[] = {
47                          "ascii",
48                          COLRFMT,
49                          CIEFMT,
50 <                        "BINARY_float",
51 <                        "BINARY_double",
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  
# Line 59 | Line 73 | const char     *hdr_ignkey[] = {
73                          "SOFTWARE",
74                          "CAPDATE",
75                          "GMT",
76 +                        "FRAME",
77                          NULL    /* terminator */
78                  };
79                                  /* header variable settings */
# Line 69 | Line 84 | LUTAB  hdr2 = LU_SINIT(free,free);
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 +
103                                  /* running real differences */
104   double  diff2sum = 0;
105 < int     nsum = 0;
105 > long    nsum = 0;
106  
107   /* Report usage and exit */
108   static void
# Line 84 | Line 110 | usage()
110   {
111          fputs("Usage: ", stderr);
112          fputs(progname, stderr);
113 <        fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] file1 file2\n",
113 >        fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n",
114                          stderr);
115 <        exit(1);
115 >        exit(2);
116   }
117  
118 + /* Read a text line, increasing buffer size as necessary */
119 + static int
120 + read_line(LINEBUF *bp, FILE *fp)
121 + {
122 +        static int      doneWarn = 0;
123 +
124 +        bp->len = 0;
125 +        if (!bp->str) {
126 +                bp->str = (char *)malloc(bp->siz = 512);
127 +                if (!bp->str)
128 +                        goto memerr;
129 +        }
130 +        while (fgets(bp->str + bp->len, bp->siz - bp->len, fp)) {
131 +                bp->len += strlen(bp->str + bp->len);
132 +                if (bp->str[bp->len-1] == '\n')
133 +                        break;          /* found EOL */
134 +                if (bp->len < bp->siz - 4)
135 +                        continue;       /* at EOF? */
136 +                if (bp->siz >= MAXBUF) {
137 +                        if ((report >= REP_WARN) & !doneWarn) {
138 +                                fprintf(stderr,
139 +                        "%s: warning - input line(s) past %ld MByte limit\n",
140 +                                        progname, MAXBUF>>20);
141 +                                doneWarn++;
142 +                        }
143 +                        break;          /* return MAXBUF partial line */
144 +                }
145 +                if ((bp->siz += bp->siz/2) > MAXBUF)
146 +                        bp->siz = MAXBUF;
147 +                bp->str = (char *)realloc(bp->str, bp->siz);
148 +                if (!bp->str)
149 +                        goto memerr;
150 +        }
151 +        return(bp->len);
152 + memerr:
153 +        fprintf(stderr,
154 +                "%s: out of memory in read_line() allocating %d byte buffer\n",
155 +                        progname, bp->siz);
156 +        exit(2);
157 + }
158 +
159 + /* Free line buffer */
160 + static void
161 + free_line(LINEBUF *bp)
162 + {
163 +        if (bp->str) free(bp->str);
164 +        init_line(bp);
165 + }
166 +
167   /* Get type ID from name (or 0 if not found) */
168   static int
169   xlate_type(const char *nm)
# Line 116 | Line 191 | real_check(double r1, double r2)
191          }
192          if (max_lim >= 0 && diff2 > max_lim*max_lim) {
193                  if (report != REP_QUIET)
194 <                        fprintf(stderr,
195 <                        "%s: %sdifference between %.8g and %.8g exceeds epsilon\n",
194 >                        printf(
195 >                        "%s: %sdifference between %.8g and %.8g exceeds epsilon of %.8g\n",
196                                          progname,
197                                          (rel_min > 0) ? "relative " : "",
198 <                                        r1, r2);
198 >                                        r1, r2, max_lim);
199                  return(0);
200          }
201          diff2sum += diff2;
# Line 128 | Line 203 | real_check(double r1, double r2)
203          return(1);
204   }
205  
206 + /* Compare two color values for equivalence */
207 + static int
208 + color_check(COLOR c1, COLOR c2)
209 + {
210 +        int     p;
211 +
212 +        if (!real_check((colval(c1,RED)+colval(c1,GRN)+colval(c1,BLU))*(1./3.),
213 +                        (colval(c2,RED)+colval(c2,GRN)+colval(c2,BLU))*(1./3.)))
214 +                return(0);
215 +
216 +        p = (colval(c1,GRN) > colval(c1,RED)) ? GRN : RED;
217 +        if (colval(c1,BLU) > colval(c1,p)) p = BLU;
218 +        
219 +        return(real_check(colval(c1,p), colval(c2,p)));
220 + }
221 +
222 + /* Compare two normal directions for equivalence */
223 + static int
224 + norm_check(FVECT nv1, FVECT nv2)
225 + {
226 +        double  max2 = nv1[2]*nv1[2];
227 +        int     imax = 2;
228 +        int     i = 2;
229 +                                        /* identify largest component */
230 +        while (i--) {
231 +                double  tm2 = nv1[i]*nv1[i];
232 +                if (tm2 > max2) {
233 +                        imax = i;
234 +                        max2 = tm2;
235 +                }
236 +        }
237 +        i = 3;                          /* compare smaller components */
238 +        while (i--) {
239 +                if (i == imax)
240 +                        continue;
241 +                if (!real_check(nv1[i], nv2[i]))
242 +                        return(0);
243 +        }
244 +        return(1);
245 + }
246 +
247   /* Compare two strings for equivalence */
248   static int
249   equiv_string(char *s1, char *s2)
# Line 138 | Line 254 | equiv_string(char *s1, char *s2)
254                                  /* skip whitespace at beginning */
255          while (isspace(*s1)) s1++;
256          while (isspace(*s2)) s2++;
141        if (!strcmp(s1, s2))    /* quick check */
142                return(1);
257          while (*s1) {           /* check each word */
258 <                int     inquote = *s1;
258 >                int     inquote;
259 >                if (!*s2)       /* unexpected EOL in s2? */
260 >                        return(0);
261 >                inquote = *s1;
262                  if ((inquote != '\'') & (inquote != '"'))
263                          inquote = 0;
264                  if (inquote) {  /* quoted text must match exactly */
# Line 205 | Line 322 | setheadvar(char *val, void *p)
322          int     kln, vln;
323          int     n;
324  
325 +        adv_linecnt(htp);       /* side-effect is to count lines */
326          if (!isalpha(*val))     /* key must start line */
327                  return(0);
328          key = val++;
# Line 220 | Line 338 | setheadvar(char *val, void *p)
338                  val++;
339          if (!*val)              /* nothing set? */
340                  return(0);
223        vln = strlen(val);      /* eliminate space and newline at end */
224        while (--vln > 0 && isspace(val[vln]))
225                ;
226        val[++vln] = '\0';
341                                  /* check if key to ignore */
342          for (n = 0; hdr_ignkey[n]; n++)
343                  if (!strcmp(key, hdr_ignkey[n]))
344                          return(0);
345 +        vln = strlen(val);      /* eliminate space and newline at end */
346 +        while (isspace(val[--vln]))
347 +                ;
348 +        val[++vln] = '\0';
349          if (!(tep = lu_find(htp, key)))
350 <                return(-1);
350 >                return(-1);     /* memory allocation error */
351          if (!tep->key)
352                  tep->key = strcpy(malloc(kln+1), key);
353          if (tep->data)
354                  free(tep->data);
355          tep->data = strcpy(malloc(vln+1), val);
238        adv_linecnt(htp);
356          return(1);
357   }
358  
# Line 246 | Line 363 | match_val(const LUENT *ep1, void *p2)
363          const LUENT     *ep2 = lu_find((LUTAB *)p2, ep1->key);
364          if (!ep2 || !ep2->data) {
365                  if (report != REP_QUIET)
366 <                        fprintf(stderr, "%s: Variable '%s' missing in '%s'\n",
366 >                        printf("%s: variable '%s' missing in '%s'\n",
367                                          progname, ep1->key, f2name);
368                  return(-1);
369          }
370          if (!equiv_string((char *)ep1->data, (char *)ep2->data)) {
371 <                if (report != REP_QUIET)
372 <                        fprintf(stderr, "%s: Header variables '%s' have different values\n",
371 >                if (report != REP_QUIET) {
372 >                        printf("%s: header variable '%s' has different values\n",
373                                          progname, ep1->key);
374 +                        if (report >= REP_VERBOSE) {
375 +                                printf("%s: %s=%s\n", f1name,
376 +                                                ep1->key, (char *)ep1->data);
377 +                                printf("%s: %s=%s\n", f2name,
378 +                                                ep2->key, (char *)ep2->data);
379 +                        }
380 +                }
381                  return(-1);
382          }
383          return(1);              /* good match */
# Line 261 | Line 385 | match_val(const LUENT *ep1, void *p2)
385  
386   /* Compare two sets of header variables */
387   static int
388 < headers_match(LUTAB *hp1, LUTAB *hp2)
388 > headers_match()
389   {
390 <        int     ne = lu_doall(hp1, match_val, hp2);
390 >        int     ne = lu_doall(&hdr1, match_val, &hdr2);
391          if (ne < 0)
392                  return(0);      /* something didn't match! */
393 <        ne = lu_doall(hp2, NULL, NULL) - ne;
394 <        if (ne) {
395 <                if (report != REP_QUIET)
272 <                        fprintf(stderr, "%s: '%s' has %d extra header variable(s)\n",
393 >                                /* non-fatal if second header has extra */
394 >        if (report >= REP_WARN && (ne = lu_doall(&hdr2, NULL, NULL) - ne))
395 >                printf("%s: warning - '%s' has %d extra header setting(s)\n",
396                                          progname, f2name, ne);
274                return(0);
275        }
397          return(1);              /* good match */
398   }
399  
# Line 284 | Line 405 | input_is_binary(FILE *fin)
405          int     c = 0;
406  
407          while ((c = getc(fin)) != EOF) {
408 +                ++n;
409                  if (!c | (c > 127))
410                          break;                  /* non-ascii character */
411 <                if (++n >= 10240)
411 >                if (n >= 10240)
412                          break;                  /* enough to be confident */
413          }
414          if (!n)
# Line 316 | Line 438 | identify_type(const char *name, FILE *fin, LUTAB *htp)
438                  char    sbuf[32];
439                  if (!fgets(sbuf, sizeof(sbuf), fin))
440                          goto badeof;
441 +                adv_linecnt(htp);               /* for #?ID string */
442                  if (report >= REP_WARN && strncmp(sbuf, "RADIANCE", 8)) {
443 <                        fputs(name, stderr);
444 <                        fputs(": warning - unexpected header ID: ", stderr);
445 <                        fputs(sbuf, stderr);
443 >                        fputs(name, stdout);
444 >                        fputs(": warning - unexpected header ID: ", stdout);
445 >                        fputs(sbuf, stdout);
446                  }
324                adv_linecnt(htp);               /* for #?ID string */
447                  if (getheader(fin, setheadvar, htp) < 0) {
448                          fputs(name, stderr);
449 <                        fputs(": Unknown error reading header\n", stderr);
449 >                        fputs(": unknown error reading header\n", stderr);
450                          return(-1);
451                  }
452                  adv_linecnt(htp);               /* for trailing emtpy line */
# Line 342 | Line 464 | identify_type(const char *name, FILE *fin, LUTAB *htp)
464          return(TYP_TEXT);
465   badeof:
466          if (report != REP_QUIET) {
467 <                fputs(name, stderr);
468 <                fputs(": Unexpected end-of-file\n", stderr);
467 >                fputs(name, stdout);
468 >                fputs(": unexpected end-of-file\n", stdout);
469          }
470          return(-1);
471   }
# Line 356 | Line 478 | good_RMS()
478                  return(1);
479          if (diff2sum/(double)nsum > rms_lim*rms_lim) {
480                  if (report != REP_QUIET)
481 <                        fprintf(stderr,
482 <        "%s: %sRMS difference between '%s' and '%s' of %.5g exceeds limit\n",
481 >                        printf(
482 >        "%s: %sRMS difference between '%s' and '%s' of %.5g exceeds limit of %.5g\n",
483                                          progname,
484                                          (rel_min > 0) ? "relative " : "",
485                                          f1name, f2name,
486 <                                        sqrt(diff2sum/(double)nsum));
486 >                                        sqrt(diff2sum/(double)nsum), rms_lim);
487                  return(0);
488          }
489          if (report >= REP_VERBOSE)
490 <                fprintf(stderr,
369 <                        "%s: %sRMS difference of reals in '%s' and '%s' is %.5g\n",
490 >                printf("%s: %sRMS difference of reals in '%s' and '%s' is %.5g\n",
491                                  progname, (rel_min > 0) ? "relative " : "",
492                                  f1name, f2name, sqrt(diff2sum/(double)nsum));
493          return(1);
# Line 376 | Line 497 | good_RMS()
497   static int
498   compare_binary()
499   {
500 +        int     c1=0, c2=0;
501 +
502          if (report >= REP_VERBOSE) {
503 <                fputs(progname, stderr);
504 <                fputs(": comparing inputs as binary\n", stderr);
503 >                fputs(progname, stdout);
504 >                fputs(": comparing inputs as binary\n", stdout);
505          }
506          for ( ; ; ) {                           /* exact byte matching */
507 <                int     c1 = getc(f1in);
508 <                int     c2 = getc(f2in);
507 >                c1 = getc(f1in);
508 >                c2 = getc(f2in);
509                  if (c1 == EOF) {
510                          if (c2 == EOF)
511                                  return(1);      /* success! */
512                          if (report != REP_QUIET) {
513 <                                fputs(f1name, stderr);
514 <                                fputs(": Unexpected end-of-file\n", stderr);
513 >                                fputs(f1name, stdout);
514 >                                fputs(": unexpected end-of-file\n", stdout);
515                          }
516                          return(0);
517                  }
518                  if (c2 == EOF) {
519                          if (report != REP_QUIET) {
520 <                                fputs(f2name, stderr);
521 <                                fputs(": Unexpected end-of-file\n", stderr);
520 >                                fputs(f2name, stdout);
521 >                                fputs(": unexpected end-of-file\n", stdout);
522                          }
523                          return(0);
524                  }
# Line 404 | Line 527 | compare_binary()
527          }
528          if (report == REP_QUIET)
529                  return(0);
530 <        fprintf(stderr, "%s: binary files '%s' and '%s' differ at offset %ld|%ld\n",
530 >        printf("%s: binary files '%s' and '%s' differ at byte offset %ld|%ld\n",
531                          progname, f1name, f2name, ftell(f1in), ftell(f2in));
532 +        if (report >= REP_VERBOSE)
533 +                printf("%s: byte in '%s' is 0x%X, byte in '%s' is 0x%X\n",
534 +                                progname, f1name, c1, f2name, c2);
535          return(0);
536   }
537  
# Line 413 | Line 539 | compare_binary()
539   static int
540   compare_text()
541   {
542 <        char    l1buf[4096], l2buf[4096];
542 >        LINEBUF l1buf, l2buf;
543  
544          if (report >= REP_VERBOSE) {
545 <                fputs(progname, stderr);
546 <                fputs(": comparing inputs as ASCII text\n", stderr);
545 >                fputs(progname, stdout);
546 >                fputs(": comparing inputs as ASCII text\n", stdout);
547          }
548 <                                                /* compare a line at a time */
549 <        while (fgets(l1buf, sizeof(l1buf), f1in)) {
548 >        init_line(&l1buf); init_line(&l2buf);   /* compare a line at a time */
549 >        while (read_line(&l1buf, f1in)) {
550                  lin1cnt++;
551 <                if (!*sskip2(l1buf,0))
551 >                if (!*sskip2(l1buf.str,0))
552                          continue;               /* ignore empty lines */
553 <                while (fgets(l2buf, sizeof(l2buf), f2in)) {
553 >
554 >                while (read_line(&l2buf, f2in)) {
555                          lin2cnt++;
556 <                        if (*sskip2(l2buf,0))
556 >                        if (*sskip2(l2buf.str,0))
557                                  break;          /* found other non-empty line */
558                  }
559 <                if (feof(f2in)) {
559 >                if (!l2buf.len) {               /* input 2 EOF? */
560                          if (report != REP_QUIET) {
561 <                                fputs(f2name, stderr);
562 <                                fputs(": Unexpected end-of-file\n", stderr);
561 >                                fputs(f2name, stdout);
562 >                                fputs(": unexpected end-of-file\n", stdout);
563                          }
564 +                        free_line(&l1buf); free_line(&l2buf);
565                          return(0);
566                  }
567                                                  /* compare non-empty lines */
568 <                if (!equiv_string(l1buf, l2buf)) {
568 >                if (!equiv_string(l1buf.str, l2buf.str)) {
569                          if (report != REP_QUIET) {
570 <                                fprintf(stderr, "%s: inputs '%s' and '%s' differ at line %d|%d\n",
570 >                                printf("%s: inputs '%s' and '%s' differ at line %d|%d\n",
571                                                  progname, f1name, f2name,
572                                                  lin1cnt, lin2cnt);
573 <                                if (report >= REP_VERBOSE) {
574 <                                        fputs("------------- Mismatch -------------\n", stderr);
575 <                                        fprintf(stderr, "%s(%d):\t%s", f1name,
576 <                                                        lin1cnt, l1buf);
577 <                                        fprintf(stderr, "%s(%d):\t%s", f2name,
578 <                                                        lin2cnt, l2buf);
573 >                                if ( report >= REP_VERBOSE &&
574 >                                                (l1buf.len < 256) &
575 >                                                (l2buf.len < 256) ) {
576 >                                        fputs("------------- Mismatch -------------\n", stdout);
577 >                                        printf("%s@%d:\t%s", f1name,
578 >                                                        lin1cnt, l1buf.str);
579 >                                        printf("%s@%d:\t%s", f2name,
580 >                                                        lin2cnt, l2buf.str);
581                                  }
582                          }
583 +                        free_line(&l1buf); free_line(&l2buf);
584                          return(0);
585                  }
586          }
587 <                                                /* check for EOF on input 2 */
588 <        while (fgets(l2buf, sizeof(l2buf), f2in)) {
589 <                if (!*sskip2(l2buf,0))
587 >        free_line(&l1buf);                      /* check for EOF on input 2 */
588 >        while (read_line(&l2buf, f2in)) {
589 >                if (!*sskip2(l2buf.str,0))
590                          continue;
591                  if (report != REP_QUIET) {
592 <                        fputs(f1name, stderr);
593 <                        fputs(": Unexpected end-of-file\n", stderr);
592 >                        fputs(f1name, stdout);
593 >                        fputs(": unexpected end-of-file\n", stdout);
594                  }
595 +                free_line(&l2buf);
596                  return(0);
597          }
598 +        free_line(&l2buf);
599          return(good_RMS());                     /* final check for reals */
600   }
601  
602 + /* Check image/map resolutions */
603 + static int
604 + check_resolu(const char *class, RESOLU *r1p, RESOLU *r2p)
605 + {
606 +        if (r1p->rt != r2p->rt) {
607 +                if (report != REP_QUIET)
608 +                        printf(
609 +                        "%s: %ss '%s' and '%s' have different pixel ordering\n",
610 +                                        progname, class, f1name, f2name);
611 +                return(0);
612 +        }
613 +        if ((r1p->xr != r2p->xr) | (r1p->yr != r2p->yr)) {
614 +                if (report != REP_QUIET)
615 +                        printf(
616 +                        "%s: %ss '%s' and '%s' are different sizes\n",
617 +                                        progname, class, f1name, f2name);
618 +                return(0);
619 +        }
620 +        return(1);
621 + }
622 +
623   /* Compare two inputs that are known to be RGBE or XYZE images */
624   static int
625   compare_hdr()
# Line 474 | Line 628 | compare_hdr()
628          COLOR   *scan1, *scan2;
629          int     x, y;
630  
631 +        if (report >= REP_VERBOSE) {
632 +                fputs(progname, stdout);
633 +                fputs(": comparing inputs as HDR images\n", stdout);
634 +        }
635          fgetsresolu(&rs1, f1in);
636          fgetsresolu(&rs2, f2in);
637 <        if (rs1.rt != rs2.rt) {
480 <                if (report != REP_QUIET)
481 <                        fprintf(stderr,
482 <                        "%s: Images '%s' and '%s' have different pixel ordering\n",
483 <                                        progname, f1name, f2name);
637 >        if (!check_resolu("HDR image", &rs1, &rs2))
638                  return(0);
485        }
486        if ((rs1.xr != rs2.xr) | (rs1.yr != rs2.yr)) {
487                if (report != REP_QUIET)
488                        fprintf(stderr,
489                        "%s: Images '%s' and '%s' are different sizes\n",
490                                        progname, f1name, f2name);
491                return(0);
492        }
639          scan1 = (COLOR *)malloc(scanlen(&rs1)*sizeof(COLOR));
640          scan2 = (COLOR *)malloc(scanlen(&rs2)*sizeof(COLOR));
641          if (!scan1 | !scan2) {
# Line 500 | Line 646 | compare_hdr()
646                  if ((freadscan(scan1, scanlen(&rs1), f1in) < 0) |
647                                  (freadscan(scan2, scanlen(&rs2), f2in) < 0)) {
648                          if (report != REP_QUIET)
649 <                                fprintf(stderr, "%s: Unexpected end-of-file\n",
649 >                                printf("%s: unexpected end-of-file\n",
650                                                  progname);
651                          free(scan1);
652                          free(scan2);
653                          return(0);
654                  }
655 <                for (x = scanlen(&rs1); x--; ) {
656 <                        if (real_check(colval(scan1[x],RED),
511 <                                                colval(scan2[x],RED)) &
512 <                                        real_check(colval(scan1[x],GRN),
513 <                                                colval(scan2[x],GRN)) &
514 <                                        real_check(colval(scan1[x],BLU),
515 <                                                colval(scan2[x],BLU)))
655 >                for (x = 0; x < scanlen(&rs1); x++) {
656 >                        if (color_check(scan1[x], scan2[x]))
657                                  continue;
658                          if (report != REP_QUIET) {
659 <                                fprintf(stderr,
659 >                                printf(
660                                  "%s: pixels at scanline %d offset %d differ\n",
661                                          progname, y, x);
662                                  if (report >= REP_VERBOSE) {
663 <                                        fprintf(stderr, "%s: (R,G,B)=(%g,%g,%g)\n",
663 >                                        printf("%s: (R,G,B)=(%g,%g,%g)\n",
664                                                  f1name, colval(scan1[x],RED),
665                                                  colval(scan1[x],GRN),
666                                                  colval(scan1[x],BLU));
667 <                                        fprintf(stderr, "%s: (R,G,B)=(%g,%g,%g)\n",
667 >                                        printf("%s: (R,G,B)=(%g,%g,%g)\n",
668                                                  f2name, colval(scan2[x],RED),
669                                                  colval(scan2[x],GRN),
670                                                  colval(scan2[x],BLU));
# Line 539 | Line 680 | compare_hdr()
680          return(good_RMS());                     /* final check of RMS */
681   }
682  
683 < const char      nsuffix[10][3] = {              /* 1st, 2nd, 3rd, etc. */
684 <                        "th","st","nd","rd","th","th","th","th","th","th"
685 <                };
683 > /* Set reference depth based on header variable */
684 > static int
685 > set_refdepth(DEPTHCODEC *dcp, LUTAB *htp)
686 > {
687 >        static char     depthvar[] = DEPTHSTR;
688 >        const char      *drval;
689  
690 +        depthvar[LDEPTHSTR] = '\0';
691 +        drval = (const char *)lu_find(htp, depthvar)->data;
692 +        if (!drval)
693 +                return(0);
694 +        dcp->refdepth = atof(drval);
695 +        if (dcp->refdepth <= 0) {
696 +                if (report != REP_QUIET) {
697 +                        fputs(dcp->inpname, stderr);
698 +                        fputs(": bad reference depth '", stderr);
699 +                        fputs(drval, stderr);
700 +                        fputs("'\n", stderr);
701 +                }
702 +                return(-1);
703 +        }
704 +        return(1);
705 + }
706 +
707 + /* Compare two encoded depth maps */
708 + static int
709 + compare_depth()
710 + {
711 +        long            nread = 0;
712 +        DEPTHCODEC      dc1, dc2;
713 +
714 +        if (report >= REP_VERBOSE) {
715 +                fputs(progname, stdout);
716 +                fputs(": comparing inputs as depth maps\n", stdout);
717 +        }
718 +        set_dc_defaults(&dc1);
719 +        dc1.hdrflags = HF_RESIN;
720 +        dc1.finp = f1in;
721 +        dc1.inpname = f1name;
722 +        set_dc_defaults(&dc2);
723 +        dc2.hdrflags = HF_RESIN;
724 +        dc2.finp = f2in;
725 +        dc2.inpname = f2name;
726 +        if (report != REP_QUIET) {
727 +                dc1.hdrflags |= HF_STDERR;
728 +                dc2.hdrflags |= HF_STDERR;
729 +        }
730 +        if (!process_dc_header(&dc1, 0, NULL))
731 +                return(0);
732 +        if (!process_dc_header(&dc2, 0, NULL))
733 +                return(0);
734 +        if (!check_resolu("Depth map", &dc1.res, &dc2.res))
735 +                return(0);
736 +        if (set_refdepth(&dc1, &hdr1) < 0)
737 +                return(0);
738 +        if (set_refdepth(&dc2, &hdr2) < 0)
739 +                return(0);
740 +        while (nread < dc1.res.xr*dc1.res.yr) {
741 +                double  d1 = decode_depth_next(&dc1);
742 +                double  d2 = decode_depth_next(&dc2);
743 +                if ((d1 < 0) | (d2 < 0)) {
744 +                        if (report != REP_QUIET)
745 +                                printf("%s: unexpected end-of-file\n",
746 +                                                progname);
747 +                        return(0);
748 +                }
749 +                ++nread;
750 +                if (real_check(d1, d2))
751 +                        continue;
752 +                if (report != REP_QUIET)
753 +                        printf("%s: %ld%s depth values differ\n",
754 +                                        progname, nread, num_sfx(nread));
755 +                return(0);
756 +        }
757 +        return(good_RMS());             /* final check of RMS */
758 + }
759 +
760 + /* Compare two encoded normal maps */
761 + static int
762 + compare_norm()
763 + {
764 +        long            nread = 0;
765 +        NORMCODEC       nc1, nc2;
766 +
767 +        if (report >= REP_VERBOSE) {
768 +                fputs(progname, stdout);
769 +                fputs(": comparing inputs as normal maps\n", stdout);
770 +        }
771 +        set_nc_defaults(&nc1);
772 +        nc1.hdrflags = HF_RESIN;
773 +        nc1.finp = f1in;
774 +        nc1.inpname = f1name;
775 +        set_nc_defaults(&nc2);
776 +        nc2.hdrflags = HF_RESIN;
777 +        nc2.finp = f2in;
778 +        nc2.inpname = f2name;
779 +        if (report != REP_QUIET) {
780 +                nc1.hdrflags |= HF_STDERR;
781 +                nc2.hdrflags |= HF_STDERR;
782 +        }
783 +        if (!process_nc_header(&nc1, 0, NULL))
784 +                return(0);
785 +        if (!process_nc_header(&nc2, 0, NULL))
786 +                return(0);
787 +        if (!check_resolu("Normal map", &nc1.res, &nc2.res))
788 +                return(0);
789 +        while (nread < nc1.res.xr*nc1.res.yr) {
790 +                FVECT   nv1, nv2;
791 +                int     rv1 = decode_normal_next(nv1, &nc1);
792 +                int     rv2 = decode_normal_next(nv2, &nc2);
793 +                if ((rv1 < 0) | (rv2 < 0)) {
794 +                        if (report != REP_QUIET)
795 +                                printf("%s: unexpected end-of-file\n",
796 +                                                progname);
797 +                        return(0);
798 +                }
799 +                ++nread;
800 +                if (rv1 == rv2 && (!rv1 || norm_check(nv1, nv2)))
801 +                        continue;
802 +                if (report != REP_QUIET)
803 +                        printf("%s: %ld%s normal vectors differ\n",
804 +                                        progname, nread, num_sfx(nread));
805 +                return(0);
806 +        }
807 +        return(good_RMS());             /* final check of RMS */
808 + }
809 +
810   /* Compare two inputs that are known to be 32-bit floating-point data */
811   static int
812   compare_float()
# Line 550 | Line 814 | compare_float()
814          long    nread = 0;
815          float   f1, f2;
816  
817 +        if (report >= REP_VERBOSE) {
818 +                fputs(progname, stdout);
819 +                fputs(": comparing inputs as 32-bit IEEE floats\n", stdout);
820 +        }
821          while (getbinary(&f1, sizeof(f1), 1, f1in)) {
822                  if (!getbinary(&f2, sizeof(f2), 1, f2in))
823                          goto badeof;
# Line 557 | Line 825 | compare_float()
825                  if (real_check(f1, f2))
826                          continue;
827                  if (report != REP_QUIET)
828 <                        fprintf(stderr, "%s: %ld%s float values differ\n",
829 <                                        progname, nread, nsuffix[nread%10]);
828 >                        printf("%s: %ld%s float values differ\n",
829 >                                        progname, nread, num_sfx(nread));
830                  return(0);
831          }
832          if (!getbinary(&f2, sizeof(f2), 1, f2in))
833                  return(good_RMS());             /* final check of RMS */
834   badeof:
835          if (report != REP_QUIET)
836 <                fprintf(stderr, "%s: Unexpected end-of-file\n", progname);
836 >                printf("%s: unexpected end-of-file\n", progname);
837          return(0);
838   }
839  
# Line 576 | Line 844 | compare_double()
844          long    nread = 0;
845          double  f1, f2;
846  
847 +        if (report >= REP_VERBOSE) {
848 +                fputs(progname, stdout);
849 +                fputs(": comparing inputs as 64-bit IEEE doubles\n", stdout);
850 +        }
851          while (getbinary(&f1, sizeof(f1), 1, f1in)) {
852                  if (!getbinary(&f2, sizeof(f2), 1, f2in))
853                          goto badeof;
# Line 583 | Line 855 | compare_double()
855                  if (real_check(f1, f2))
856                          continue;
857                  if (report != REP_QUIET)
858 <                        fprintf(stderr, "%s: %ld%s float values differ\n",
859 <                                        progname, nread, nsuffix[nread%10]);
858 >                        printf("%s: %ld%s double values differ\n",
859 >                                        progname, nread, num_sfx(nread));
860                  return(0);
861          }
862          if (!getbinary(&f2, sizeof(f2), 1, f2in))
863                  return(good_RMS());             /* final check of RMS */
864   badeof:
865          if (report != REP_QUIET)
866 <                fprintf(stderr, "%s: Unexpected end-of-file\n", progname);
866 >                printf("%s: unexpected end-of-file\n", progname);
867          return(0);
868   }
869  
# Line 638 | Line 910 | main(int argc, char *argv[])
910                  }
911                  break;
912          }
913 <        if (a != argc-2)
913 >        if (a != argc-2)                        /* make sure of two inputs */
914                  usage();
915 <        if (!f1name) f1name = argv[a];
644 <        if (!f2name) f2name = argv[a+1];
645 <
646 <        if (!strcmp(f1name, f2name)) {          /* inputs are same? */
915 >        if (!strcmp(argv[a], argv[a+1])) {      /* inputs are same? */
916                  if (report >= REP_WARN)
917 <                        fprintf(stderr, "%s: warning - identical inputs given\n",
917 >                        printf("%s: warning - identical inputs given\n",
918                                          progname);
919                  return(0);
920          }
921 +        if (!f1name) f1name = argv[a];
922 +        if (!f2name) f2name = argv[a+1];
923                                                  /* open inputs */
924          SET_FILE_BINARY(stdin);                 /* in case we're using it */
925          if (!f1in && !(f1in = fopen(f1name, "rb"))) {
926                  fprintf(stderr, "%s: cannot open for reading\n", f1name);
927 <                return(1);
927 >                return(2);
928          }
929          if (!strcmp(f2name, "-")) {
930                  f2in = stdin;
931                  f2name = stdin_name;
932          } else if (!(f2in = fopen(f2name, "rb"))) {
933                  fprintf(stderr, "%s: cannot open for reading\n", f2name);
934 <                return(1);
934 >                return(2);
935          }
936                                                  /* load headers */
937          if ((typ1 = identify_type(f1name, f1in, &hdr1)) < 0)
938 <                return(1);
938 >                return(2);
939          if ((typ2 = identify_type(f2name, f2in, &hdr2)) < 0)
940 <                return(1);
940 >                return(2);
941          if (typ1 != typ2) {
942                  if (report != REP_QUIET)
943 <                        fprintf(stderr, "%s: '%s' is %s and '%s' is %s\n",
943 >                        printf("%s: '%s' is %s and '%s' is %s\n",
944                                          progname, f1name, file_type[typ1],
945                                          f2name, file_type[typ2]);
946                  return(1);
947          }
948          ign_header |= !has_header(typ1);        /* check headers if indicated */
949 <        if (!ign_header && !headers_match(&hdr1, &hdr2))
949 >        if (!ign_header && !headers_match())
950                  return(1);
680        lu_done(&hdr1); lu_done(&hdr2);
951          if (!ign_header & (report >= REP_WARN)) {
682                if (typ1 == TYP_UNKNOWN)
683                        fprintf(stderr, "%s: warning - unrecognized format, comparing as binary\n",
684                                        progname);
952                  if (lin1cnt != lin2cnt)
953 <                        fprintf(stderr, "%s: warning - headers are different lengths\n",
953 >                        printf("%s: warning - headers are different lengths\n",
954                                          progname);
955 +                if (typ1 == TYP_UNKNOWN)
956 +                        printf("%s: warning - unrecognized format\n",
957 +                                        progname);
958          }
959          if (report >= REP_VERBOSE)
960 <                fprintf(stderr, "%s: input file type is %s\n",
960 >                printf("%s: input file type is %s\n",
961                                  progname, file_type[typ1]);
962  
963          switch (typ1) {                         /* compare based on type */
# Line 695 | Line 965 | main(int argc, char *argv[])
965          case TYP_TMESH:
966          case TYP_OCTREE:
967          case TYP_RBFMESH:
968 +        case TYP_ID8:
969 +        case TYP_ID16:
970 +        case TYP_ID24:
971          case TYP_UNKNOWN:
972                  return( !compare_binary() );
973          case TYP_TEXT:
# Line 703 | Line 976 | main(int argc, char *argv[])
976          case TYP_RGBE:
977          case TYP_XYZE:
978                  return( !compare_hdr() );
979 +        case TYP_DEPTH:
980 +                return( !compare_depth() );
981 +        case TYP_NORM:
982 +                return( !compare_norm() );
983          case TYP_FLOAT:
984                  return( !compare_float() );
985          case TYP_DOUBLE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines