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]); |
233 |
|
cmon[RED] = cmon[GRN] = cmon[BLU] = lum; |
234 |
|
} |
235 |
|
d = tms->clf[RED]*cmon[RED]/lum; |
236 |
< |
cs[3*i ] = d>=.999 ? 255 : |
228 |
< |
(int)(256.*pow(d, 1./tms->mongam)); |
236 |
> |
cs[3*i ] = d>=.999 ? 255 : gamtab[(int)(1024.*d)]; |
237 |
|
d = tms->clf[GRN]*cmon[GRN]/lum; |
238 |
< |
cs[3*i+1] = d>=.999 ? 255 : |
231 |
< |
(int)(256.*pow(d, 1./tms->mongam)); |
238 |
> |
cs[3*i+1] = d>=.999 ? 255 : gamtab[(int)(1024.*d)]; |
239 |
|
d = tms->clf[BLU]*cmon[BLU]/lum; |
240 |
< |
cs[3*i+2] = d>=.999 ? 255 : |
234 |
< |
(int)(256.*pow(d, 1./tms->mongam)); |
240 |
> |
cs[3*i+2] = d>=.999 ? 255 : gamtab[(int)(1024.*d)]; |
241 |
|
} |
242 |
|
returnOK; |
243 |
|
} |
244 |
|
|
245 |
|
|
246 |
+ |
TMbright |
247 |
+ |
tmCvLuminance( /* convert a single luminance */ |
248 |
+ |
double lum |
249 |
+ |
) |
250 |
+ |
{ |
251 |
+ |
double d; |
252 |
+ |
|
253 |
+ |
if (lum <= TM_NOLUM) |
254 |
+ |
return(TM_NOBRT); |
255 |
+ |
d = TM_BRTSCALE*log(lum); |
256 |
+ |
if (d > 0.) |
257 |
+ |
return((TMbright)(d+.5)); |
258 |
+ |
return((TMbright)(d-.5)); |
259 |
+ |
} |
260 |
+ |
|
261 |
+ |
|
262 |
|
int |
263 |
|
tmCvGrays( /* convert float gray values */ |
264 |
|
TMstruct *tms, |
267 |
|
int len |
268 |
|
) |
269 |
|
{ |
270 |
< |
static char funcName[] = "tmCvGrays"; |
270 |
> |
static const char funcName[] = "tmCvGrays"; |
271 |
|
double d; |
272 |
|
int i; |
273 |
|
|
294 |
|
int wt |
295 |
|
) |
296 |
|
{ |
297 |
< |
static char funcName[] = "tmAddHisto"; |
297 |
> |
static const char funcName[] = "tmAddHisto"; |
298 |
|
int oldorig=0, oldlen, horig, hlen; |
299 |
|
int i, j; |
300 |
|
|
397 |
|
double gamval |
398 |
|
) |
399 |
|
{ |
400 |
< |
static char funcName[] = "tmFixedMapping"; |
400 |
> |
static const char funcName[] = "tmFixedMapping"; |
401 |
|
double d; |
402 |
|
int i; |
403 |
|
|
424 |
|
double Ldmax |
425 |
|
) |
426 |
|
{ |
427 |
< |
static char funcName[] = "tmComputeMapping"; |
427 |
> |
static const char funcName[] = "tmComputeMapping"; |
428 |
|
int *histo; |
429 |
|
float *cumf; |
430 |
|
int brt0, histlen, threshold, ceiling, trimmings; |
532 |
|
int len |
533 |
|
) |
534 |
|
{ |
535 |
< |
static char funcName[] = "tmMapPixels"; |
535 |
> |
static const char funcName[] = "tmMapPixels"; |
536 |
|
int32 li, pv; |
537 |
|
|
538 |
|
if (tms == NULL || tms->lumap == NULL) |
644 |
|
|
645 |
|
int |
646 |
|
tmErrorReturn( /* error return (with message) */ |
647 |
< |
char *func, |
647 |
> |
const char *func, |
648 |
|
TMstruct *tms, |
649 |
|
int err |
650 |
|
) |
651 |
|
{ |
652 |
< |
tmLastFunction = func; |
653 |
< |
tmLastError = err; |
654 |
< |
if (tms != NULL && tms->flags & TM_F_NOSTDERR) |
655 |
< |
return(err); |
652 |
> |
if (tms != NULL) { |
653 |
> |
tms->lastFunc = func; |
654 |
> |
tms->lastError = err; |
655 |
> |
if (tms->flags & TM_F_NOSTDERR) |
656 |
> |
return(err); |
657 |
> |
} |
658 |
|
fputs(func, stderr); |
659 |
|
fputs(": ", stderr); |
660 |
|
fputs(tmErrorMessage[err], stderr); |