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.35 by greg, Tue Oct 13 00:08:46 2020 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 119 | Line 125 | int    len
125                          cmon[RED] = cmon[GRN] = cmon[BLU] = li;
126                  } else {
127                          for (j = 3; j--; )
128 <                                if (cmon[j] < 0) cmon[j] = 0;
128 >                                cmon[j] *= (cmon[j] > 0);
129                  }
130                  bi = ( (uint32)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 12;
131                  cs[3*i  ] = bi>=GAMTSZ ? 255 : cd->gamb[bi];
# Line 151 | Line 157 | headline(                      /* grok a header line */
157          void    *vrh
158   )
159   {
160 <        char    fmt[32];
160 >        char    fmt[MAXFMTLEN];
161          struct radhead  *rh = vrh;
162  
163          if (formatval(fmt, s)) {
# Line 180 | Line 186 | int
186   tmLoadPicture(                          /* convert Radiance picture */
187   TMstruct        *tms,
188   TMbright        **lpp,
189 < BYTE    **cpp,
189 > uby8    **cpp,
190   int     *xp,
191   int     *yp,
192   char    *fname,
# Line 224 | Line 230 | FILE   *fp
230          if (*lpp == NULL)
231                  goto done;
232          if (cpp != TM_NOCHROMP) {
233 <                *cpp = (BYTE *)malloc(3*sizeof(BYTE) * *xp * *yp);
233 >                *cpp = (uby8 *)malloc(3*sizeof(uby8) * *xp * *yp);
234                  if (*cpp == NULL)
235                          goto done;
236          }
# Line 261 | Line 267 | done:                                          /* clean up */
267   #ifdef PCOND
268   static int                                      /* run pcond to map picture */
269   dopcond(psp, xp, yp, flags, monpri, gamval, Lddyn, Ldmax, fname)
270 < BYTE    **psp;
270 > uby8    **psp;
271   int     *xp, *yp;
272   int     flags;
273   RGBPRIMP        monpri;
# Line 273 | Line 279 | char   *fname;
279          char    cmdbuf[1024];
280          FILE    *infp;
281          COLR    *scan;
282 <        BYTE    *rp;
282 >        uby8    *rp;
283          int     y;
284          int     x;
285                                          /* set up gamma correction */
# Line 312 | Line 318 | char   *fname;
318                                          /* allocate arrays */
319          scan = (COLR *)malloc(sizeof(COLR) * *xp);
320          if (flags & TM_F_BW)
321 <                rp = (BYTE *)malloc(sizeof(BYTE) * *xp * *yp);
321 >                rp = (uby8 *)malloc(sizeof(uby8) * *xp * *yp);
322          else
323 <                rp = (BYTE *)malloc(3*sizeof(BYTE) * *xp * *yp);
323 >                rp = (uby8 *)malloc(3*sizeof(uby8) * *xp * *yp);
324          if (((*psp = rp) == NULL) | (scan == NULL)) {
325                  pclose(infp);
326                  returnErr(TM_E_NOMEM);
# Line 348 | Line 354 | char   *fname;
354  
355   int                                     /* map a Radiance picture */
356   tmMapPicture(psp, xp, yp, flags, monpri, gamval, Lddyn, Ldmax, fname, fp)
357 < BYTE    **psp;
357 > uby8    **psp;
358   int     *xp, *yp;
359   int     flags;
360   RGBPRIMP        monpri;
# Line 357 | Line 363 | char   *fname;
363   FILE    *fp;
364   {
365          char    *funcName = fname==NULL ? "tmMapPicture" : fname;
366 <        TMstruct        *tms;
367 <        BYTE    *cp;
366 >        TMstruct        *tms = NULL;
367 >        uby8    *cp;
368          TMbright        *lp;
369          int     err;
370                                                  /* check arguments */
# Line 388 | Line 394 | FILE   *fp;
394          }
395                                                  /* allocate space for result */
396          if (flags & TM_F_BW) {
397 <                *psp = (BYTE *)malloc(sizeof(BYTE) * *xp * *yp);
397 >                *psp = (uby8 *)malloc(sizeof(uby8) * *xp * *yp);
398                  if (*psp == NULL) {
399                          free((MEM_PTR)lp);
400                          tmDone(tms);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines