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.24 by greg, Thu May 18 01:58:18 2006 UTC vs.
Revision 3.33 by greg, Fri Jul 19 17:37:56 2019 UTC

# Line 10 | Line 10 | static const char      RCSid[] = "$Id$";
10   #include "copyright.h"
11  
12   #include        <stdio.h>
13 + #include        <stdlib.h>
14   #include        <string.h>
15   #include        <math.h>
16   #include        <time.h>
17  
17 #include        "tmprivat.h"
18 #include        "resolu.h"
18   #ifdef PCOND
19 < #include        "rtprocess.h"
19 > #include        "paths.h"
20   #endif
21 + #include        "tmprivat.h"
22 + #include        "rtio.h"
23 + #include        "resolu.h"
24  
25 < #define GAMTSZ  1024
25 > #define GAMTSZ  4096
26  
27   typedef struct {
28 <        BYTE            gamb[GAMTSZ];   /* gamma lookup table */
28 >        uby8            gamb[GAMTSZ];   /* gamma lookup table */
29          int             clfb[3];        /* encoded tm->clf */
30          int32           cmatb[3][3];    /* encoded color transform */
31          TMbright        inpsfb;         /* encoded tm->inpsf */
# Line 38 | Line 40 | static struct tmPackage        colrPkg = {     /* our package fun
40   };
41   static int      colrReg = -1;           /* our package registration number */
42  
43 < #define LOGISZ  260
42 < static TMbright logi[LOGISZ];
43 > static TMbright logi[256];
44  
45  
46   int
47   tmCvColrs(                              /* convert RGBE/XYZE colors */
48   TMstruct        *tms,
49   TMbright        *ls,
50 < BYTE    *cs,
50 > uby8    *cs,
51   COLR    *scan,
52   int     len
53   )
54   {
55          static const char       funcName[] = "tmCvColrs";
56          int     cmon[4];
57 <        register COLRDATA       *cd;
58 <        register int    i, j, li, bi;
59 <        int32   vl;
57 >        COLRDATA        *cd;
58 >        int     i, j, bi;
59 >        int32   li, vl;
60  
61          if (tms == NULL)
62                  returnErr(TM_E_TMINVAL);
# Line 67 | Line 68 | int    len
68                          returnErr(TM_E_CODERR1);
69                  for (i = 256; i--; )
70                          logi[i] = TM_BRTSCALE*log((i+.5)/256.) - .5;
70                for (i = 256; i < LOGISZ; i++)
71                        logi[i] = 0;
71                  tmMkMesofact();
72          }
73          if ((cd = (COLRDATA *)tmPkgData(tms,colrReg)) == NULL)
# Line 86 | Line 85 | int    len
85                  } else
86                          copycolr(cmon, scan[i]);
87                                                          /* world luminance */
88 <                li =    cd->clfb[RED]*cmon[RED] +
89 <                        cd->clfb[GRN]*cmon[GRN] +
90 <                        cd->clfb[BLU]*cmon[BLU] ;
91 <                if (li >= 0xfff00) li = 255;
88 >                li =    cd->clfb[RED]*(int32)cmon[RED] +
89 >                        cd->clfb[GRN]*(int32)cmon[GRN] +
90 >                        cd->clfb[BLU]*(int32)cmon[BLU] ;
91 >                if (li >= 1L<<(12+8)) li = 255;
92                  else li >>= 12;
93                  bi = BRT2SCALE(cmon[EXP]-COLXS) + cd->inpsfb;
94                  if (li > 0)
# Line 123 | Line 122 | int    len
122                          for (j = 3; j--; )
123                                  if (cmon[j] < 0) cmon[j] = 0;
124                  }
125 <                bi = ( (int32)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 12;
125 >                bi = ( (uint32)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 12;
126                  cs[3*i  ] = bi>=GAMTSZ ? 255 : cd->gamb[bi];
127 <                bi = ( (int32)GAMTSZ*cd->clfb[GRN]*cmon[GRN]/li ) >> 12;
127 >                bi = ( (uint32)GAMTSZ*cd->clfb[GRN]*cmon[GRN]/li ) >> 12;
128                  cs[3*i+1] = bi>=GAMTSZ ? 255 : cd->gamb[bi];
129 <                bi = ( (int32)GAMTSZ*cd->clfb[BLU]*cmon[BLU]/li ) >> 12;
129 >                bi = ( (uint32)GAMTSZ*cd->clfb[BLU]*cmon[BLU]/li ) >> 12;
130                  cs[3*i+2] = bi>=GAMTSZ ? 255 : cd->gamb[bi];
131          }
132          returnOK;
# Line 149 | Line 148 | static struct radhead {
148  
149   static int
150   headline(                       /* grok a header line */
151 <        register char   *s,
151 >        char    *s,
152          void    *vrh
153   )
154   {
155 <        char    fmt[32];
156 <        register struct radhead *rh = vrh;
155 >        char    fmt[MAXFMTLEN];
156 >        struct radhead  *rh = vrh;
157  
158          if (formatval(fmt, s)) {
159                  if (!strcmp(fmt, COLRFMT))
# Line 182 | Line 181 | int
181   tmLoadPicture(                          /* convert Radiance picture */
182   TMstruct        *tms,
183   TMbright        **lpp,
184 < BYTE    **cpp,
184 > uby8    **cpp,
185   int     *xp,
186   int     *yp,
187   char    *fname,
# Line 226 | Line 225 | FILE   *fp
225          if (*lpp == NULL)
226                  goto done;
227          if (cpp != TM_NOCHROMP) {
228 <                *cpp = (BYTE *)malloc(3*sizeof(BYTE) * *xp * *yp);
228 >                *cpp = (uby8 *)malloc(3*sizeof(uby8) * *xp * *yp);
229                  if (*cpp == NULL)
230                          goto done;
231          }
# Line 263 | Line 262 | done:                                          /* clean up */
262   #ifdef PCOND
263   static int                                      /* run pcond to map picture */
264   dopcond(psp, xp, yp, flags, monpri, gamval, Lddyn, Ldmax, fname)
265 < BYTE    **psp;
265 > uby8    **psp;
266   int     *xp, *yp;
267   int     flags;
268   RGBPRIMP        monpri;
# Line 274 | Line 273 | char   *fname;
273          TMstruct        *tms = NULL;
274          char    cmdbuf[1024];
275          FILE    *infp;
276 <        register COLR   *scan;
277 <        register BYTE   *rp;
276 >        COLR    *scan;
277 >        uby8    *rp;
278          int     y;
279 <        register int    x;
279 >        int     x;
280                                          /* set up gamma correction */
281          if (setcolrcor(pow, 1./gamval) < 0)
282                  returnErr(TM_E_NOMEM);
# Line 314 | Line 313 | char   *fname;
313                                          /* allocate arrays */
314          scan = (COLR *)malloc(sizeof(COLR) * *xp);
315          if (flags & TM_F_BW)
316 <                rp = (BYTE *)malloc(sizeof(BYTE) * *xp * *yp);
316 >                rp = (uby8 *)malloc(sizeof(uby8) * *xp * *yp);
317          else
318 <                rp = (BYTE *)malloc(3*sizeof(BYTE) * *xp * *yp);
318 >                rp = (uby8 *)malloc(3*sizeof(uby8) * *xp * *yp);
319          if (((*psp = rp) == NULL) | (scan == NULL)) {
320                  pclose(infp);
321                  returnErr(TM_E_NOMEM);
# Line 350 | Line 349 | char   *fname;
349  
350   int                                     /* map a Radiance picture */
351   tmMapPicture(psp, xp, yp, flags, monpri, gamval, Lddyn, Ldmax, fname, fp)
352 < BYTE    **psp;
352 > uby8    **psp;
353   int     *xp, *yp;
354   int     flags;
355   RGBPRIMP        monpri;
# Line 359 | Line 358 | char   *fname;
358   FILE    *fp;
359   {
360          char    *funcName = fname==NULL ? "tmMapPicture" : fname;
361 <        TMstruct        *tms;
362 <        BYTE    *cp;
361 >        TMstruct        *tms = NULL;
362 >        uby8    *cp;
363          TMbright        *lp;
364          int     err;
365                                                  /* check arguments */
# Line 390 | Line 389 | FILE   *fp;
389          }
390                                                  /* allocate space for result */
391          if (flags & TM_F_BW) {
392 <                *psp = (BYTE *)malloc(sizeof(BYTE) * *xp * *yp);
392 >                *psp = (uby8 *)malloc(sizeof(uby8) * *xp * *yp);
393                  if (*psp == NULL) {
394                          free((MEM_PTR)lp);
395                          tmDone(tms);
# Line 423 | Line 422 | done:                                          /* clean up */
422  
423   static void
424   colrNewSpace(tms)               /* color space changed for tone mapping */
425 < register TMstruct       *tms;
425 > TMstruct        *tms;
426   {
427 <        register COLRDATA       *cd;
427 >        COLRDATA        *cd;
428          double  d;
429          int     i, j;
430  
431          cd = (COLRDATA *)tms->pd[colrReg];
432          for (i = 3; i--; )
433                  cd->clfb[i] = 0x1000*tms->clf[i] + .5;
435 fprintf(stderr, "(%d %d %d)\n", cd->clfb[0], cd->clfb[1], cd->clfb[2]);
434          cd->inpsfb = tmCvLuminance(tms->inpsf);
435          for (i = 3; i--; )
436                  for (j = 3; j--; ) {
# Line 444 | Line 442 | fprintf(stderr, "(%d %d %d)\n", cd->clfb[0], cd->clfb[
442  
443   static MEM_PTR
444   colrInit(tms)                   /* initialize private data for tone mapping */
445 < register TMstruct       *tms;
445 > TMstruct        *tms;
446   {
447 <        register COLRDATA       *cd;
448 <        register int    i;
447 >        COLRDATA        *cd;
448 >        int     i;
449                                          /* allocate our data */
450          cd = (COLRDATA *)malloc(sizeof(COLRDATA));
451          if (cd == NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines