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.34 by greg, Sat Dec 28 18:05:14 2019 UTC

# Line 9 | Line 9 | static const char      RCSid[] = "$Id$";
9  
10   #include "copyright.h"
11  
12 < #include        <stdio.h>
13 < #include        <string.h>
12 > #include        <stdlib.h>
13   #include        <math.h>
15 #include        <time.h>
14  
17 #include        "tmprivat.h"
18 #include        "resolu.h"
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  1024
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 38 | Line 37 | static struct tmPackage        colrPkg = {     /* our package fun
37   };
38   static int      colrReg = -1;           /* our package registration number */
39  
40 < #define LOGISZ  260
42 < static TMbright logi[LOGISZ];
40 > static TMbright logi[256];
41  
42  
43   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   )
51   {
52          static const char       funcName[] = "tmCvColrs";
53          int     cmon[4];
54 <        register COLRDATA       *cd;
55 <        register int    i, j, li, bi;
56 <        int32   vl;
54 >        COLRDATA        *cd;
55 >        int     i, j, bi;
56 >        int32   li, vl;
57  
58          if (tms == NULL)
59                  returnErr(TM_E_TMINVAL);
# Line 67 | Line 65 | int    len
65                          returnErr(TM_E_CODERR1);
66                  for (i = 256; i--; )
67                          logi[i] = TM_BRTSCALE*log((i+.5)/256.) - .5;
70                for (i = 256; i < LOGISZ; i++)
71                        logi[i] = 0;
68                  tmMkMesofact();
69          }
70          if ((cd = (COLRDATA *)tmPkgData(tms,colrReg)) == NULL)
# Line 86 | Line 82 | int    len
82                  } else
83                          copycolr(cmon, scan[i]);
84                                                          /* world luminance */
85 <                li =    cd->clfb[RED]*cmon[RED] +
86 <                        cd->clfb[GRN]*cmon[GRN] +
87 <                        cd->clfb[BLU]*cmon[BLU] ;
88 <                if (li >= 0xfff00) li = 255;
85 >                li =    cd->clfb[RED]*(int32)cmon[RED] +
86 >                        cd->clfb[GRN]*(int32)cmon[GRN] +
87 >                        cd->clfb[BLU]*(int32)cmon[BLU] ;
88 >                if (li >= 1L<<(12+8)) li = 255;
89                  else li >>= 12;
90                  bi = BRT2SCALE(cmon[EXP]-COLXS) + cd->inpsfb;
91                  if (li > 0)
# Line 123 | Line 119 | int    len
119                          for (j = 3; j--; )
120                                  if (cmon[j] < 0) cmon[j] = 0;
121                  }
122 <                bi = ( (int32)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 12;
122 >                bi = ( (uint32)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 12;
123                  cs[3*i  ] = bi>=GAMTSZ ? 255 : cd->gamb[bi];
124 <                bi = ( (int32)GAMTSZ*cd->clfb[GRN]*cmon[GRN]/li ) >> 12;
124 >                bi = ( (uint32)GAMTSZ*cd->clfb[GRN]*cmon[GRN]/li ) >> 12;
125                  cs[3*i+1] = bi>=GAMTSZ ? 255 : cd->gamb[bi];
126 <                bi = ( (int32)GAMTSZ*cd->clfb[BLU]*cmon[BLU]/li ) >> 12;
126 >                bi = ( (uint32)GAMTSZ*cd->clfb[BLU]*cmon[BLU]/li ) >> 12;
127                  cs[3*i+2] = bi>=GAMTSZ ? 255 : cd->gamb[bi];
128          }
129          returnOK;
# Line 149 | Line 145 | static struct radhead {
145  
146   static int
147   headline(                       /* grok a header line */
148 <        register char   *s,
148 >        char    *s,
149          void    *vrh
150   )
151   {
152 <        char    fmt[32];
153 <        register struct radhead *rh = vrh;
152 >        char    fmt[MAXFMTLEN];
153 >        struct radhead  *rh = vrh;
154  
155          if (formatval(fmt, s)) {
156                  if (!strcmp(fmt, COLRFMT))
# Line 182 | Line 178 | int
178   tmLoadPicture(                          /* convert Radiance picture */
179   TMstruct        *tms,
180   TMbright        **lpp,
181 < BYTE    **cpp,
181 > uby8    **cpp,
182   int     *xp,
183   int     *yp,
184   char    *fname,
# Line 226 | Line 222 | FILE   *fp
222          if (*lpp == NULL)
223                  goto done;
224          if (cpp != TM_NOCHROMP) {
225 <                *cpp = (BYTE *)malloc(3*sizeof(BYTE) * *xp * *yp);
225 >                *cpp = (uby8 *)malloc(3*sizeof(uby8) * *xp * *yp);
226                  if (*cpp == NULL)
227                          goto done;
228          }
# Line 263 | Line 259 | done:                                          /* clean up */
259   #ifdef PCOND
260   static int                                      /* run pcond to map picture */
261   dopcond(psp, xp, yp, flags, monpri, gamval, Lddyn, Ldmax, fname)
262 < BYTE    **psp;
262 > uby8    **psp;
263   int     *xp, *yp;
264   int     flags;
265   RGBPRIMP        monpri;
# Line 274 | Line 270 | char   *fname;
270          TMstruct        *tms = NULL;
271          char    cmdbuf[1024];
272          FILE    *infp;
273 <        register COLR   *scan;
274 <        register BYTE   *rp;
273 >        COLR    *scan;
274 >        uby8    *rp;
275          int     y;
276 <        register int    x;
276 >        int     x;
277                                          /* set up gamma correction */
278          if (setcolrcor(pow, 1./gamval) < 0)
279                  returnErr(TM_E_NOMEM);
# Line 314 | Line 310 | char   *fname;
310                                          /* allocate arrays */
311          scan = (COLR *)malloc(sizeof(COLR) * *xp);
312          if (flags & TM_F_BW)
313 <                rp = (BYTE *)malloc(sizeof(BYTE) * *xp * *yp);
313 >                rp = (uby8 *)malloc(sizeof(uby8) * *xp * *yp);
314          else
315 <                rp = (BYTE *)malloc(3*sizeof(BYTE) * *xp * *yp);
315 >                rp = (uby8 *)malloc(3*sizeof(uby8) * *xp * *yp);
316          if (((*psp = rp) == NULL) | (scan == NULL)) {
317                  pclose(infp);
318                  returnErr(TM_E_NOMEM);
# Line 350 | Line 346 | char   *fname;
346  
347   int                                     /* map a Radiance picture */
348   tmMapPicture(psp, xp, yp, flags, monpri, gamval, Lddyn, Ldmax, fname, fp)
349 < BYTE    **psp;
349 > uby8    **psp;
350   int     *xp, *yp;
351   int     flags;
352   RGBPRIMP        monpri;
# Line 359 | Line 355 | char   *fname;
355   FILE    *fp;
356   {
357          char    *funcName = fname==NULL ? "tmMapPicture" : fname;
358 <        TMstruct        *tms;
359 <        BYTE    *cp;
358 >        TMstruct        *tms = NULL;
359 >        uby8    *cp;
360          TMbright        *lp;
361          int     err;
362                                                  /* check arguments */
# Line 390 | Line 386 | FILE   *fp;
386          }
387                                                  /* allocate space for result */
388          if (flags & TM_F_BW) {
389 <                *psp = (BYTE *)malloc(sizeof(BYTE) * *xp * *yp);
389 >                *psp = (uby8 *)malloc(sizeof(uby8) * *xp * *yp);
390                  if (*psp == NULL) {
391                          free((MEM_PTR)lp);
392                          tmDone(tms);
# Line 423 | Line 419 | done:                                          /* clean up */
419  
420   static void
421   colrNewSpace(tms)               /* color space changed for tone mapping */
422 < register TMstruct       *tms;
422 > TMstruct        *tms;
423   {
424 <        register COLRDATA       *cd;
424 >        COLRDATA        *cd;
425          double  d;
426          int     i, j;
427  
428          cd = (COLRDATA *)tms->pd[colrReg];
429          for (i = 3; i--; )
430                  cd->clfb[i] = 0x1000*tms->clf[i] + .5;
435 fprintf(stderr, "(%d %d %d)\n", cd->clfb[0], cd->clfb[1], cd->clfb[2]);
431          cd->inpsfb = tmCvLuminance(tms->inpsf);
432          for (i = 3; i--; )
433                  for (j = 3; j--; ) {
# Line 444 | Line 439 | fprintf(stderr, "(%d %d %d)\n", cd->clfb[0], cd->clfb[
439  
440   static MEM_PTR
441   colrInit(tms)                   /* initialize private data for tone mapping */
442 < register TMstruct       *tms;
442 > TMstruct        *tms;
443   {
444 <        register COLRDATA       *cd;
445 <        register int    i;
444 >        COLRDATA        *cd;
445 >        int     i;
446                                          /* allocate our data */
447          cd = (COLRDATA *)malloc(sizeof(COLRDATA));
448          if (cd == NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines