458 |
|
if (gamval < MINGAM) |
459 |
|
gamval = tms->mongam; |
460 |
|
d = log(expmult/tms->inpsf); |
461 |
< |
for (i = tms->mbrmax-tms->mbrmin+1; i--; ) |
462 |
< |
tms->lumap[i] = 256. * exp( |
461 |
> |
for (i = tms->mbrmax-tms->mbrmin+1; i--; ) { |
462 |
> |
double val = 256. * exp( |
463 |
|
( d + (tms->mbrmin+i)*(1./TM_BRTSCALE) ) |
464 |
< |
/ gamval ); |
464 |
> |
/ gamval); |
465 |
> |
tms->lumap[i] = val >= (double)0xffff ? 0xffff : (int)val; |
466 |
> |
} |
467 |
|
returnOK; |
468 |
|
} |
469 |
|
|
507 |
|
sum += (j -= HISTEP) * tms->histo[i]; |
508 |
|
} |
509 |
|
threshold = histot*0.005 + .5; |
510 |
< |
if (threshold < 4) |
510 |
> |
if (!histot) |
511 |
|
returnErr(TM_E_TMFAIL); |
512 |
|
Lwavg = tmLuminance( (double)sum / histot ); |
513 |
+ |
/* use linear tone mapping? */ |
514 |
+ |
if (tms->flags & TM_F_LINEAR || threshold < 4) |
515 |
+ |
goto linearmap; |
516 |
|
/* allocate space for mapping */ |
517 |
|
if (!tmNewMap(tms)) |
518 |
|
returnErr(TM_E_NOMEM); |
514 |
– |
/* use linear tone mapping? */ |
515 |
– |
if (tms->flags & TM_F_LINEAR) |
516 |
– |
goto linearmap; |
519 |
|
/* clamp histogram */ |
520 |
|
histo = (int *)malloc(histlen*sizeof(int)); |
521 |
|
cumf = (float *)malloc((histlen+2)*sizeof(float)); |