75 |
|
tmnew->inpsf = WHTEFFICACY; |
76 |
|
tmnew->cmat[0][1] = tmnew->cmat[0][2] = tmnew->cmat[1][0] = |
77 |
|
tmnew->cmat[1][2] = tmnew->cmat[2][0] = tmnew->cmat[2][1] = 0.; |
78 |
– |
tmnew->inpdat = NULL; |
78 |
|
tmnew->hbrmin = 10; tmnew->hbrmax = -10; |
79 |
|
tmnew->histo = NULL; |
80 |
|
tmnew->mbrmin = 10; tmnew->mbrmax = -10; |
93 |
|
tmSetSpace( /* set input color space for conversions */ |
94 |
|
TMstruct *tms, |
95 |
|
RGBPRIMP pri, |
96 |
< |
double sf, |
98 |
< |
MEM_PTR dat |
96 |
> |
double sf |
97 |
|
) |
98 |
|
{ |
99 |
|
static const char funcName[] = "tmSetSpace"; |
104 |
|
if (sf <= 1e-12) |
105 |
|
returnErr(TM_E_ILLEGAL); |
106 |
|
/* check if no change */ |
107 |
< |
if (pri == tms->inppri && FEQ(sf, tms->inpsf) && dat == tms->inpdat) |
107 |
> |
if (pri == tms->inppri && FEQ(sf, tms->inpsf)) |
108 |
|
returnOK; |
109 |
|
tms->inppri = pri; /* let's set it */ |
110 |
|
tms->inpsf = sf; |
113 |
– |
tms->inpdat = dat; |
111 |
|
|
112 |
|
if (tms->flags & TM_F_BW) { /* color doesn't matter */ |
113 |
|
tms->monpri = tms->inppri; /* eliminate xform */ |
157 |
|
if (tms == NULL || tms->histo == NULL) |
158 |
|
return; |
159 |
|
free(tms->histo); |
160 |
+ |
tms->hbrmin = 10; tms->hbrmax = -10; |
161 |
|
tms->histo = NULL; |
162 |
|
} |
163 |
|
|
318 |
|
cmon[BLU] += d; |
319 |
|
} |
320 |
|
} else if (tms->flags & TM_F_BW) { |
321 |
< |
cmon[RED] = cmon[GRN] = cmon[BLU] = lum; |
321 |
> |
int j = 3; |
322 |
> |
while (j--) cs[3*i+j] = tms->cdiv[j]/(TM_BRES>>8); |
323 |
> |
continue; |
324 |
|
} |
325 |
|
d = tms->clf[RED]*cmon[RED]/lum; |
326 |
|
cs[3*i ] = d>=.999f ? 255 : gamtab[(int)(1024.f*d)]; |
343 |
|
{ |
344 |
|
static const char funcName[] = "tmAddHisto"; |
345 |
|
int oldorig=0, oldlen, horig, hlen; |
346 |
< |
int i, j; |
346 |
> |
int i; |
347 |
|
|
348 |
|
if (tms == NULL) |
349 |
|
returnErr(TM_E_TMINVAL); |
364 |
|
oldlen = HISTI(tms->hbrmax) + 1 - oldorig; |
365 |
|
} |
366 |
|
for (i = len; i--; ) { |
367 |
< |
if ((j = ls[i]) < MINBRT) |
367 |
> |
if (ls[i] < MINBRT) |
368 |
|
continue; |
369 |
< |
if (j < tms->hbrmin) |
370 |
< |
tms->hbrmin = j; |
371 |
< |
else if (j > tms->hbrmax) |
372 |
< |
tms->hbrmax = j; |
369 |
> |
if (ls[i] < tms->hbrmin) |
370 |
> |
tms->hbrmin = ls[i]; |
371 |
> |
else if (ls[i] > tms->hbrmax) |
372 |
> |
tms->hbrmax = ls[i]; |
373 |
|
} |
374 |
|
horig = HISTI(tms->hbrmin); |
375 |
|
hlen = HISTI(tms->hbrmax) + 1 - horig; |
425 |
|
) |
426 |
|
{ |
427 |
|
static const char funcName[] = "tmFixedMapping"; |
428 |
< |
int maxV = (1L<<(8*sizeof(TMAP_TYP))) - 1; |
429 |
< |
double minD; |
430 |
< |
int i; |
428 |
> |
const int maxV = (1L<<(8*sizeof(TMAP_TYP))) - 1; |
429 |
> |
double minD; |
430 |
> |
int i; |
431 |
|
|
432 |
|
if (!tmNewMap(tms)) |
433 |
|
returnErr(TM_E_NOMEM); |
439 |
|
for (i = tms->mbrmax-tms->mbrmin+1; i--; ) { |
440 |
|
double d; |
441 |
|
d = expmult/tms->inpsf * tmLuminance(tms->mbrmin + i); |
442 |
< |
if (d <= minD) |
443 |
< |
break; /* map initialized to zeroes */ |
444 |
< |
d = (d - minD)/(1. - minD); |
442 |
> |
if (d >= 2.*minD) |
443 |
> |
d -= minD; |
444 |
> |
else /* soft black crushing */ |
445 |
> |
d *= d/(4.*minD); |
446 |
> |
d /= 1. - minD; |
447 |
|
d = TM_BRES*pow(d, 1./gamval); |
448 |
< |
tms->lumap[i] = (d >= maxV) ? maxV : (int)d; |
448 |
> |
tms->lumap[i] = (d > maxV) ? maxV : (int)d; |
449 |
|
} |
450 |
|
returnOK; |
451 |
|
} |
488 |
|
histot += tms->histo[i]; |
489 |
|
sum += (double)(j -= HISTEP) * tms->histo[i]; |
490 |
|
} |
489 |
– |
threshold = histot*0.002 + .5; |
491 |
|
if (!histot) |
492 |
|
returnErr(TM_E_TMFAIL); |
493 |
+ |
threshold = histot/500 + 1; |
494 |
|
Lwavg = tmLuminance( (double)sum / histot ); |
495 |
|
/* use linear tone mapping? */ |
496 |
< |
if (tms->flags & TM_F_LINEAR || threshold < 4 || |
496 |
> |
if (tms->flags & TM_F_LINEAR || |
497 |
|
tms->hbrmax - tms->hbrmin < TM_BRTSCALE*logLddyn) |
498 |
|
goto linearmap; |
499 |
|
/* clamp histogram */ |
534 |
|
free(cumf); |
535 |
|
goto linearmap; |
536 |
|
} |
537 |
< |
} while (trimmings > threshold); |
537 |
> |
} while (40*trimmings > histot); |
538 |
|
/* allocate space for mapping */ |
539 |
|
if (!tmNewMap(tms)) |
540 |
|
returnErr(TM_E_NOMEM); |
690 |
|
tms->mbrmin = tms->hbrmin; |
691 |
|
tms->mbrmax = tms->hbrmax; |
692 |
|
if (tms->mbrmin > tms->mbrmax) |
693 |
< |
return 0; |
693 |
> |
return(0); |
694 |
|
if (tms->lumap == NULL) |
695 |
|
tms->lumap = (TMAP_TYP *)calloc(tms->mbrmax-tms->mbrmin+1, |
696 |
|
sizeof(TMAP_TYP)); |