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.9 by gwlarson, Wed Oct 28 09:26:03 1998 UTC vs.
Revision 3.16 by schorsch, Sat Oct 23 18:55:52 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Routines for tone mapping on Radiance RGBE and XYZE pictures.
6 < * See tonemap.h for detailed function descriptions.
6 > *
7 > * Externals declared in tonemap.h
8   */
9  
10 + #include "copyright.h"
11 +
12   #include        <stdio.h>
13 + #include        <string.h>
14   #include        <math.h>
15 + #include        <time.h>
16 +
17   #include        "tmprivat.h"
18   #include        "resolu.h"
19 + #include        "rtprocess.h"
20  
21 + #ifndef TM_PIC_CTRANS
22 + #define TM_PIC_CTRANS   1               /* transform colors? (expensive) */
23 + #endif
24  
18 extern char     *tempbuffer();
19
25   #define GAMTSZ  1024
26  
27   typedef struct {
# Line 25 | Line 30 | typedef struct {
30          TMbright        inpsfb;         /* encoded tm->inpsf */
31   } COLRDATA;
32  
33 < static MEM_PTR  colrInit();
34 < static void     colrNewSpace();
35 < extern void     free();
33 > static MEM_PTR  colrInit(struct tmStruct *);
34 > static void     colrNewSpace(struct tmStruct *);
35 > static gethfunc headline;
36 >
37   static struct tmPackage colrPkg = {     /* our package functions */
38          colrInit, colrNewSpace, free
39   };
# Line 35 | Line 41 | static int     colrReg = -1;           /* our package registration
41  
42   #define LOGISZ  260
43   static TMbright logi[LOGISZ];
38 static BYTE     photofact[BMESUPPER-BMESLOWER];
44  
45  
46   int
# Line 52 | Line 57 | int    len;
57  
58          if (tmTop == NULL)
59                  returnErr(TM_E_TMINVAL);
60 <        if (ls == NULL | scan == NULL | len < 0)
60 >        if ((ls == NULL) | (scan == NULL) | (len < 0))
61                  returnErr(TM_E_ILLEGAL);
62 + #if TM_PIC_CTRANS
63          if (tmNeedMatrix(tmTop)) {              /* need floating point */
64 + #else
65 +        if (tmTop->inppri == TM_XYZPRIM) {      /* no way around this */
66 + #endif
67                  register COLOR  *newscan;
68                  newscan = (COLOR *)tempbuffer(len*sizeof(COLOR));
69                  if (newscan == NULL)
# Line 70 | Line 79 | int    len;
79                  for (i = 256; i--; )
80                          logi[i] = TM_BRTSCALE*log((i+.5)/256.) - .5;
81                  for (i = 256; i < LOGISZ; i++)
82 <                        logi[i] = logi[255];
83 <                for (i = BMESLOWER; i < BMESUPPER; i++)
75 <                        photofact[i-BMESLOWER] = 256. *
76 <                                        (tmLuminance(i) - LMESLOWER) /
77 <                                        (LMESUPPER - LMESLOWER);
82 >                        logi[i] = 0;
83 >                tmMkMesofact();
84          }
85          if ((cd = (COLRDATA *)tmPkgData(tmTop,colrReg)) == NULL)
86                  returnErr(TM_E_NOMEM);
# Line 84 | Line 90 | int    len;
90                  li =  ( cd->clfb[RED]*cmon[RED] +
91                          cd->clfb[GRN]*cmon[GRN] +
92                          cd->clfb[BLU]*cmon[BLU] ) >> 8;
93 <                bi = BRT2SCALE*(cmon[EXP]-COLXS) +
93 >                bi = BRT2SCALE(cmon[EXP]-COLXS) +
94                                  logi[li] + cd->inpsfb;
95 <                if (bi < MINBRT) {
96 <                        bi = MINBRT-1;                  /* bogus value */
97 <                        li++;                           /* avoid li==0 */
95 >                if (li <= 0) {
96 >                        bi = TM_NOBRT;                  /* bogus value */
97 >                        li = 1;                         /* avoid li==0 */
98                  }
99                  ls[i] = bi;
100                  if (cs == TM_NOCHROM)                   /* no color? */
# Line 101 | Line 107 | int    len;
107                          else {
108                                  if (tmTop->flags & TM_F_BW)
109                                          cmon[RED] = cmon[GRN] = cmon[BLU] = li;
110 <                                pf = photofact[bi-BMESLOWER];
110 >                                pf = tmMesofact[bi-BMESLOWER];
111                                  sli *= 256 - pf;
112                                  cmon[RED] = ( sli + pf*cmon[RED] ) >> 8;
113                                  cmon[GRN] = ( sli + pf*cmon[GRN] ) >> 8;
# Line 110 | Line 116 | int    len;
116                  } else if (tmTop->flags & TM_F_BW) {
117                          cmon[RED] = cmon[GRN] = cmon[BLU] = li;
118                  }
119 <                bi = ( (int4)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 8;
119 >                bi = ( (int32)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 8;
120                  cs[3*i  ] = bi>=GAMTSZ ? 255 : cd->gamb[bi];
121 <                bi = ( (int4)GAMTSZ*cd->clfb[GRN]*cmon[GRN]/li ) >> 8;
121 >                bi = ( (int32)GAMTSZ*cd->clfb[GRN]*cmon[GRN]/li ) >> 8;
122                  cs[3*i+1] = bi>=GAMTSZ ? 255 : cd->gamb[bi];
123 <                bi = ( (int4)GAMTSZ*cd->clfb[BLU]*cmon[BLU]/li ) >> 8;
123 >                bi = ( (int32)GAMTSZ*cd->clfb[BLU]*cmon[BLU]/li ) >> 8;
124                  cs[3*i+2] = bi>=GAMTSZ ? 255 : cd->gamb[bi];
125          }
126          returnOK;
# Line 135 | Line 141 | static struct radhead {
141  
142  
143   static int
144 < headline(s, rh)                 /* grok a header line */
145 < register char   *s;
146 < register struct radhead *rh;
144 > headline(                       /* grok a header line */
145 >        register char   *s,
146 >        void    *vrh
147 > )
148   {
149          char    fmt[32];
150 +        register struct radhead *rh = vrh;
151  
152          if (formatval(fmt, s)) {
153                  if (!strcmp(fmt, COLRFMT))
# Line 180 | Line 188 | FILE   *fp;
188                                                  /* check arguments */
189          if (tmTop == NULL)
190                  returnErr(TM_E_TMINVAL);
191 <        if (lpp == NULL | xp == NULL | yp == NULL |
192 <                        (fname == NULL & fp == TM_GETFILE))
191 >        if ((lpp == NULL) | (xp == NULL) | (yp == NULL) |
192 >                        ((fname == NULL) & (fp == TM_GETFILE)))
193                  returnErr(TM_E_ILLEGAL);
194          *xp = *yp = 0;                          /* error precaution */
195          if ((inpf = fp) == TM_GETFILE && (inpf = fopen(fname, "r")) == NULL)
# Line 189 | Line 197 | FILE   *fp;
197          *lpp = NULL;
198          if (cpp != TM_NOCHROMP) *cpp = NULL;
199          info = rhdefault;                       /* get our header */
200 <        getheader(inpf, headline, (MEM_PTR)&info);
201 <        if (info.format == FMTBAD | info.expos <= 0. ||
200 >        getheader(inpf, headline, &info);
201 >        if ((info.format == FMTBAD) | (info.expos <= 0.) ||
202                          fgetresolu(xp, yp, inpf) < 0) {
203                  err = TM_E_BADFILE; goto done;
204          }
# Line 243 | Line 251 | done:                                          /* clean up */
251  
252  
253   #ifdef PCOND
254 < int                                     /* run pcond to map picture */
254 > static int                                      /* run pcond to map picture */
255   dopcond(psp, xp, yp, flags, monpri, gamval, Lddyn, Ldmax, fname)
256   BYTE    **psp;
257   int     *xp, *yp;
# Line 253 | Line 261 | double gamval, Lddyn, Ldmax;
261   char    *fname;
262   {
263          char    *funcName = fname;
264 <        char    cmdbuf[512];
264 >        char    cmdbuf[1024];
265          FILE    *infp;
266          register COLR   *scan;
267          register BYTE   *rp;
# Line 298 | Line 306 | char   *fname;
306                  rp = (BYTE *)malloc(sizeof(BYTE) * *xp * *yp);
307          else
308                  rp = (BYTE *)malloc(3*sizeof(BYTE) * *xp * *yp);
309 <        if ((*psp = rp) == NULL | scan == NULL) {
309 >        if (((*psp = rp) == NULL) | (scan == NULL)) {
310                  pclose(infp);
311                  returnErr(TM_E_NOMEM);
312          }
# Line 344 | Line 352 | FILE   *fp;
352          TMbright        *lp;
353          int     err;
354                                                  /* check arguments */
355 <        if (psp == NULL | xp == NULL | yp == NULL | monpri == NULL |
356 <                        (fname == NULL & fp == TM_GETFILE))
355 >        if ((psp == NULL) | (xp == NULL) | (yp == NULL) | (monpri == NULL) |
356 >                        ((fname == NULL) & (fp == TM_GETFILE)))
357                  returnErr(TM_E_ILLEGAL);
358                                                  /* set defaults */
359          if (gamval < MINGAM) gamval = DEFGAM;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines