160 |
|
if (tms == NULL || tms->histo == NULL) |
161 |
|
return; |
162 |
|
free(tms->histo); |
163 |
+ |
tms->hbrmin = 10; tms->hbrmax = -10; |
164 |
|
tms->histo = NULL; |
165 |
|
} |
166 |
|
|
344 |
|
{ |
345 |
|
static const char funcName[] = "tmAddHisto"; |
346 |
|
int oldorig=0, oldlen, horig, hlen; |
347 |
< |
int i, j; |
347 |
> |
int i; |
348 |
|
|
349 |
|
if (tms == NULL) |
350 |
|
returnErr(TM_E_TMINVAL); |
365 |
|
oldlen = HISTI(tms->hbrmax) + 1 - oldorig; |
366 |
|
} |
367 |
|
for (i = len; i--; ) { |
368 |
< |
if ((j = ls[i]) < MINBRT) |
368 |
> |
if (ls[i] < MINBRT) |
369 |
|
continue; |
370 |
< |
if (j < tms->hbrmin) |
371 |
< |
tms->hbrmin = j; |
372 |
< |
else if (j > tms->hbrmax) |
373 |
< |
tms->hbrmax = j; |
370 |
> |
if (ls[i] < tms->hbrmin) |
371 |
> |
tms->hbrmin = ls[i]; |
372 |
> |
else if (ls[i] > tms->hbrmax) |
373 |
> |
tms->hbrmax = ls[i]; |
374 |
|
} |
375 |
|
horig = HISTI(tms->hbrmin); |
376 |
|
hlen = HISTI(tms->hbrmax) + 1 - horig; |
426 |
|
) |
427 |
|
{ |
428 |
|
static const char funcName[] = "tmFixedMapping"; |
429 |
< |
int maxV = (1L<<(8*sizeof(TMAP_TYP))) - 1; |
430 |
< |
double minD; |
431 |
< |
int i; |
429 |
> |
const int maxV = (1L<<(8*sizeof(TMAP_TYP))) - 1; |
430 |
> |
double minD; |
431 |
> |
int i; |
432 |
|
|
433 |
|
if (!tmNewMap(tms)) |
434 |
|
returnErr(TM_E_NOMEM); |
440 |
|
for (i = tms->mbrmax-tms->mbrmin+1; i--; ) { |
441 |
|
double d; |
442 |
|
d = expmult/tms->inpsf * tmLuminance(tms->mbrmin + i); |
443 |
< |
if (d <= minD) |
444 |
< |
break; /* map initialized to zeroes */ |
445 |
< |
d = (d - minD)/(1. - minD); |
443 |
> |
if (d >= 2.*minD) |
444 |
> |
d -= minD; |
445 |
> |
else /* soft black crushing */ |
446 |
> |
d *= d/(4.*minD); |
447 |
> |
d /= 1. - minD; |
448 |
|
d = TM_BRES*pow(d, 1./gamval); |
449 |
< |
tms->lumap[i] = (d >= maxV) ? maxV : (int)d; |
449 |
> |
tms->lumap[i] = (d > maxV) ? maxV : (int)d; |
450 |
|
} |
451 |
|
returnOK; |
452 |
|
} |
489 |
|
histot += tms->histo[i]; |
490 |
|
sum += (double)(j -= HISTEP) * tms->histo[i]; |
491 |
|
} |
489 |
– |
threshold = histot*0.002 + .5; |
492 |
|
if (!histot) |
493 |
|
returnErr(TM_E_TMFAIL); |
494 |
+ |
threshold = histot/40 + 1; |
495 |
|
Lwavg = tmLuminance( (double)sum / histot ); |
496 |
|
/* use linear tone mapping? */ |
497 |
|
if (tms->flags & TM_F_LINEAR || threshold < 4 || |
535 |
|
free(cumf); |
536 |
|
goto linearmap; |
537 |
|
} |
538 |
< |
} while (trimmings > threshold); |
538 |
> |
} while (40*trimmings > histot); |
539 |
|
/* allocate space for mapping */ |
540 |
|
if (!tmNewMap(tms)) |
541 |
|
returnErr(TM_E_NOMEM); |
691 |
|
tms->mbrmin = tms->hbrmin; |
692 |
|
tms->mbrmax = tms->hbrmax; |
693 |
|
if (tms->mbrmin > tms->mbrmax) |
694 |
< |
return 0; |
694 |
> |
return(0); |
695 |
|
if (tms->lumap == NULL) |
696 |
|
tms->lumap = (TMAP_TYP *)calloc(tms->mbrmax-tms->mbrmin+1, |
697 |
|
sizeof(TMAP_TYP)); |