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.30 by greg, Tue May 24 22:34:18 2022 UTC vs.
Revision 2.34 by greg, Tue Nov 21 20:01:39 2023 UTC

# Line 51 | Line 51 | const char     *file_type[] = {
51                          "ascii",
52                          COLRFMT,
53                          CIEFMT,
54 +                        SPECFMT,
55                          DEPTH16FMT,
56                          NORMAL32FMT,
57                          "float",
# Line 65 | 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 75 | enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_
75  
76                                  /* header variables to always ignore */
77   const char      *hdr_ignkey[] = {
77                        "FORMAT",
78                          "SOFTWARE",
79                          "CAPDATE",
80                          "GMT",
# Line 245 | Line 245 | color_check(COLOR c1, COLOR c2)
245          return(real_check(colval(c1,p), colval(c2,p)));
246   }
247  
248 + #if 1
249 + /* Compare two color spectra for equivalence */
250 + static int
251 + spec_check(COLORV *sc1, COLORV *sc2)
252 + {
253 +        int     p, k;
254 +
255 +        if (!real_check(scolor_mean(sc1), scolor_mean(sc2)))
256 +                return(0);
257 +
258 +        p = 0;                          /* find max. component */
259 +        for (k = NCSAMP; --k; )
260 +                if (sc1[k] > sc1[p])
261 +                        p = k;
262 +
263 +        return(real_check(sc1[p], sc2[p]));
264 + }
265 + #else
266 + /* Compare two color spectra for equivalence */
267 + static int
268 + spec_check(COLORV *sc1, COLORV *sc2)
269 + {
270 +        COLOR   c1, c2;
271 +        int     p;
272 +
273 +        if (!real_check(scolor_mean(sc1), scolor_mean(sc2)))
274 +                return(0);
275 +                                        /* do comparisons in RGB space */
276 +        scolor_rgb(c1, sc1);
277 +        scolor_rgb(c2, sc2);
278 +
279 +        p = (colval(c1,GRN) > colval(c1,RED)) ? GRN : RED;
280 +        if (colval(c1,BLU) > colval(c1,p)) p = BLU;
281 +
282 +        return(real_check(colval(c1,p), colval(c2,p)));
283 + }
284 + #endif
285 +
286   /* Compare two normal directions for equivalence */
287   static int
288   norm_check(FVECT nv1, FVECT nv2)
# Line 616 | Line 654 | compare_text()
654                                                  /* compare non-empty lines */
655                  if (!equiv_string(l1buf.str, l2buf.str)) {
656                          if (report != REP_QUIET) {
657 <                                printf("%s: inputs '%s' and '%s' differ at line %d|%d\n",
658 <                                                progname, f1name, f2name,
659 <                                                lin1cnt, lin2cnt);
657 >                                printf("%s: inputs '%s' and '%s' differ at line %d",
658 >                                                progname, f1name, f2name, lin1cnt);
659 >                                if (lin1cnt != lin2cnt)
660 >                                        printf("|%d\n", lin2cnt);
661 >                                else
662 >                                        putchar('\n');
663                                  if ( report >= REP_VERBOSE &&
664                                                  (l1buf.len < 256) &
665                                                  (l2buf.len < 256) ) {
# Line 648 | Line 689 | compare_text()
689          return(good_RMS());                     /* final check for reals */
690   }
691  
692 + /* Set resolution based on NROWS, NCOLS in header */
693 + static int
694 + set_resolu(RESOLU *rs, LUTAB *htp)
695 + {
696 +        const char      *val;
697 +
698 +        rs->rt = PIXSTANDARD;
699 +        val = (const char *)lu_find(htp, "NROWS")->data;
700 +        if (!val) return(0);
701 +        rs->yr = atoi(val);
702 +        if (rs->yr <= 0) return(-1);
703 +        val = (const char *)lu_find(htp, "NCOLS")->data;
704 +        if (!val) return(0);
705 +        rs->xr = atoi(val);
706 +        if (rs->xr <= 0) return(-1);
707 +        return(1);
708 + }
709 +
710   /* Check image/map resolutions */
711   static int
712   check_resolu(const char *class, RESOLU *r1p, RESOLU *r2p)
# Line 705 | Line 764 | compare_hdr()
764                          if (color_check(scan1[x], scan2[x]))
765                                  continue;
766                          if (report != REP_QUIET) {
767 <                                printf(
709 <                                "%s: pixels at scanline %d offset %d differ\n",
767 >                                printf("%s: pixels at scanline %d offset %d differ\n",
768                                          progname, y, x);
769                                  if (report >= REP_VERBOSE) {
770                                          printf("%s: (R,G,B)=(%g,%g,%g)\n",
# Line 729 | Line 787 | compare_hdr()
787          return(good_RMS());                     /* final check of RMS */
788   }
789  
790 + /* Compare two inputs that are known to be spectral images */
791 + static int
792 + compare_spec()
793 + {
794 +        static char     NCstr[] = NCOMPSTR;
795 +        RESOLU          rs1, rs2;
796 +        COLORV          *scan1, *scan2;
797 +        const char      *val;
798 +        int             x, y;
799 +
800 +        if (report >= REP_VERBOSE) {
801 +                fputs(progname, stdout);
802 +                fputs(": comparing inputs as spectral images\n", stdout);
803 +        }
804 +        if (!(set_resolu(&rs1, &hdr1) || fgetsresolu(&rs1, f1in)))
805 +                return(0);
806 +        if (!(set_resolu(&rs2, &hdr2) || fgetsresolu(&rs2, f2in)))
807 +                return(0);
808 +        if (!check_resolu("Spectral image", &rs1, &rs2))
809 +                return(0);
810 +        NCstr[LNCOMPSTR-1] = '\0';
811 +        val = (const char *)lu_find(&hdr1, NCstr)->data;
812 +        if (!val || (NCSAMP = atoi(val)) < 3) {
813 +                if (report != REP_QUIET) {
814 +                        if (val)
815 +                                printf("%s: illegal # components (%d) for spectral image\n",
816 +                                        progname, NCSAMP);
817 +                        else
818 +                                printf("%s: missing %s in header for spectral image\n",
819 +                                        progname, NCstr);
820 +                }
821 +                return(0);
822 +        }
823 +        scan1 = (COLORV *)malloc(sizeof(COLORV)*NCSAMP*scanlen(&rs1));
824 +        scan2 = (COLORV *)malloc(sizeof(COLORV)*NCSAMP*scanlen(&rs2));
825 +        if (!scan1 | !scan2) {
826 +                fprintf(stderr, "%s: out of memory in compare_hdr()\n", progname);
827 +                exit(2);
828 +        }
829 +        for (y = 0; y < numscans(&rs1); y++) {
830 +                if ((freadsscan(scan1, NCSAMP, scanlen(&rs1), f1in) < 0) |
831 +                                (freadsscan(scan2, NCSAMP, scanlen(&rs2), f2in) < 0)) {
832 +                        if (report != REP_QUIET)
833 +                                printf("%s: unexpected end-of-file\n", progname);
834 +                        free(scan1);
835 +                        free(scan2);
836 +                        return(0);
837 +                }
838 +                for (x = 0; x < scanlen(&rs1); x++) {
839 +                        if (spec_check(scan1+x*NCSAMP, scan2+x*NCSAMP))
840 +                                continue;
841 +                        if (report != REP_QUIET) {
842 +                                int     k;
843 +                                printf("%s: spectra at scanline %d offset %d differ\n",
844 +                                        progname, y, x);
845 +                                if (report >= REP_VERBOSE) {
846 +                                        printf("%s: spectrum =", f1name);
847 +                                        for (k = 0; k < NCSAMP; k++)
848 +                                                printf(" %g", scan1[x*NCSAMP+k]);
849 +                                        fputc('\n', stdout);
850 +                                        printf("%s: spectrum =", f2name);
851 +                                        for (k = 0; k < NCSAMP; k++)
852 +                                                printf(" %g", scan2[x*NCSAMP+k]);
853 +                                        fputc('\n', stdout);
854 +                                }
855 +                        }
856 +                        free(scan1);
857 +                        free(scan2);
858 +                        return(0);
859 +                }
860 +        }
861 +        free(scan1);
862 +        free(scan2);
863 +        return(good_RMS());                     /* final check of RMS */
864 + }
865 +
866   /* Set reference depth based on header variable */
867   static int
868   set_refdepth(DEPTHCODEC *dcp, LUTAB *htp)
# Line 1042 | Line 1176 | main(int argc, char *argv[])
1176          case TYP_RGBE:
1177          case TYP_XYZE:
1178                  return( !compare_hdr() );
1179 +        case TYP_SPEC:
1180 +                return( !compare_spec() );
1181          case TYP_DEPTH:
1182                  return( !compare_depth() );
1183          case TYP_NORM:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines