ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/macbethcal.c
(Generate patch)

Comparing ray/src/px/macbethcal.c (file contents):
Revision 2.12 by greg, Thu Jan 30 19:14:11 1997 UTC vs.
Revision 2.13 by greg, Fri Jan 31 15:56:17 1997 UTC

# Line 106 | Line 106 | long   inpflags = 0;           /* flags of which colors were inpu
106   long    gmtflags = 0;           /* flags of out-of-gamut colors */
107  
108   COLOR   bramp[NMBNEU][2];       /* brightness ramp (per primary) */
109 < double  solmat[3][3];           /* color mapping matrix */
109 > COLORMAT        solmat;         /* color mapping matrix */
110 > COLOR   colmin, colmax;         /* gamut limits */
111  
112   FILE    *debugfp = NULL;        /* debug output picture */
113   char    *progname;
# Line 158 | Line 159 | char   **argv;
159                  }
160                                                          /* open files */
161          if (i < argc && freopen(argv[i], "r", stdin) == NULL) {
162 <                perror(argv[1]);
162 >                perror(argv[i]);
163                  exit(1);
164          }
165          if (i+1 < argc && freopen(argv[i+1], "w", stdout) == NULL) {
166 <                perror(argv[2]);
166 >                perror(argv[i+1]);
167                  exit(1);
168          }
169          if (scanning) {                 /* load input picture header */
# Line 385 | Line 386 | compute()                      /* compute color mapping */
386          COLOR   clrin[24], clrout[24];
387          long    cflags;
388          COLOR   ctmp;
389 <        register int    i, j, n;
389 >        register int    i, n;
390                                          /* did we get what we need? */
391          if ((inpflags & REQFLGS) != REQFLGS) {
392                  fprintf(stderr, "%s: missing required input colors\n",
# Line 397 | Line 398 | compute()                      /* compute color mapping */
398                  copycolor(bramp[i][0], inpRGB[mbneu[i]]);
399                  copycolor(bramp[i][1], mbRGB[mbneu[i]]);
400          }
401 +                                        /* compute color space gamut */
402 +        if (scanning) {
403 +                copycolor(colmin, cblack);
404 +                copycolor(colmax, cwhite);
405 +        } else
406 +                for (i = 0; i < 3; i++) {
407 +                        colval(colmin,i) = colval(bramp[0][0],i) -
408 +                                colval(bramp[0][1],i) *
409 +                                (colval(bramp[1][0],i)-colval(bramp[0][0],i)) /
410 +                                (colval(bramp[1][1],i)-colval(bramp[1][0],i));
411 +                        colval(colmax,i) = colval(bramp[NMBNEU-2][0],i) +
412 +                                (1.-colval(bramp[NMBNEU-2][1],i)) *
413 +                                (colval(bramp[NMBNEU-1][0],i) -
414 +                                        colval(bramp[NMBNEU-2][0],i)) /
415 +                                (colval(bramp[NMBNEU-1][1],i) -
416 +                                        colval(bramp[NMBNEU-2][1],i));
417 +                }
418                                          /* compute color mapping */
419          do {
420                  cflags = inpflags & ~gmtflags;
# Line 410 | Line 428 | compute()                      /* compute color mapping */
428                  compsoln(clrin, clrout, n);
429                                                  /* check out-of-gamut colors */
430                  for (i = 0; i < 24; i++)
431 <                        if (cflags & 1L<<i) {
432 <                                cvtcolor(ctmp, mbRGB[i]);
415 <                                for (j = 0; j < 3; j++)
416 <                                        if (colval(ctmp,j) <= 1e-6 ||
417 <                                                colval(ctmp,j) >= 1.-1e-6) {
418 <                                                gmtflags |= 1L<<i;
419 <                                                break;
420 <                                        }
421 <                        }
431 >                        if (cflags & 1L<<i && cvtcolor(ctmp, mbRGB[i]))
432 >                                gmtflags |= 1L<<i;
433          } while (cflags & gmtflags);
434          if (gmtflags & MODFLGS)
435                  fprintf(stderr,
# Line 535 | Line 546 | int    n;
546   }
547  
548  
549 + int
550   cvtcolor(cout, cin)             /* convert color according to our mapping */
551   COLOR   cout, cin;
552   {
553          COLOR   ctmp;
554 +        int     clipped;
555  
556          if (scanning) {
557                  bresp(ctmp, cin);
558 <                cresp(cout, ctmp);
558 >                clipped = cresp(cout, ctmp);
559          } else {
560 <                cresp(ctmp, cin);
560 >                clipped = cresp(ctmp, cin);
561                  bresp(cout, ctmp);
562          }
563 <        if (colval(cout,RED) < 0.)
551 <                colval(cout,RED) = 0.;
552 <        if (colval(cout,GRN) < 0.)
553 <                colval(cout,GRN) = 0.;
554 <        if (colval(cout,BLU) < 0.)
555 <                colval(cout,BLU) = 0.;
563 >        return(clipped);
564   }
565  
566  
567 + int
568   cresp(cout, cin)                /* transform color according to matrix */
569   COLOR   cout, cin;
570   {
571 <        double  r, g, b;
572 <
564 <        r = colval(cin,0)*solmat[0][0] + colval(cin,1)*solmat[0][1]
565 <                        + colval(cin,2)*solmat[0][2];
566 <        g = colval(cin,0)*solmat[1][0] + colval(cin,1)*solmat[1][1]
567 <                        + colval(cin,2)*solmat[1][2];
568 <        b = colval(cin,0)*solmat[2][0] + colval(cin,1)*solmat[2][1]
569 <                        + colval(cin,2)*solmat[2][2];
570 <        setcolor(cout, r, g, b);
571 >        colortrans(cout, solmat, cin);
572 >        return(clipgamut(cout, bright(cout), CGAMUT, colmin, colmax));
573   }
574  
575  
# Line 582 | Line 584 | register float xyYin[3];
584          ctmp[0] = xyYin[0] * d;
585          ctmp[1] = xyYin[2];
586          ctmp[2] = (1. - xyYin[0] - xyYin[1]) * d;
585        cie_rgb(rgbout, ctmp);
587                                  /* allow negative values */
588 <        colortrans(rgbout, xyz2rgbmat, ctmp, 0);
588 >        colortrans(rgbout, xyz2rgbmat, ctmp);
589   }
590  
591  
# Line 621 | Line 622 | picdebug()                     /* put out debugging picture */
622                  for (x = 0; x < xmax; x++) {
623                          rg = chartndx(x, y, &i);
624                          if (rg == RG_CENT) {
625 <                                if (!(1L<<i & gmtflags) || (x+y)&07)
625 >                                if (!(1L<<i & gmtflags) || (x+y)&07) {
626                                          copycolor(scan[x], mbRGB[i]);
627 <                                else
627 >                                        clipgamut(scan[x], bright(scan[x]),
628 >                                                CGAMUT, cblack, cwhite);
629 >                                } else
630                                          copycolor(scan[x], blkcol);
631                          } else if (rg == RG_CORR)
632                                  cvtcolor(scan[x], scan[x]);
# Line 647 | Line 650 | clrdebug()                     /* put out debug picture from color input
650          static COLR     blkclr = BLKCOLR;
651          COLR    mbclr[24], cvclr[24], orclr[24];
652          COLR    *scan;
653 <        COLOR   ctmp;
653 >        COLOR   ctmp, ct2;
654          int     y, i;
655          register int    x, rg;
656                                                  /* convert colors */
657          for (i = 0; i < 24; i++) {
658 <                setcolr(mbclr[i], colval(mbRGB[i],RED),
659 <                                colval(mbRGB[i],GRN), colval(mbRGB[i],BLU));
658 >                copycolor(ctmp, mbRGB[i]);
659 >                clipgamut(ctmp, bright(ctmp), CGAMUT, cblack, cwhite);
660 >                setcolr(mbclr[i], colval(ctmp,RED),
661 >                                colval(ctmp,GRN), colval(ctmp,BLU));
662                  if (inpflags & 1L<<i) {
663 <                        setcolr(orclr[i], colval(inpRGB[i],RED),
664 <                                        colval(inpRGB[i],GRN),
665 <                                        colval(inpRGB[i],BLU));
661 <                        cvtcolor(ctmp, inpRGB[i]);
662 <                        setcolr(cvclr[i], colval(ctmp,RED),
663 >                        copycolor(ctmp, inpRGB[i]);
664 >                        clipgamut(ctmp, bright(ctmp), CGAMUT, cblack, cwhite);
665 >                        setcolr(orclr[i], colval(ctmp,RED),
666                                          colval(ctmp,GRN), colval(ctmp,BLU));
667 +                        bresp(ctmp, inpRGB[i]);
668 +                        colortrans(ct2, solmat, ctmp);
669 +                        clipgamut(ct2, bright(ct2), CGAMUT, cblack, cwhite);
670 +                        setcolr(cvclr[i], colval(ct2,RED),
671 +                                        colval(ct2,GRN), colval(ct2,BLU));
672                  }
673          }
674                                                  /* allocate scanline */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines