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.3 by greg, Mon Oct 15 18:31:15 2018 UTC vs.
Revision 2.22 by greg, Sat Aug 24 02:22:02 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 + int             f1swap=0, f2swap=0;
103  
104                                  /* running real differences */
105   double  diff2sum = 0;
106 < int     nsum = 0;
106 > long    nsum = 0;
107  
108   /* Report usage and exit */
109   static void
# Line 85 | Line 111 | usage()
111   {
112          fputs("Usage: ", stderr);
113          fputs(progname, stderr);
114 <        fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] file1 file2\n",
114 >        fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n",
115                          stderr);
116 <        exit(1);
116 >        exit(2);
117   }
118  
119 + /* Read a text line, increasing buffer size as necessary */
120 + static int
121 + read_line(LINEBUF *bp, FILE *fp)
122 + {
123 +        static int      doneWarn = 0;
124 +
125 +        bp->len = 0;
126 +        if (!bp->str) {
127 +                bp->str = (char *)malloc(bp->siz = 512);
128 +                if (!bp->str)
129 +                        goto memerr;
130 +        }
131 +        while (fgets(bp->str + bp->len, bp->siz - bp->len, fp)) {
132 +                bp->len += strlen(bp->str + bp->len);
133 +                if (bp->str[bp->len-1] == '\n')
134 +                        break;          /* found EOL */
135 +                if (bp->len < bp->siz - 4)
136 +                        continue;       /* at EOF? */
137 +                if (bp->siz >= MAXBUF) {
138 +                        if ((report >= REP_WARN) & !doneWarn) {
139 +                                fprintf(stderr,
140 +                        "%s: warning - input line(s) past %ld MByte limit\n",
141 +                                        progname, MAXBUF>>20);
142 +                                doneWarn++;
143 +                        }
144 +                        break;          /* return MAXBUF partial line */
145 +                }
146 +                if ((bp->siz += bp->siz/2) > MAXBUF)
147 +                        bp->siz = MAXBUF;
148 +                bp->str = (char *)realloc(bp->str, bp->siz);
149 +                if (!bp->str)
150 +                        goto memerr;
151 +        }
152 +        return(bp->len);
153 + memerr:
154 +        fprintf(stderr,
155 +                "%s: out of memory in read_line() allocating %d byte buffer\n",
156 +                        progname, bp->siz);
157 +        exit(2);
158 + }
159 +
160 + /* Free line buffer */
161 + static void
162 + free_line(LINEBUF *bp)
163 + {
164 +        if (bp->str) free(bp->str);
165 +        init_line(bp);
166 + }
167 +
168   /* Get type ID from name (or 0 if not found) */
169   static int
170   xlate_type(const char *nm)
# Line 117 | Line 192 | real_check(double r1, double r2)
192          }
193          if (max_lim >= 0 && diff2 > max_lim*max_lim) {
194                  if (report != REP_QUIET)
195 <                        fprintf(stderr,
196 <                        "%s: %sdifference between %.8g and %.8g exceeds epsilon\n",
195 >                        printf(
196 >                        "%s: %sdifference between %.8g and %.8g exceeds epsilon of %.8g\n",
197                                          progname,
198                                          (rel_min > 0) ? "relative " : "",
199 <                                        r1, r2);
199 >                                        r1, r2, max_lim);
200                  return(0);
201          }
202          diff2sum += diff2;
# Line 129 | Line 204 | real_check(double r1, double r2)
204          return(1);
205   }
206  
207 + /* Compare two color values for equivalence */
208 + static int
209 + color_check(COLOR c1, COLOR c2)
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.)))
215 +                return(0);
216 +
217 +        p = (colval(c1,GRN) > colval(c1,RED)) ? GRN : RED;
218 +        if (colval(c1,BLU) > colval(c1,p)) p = BLU;
219 +        
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)
# Line 210 | Line 326 | setheadvar(char *val, void *p)
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++;
# Line 223 | Line 347 | setheadvar(char *val, void *p)
347                  val++;
348          if (!*val)              /* nothing set? */
349                  return(0);
226        vln = strlen(val);      /* eliminate space and newline at end */
227        while (--vln > 0 && isspace(val[vln]))
228                ;
229        val[++vln] = '\0';
350                                  /* check if key to ignore */
351          for (n = 0; hdr_ignkey[n]; n++)
352                  if (!strcmp(key, hdr_ignkey[n]))
353                          return(0);
354 +        vln = strlen(val);      /* eliminate space and newline at end */
355 +        while (isspace(val[--vln]))
356 +                ;
357 +        val[++vln] = '\0';
358          if (!(tep = lu_find(htp, key)))
359 <                return(-1);
359 >                return(-1);     /* memory allocation error */
360          if (!tep->key)
361                  tep->key = strcpy(malloc(kln+1), key);
362          if (tep->data)
# Line 248 | Line 372 | match_val(const LUENT *ep1, void *p2)
372          const LUENT     *ep2 = lu_find((LUTAB *)p2, ep1->key);
373          if (!ep2 || !ep2->data) {
374                  if (report != REP_QUIET)
375 <                        fprintf(stderr, "%s: Variable '%s' missing in '%s'\n",
375 >                        printf("%s: variable '%s' missing in '%s'\n",
376                                          progname, ep1->key, f2name);
377                  return(-1);
378          }
379          if (!equiv_string((char *)ep1->data, (char *)ep2->data)) {
380 <                if (report != REP_QUIET)
381 <                        fprintf(stderr, "%s: Header variables '%s' have different values\n",
380 >                if (report != REP_QUIET) {
381 >                        printf("%s: header variable '%s' has different values\n",
382                                          progname, ep1->key);
383 +                        if (report >= REP_VERBOSE) {
384 +                                printf("%s: %s=%s\n", f1name,
385 +                                                ep1->key, (char *)ep1->data);
386 +                                printf("%s: %s=%s\n", f2name,
387 +                                                ep2->key, (char *)ep2->data);
388 +                        }
389 +                }
390                  return(-1);
391          }
392          return(1);              /* good match */
# Line 263 | Line 394 | match_val(const LUENT *ep1, void *p2)
394  
395   /* Compare two sets of header variables */
396   static int
397 < headers_match(LUTAB *hp1, LUTAB *hp2)
397 > headers_match()
398   {
399 <        int     ne = lu_doall(hp1, match_val, hp2);
399 >        int     ne = lu_doall(&hdr1, match_val, &hdr2);
400          if (ne < 0)
401                  return(0);      /* something didn't match! */
402 <        ne = lu_doall(hp2, NULL, NULL) - ne;
403 <        if (ne) {
404 <                if (report != REP_QUIET)
274 <                        fprintf(stderr, "%s: '%s' has %d extra header variable(s)\n",
402 >                                /* non-fatal if second header has extra */
403 >        if (report >= REP_WARN && (ne = lu_doall(&hdr2, NULL, NULL) - ne))
404 >                printf("%s: warning - '%s' has %d extra header setting(s)\n",
405                                          progname, f2name, ne);
276                return(0);
277        }
406          return(1);              /* good match */
407   }
408  
# Line 286 | Line 414 | input_is_binary(FILE *fin)
414          int     c = 0;
415  
416          while ((c = getc(fin)) != EOF) {
417 +                ++n;
418                  if (!c | (c > 127))
419                          break;                  /* non-ascii character */
420 <                if (++n >= 10240)
420 >                if (n >= 10240)
421                          break;                  /* enough to be confident */
422          }
423          if (!n)
# Line 320 | Line 449 | identify_type(const char *name, FILE *fin, LUTAB *htp)
449                          goto badeof;
450                  adv_linecnt(htp);               /* for #?ID string */
451                  if (report >= REP_WARN && strncmp(sbuf, "RADIANCE", 8)) {
452 <                        fputs(name, stderr);
453 <                        fputs(": warning - unexpected header ID: ", stderr);
454 <                        fputs(sbuf, stderr);
452 >                        fputs(name, stdout);
453 >                        fputs(": warning - unexpected header ID: ", stdout);
454 >                        fputs(sbuf, stdout);
455                  }
456                  if (getheader(fin, setheadvar, htp) < 0) {
457                          fputs(name, stderr);
458 <                        fputs(": Unknown error reading header\n", stderr);
458 >                        fputs(": unknown error reading header\n", stderr);
459                          return(-1);
460                  }
461                  adv_linecnt(htp);               /* for trailing emtpy line */
# Line 344 | Line 473 | identify_type(const char *name, FILE *fin, LUTAB *htp)
473          return(TYP_TEXT);
474   badeof:
475          if (report != REP_QUIET) {
476 <                fputs(name, stderr);
477 <                fputs(": Unexpected end-of-file\n", stderr);
476 >                fputs(name, stdout);
477 >                fputs(": unexpected end-of-file\n", stdout);
478          }
479          return(-1);
480   }
# Line 358 | Line 487 | good_RMS()
487                  return(1);
488          if (diff2sum/(double)nsum > rms_lim*rms_lim) {
489                  if (report != REP_QUIET)
490 <                        fprintf(stderr,
491 <        "%s: %sRMS difference between '%s' and '%s' of %.5g exceeds limit\n",
490 >                        printf(
491 >        "%s: %sRMS difference between '%s' and '%s' of %.5g exceeds limit of %.5g\n",
492                                          progname,
493                                          (rel_min > 0) ? "relative " : "",
494                                          f1name, f2name,
495 <                                        sqrt(diff2sum/(double)nsum));
495 >                                        sqrt(diff2sum/(double)nsum), rms_lim);
496                  return(0);
497          }
498          if (report >= REP_VERBOSE)
499 <                fprintf(stderr,
371 <                        "%s: %sRMS difference of reals in '%s' and '%s' is %.5g\n",
499 >                printf("%s: %sRMS difference of reals in '%s' and '%s' is %.5g\n",
500                                  progname, (rel_min > 0) ? "relative " : "",
501                                  f1name, f2name, sqrt(diff2sum/(double)nsum));
502          return(1);
# Line 378 | Line 506 | good_RMS()
506   static int
507   compare_binary()
508   {
509 +        int     c1=0, c2=0;
510 +
511          if (report >= REP_VERBOSE) {
512 <                fputs(progname, stderr);
513 <                fputs(": comparing inputs as binary\n", stderr);
512 >                fputs(progname, stdout);
513 >                fputs(": comparing inputs as binary\n", stdout);
514          }
515          for ( ; ; ) {                           /* exact byte matching */
516 <                int     c1 = getc(f1in);
517 <                int     c2 = getc(f2in);
516 >                c1 = getc(f1in);
517 >                c2 = getc(f2in);
518                  if (c1 == EOF) {
519                          if (c2 == EOF)
520                                  return(1);      /* success! */
521                          if (report != REP_QUIET) {
522 <                                fputs(f1name, stderr);
523 <                                fputs(": Unexpected end-of-file\n", stderr);
522 >                                fputs(f1name, stdout);
523 >                                fputs(": unexpected end-of-file\n", stdout);
524                          }
525                          return(0);
526                  }
527                  if (c2 == EOF) {
528                          if (report != REP_QUIET) {
529 <                                fputs(f2name, stderr);
530 <                                fputs(": Unexpected end-of-file\n", stderr);
529 >                                fputs(f2name, stdout);
530 >                                fputs(": unexpected end-of-file\n", stdout);
531                          }
532                          return(0);
533                  }
# Line 406 | Line 536 | compare_binary()
536          }
537          if (report == REP_QUIET)
538                  return(0);
539 <        fprintf(stderr, "%s: binary files '%s' and '%s' differ at offset %ld|%ld\n",
539 >        printf("%s: binary files '%s' and '%s' differ at byte offset %ld|%ld\n",
540                          progname, f1name, f2name, ftell(f1in), ftell(f2in));
541 +        if (report >= REP_VERBOSE)
542 +                printf("%s: byte in '%s' is 0x%X, byte in '%s' is 0x%X\n",
543 +                                progname, f1name, c1, f2name, c2);
544          return(0);
545   }
546  
# Line 415 | Line 548 | compare_binary()
548   static int
549   compare_text()
550   {
551 <        char    l1buf[4096], l2buf[4096];
551 >        LINEBUF l1buf, l2buf;
552  
553          if (report >= REP_VERBOSE) {
554 <                fputs(progname, stderr);
555 <                fputs(": comparing inputs as ASCII text\n", stderr);
554 >                fputs(progname, stdout);
555 >                fputs(": comparing inputs as ASCII text\n", stdout);
556          }
557 <                                                /* compare a line at a time */
558 <        while (fgets(l1buf, sizeof(l1buf), f1in)) {
557 >        init_line(&l1buf); init_line(&l2buf);   /* compare a line at a time */
558 >        while (read_line(&l1buf, f1in)) {
559                  lin1cnt++;
560 <                if (!*sskip2(l1buf,0))
560 >                if (!*sskip2(l1buf.str,0))
561                          continue;               /* ignore empty lines */
562 <                while (fgets(l2buf, sizeof(l2buf), f2in)) {
562 >
563 >                while (read_line(&l2buf, f2in)) {
564                          lin2cnt++;
565 <                        if (*sskip2(l2buf,0))
565 >                        if (*sskip2(l2buf.str,0))
566                                  break;          /* found other non-empty line */
567                  }
568 <                if (feof(f2in)) {
568 >                if (!l2buf.len) {               /* input 2 EOF? */
569                          if (report != REP_QUIET) {
570 <                                fputs(f2name, stderr);
571 <                                fputs(": Unexpected end-of-file\n", stderr);
570 >                                fputs(f2name, stdout);
571 >                                fputs(": unexpected end-of-file\n", stdout);
572                          }
573 +                        free_line(&l1buf); free_line(&l2buf);
574                          return(0);
575                  }
576                                                  /* compare non-empty lines */
577 <                if (!equiv_string(l1buf, l2buf)) {
577 >                if (!equiv_string(l1buf.str, l2buf.str)) {
578                          if (report != REP_QUIET) {
579 <                                fprintf(stderr, "%s: inputs '%s' and '%s' differ at line %d|%d\n",
579 >                                printf("%s: inputs '%s' and '%s' differ at line %d|%d\n",
580                                                  progname, f1name, f2name,
581                                                  lin1cnt, lin2cnt);
582 <                                if (report >= REP_VERBOSE) {
583 <                                        fputs("------------- Mismatch -------------\n", stderr);
584 <                                        fprintf(stderr, "%s(%d):\t%s", f1name,
585 <                                                        lin1cnt, l1buf);
586 <                                        fprintf(stderr, "%s(%d):\t%s", f2name,
587 <                                                        lin2cnt, l2buf);
582 >                                if ( report >= REP_VERBOSE &&
583 >                                                (l1buf.len < 256) &
584 >                                                (l2buf.len < 256) ) {
585 >                                        fputs("------------- Mismatch -------------\n", stdout);
586 >                                        printf("%s@%d:\t%s", f1name,
587 >                                                        lin1cnt, l1buf.str);
588 >                                        printf("%s@%d:\t%s", f2name,
589 >                                                        lin2cnt, l2buf.str);
590                                  }
591                          }
592 +                        free_line(&l1buf); free_line(&l2buf);
593                          return(0);
594                  }
595          }
596 <                                                /* check for EOF on input 2 */
597 <        while (fgets(l2buf, sizeof(l2buf), f2in)) {
598 <                if (!*sskip2(l2buf,0))
596 >        free_line(&l1buf);                      /* check for EOF on input 2 */
597 >        while (read_line(&l2buf, f2in)) {
598 >                if (!*sskip2(l2buf.str,0))
599                          continue;
600                  if (report != REP_QUIET) {
601 <                        fputs(f1name, stderr);
602 <                        fputs(": Unexpected end-of-file\n", stderr);
601 >                        fputs(f1name, stdout);
602 >                        fputs(": unexpected end-of-file\n", stdout);
603                  }
604 +                free_line(&l2buf);
605                  return(0);
606          }
607 +        free_line(&l2buf);
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()
# Line 476 | Line 637 | compare_hdr()
637          COLOR   *scan1, *scan2;
638          int     x, y;
639  
640 +        if (report >= REP_VERBOSE) {
641 +                fputs(progname, stdout);
642 +                fputs(": comparing inputs as HDR images\n", stdout);
643 +        }
644          fgetsresolu(&rs1, f1in);
645          fgetsresolu(&rs2, f2in);
646 <        if (rs1.rt != rs2.rt) {
482 <                if (report != REP_QUIET)
483 <                        fprintf(stderr,
484 <                        "%s: Images '%s' and '%s' have different pixel ordering\n",
485 <                                        progname, f1name, f2name);
646 >        if (!check_resolu("HDR image", &rs1, &rs2))
647                  return(0);
487        }
488        if ((rs1.xr != rs2.xr) | (rs1.yr != rs2.yr)) {
489                if (report != REP_QUIET)
490                        fprintf(stderr,
491                        "%s: Images '%s' and '%s' are different sizes\n",
492                                        progname, f1name, f2name);
493                return(0);
494        }
648          scan1 = (COLOR *)malloc(scanlen(&rs1)*sizeof(COLOR));
649          scan2 = (COLOR *)malloc(scanlen(&rs2)*sizeof(COLOR));
650          if (!scan1 | !scan2) {
# Line 502 | Line 655 | compare_hdr()
655                  if ((freadscan(scan1, scanlen(&rs1), f1in) < 0) |
656                                  (freadscan(scan2, scanlen(&rs2), f2in) < 0)) {
657                          if (report != REP_QUIET)
658 <                                fprintf(stderr, "%s: Unexpected end-of-file\n",
658 >                                printf("%s: unexpected end-of-file\n",
659                                                  progname);
660                          free(scan1);
661                          free(scan2);
662                          return(0);
663                  }
664 <                for (x = scanlen(&rs1); x--; ) {
665 <                        if (real_check(colval(scan1[x],RED),
513 <                                                colval(scan2[x],RED)) &
514 <                                        real_check(colval(scan1[x],GRN),
515 <                                                colval(scan2[x],GRN)) &
516 <                                        real_check(colval(scan1[x],BLU),
517 <                                                colval(scan2[x],BLU)))
664 >                for (x = 0; x < scanlen(&rs1); x++) {
665 >                        if (color_check(scan1[x], scan2[x]))
666                                  continue;
667                          if (report != REP_QUIET) {
668 <                                fprintf(stderr,
668 >                                printf(
669                                  "%s: pixels at scanline %d offset %d differ\n",
670                                          progname, y, x);
671                                  if (report >= REP_VERBOSE) {
672 <                                        fprintf(stderr, "%s: (R,G,B)=(%g,%g,%g)\n",
672 >                                        printf("%s: (R,G,B)=(%g,%g,%g)\n",
673                                                  f1name, colval(scan1[x],RED),
674                                                  colval(scan1[x],GRN),
675                                                  colval(scan1[x],BLU));
676 <                                        fprintf(stderr, "%s: (R,G,B)=(%g,%g,%g)\n",
676 >                                        printf("%s: (R,G,B)=(%g,%g,%g)\n",
677                                                  f2name, colval(scan2[x],RED),
678                                                  colval(scan2[x],GRN),
679                                                  colval(scan2[x],BLU));
# Line 541 | Line 689 | compare_hdr()
689          return(good_RMS());                     /* final check of RMS */
690   }
691  
692 < const char      nsuffix[10][3] = {              /* 1st, 2nd, 3rd, etc. */
693 <                        "th","st","nd","rd","th","th","th","th","th","th"
694 <                };
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()
# Line 552 | Line 823 | compare_float()
823          long    nread = 0;
824          float   f1, f2;
825  
826 +        if (report >= REP_VERBOSE) {
827 +                fputs(progname, stdout);
828 +                fputs(": comparing inputs as 32-bit IEEE floats\n", stdout);
829 +        }
830          while (getbinary(&f1, sizeof(f1), 1, f1in)) {
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)
839 <                        fprintf(stderr, "%s: %ld%s float values differ\n",
840 <                                        progname, nread, nsuffix[nread%10]);
839 >                        printf("%s: %ld%s float values differ\n",
840 >                                        progname, nread, num_sfx(nread));
841                  return(0);
842          }
843          if (!getbinary(&f2, sizeof(f2), 1, f2in))
844                  return(good_RMS());             /* final check of RMS */
845   badeof:
846          if (report != REP_QUIET)
847 <                fprintf(stderr, "%s: Unexpected end-of-file\n", progname);
847 >                printf("%s: unexpected end-of-file\n", progname);
848          return(0);
849   }
850  
# Line 578 | Line 855 | compare_double()
855          long    nread = 0;
856          double  f1, f2;
857  
858 +        if (report >= REP_VERBOSE) {
859 +                fputs(progname, stdout);
860 +                fputs(": comparing inputs as 64-bit IEEE doubles\n", stdout);
861 +        }
862          while (getbinary(&f1, sizeof(f1), 1, f1in)) {
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)
871 <                        fprintf(stderr, "%s: %ld%s float values differ\n",
872 <                                        progname, nread, nsuffix[nread%10]);
871 >                        printf("%s: %ld%s double values differ\n",
872 >                                        progname, nread, num_sfx(nread));
873                  return(0);
874          }
875          if (!getbinary(&f2, sizeof(f2), 1, f2in))
876                  return(good_RMS());             /* final check of RMS */
877   badeof:
878          if (report != REP_QUIET)
879 <                fprintf(stderr, "%s: Unexpected end-of-file\n", progname);
879 >                printf("%s: unexpected end-of-file\n", progname);
880          return(0);
881   }
882  
# Line 640 | Line 923 | main(int argc, char *argv[])
923                  }
924                  break;
925          }
926 <        if (a != argc-2)
926 >        if (a != argc-2)                        /* make sure of two inputs */
927                  usage();
928 <        if (!f1name) f1name = argv[a];
646 <        if (!f2name) f2name = argv[a+1];
647 <
648 <        if (!strcmp(f1name, f2name)) {          /* inputs are same? */
928 >        if (!strcmp(argv[a], argv[a+1])) {      /* inputs are same? */
929                  if (report >= REP_WARN)
930 <                        fprintf(stderr, "%s: warning - identical inputs given\n",
930 >                        printf("%s: warning - identical inputs given\n",
931                                          progname);
932                  return(0);
933          }
934 +        if (!f1name) f1name = argv[a];
935 +        if (!f2name) f2name = argv[a+1];
936                                                  /* open inputs */
937          SET_FILE_BINARY(stdin);                 /* in case we're using it */
938          if (!f1in && !(f1in = fopen(f1name, "rb"))) {
939                  fprintf(stderr, "%s: cannot open for reading\n", f1name);
940 <                return(1);
940 >                return(2);
941          }
942          if (!strcmp(f2name, "-")) {
943                  f2in = stdin;
944                  f2name = stdin_name;
945          } else if (!(f2in = fopen(f2name, "rb"))) {
946                  fprintf(stderr, "%s: cannot open for reading\n", f2name);
947 <                return(1);
947 >                return(2);
948          }
949                                                  /* load headers */
950          if ((typ1 = identify_type(f1name, f1in, &hdr1)) < 0)
951 <                return(1);
951 >                return(2);
952          if ((typ2 = identify_type(f2name, f2in, &hdr2)) < 0)
953 <                return(1);
953 >                return(2);
954          if (typ1 != typ2) {
955                  if (report != REP_QUIET)
956 <                        fprintf(stderr, "%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);
960          }
961          ign_header |= !has_header(typ1);        /* check headers if indicated */
962 <        if (!ign_header && !headers_match(&hdr1, &hdr2))
962 >        if (!ign_header && !headers_match())
963                  return(1);
682        lu_done(&hdr1); lu_done(&hdr2);
964          if (!ign_header & (report >= REP_WARN)) {
684                if (typ1 == TYP_UNKNOWN)
685                        fprintf(stderr, "%s: warning - unrecognized format, comparing as binary\n",
686                                        progname);
965                  if (lin1cnt != lin2cnt)
966 <                        fprintf(stderr, "%s: warning - headers are different lengths\n",
966 >                        printf("%s: warning - headers are different lengths\n",
967                                          progname);
968 +                if (typ1 == TYP_UNKNOWN)
969 +                        printf("%s: warning - unrecognized format\n",
970 +                                        progname);
971          }
972 <        if (report >= REP_VERBOSE)
973 <                fprintf(stderr, "%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:
# Line 705 | Line 996 | main(int argc, char *argv[])
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:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines