22 |
|
struct tmPackage *tmPkg[TM_MAXPKG]; |
23 |
|
int tmNumPkgs = 0; /* number of registered packages */ |
24 |
|
|
25 |
– |
int tmLastError; /* last error incurred by library */ |
26 |
– |
char *tmLastFunction; /* error-generating function name */ |
25 |
|
|
28 |
– |
|
26 |
|
TMstruct * |
27 |
|
tmInit( /* initialize new tone mapping */ |
28 |
|
int flags, |
68 |
|
tmnew->inpsf = WHTEFFICACY; |
69 |
|
tmnew->cmat[0][1] = tmnew->cmat[0][2] = tmnew->cmat[1][0] = |
70 |
|
tmnew->cmat[1][2] = tmnew->cmat[2][0] = tmnew->cmat[2][1] = 0.; |
71 |
+ |
tmnew->inpdat = NULL; |
72 |
|
tmnew->hbrmin = 10; tmnew->hbrmax = -10; |
73 |
|
tmnew->histo = NULL; |
74 |
|
tmnew->mbrmin = 10; tmnew->mbrmax = -10; |
76 |
|
/* zero private data */ |
77 |
|
for (i = TM_MAXPKG; i--; ) |
78 |
|
tmnew->pd[i] = NULL; |
79 |
+ |
tmnew->lastError = TM_E_OK; |
80 |
+ |
tmnew->lastFunc = "NoErr"; |
81 |
|
/* return new TMstruct */ |
82 |
|
return(tmnew); |
83 |
|
} |
87 |
|
tmSetSpace( /* set input color space for conversions */ |
88 |
|
TMstruct *tms, |
89 |
|
RGBPRIMP pri, |
90 |
< |
double sf |
90 |
> |
double sf, |
91 |
> |
MEM_PTR dat |
92 |
|
) |
93 |
|
{ |
94 |
< |
static char funcName[] = "tmSetSpace"; |
94 |
> |
static const char funcName[] = "tmSetSpace"; |
95 |
|
int i, j; |
96 |
|
/* error check */ |
97 |
|
if (tms == NULL) |
99 |
|
if (sf <= 1e-12) |
100 |
|
returnErr(TM_E_ILLEGAL); |
101 |
|
/* check if no change */ |
102 |
< |
if (pri == tms->inppri && FEQ(sf, tms->inpsf)) |
102 |
> |
if (pri == tms->inppri && FEQ(sf, tms->inpsf) && dat == tms->inpdat) |
103 |
|
returnOK; |
104 |
|
tms->inppri = pri; /* let's set it */ |
105 |
|
tms->inpsf = sf; |
106 |
+ |
tms->inpdat = dat; |
107 |
|
|
108 |
|
if (tms->flags & TM_F_BW) { /* color doesn't matter */ |
109 |
|
tms->monpri = tms->inppri; /* eliminate xform */ |
169 |
|
int len |
170 |
|
) |
171 |
|
{ |
172 |
< |
static char funcName[] = "tmCvColors"; |
172 |
> |
static const char funcName[] = "tmCvColors"; |
173 |
|
static COLOR csmall = {.5*MINLUM, .5*MINLUM, .5*MINLUM}; |
174 |
+ |
static BYTE gamtab[1024]; |
175 |
+ |
static double curgam = .0; |
176 |
|
COLOR cmon; |
177 |
|
double lum, slum; |
178 |
|
double d; |
182 |
|
returnErr(TM_E_TMINVAL); |
183 |
|
if ((ls == NULL) | (scan == NULL) | (len < 0)) |
184 |
|
returnErr(TM_E_ILLEGAL); |
185 |
+ |
if (cs != TM_NOCHROM && fabs(tms->mongam - curgam) > .02) { |
186 |
+ |
curgam = tms->mongam; /* (re)build table */ |
187 |
+ |
for (i = 1024; i--; ) |
188 |
+ |
gamtab[i] = (int)(256.*pow((i+.5)/1024., 1./curgam)); |
189 |
+ |
} |
190 |
|
for (i = len; i--; ) { |
191 |
|
if (tmNeedMatrix(tms)) { /* get monitor RGB */ |
192 |
|
colortrans(cmon, tms->cmat, scan[i]); |
195 |
|
cmon[GRN] = tms->inpsf*scan[i][GRN]; |
196 |
|
cmon[BLU] = tms->inpsf*scan[i][BLU]; |
197 |
|
} |
198 |
+ |
#ifdef isnan |
199 |
+ |
if (isnan(cmon[RED]) || isinf(cmon[RED])) cmon[RED] = .0f; |
200 |
+ |
if (isnan(cmon[GRN]) || isinf(cmon[GRN])) cmon[GRN] = .0f; |
201 |
+ |
if (isnan(cmon[BLU]) || isinf(cmon[BLU])) cmon[BLU] = .0f; |
202 |
+ |
#endif |
203 |
|
/* world luminance */ |
204 |
|
lum = tms->clf[RED]*cmon[RED] + |
205 |
|
tms->clf[GRN]*cmon[GRN] + |
238 |
|
cmon[RED] = cmon[GRN] = cmon[BLU] = lum; |
239 |
|
} |
240 |
|
d = tms->clf[RED]*cmon[RED]/lum; |
241 |
< |
cs[3*i ] = d>=.999 ? 255 : |
228 |
< |
(int)(256.*pow(d, 1./tms->mongam)); |
241 |
> |
cs[3*i ] = d>=.999 ? 255 : gamtab[(int)(1024.*d)]; |
242 |
|
d = tms->clf[GRN]*cmon[GRN]/lum; |
243 |
< |
cs[3*i+1] = d>=.999 ? 255 : |
231 |
< |
(int)(256.*pow(d, 1./tms->mongam)); |
243 |
> |
cs[3*i+1] = d>=.999 ? 255 : gamtab[(int)(1024.*d)]; |
244 |
|
d = tms->clf[BLU]*cmon[BLU]/lum; |
245 |
< |
cs[3*i+2] = d>=.999 ? 255 : |
234 |
< |
(int)(256.*pow(d, 1./tms->mongam)); |
245 |
> |
cs[3*i+2] = d>=.999 ? 255 : gamtab[(int)(1024.*d)]; |
246 |
|
} |
247 |
|
returnOK; |
248 |
|
} |
249 |
|
|
250 |
|
|
251 |
+ |
TMbright |
252 |
+ |
tmCvLuminance( /* convert a single luminance */ |
253 |
+ |
double lum |
254 |
+ |
) |
255 |
+ |
{ |
256 |
+ |
double d; |
257 |
+ |
|
258 |
+ |
if (lum <= TM_NOLUM) |
259 |
+ |
return(TM_NOBRT); |
260 |
+ |
d = TM_BRTSCALE*log(lum); |
261 |
+ |
if (d > 0.) |
262 |
+ |
return((TMbright)(d+.5)); |
263 |
+ |
return((TMbright)(d-.5)); |
264 |
+ |
} |
265 |
+ |
|
266 |
+ |
|
267 |
|
int |
268 |
|
tmCvGrays( /* convert float gray values */ |
269 |
|
TMstruct *tms, |
272 |
|
int len |
273 |
|
) |
274 |
|
{ |
275 |
< |
static char funcName[] = "tmCvGrays"; |
275 |
> |
static const char funcName[] = "tmCvGrays"; |
276 |
|
double d; |
277 |
|
int i; |
278 |
|
|
299 |
|
int wt |
300 |
|
) |
301 |
|
{ |
302 |
< |
static char funcName[] = "tmAddHisto"; |
302 |
> |
static const char funcName[] = "tmAddHisto"; |
303 |
|
int oldorig=0, oldlen, horig, hlen; |
304 |
|
int i, j; |
305 |
|
|
402 |
|
double gamval |
403 |
|
) |
404 |
|
{ |
405 |
< |
static char funcName[] = "tmFixedMapping"; |
405 |
> |
static const char funcName[] = "tmFixedMapping"; |
406 |
|
double d; |
407 |
|
int i; |
408 |
|
|
429 |
|
double Ldmax |
430 |
|
) |
431 |
|
{ |
432 |
< |
static char funcName[] = "tmComputeMapping"; |
432 |
> |
static const char funcName[] = "tmComputeMapping"; |
433 |
|
int *histo; |
434 |
|
float *cumf; |
435 |
|
int brt0, histlen, threshold, ceiling, trimmings; |
537 |
|
int len |
538 |
|
) |
539 |
|
{ |
540 |
< |
static char funcName[] = "tmMapPixels"; |
540 |
> |
static const char funcName[] = "tmMapPixels"; |
541 |
|
int32 li, pv; |
542 |
|
|
543 |
|
if (tms == NULL || tms->lumap == NULL) |
649 |
|
|
650 |
|
int |
651 |
|
tmErrorReturn( /* error return (with message) */ |
652 |
< |
char *func, |
652 |
> |
const char *func, |
653 |
|
TMstruct *tms, |
654 |
|
int err |
655 |
|
) |
656 |
|
{ |
657 |
< |
tmLastFunction = func; |
658 |
< |
tmLastError = err; |
659 |
< |
if (tms != NULL && tms->flags & TM_F_NOSTDERR) |
660 |
< |
return(err); |
657 |
> |
if (tms != NULL) { |
658 |
> |
tms->lastFunc = func; |
659 |
> |
tms->lastError = err; |
660 |
> |
if (tms->flags & TM_F_NOSTDERR) |
661 |
> |
return(err); |
662 |
> |
} |
663 |
|
fputs(func, stderr); |
664 |
|
fputs(": ", stderr); |
665 |
|
fputs(tmErrorMessage[err], stderr); |