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

Comparing ray/src/common/tmapcolrs.c (file contents):
Revision 3.20 by greg, Wed Feb 23 00:08:08 2005 UTC vs.
Revision 3.21 by greg, Sat Sep 24 20:15:54 2005 UTC

# Line 16 | Line 16 | static const char      RCSid[] = "$Id$";
16  
17   #include        "tmprivat.h"
18   #include        "resolu.h"
19 + #ifdef PCOND
20   #include        "rtprocess.h"
20
21 #ifndef TM_PIC_CTRANS
22 #define TM_PIC_CTRANS   1               /* transform colors? (expensive) */
21   #endif
22  
23   #define GAMTSZ  1024
24  
25   typedef struct {
26          BYTE            gamb[GAMTSZ];   /* gamma lookup table */
27 <        COLR            clfb;           /* encoded tm->clf */
27 >        int             clfb[3];        /* encoded tm->clf */
28 >        int32           cmatb[3][3];    /* encoded color transform */
29          TMbright        inpsfb;         /* encoded tm->inpsf */
30   } COLRDATA;
31  
# Line 53 | Line 52 | int    len
52   )
53   {
54          static const char       funcName[] = "tmCvColrs";
55 <        COLR    cmon;
55 >        int     cmon[4];
56          register COLRDATA       *cd;
57 <        register int    i, bi, li;
57 >        register int    i, j, li, bi;
58 >        int32   vl;
59  
60          if (tms == NULL)
61                  returnErr(TM_E_TMINVAL);
62          if ((ls == NULL) | (scan == NULL) | (len < 0))
63                  returnErr(TM_E_ILLEGAL);
64 #if TM_PIC_CTRANS
65        if (tmNeedMatrix(tms)) {                /* need floating point */
66 #else
67        if (tms->inppri == TM_XYZPRIM) {        /* no way around this */
68 #endif
69                register COLOR  *newscan;
70                newscan = (COLOR *)tempbuffer(len*sizeof(COLOR));
71                if (newscan == NULL)
72                        returnErr(TM_E_NOMEM);
73                for (i = len; i--; )
74                        colr_color(newscan[i], scan[i]);
75                return(tmCvColors(tms, ls, cs, newscan, len));
76        }
64          if (colrReg < 0) {                      /* build tables if necessary */
65                  colrReg = tmRegPkg(&colrPkg);
66                  if (colrReg < 0)
# Line 87 | Line 74 | int    len
74          if ((cd = (COLRDATA *)tmPkgData(tms,colrReg)) == NULL)
75                  returnErr(TM_E_NOMEM);
76          for (i = len; i--; ) {
77 <                copycolr(cmon, scan[i]);
77 >                if (tmNeedMatrix(tms)) {                /* apply color xform */
78 >                        for (j = 3; j--; ) {
79 >                                vl =    cd->cmatb[j][RED]*(int32)scan[i][RED] +
80 >                                        cd->cmatb[j][GRN]*(int32)scan[i][GRN] +
81 >                                        cd->cmatb[j][BLU]*(int32)scan[i][BLU] ;
82 >                                if (vl < 0) cmon[j] = vl/0x10000;
83 >                                else cmon[j] = vl>>16;
84 >                        }
85 >                        cmon[EXP] = scan[i][EXP];
86 >                } else
87 >                        copycolr(cmon, scan[i]);
88                                                          /* world luminance */
89 <                li =  ( cd->clfb[RED]*cmon[RED] +
89 >                li =    cd->clfb[RED]*cmon[RED] +
90                          cd->clfb[GRN]*cmon[GRN] +
91 <                        cd->clfb[BLU]*cmon[BLU] ) >> 8;
92 <                bi = BRT2SCALE(cmon[EXP]-COLXS) +
93 <                                logi[li] + cd->inpsfb;
91 >                        cd->clfb[BLU]*cmon[BLU] ;
92 >                if (li >= 0xff00) li = 255;
93 >                else li >>= 8;
94                  if (li <= 0) {
95                          bi = TM_NOBRT;                  /* bogus value */
96                          li = 1;                         /* avoid li==0 */
97 +                } else {
98 +                        bi = BRT2SCALE(cmon[EXP]-COLXS) +
99 +                                logi[li] + cd->inpsfb;
100                  }
101                  ls[i] = bi;
102                  if (cs == TM_NOCHROM)                   /* no color? */
103                          continue;
104                                                          /* mesopic adj. */
105                  if (tms->flags & TM_F_MESOPIC && bi < BMESUPPER) {
106 <                        register int    pf, sli = normscot(cmon);
107 <                        if (bi < BMESLOWER)
106 >                        int     pf, sli = normscot(cmon);
107 >                        if (bi < BMESLOWER) {
108                                  cmon[RED] = cmon[GRN] = cmon[BLU] = sli;
109 <                        else {
109 >                        } else {
110                                  if (tms->flags & TM_F_BW)
111                                          cmon[RED] = cmon[GRN] = cmon[BLU] = li;
112                                  pf = tmMesofact[bi-BMESLOWER];
113                                  sli *= 256 - pf;
114 <                                cmon[RED] = ( sli + pf*cmon[RED] ) >> 8;
115 <                                cmon[GRN] = ( sli + pf*cmon[GRN] ) >> 8;
116 <                                cmon[BLU] = ( sli + pf*cmon[BLU] ) >> 8;
114 >                                for (j = 3; j--; ) {
115 >                                        cmon[j] = sli + pf*cmon[j];
116 >                                        if (cmon[j] <= 0) cmon[j] = 0;
117 >                                        else cmon[j] >>= 8;
118 >                                }
119                          }
120                  } else if (tms->flags & TM_F_BW) {
121                          cmon[RED] = cmon[GRN] = cmon[BLU] = li;
122 +                } else {
123 +                        for (j = 3; j--; )
124 +                                if (cmon[j] < 0) cmon[j] = 0;
125                  }
126                  bi = ( (int32)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 8;
127                  cs[3*i  ] = bi>=GAMTSZ ? 255 : cd->gamb[bi];
# Line 422 | Line 427 | register TMstruct      *tms;
427   {
428          register COLRDATA       *cd;
429          double  d;
430 +        int     i, j;
431  
432          cd = (COLRDATA *)tms->pd[colrReg];
433 <        cd->clfb[RED] = 256.*tms->clf[RED] + .5;
434 <        cd->clfb[GRN] = 256.*tms->clf[GRN] + .5;
429 <        cd->clfb[BLU] = 256.*tms->clf[BLU] + .5;
430 <        cd->clfb[EXP] = COLXS;
433 >        for (i = 3; i--; )
434 >                cd->clfb[i] = 0x100*tms->clf[i] + .5;
435          d = TM_BRTSCALE*log(tms->inpsf);
436          cd->inpsfb = d<0. ? d-.5 : d+.5;
437 +        for (i = 3; i--; )
438 +                for (j = 3; j--; ) {
439 +                        d = tms->cmat[i][j] / tms->inpsf;
440 +                        cd->cmatb[i][j] = 0x10000*d + (d<0. ? -.5 : .5);
441 +                }
442   }
443  
444  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines