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.29 by greg, Thu Mar 3 00:01:48 2022 UTC vs.
Revision 2.35 by greg, Mon Dec 9 00:29:30 2024 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 78 | Line 79 | const char     *hdr_ignkey[] = {
79                          "CAPDATE",
80                          "GMT",
81                          "FRAME",
82 +                        "TILED",
83                          NULL    /* terminator */
84                  };
85                                  /* header variable settings */
# Line 244 | 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 615 | 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 647 | 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 704 | Line 765 | compare_hdr()
765                          if (color_check(scan1[x], scan2[x]))
766                                  continue;
767                          if (report != REP_QUIET) {
768 <                                printf(
708 <                                "%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 728 | 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 1041 | 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