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.28 by greg, Fri Apr 22 17:06:26 2011 UTC vs.
Revision 3.36 by greg, Fri Jan 7 23:01:01 2022 UTC

# Line 9 | Line 9 | static const char      RCSid[] = "$Id$";
9  
10   #include "copyright.h"
11  
12 #include        <stdio.h>
12   #include        <stdlib.h>
14 #include        <string.h>
13   #include        <math.h>
16 #include        <time.h>
14  
15   #ifdef PCOND
16 < #include        "rtprocess.h"
16 > #include        "paths.h"
17   #endif
18   #include        "tmprivat.h"
19 + #include        "rtio.h"
20   #include        "resolu.h"
21  
22   #define GAMTSZ  4096
23  
24   typedef struct {
25 <        BYTE            gamb[GAMTSZ];   /* gamma lookup table */
25 >        uby8            gamb[GAMTSZ];   /* gamma lookup table */
26          int             clfb[3];        /* encoded tm->clf */
27          int32           cmatb[3][3];    /* encoded color transform */
28          TMbright        inpsfb;         /* encoded tm->inpsf */
# Line 46 | Line 44 | int
44   tmCvColrs(                              /* convert RGBE/XYZE colors */
45   TMstruct        *tms,
46   TMbright        *ls,
47 < BYTE    *cs,
47 > uby8    *cs,
48   COLR    *scan,
49   int     len
50   )
# Line 73 | Line 71 | int    len
71                  returnErr(TM_E_NOMEM);
72          for (i = len; i--; ) {
73                  if (tmNeedMatrix(tms)) {                /* apply color xform */
74 +                        bi = 0;
75                          for (j = 3; j--; ) {
76                                  vl =    cd->cmatb[j][RED]*(int32)scan[i][RED] +
77                                          cd->cmatb[j][GRN]*(int32)scan[i][GRN] +
78                                          cd->cmatb[j][BLU]*(int32)scan[i][BLU] ;
79 <                                if (vl < 0) cmon[j] = vl/0x10000;
80 <                                else cmon[j] = vl>>16;
79 >                                if (vl < 0)
80 >                                        cmon[j] = vl/(int32)0x10000;
81 >                                else if ((cmon[j] = vl>>16) > bi)
82 >                                        bi = cmon[j];
83                          }
84                          cmon[EXP] = scan[i][EXP];
85 +                        while (bi >= 256) {             /* handle overflow */
86 +                                cmon[EXP]++;
87 +                                for (j = 3; j--; ) cmon[j] >>= 1;
88 +                                bi >>= 1;
89 +                        }
90                  } else
91                          copycolr(cmon, scan[i]);
92                                                          /* world luminance */
# Line 116 | Line 122 | int    len
122                                  }
123                          }
124                  } else if (tms->flags & TM_F_BW) {
125 <                        cmon[RED] = cmon[GRN] = cmon[BLU] = li;
125 >                        for (j = 3; j--; )
126 >                                cs[3*i+j] = tms->cdiv[j]/(TM_BRES>>8);
127 >                        continue;
128                  } else {
129                          for (j = 3; j--; )
130 <                                if (cmon[j] < 0) cmon[j] = 0;
130 >                                cmon[j] *= (cmon[j] > 0);
131                  }
132                  bi = ( (uint32)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 12;
133                  cs[3*i  ] = bi>=GAMTSZ ? 255 : cd->gamb[bi];
# Line 151 | Line 159 | headline(                      /* grok a header line */
159          void    *vrh
160   )
161   {
162 <        char    fmt[32];
162 >        char    fmt[MAXFMTLEN];
163          struct radhead  *rh = vrh;
164  
165          if (formatval(fmt, s)) {
# Line 180 | Line 188 | int
188   tmLoadPicture(                          /* convert Radiance picture */
189   TMstruct        *tms,
190   TMbright        **lpp,
191 < BYTE    **cpp,
191 > uby8    **cpp,
192   int     *xp,
193   int     *yp,
194   char    *fname,
# Line 224 | Line 232 | FILE   *fp
232          if (*lpp == NULL)
233                  goto done;
234          if (cpp != TM_NOCHROMP) {
235 <                *cpp = (BYTE *)malloc(3*sizeof(BYTE) * *xp * *yp);
235 >                *cpp = (uby8 *)malloc(3*sizeof(uby8) * *xp * *yp);
236                  if (*cpp == NULL)
237                          goto done;
238          }
# Line 261 | Line 269 | done:                                          /* clean up */
269   #ifdef PCOND
270   static int                                      /* run pcond to map picture */
271   dopcond(psp, xp, yp, flags, monpri, gamval, Lddyn, Ldmax, fname)
272 < BYTE    **psp;
272 > uby8    **psp;
273   int     *xp, *yp;
274   int     flags;
275   RGBPRIMP        monpri;
# Line 273 | Line 281 | char   *fname;
281          char    cmdbuf[1024];
282          FILE    *infp;
283          COLR    *scan;
284 <        BYTE    *rp;
284 >        uby8    *rp;
285          int     y;
286          int     x;
287                                          /* set up gamma correction */
# Line 312 | Line 320 | char   *fname;
320                                          /* allocate arrays */
321          scan = (COLR *)malloc(sizeof(COLR) * *xp);
322          if (flags & TM_F_BW)
323 <                rp = (BYTE *)malloc(sizeof(BYTE) * *xp * *yp);
323 >                rp = (uby8 *)malloc(sizeof(uby8) * *xp * *yp);
324          else
325 <                rp = (BYTE *)malloc(3*sizeof(BYTE) * *xp * *yp);
325 >                rp = (uby8 *)malloc(3*sizeof(uby8) * *xp * *yp);
326          if (((*psp = rp) == NULL) | (scan == NULL)) {
327                  pclose(infp);
328                  returnErr(TM_E_NOMEM);
# Line 348 | Line 356 | char   *fname;
356  
357   int                                     /* map a Radiance picture */
358   tmMapPicture(psp, xp, yp, flags, monpri, gamval, Lddyn, Ldmax, fname, fp)
359 < BYTE    **psp;
359 > uby8    **psp;
360   int     *xp, *yp;
361   int     flags;
362   RGBPRIMP        monpri;
# Line 357 | Line 365 | char   *fname;
365   FILE    *fp;
366   {
367          char    *funcName = fname==NULL ? "tmMapPicture" : fname;
368 <        TMstruct        *tms;
369 <        BYTE    *cp;
368 >        TMstruct        *tms = NULL;
369 >        uby8    *cp;
370          TMbright        *lp;
371          int     err;
372                                                  /* check arguments */
# Line 388 | Line 396 | FILE   *fp;
396          }
397                                                  /* allocate space for result */
398          if (flags & TM_F_BW) {
399 <                *psp = (BYTE *)malloc(sizeof(BYTE) * *xp * *yp);
399 >                *psp = (uby8 *)malloc(sizeof(uby8) * *xp * *yp);
400                  if (*psp == NULL) {
401                          free((MEM_PTR)lp);
402                          tmDone(tms);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines