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.23 by greg, Tue Jun 30 01:17:54 2020 UTC vs.
Revision 2.35 by greg, Mon Dec 9 00:29:30 2024 UTC

# Line 27 | 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 35 | 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 47 | Line 51 | const char     *file_type[] = {
51                          "ascii",
52                          COLRFMT,
53                          CIEFMT,
54 +                        SPECFMT,
55                          DEPTH16FMT,
56                          NORMAL32FMT,
57                          "float",
# Line 61 | Line 66 | const char     *file_type[] = {
66                          NULL    /* terminator */
67                  };
68                                  /* keep consistent with above */
69 < enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE,
69 > enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE, TYP_SPEC,
70                  TYP_DEPTH, TYP_NORM, TYP_FLOAT, TYP_DOUBLE,
71                  TYP_RBFMESH, TYP_OCTREE, TYP_TMESH,
72                  TYP_ID8, TYP_ID16, TYP_ID24, TYP_BINARY};
# Line 74 | Line 79 | const char     *hdr_ignkey[] = {
79                          "CAPDATE",
80                          "GMT",
81                          "FRAME",
82 +                        "TILED",
83                          NULL    /* terminator */
84                  };
85                                  /* header variable settings */
# Line 111 | Line 117 | usage()
117   {
118          fputs("Usage: ", stderr);
119          fputs(progname, stderr);
120 <        fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n",
120 >        fputs(" [-h][-c#][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n",
121                          stderr);
122          exit(2);
123   }
# Line 130 | Line 136 | read_line(LINEBUF *bp, FILE *fp)
136          }
137          while (fgets(bp->str + bp->len, bp->siz - bp->len, fp)) {
138                  bp->len += strlen(bp->str + bp->len);
139 <                if (bp->str[bp->len-1] == '\n')
139 >                if (bp->str[bp->len-1] == '\n') {
140 >                        if (bp->len > 1 && bp->str[bp->len-2] == '\r') {
141 >                                bp->str[--bp->len] = '\0';
142 >                                bp->str[bp->len-1] = '\n';
143 >                        }
144 >                        if (escape_newlines && bp->len > 1 &&
145 >                                        bp->str[bp->len-2] == '\\') {
146 >                                bp->str[--bp->len] = '\0';
147 >                                bp->str[bp->len-1] = ' ';
148 >                                continue;
149 >                        }
150                          break;          /* found EOL */
151 +                }
152                  if (bp->len < bp->siz - 4)
153                          continue;       /* at EOF? */
154                  if (bp->siz >= MAXBUF) {
# Line 149 | Line 166 | read_line(LINEBUF *bp, FILE *fp)
166                  if (!bp->str)
167                          goto memerr;
168          }
169 +        if (comment_c) {                /* elide comment? */
170 +                char    *cp = sskip2(bp->str,0);
171 +                if (*cp == comment_c) {
172 +                        *cp++ = '\n';
173 +                        *cp = '\0';
174 +                        bp->len = cp - bp->str;
175 +                }
176 +        }
177          return(bp->len);
178   memerr:
179          fprintf(stderr,
# Line 187 | Line 212 | real_check(double r1, double r2)
212  
213          if (rel_min > 0) {      /* doing relative differences? */
214                  double  av2 = .25*(r1*r1 + 2.*fabs(r1*r2) + r2*r2);
215 <                if (av2 > rel_min*rel_min)
216 <                        diff2 /= av2;
215 >                if (av2 < rel_min*rel_min)
216 >                        av2 = rel_min*rel_min;
217 >                diff2 /= av2;
218          }
219          if (max_lim >= 0 && diff2 > max_lim*max_lim) {
220                  if (report != REP_QUIET)
# Line 220 | Line 246 | color_check(COLOR c1, COLOR c2)
246          return(real_check(colval(c1,p), colval(c2,p)));
247   }
248  
249 + #if 1
250 + /* Compare two color spectra for equivalence */
251 + static int
252 + spec_check(COLORV *sc1, COLORV *sc2)
253 + {
254 +        int     p, k;
255 +
256 +        if (!real_check(scolor_mean(sc1), scolor_mean(sc2)))
257 +                return(0);
258 +
259 +        p = 0;                          /* find max. component */
260 +        for (k = NCSAMP; --k; )
261 +                if (sc1[k] > sc1[p])
262 +                        p = k;
263 +
264 +        return(real_check(sc1[p], sc2[p]));
265 + }
266 + #else
267 + /* Compare two color spectra for equivalence */
268 + static int
269 + spec_check(COLORV *sc1, COLORV *sc2)
270 + {
271 +        COLOR   c1, c2;
272 +        int     p;
273 +
274 +        if (!real_check(scolor_mean(sc1), scolor_mean(sc2)))
275 +                return(0);
276 +                                        /* do comparisons in RGB space */
277 +        scolor_rgb(c1, sc1);
278 +        scolor_rgb(c2, sc2);
279 +
280 +        p = (colval(c1,GRN) > colval(c1,RED)) ? GRN : RED;
281 +        if (colval(c1,BLU) > colval(c1,p)) p = BLU;
282 +
283 +        return(real_check(colval(c1,p), colval(c2,p)));
284 + }
285 + #endif
286 +
287   /* Compare two normal directions for equivalence */
288   static int
289   norm_check(FVECT nv1, FVECT nv2)
# Line 317 | Line 381 | equiv_string(char *s1, char *s2)
381   static int
382   setheadvar(char *val, void *p)
383   {
384 +        char    newval[128];
385          LUTAB   *htp = (LUTAB *)p;
386          LUENT   *tep;
387          char    *key;
# Line 359 | Line 424 | setheadvar(char *val, void *p)
424                  return(-1);     /* memory allocation error */
425          if (!tep->key)
426                  tep->key = strcpy(malloc(kln+1), key);
427 <        if (tep->data)
427 >        if (tep->data) {        /* check for special cases */
428 >                if (!strcmp(key, "EXPOSURE")) {
429 >                        sprintf(newval, "%.6e", atof(tep->data)*atof(val));
430 >                        vln = strlen(val = newval);
431 >                }
432                  free(tep->data);
433 +        }
434          tep->data = strcpy(malloc(vln+1), val);
435          return(1);
436   }
# Line 469 | Line 539 | identify_type(const char *name, FILE *fin, LUTAB *htp)
539          }
540          if (c)
541                  return(TYP_BINARY);
472        SET_FILE_TEXT(fin);                     /* originally set to binary */
542          return(TYP_TEXT);
543   badeof:
544          if (report != REP_QUIET) {
# Line 552 | Line 621 | compare_text()
621  
622          if (report >= REP_VERBOSE) {
623                  fputs(progname, stdout);
624 <                fputs(": comparing inputs as ASCII text\n", stdout);
624 >                fputs(": comparing inputs as ASCII text", stdout);
625 >                if (escape_newlines)
626 >                        fputs(", allowing escaped newlines", stdout);
627 >                if (comment_c) {
628 >                        fputs(", ignoring comments starting with '", stdout);
629 >                        fputc(comment_c, stdout);
630 >                        fputc('\'', stdout);
631 >                }
632 >                fputc('\n', stdout);
633          }
634 +        SET_FILE_TEXT(f1in);                    /* originally set to binary */
635 +        SET_FILE_TEXT(f2in);
636          init_line(&l1buf); init_line(&l2buf);   /* compare a line at a time */
637          while (read_line(&l1buf, f1in)) {
638                  lin1cnt++;
# Line 576 | Line 655 | compare_text()
655                                                  /* compare non-empty lines */
656                  if (!equiv_string(l1buf.str, l2buf.str)) {
657                          if (report != REP_QUIET) {
658 <                                printf("%s: inputs '%s' and '%s' differ at line %d|%d\n",
659 <                                                progname, f1name, f2name,
660 <                                                lin1cnt, lin2cnt);
658 >                                printf("%s: inputs '%s' and '%s' differ at line %d",
659 >                                                progname, f1name, f2name, lin1cnt);
660 >                                if (lin1cnt != lin2cnt)
661 >                                        printf("|%d\n", lin2cnt);
662 >                                else
663 >                                        putchar('\n');
664                                  if ( report >= REP_VERBOSE &&
665                                                  (l1buf.len < 256) &
666                                                  (l2buf.len < 256) ) {
# Line 608 | Line 690 | compare_text()
690          return(good_RMS());                     /* final check for reals */
691   }
692  
693 + /* Set resolution based on NROWS, NCOLS in header */
694 + static int
695 + set_resolu(RESOLU *rs, LUTAB *htp)
696 + {
697 +        const char      *val;
698 +
699 +        rs->rt = PIXSTANDARD;
700 +        val = (const char *)lu_find(htp, "NROWS")->data;
701 +        if (!val) return(0);
702 +        rs->yr = atoi(val);
703 +        if (rs->yr <= 0) return(-1);
704 +        val = (const char *)lu_find(htp, "NCOLS")->data;
705 +        if (!val) return(0);
706 +        rs->xr = atoi(val);
707 +        if (rs->xr <= 0) return(-1);
708 +        return(1);
709 + }
710 +
711   /* Check image/map resolutions */
712   static int
713   check_resolu(const char *class, RESOLU *r1p, RESOLU *r2p)
# Line 665 | Line 765 | compare_hdr()
765                          if (color_check(scan1[x], scan2[x]))
766                                  continue;
767                          if (report != REP_QUIET) {
768 <                                printf(
669 <                                "%s: pixels at scanline %d offset %d differ\n",
768 >                                printf("%s: pixels at scanline %d offset %d differ\n",
769                                          progname, y, x);
770                                  if (report >= REP_VERBOSE) {
771                                          printf("%s: (R,G,B)=(%g,%g,%g)\n",
# Line 689 | Line 788 | compare_hdr()
788          return(good_RMS());                     /* final check of RMS */
789   }
790  
791 + /* Compare two inputs that are known to be spectral images */
792 + static int
793 + compare_spec()
794 + {
795 +        static char     NCstr[] = NCOMPSTR;
796 +        RESOLU          rs1, rs2;
797 +        COLORV          *scan1, *scan2;
798 +        const char      *val;
799 +        int             x, y;
800 +
801 +        if (report >= REP_VERBOSE) {
802 +                fputs(progname, stdout);
803 +                fputs(": comparing inputs as spectral images\n", stdout);
804 +        }
805 +        if (!(set_resolu(&rs1, &hdr1) || fgetsresolu(&rs1, f1in)))
806 +                return(0);
807 +        if (!(set_resolu(&rs2, &hdr2) || fgetsresolu(&rs2, f2in)))
808 +                return(0);
809 +        if (!check_resolu("Spectral image", &rs1, &rs2))
810 +                return(0);
811 +        NCstr[LNCOMPSTR-1] = '\0';
812 +        val = (const char *)lu_find(&hdr1, NCstr)->data;
813 +        if (!val || (NCSAMP = atoi(val)) < 3) {
814 +                if (report != REP_QUIET) {
815 +                        if (val)
816 +                                printf("%s: illegal # components (%d) for spectral image\n",
817 +                                        progname, NCSAMP);
818 +                        else
819 +                                printf("%s: missing %s in header for spectral image\n",
820 +                                        progname, NCstr);
821 +                }
822 +                return(0);
823 +        }
824 +        scan1 = (COLORV *)malloc(sizeof(COLORV)*NCSAMP*scanlen(&rs1));
825 +        scan2 = (COLORV *)malloc(sizeof(COLORV)*NCSAMP*scanlen(&rs2));
826 +        if (!scan1 | !scan2) {
827 +                fprintf(stderr, "%s: out of memory in compare_hdr()\n", progname);
828 +                exit(2);
829 +        }
830 +        for (y = 0; y < numscans(&rs1); y++) {
831 +                if ((freadsscan(scan1, NCSAMP, scanlen(&rs1), f1in) < 0) |
832 +                                (freadsscan(scan2, NCSAMP, scanlen(&rs2), f2in) < 0)) {
833 +                        if (report != REP_QUIET)
834 +                                printf("%s: unexpected end-of-file\n", progname);
835 +                        free(scan1);
836 +                        free(scan2);
837 +                        return(0);
838 +                }
839 +                for (x = 0; x < scanlen(&rs1); x++) {
840 +                        if (spec_check(scan1+x*NCSAMP, scan2+x*NCSAMP))
841 +                                continue;
842 +                        if (report != REP_QUIET) {
843 +                                int     k;
844 +                                printf("%s: spectra at scanline %d offset %d differ\n",
845 +                                        progname, y, x);
846 +                                if (report >= REP_VERBOSE) {
847 +                                        printf("%s: spectrum =", f1name);
848 +                                        for (k = 0; k < NCSAMP; k++)
849 +                                                printf(" %g", scan1[x*NCSAMP+k]);
850 +                                        fputc('\n', stdout);
851 +                                        printf("%s: spectrum =", f2name);
852 +                                        for (k = 0; k < NCSAMP; k++)
853 +                                                printf(" %g", scan2[x*NCSAMP+k]);
854 +                                        fputc('\n', stdout);
855 +                                }
856 +                        }
857 +                        free(scan1);
858 +                        free(scan2);
859 +                        return(0);
860 +                }
861 +        }
862 +        free(scan1);
863 +        free(scan2);
864 +        return(good_RMS());                     /* final check of RMS */
865 + }
866 +
867   /* Set reference depth based on header variable */
868   static int
869   set_refdepth(DEPTHCODEC *dcp, LUTAB *htp)
# Line 893 | Line 1068 | main(int argc, char *argv[])
1068                  case 'h':                       /* ignore header info. */
1069                          ign_header = !ign_header;
1070                          continue;
1071 +                case 'n':                       /* allow newline escapes */
1072 +                        escape_newlines = !escape_newlines;
1073 +                        continue;
1074 +                case 'c':                       /* ignore comments */
1075 +                        comment_c = argv[a][2];
1076 +                        continue;
1077                  case 's':                       /* silent operation */
1078                          report = REP_QUIET;
1079                          continue;
# Line 996 | Line 1177 | main(int argc, char *argv[])
1177          case TYP_RGBE:
1178          case TYP_XYZE:
1179                  return( !compare_hdr() );
1180 +        case TYP_SPEC:
1181 +                return( !compare_spec() );
1182          case TYP_DEPTH:
1183                  return( !compare_depth() );
1184          case TYP_NORM:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines