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.2 by greg, Wed Apr 16 20:28:05 1997 UTC vs.
Revision 3.34 by greg, Sat Dec 28 18:05:14 2019 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1997 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
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        <stdio.h>
10 > #include "copyright.h"
11 >
12 > #include        <stdlib.h>
13   #include        <math.h>
14 +
15 + #ifdef PCOND
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 < extern char     *tempbuffer();
24 > typedef struct {
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 */
29 > } COLRDATA;
30  
31 < #define LOGISZ  260
32 < static TMbright logi[LOGISZ];
33 < static BYTE     photofact[BMESUPPER-BMESLOWER];
31 > static MEM_PTR  colrInit(TMstruct *);
32 > static void     colrNewSpace(TMstruct *);
33 > static gethfunc headline;
34  
35 + static struct tmPackage colrPkg = {     /* our package functions */
36 +        colrInit, colrNewSpace, free
37 + };
38 + static int      colrReg = -1;           /* our package registration number */
39  
40 + static TMbright logi[256];
41 +
42 +
43   int
44 < tmCvColrs(ls, cs, scan, len)            /* tone map RGBE/XYZE colors */
45 < TMbright        *ls;
46 < BYTE    *cs;
47 < COLR    *scan;
48 < int     len;
44 > tmCvColrs(                              /* convert RGBE/XYZE colors */
45 > TMstruct        *tms,
46 > TMbright        *ls,
47 > uby8    *cs,
48 > COLR    *scan,
49 > int     len
50 > )
51   {
52 <        static char     funcName[] = "tmCvColrs";
53 <        COLR    cmon;
54 <        register int    i, bi, li;
52 >        static const char       funcName[] = "tmCvColrs";
53 >        int     cmon[4];
54 >        COLRDATA        *cd;
55 >        int     i, j, bi;
56 >        int32   li, vl;
57  
58 <        if (tmTop == NULL)
58 >        if (tms == 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 (tmTop->flags & TM_F_NEEDMAT) {      /* need floating point */
63 <                register COLOR  *newscan;
64 <                newscan = (COLOR *)tempbuffer(len*sizeof(COLOR));
65 <                if (newscan == NULL)
44 <                        returnErr(TM_E_NOMEM);
45 <                for (i = len; i--; )
46 <                        colr_color(newscan[i], scan[i]);
47 <                return(tmCvColors(ls, cs, newscan, len));
48 <        }
49 <        if (logi[0] == 0) {                     /* build tables if necessary */
62 >        if (colrReg < 0) {                      /* build tables if necessary */
63 >                colrReg = tmRegPkg(&colrPkg);
64 >                if (colrReg < 0)
65 >                        returnErr(TM_E_CODERR1);
66                  for (i = 256; i--; )
67                          logi[i] = TM_BRTSCALE*log((i+.5)/256.) - .5;
68 <                for (i = 256; i < LOGISZ; i++)
53 <                        logi[i] = logi[255];
54 <                for (i = BMESLOWER; i < BMESUPPER; i++)
55 <                        photofact[i-BMESLOWER] = 256. *
56 <                                        (tmLuminance(i) - LMESLOWER) /
57 <                                        (LMESUPPER - LMESLOWER);
68 >                tmMkMesofact();
69          }
70 +        if ((cd = (COLRDATA *)tmPkgData(tms,colrReg)) == NULL)
71 +                returnErr(TM_E_NOMEM);
72          for (i = len; i--; ) {
73 <                copycolr(cmon, scan[i]);
73 >                if (tmNeedMatrix(tms)) {                /* apply color xform */
74 >                        for (j = 3; j--; ) {
75 >                                vl =    cd->cmatb[j][RED]*(int32)scan[i][RED] +
76 >                                        cd->cmatb[j][GRN]*(int32)scan[i][GRN] +
77 >                                        cd->cmatb[j][BLU]*(int32)scan[i][BLU] ;
78 >                                if (vl < 0) cmon[j] = vl/0x10000;
79 >                                else cmon[j] = vl>>16;
80 >                        }
81 >                        cmon[EXP] = scan[i][EXP];
82 >                } else
83 >                        copycolr(cmon, scan[i]);
84                                                          /* world luminance */
85 <                li =  ( tmTop->clfb[RED]*cmon[RED] +
86 <                        tmTop->clfb[GRN]*cmon[GRN] +
87 <                        tmTop->clfb[BLU]*cmon[BLU] ) >> 8;
88 <                bi = BRT2SCALE*(cmon[EXP]-COLXS) +
89 <                                logi[li] + tmTop->inpsfb;
90 <                if (bi < MINBRT) {
91 <                        bi = MINBRT-1;                  /* bogus value */
92 <                        li++;                           /* avoid li==0 */
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)
92 >                        bi += logi[li];
93 >                else {
94 >                        bi += logi[0];
95 >                        li = 1;                         /* avoid /0 */
96                  }
97                  ls[i] = bi;
98                  if (cs == TM_NOCHROM)                   /* no color? */
99                          continue;
100                                                          /* mesopic adj. */
101 <                if (tmTop->flags & TM_F_MESOPIC && bi < BMESUPPER) {
102 <                        register int    pf, sli = normscot(cmon);
103 <                        if (bi < BMESLOWER)
101 >                if (tms->flags & TM_F_MESOPIC && bi < BMESUPPER) {
102 >                        int     pf, sli = normscot(cmon);
103 >                        if (bi < BMESLOWER) {
104                                  cmon[RED] = cmon[GRN] = cmon[BLU] = sli;
105 <                        else {
106 <                                if (tmTop->flags & TM_F_BW)
105 >                        } else {
106 >                                if (tms->flags & TM_F_BW)
107                                          cmon[RED] = cmon[GRN] = cmon[BLU] = li;
108 <                                pf = photofact[bi-BMESLOWER];
108 >                                pf = tmMesofact[bi-BMESLOWER];
109                                  sli *= 256 - pf;
110 <                                cmon[RED] = ( sli + pf*cmon[RED] ) >> 8;
111 <                                cmon[GRN] = ( sli + pf*cmon[GRN] ) >> 8;
112 <                                cmon[BLU] = ( sli + pf*cmon[BLU] ) >> 8;
110 >                                for (j = 3; j--; ) {
111 >                                        cmon[j] = sli + pf*cmon[j];
112 >                                        if (cmon[j] <= 0) cmon[j] = 0;
113 >                                        else cmon[j] >>= 8;
114 >                                }
115                          }
116 <                } else if (tmTop->flags & TM_F_BW) {
116 >                } else if (tms->flags & TM_F_BW) {
117                          cmon[RED] = cmon[GRN] = cmon[BLU] = li;
118 +                } else {
119 +                        for (j = 3; j--; )
120 +                                if (cmon[j] < 0) cmon[j] = 0;
121                  }
122 <                bi = ( (int4)TM_GAMTSZ*tmTop->clfb[RED]*cmon[RED]/li ) >> 8;
123 <                cs[3*i  ] = bi>=TM_GAMTSZ ? 255 : tmTop->gamb[bi];
124 <                bi = ( (int4)TM_GAMTSZ*tmTop->clfb[GRN]*cmon[GRN]/li ) >> 8;
125 <                cs[3*i+1] = bi>=TM_GAMTSZ ? 255 : tmTop->gamb[bi];
126 <                bi = ( (int4)TM_GAMTSZ*tmTop->clfb[BLU]*cmon[BLU]/li ) >> 8;
127 <                cs[3*i+2] = bi>=TM_GAMTSZ ? 255 : tmTop->gamb[bi];
122 >                bi = ( (uint32)GAMTSZ*cd->clfb[RED]*cmon[RED]/li ) >> 12;
123 >                cs[3*i  ] = bi>=GAMTSZ ? 255 : cd->gamb[bi];
124 >                bi = ( (uint32)GAMTSZ*cd->clfb[GRN]*cmon[GRN]/li ) >> 12;
125 >                cs[3*i+1] = bi>=GAMTSZ ? 255 : cd->gamb[bi];
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;
130   }
# Line 113 | Line 144 | static struct radhead {
144  
145  
146   static int
147 < headline(s, rh)                 /* grok a header line */
148 < register char   *s;
149 < register struct radhead *rh;
147 > headline(                       /* grok a header line */
148 >        char    *s,
149 >        void    *vrh
150 > )
151   {
152 <        char    fmt[32];
152 >        char    fmt[MAXFMTLEN];
153 >        struct radhead  *rh = vrh;
154  
155          if (formatval(fmt, s)) {
156                  if (!strcmp(fmt, COLRFMT))
# Line 126 | Line 159 | register struct radhead        *rh;
159                          rh->format = FMTCIE;
160                  else
161                          rh->format = FMTBAD;
162 <                return;
162 >                return(0);
163          }
164          if (isexpos(s)) {
165                  rh->expos *= exposval(s);
166 <                return;
166 >                return(0);
167          }
168          if (isprims(s)) {
169                  primsval(rh->mypri, s);
170                  rh->primp = rh->mypri;
171 <                return;
171 >                return(0);
172          }
173 +        return(0);
174   }
175  
176  
177   int
178 < tmLoadPicture(lpp, cpp, xp, yp, fname, fp)      /* convert Radiance picture */
179 < TMbright        **lpp;
180 < BYTE    **cpp;
181 < int     *xp, *yp;
182 < char    *fname;
183 < FILE    *fp;
178 > tmLoadPicture(                          /* convert Radiance picture */
179 > TMstruct        *tms,
180 > TMbright        **lpp,
181 > uby8    **cpp,
182 > int     *xp,
183 > int     *yp,
184 > char    *fname,
185 > FILE    *fp
186 > )
187   {
188          char    *funcName = fname==NULL ? "tmLoadPicture" : fname;
189          FILE    *inpf;
# Line 155 | Line 192 | FILE   *fp;
192          COLR    *scanin = NULL;
193          int     i;
194                                                  /* check arguments */
195 <        if (tmTop == NULL)
195 >        if (tms == NULL)
196                  returnErr(TM_E_TMINVAL);
197 <        if (lpp == NULL | xp == NULL | yp == NULL |
198 <                        (fname == NULL & fp == TM_GETFILE))
197 >        if ((lpp == NULL) | (xp == NULL) | (yp == NULL) |
198 >                        ((fname == NULL) & (fp == TM_GETFILE)))
199                  returnErr(TM_E_ILLEGAL);
200          *xp = *yp = 0;                          /* error precaution */
201 <        if ((inpf = fp) == TM_GETFILE && (inpf = fopen(fname, "r")) == NULL)
201 >        if ((inpf = fp) == TM_GETFILE && (inpf = fopen(fname, "rb")) == NULL)
202                  returnErr(TM_E_BADFILE);
203 +        *lpp = NULL;
204 +        if (cpp != TM_NOCHROMP) *cpp = NULL;
205          info = rhdefault;                       /* get our header */
206 <        getheader(inpf, headline, (char *)&info);
207 <        if (info.format == FMTBAD | info.expos <= 0. ||
206 >        getheader(inpf, headline, &info);
207 >        if ((info.format == FMTBAD) | (info.expos <= 0.) ||
208                          fgetresolu(xp, yp, inpf) < 0) {
209                  err = TM_E_BADFILE; goto done;
210          }
# Line 176 | Line 215 | FILE   *fp;
215          else if (info.format == FMTCIE)
216                  info.primp = TM_XYZPRIM;
217                                                  /* prepare library */
218 <        if ((err = tmSetSpace(info.primp, 1./info.expos)) != TM_E_OK)
218 >        if ((err = tmSetSpace(tms, info.primp, 1./info.expos, NULL)) != TM_E_OK)
219                  goto done;
220          err = TM_E_NOMEM;                       /* allocate arrays */
221          *lpp = (TMbright *)malloc(sizeof(TMbright) * *xp * *yp);
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 195 | Line 234 | FILE   *fp;
234                  if (freadcolrs(scanin, *xp, inpf) < 0) {
235                          err = TM_E_BADFILE; break;
236                  }
237 <                err = tmCvColrs(*lpp + (i * *xp),
237 >                err = tmCvColrs(tms, *lpp + (i * *xp),
238                          cpp==TM_NOCHROMP ? TM_NOCHROM : *cpp + (i * 3 * *xp),
239                                  scanin, *xp);
240                  if (err != TM_E_OK)
# Line 205 | Line 244 | done:                                          /* clean up */
244          if (fp == NULL)
245                  fclose(inpf);
246          if (scanin != NULL)
247 <                free((char *)scanin);
248 <        if (err != TM_E_OK)
247 >                free((MEM_PTR)scanin);
248 >        if (err != TM_E_OK) {
249 >                if (*lpp != NULL)
250 >                        free((MEM_PTR)*lpp);
251 >                if (cpp != TM_NOCHROMP && *cpp != NULL)
252 >                        free((MEM_PTR)*cpp);
253                  returnErr(err);
254 +        }
255          returnOK;
256   }
257  
258  
259 < int                                     /* run pcond to map picture */
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 222 | Line 267 | double gamval, Lddyn, Ldmax;
267   char    *fname;
268   {
269          char    *funcName = fname;
270 <        char    cmdbuf[512];
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);
280                                          /* create command */
281 <        strcpy(cmdbuf, "pcond ");
281 >        strcpy(cmdbuf, PCOND);
282          if (flags & TM_F_HCONTR)
283 <                strcat(cmdbuf, "-s ");
283 >                strcat(cmdbuf, " -s");
284          if (flags & TM_F_MESOPIC)
285 <                strcat(cmdbuf, "-c ");
285 >                strcat(cmdbuf, " -c");
286          if (flags & TM_F_LINEAR)
287 <                strcat(cmdbuf, "-l ");
287 >                strcat(cmdbuf, " -l");
288          if (flags & TM_F_ACUITY)
289 <                strcat(cmdbuf, "-a ");
289 >                strcat(cmdbuf, " -a");
290          if (flags & TM_F_VEIL)
291 <                strcat(cmdbuf, "-v ");
291 >                strcat(cmdbuf, " -v");
292          if (flags & TM_F_CWEIGHT)
293 <                strcat(cmdbuf, "-w ");
294 <        sprintf(cmdbuf+strlen(cmdbuf),
295 <                        "-p %f %f %f %f %f %f %f %f -d %f -u %f %s",
296 <                        monpri[RED][CIEX], monpri[RED][CIEY],
297 <                        monpri[GRN][CIEX], monpri[GRN][CIEY],
298 <                        monpri[BLU][CIEX], monpri[BLU][CIEY],
299 <                        monpri[WHT][CIEX], monpri[WHT][CIEY],
300 <                        Lddyn, Ldmax, fname);
293 >                strcat(cmdbuf, " -w");
294 >        if (monpri != stdprims)
295 >                sprintf(cmdbuf+strlen(cmdbuf), " -p %f %f %f %f %f %f %f %f",
296 >                                monpri[RED][CIEX], monpri[RED][CIEY],
297 >                                monpri[GRN][CIEX], monpri[GRN][CIEY],
298 >                                monpri[BLU][CIEX], monpri[BLU][CIEY],
299 >                                monpri[WHT][CIEX], monpri[WHT][CIEY]);
300 >        sprintf(cmdbuf+strlen(cmdbuf), " -d %f -u %f %s", Lddyn, Ldmax, fname);
301                                          /* start pcond */
302          if ((infp = popen(cmdbuf, "r")) == NULL)
303                  returnErr(TM_E_BADFILE);
# Line 264 | 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);
316 <        if ((*psp = rp) == NULL | scan == NULL) {
315 >                rp = (uby8 *)malloc(3*sizeof(uby8) * *xp * *yp);
316 >        if (((*psp = rp) == NULL) | (scan == NULL)) {
317                  pclose(infp);
318                  returnErr(TM_E_NOMEM);
319          }
# Line 275 | Line 321 | char   *fname;
321          for (y = 0; y < *yp; y++) {
322                  if (freadcolrs(scan, *xp, infp) < 0) {
323                          pclose(infp);
324 <                        free((char *)scan);
325 <                        free((char *)*psp);
324 >                        free((MEM_PTR)scan);
325 >                        free((MEM_PTR)*psp);
326                          *psp = NULL;
327                          returnErr(TM_E_BADFILE);
328                  }
# Line 291 | Line 337 | char   *fname;
337                                  *rp++ = scan[x][BLU];
338                          }
339          }
340 <        free((char *)scan);
340 >        free((MEM_PTR)scan);
341          pclose(infp);
342          returnOK;
343   }
344 + #endif
345  
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 308 | Line 355 | char   *fname;
355   FILE    *fp;
356   {
357          char    *funcName = fname==NULL ? "tmMapPicture" : fname;
358 <        FILE    *inpf;
359 <        BYTE    *cp;
358 >        TMstruct        *tms = NULL;
359 >        uby8    *cp;
360          TMbright        *lp;
361          int     err;
362                                                  /* check arguments */
363 <        if (psp == NULL | xp == NULL | yp == NULL | monpri == NULL |
364 <                        (fname == NULL & fp == TM_GETFILE))
363 >        if ((psp == NULL) | (xp == NULL) | (yp == NULL) | (monpri == NULL) |
364 >                        ((fname == NULL) & (fp == TM_GETFILE)))
365                  returnErr(TM_E_ILLEGAL);
366                                                  /* set defaults */
367          if (gamval < MINGAM) gamval = DEFGAM;
368          if (Lddyn < MINLDDYN) Lddyn = DEFLDDYN;
369          if (Ldmax < MINLDMAX) Ldmax = DEFLDMAX;
370          if (flags & TM_F_BW) monpri = stdprims;
371 + #ifdef PCOND
372                                                  /* check for pcond run */
373          if (fp == TM_GETFILE && flags & TM_F_UNIMPL)
374                  return( dopcond(psp, xp, yp, flags,
375                                  monpri, gamval, Lddyn, Ldmax, fname) );
376 + #endif
377                                                  /* initialize tone mapping */
378 <        if (tmInit(flags, monpri, gamval) == NULL)
378 >        if ((tms = tmInit(flags, monpri, gamval)) == NULL)
379                  returnErr(TM_E_NOMEM);
380                                                  /* load & convert picture */
381 <        err = tmLoadPicture(&lp, (flags&TM_F_BW) ? TM_NOCHROMP : &cp,
381 >        err = tmLoadPicture(tms, &lp, (flags&TM_F_BW) ? TM_NOCHROMP : &cp,
382                          xp, yp, fname, fp);
383          if (err != TM_E_OK) {
384 <                tmDone(NULL);
384 >                tmDone(tms);
385                  return(err);
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((char *)lp);
392 <                        tmDone(NULL);
391 >                        free((MEM_PTR)lp);
392 >                        tmDone(tms);
393                          returnErr(TM_E_NOMEM);
394                  }
395                  cp = TM_NOCHROM;
396          } else
397                  *psp = cp;
398                                                  /* compute color mapping */
399 <        err = tmAddHisto(lp, *xp * *yp, 1);
399 >        err = tmAddHisto(tms, lp, *xp * *yp, 1);
400          if (err != TM_E_OK)
401                  goto done;
402 <        err = tmComputeMapping(gamval, Lddyn, Ldmax);
402 >        err = tmComputeMapping(tms, gamval, Lddyn, Ldmax);
403          if (err != TM_E_OK)
404                  goto done;
405                                                  /* map colors */
406 <        err = tmMapPixels(*psp, lp, cp, *xp * *yp);
406 >        err = tmMapPixels(tms, *psp, lp, cp, *xp * *yp);
407  
408   done:                                           /* clean up */
409 <        free((char *)lp);
410 <        tmDone(NULL);
409 >        free((MEM_PTR)lp);
410 >        tmDone(tms);
411          if (err != TM_E_OK) {                   /* free memory on error */
412 <                free((char *)*psp);
412 >                free((MEM_PTR)*psp);
413                  *psp = NULL;
414                  returnErr(err);
415          }
416          returnOK;
417 + }
418 +
419 +
420 + static void
421 + colrNewSpace(tms)               /* color space changed for tone mapping */
422 + TMstruct        *tms;
423 + {
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;
431 +        cd->inpsfb = tmCvLuminance(tms->inpsf);
432 +        for (i = 3; i--; )
433 +                for (j = 3; j--; ) {
434 +                        d = tms->cmat[i][j] / tms->inpsf;
435 +                        cd->cmatb[i][j] = 0x10000*d + (d<0. ? -.5 : .5);
436 +                }
437 + }
438 +
439 +
440 + static MEM_PTR
441 + colrInit(tms)                   /* initialize private data for tone mapping */
442 + TMstruct        *tms;
443 + {
444 +        COLRDATA        *cd;
445 +        int     i;
446 +                                        /* allocate our data */
447 +        cd = (COLRDATA *)malloc(sizeof(COLRDATA));
448 +        if (cd == NULL)
449 +                return(NULL);
450 +        tms->pd[colrReg] = (MEM_PTR)cd;
451 +                                        /* compute gamma table */
452 +        for (i = GAMTSZ; i--; )
453 +                cd->gamb[i] = 256.*pow((i+.5)/GAMTSZ, 1./tms->mongam);
454 +                                        /* compute color and scale factors */
455 +        colrNewSpace(tms);
456 +        return((MEM_PTR)cd);
457   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines