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