504 |
|
j = brt0 + histlen*HISTEP; |
505 |
|
for (i = histlen; i--; ) { |
506 |
|
histot += tms->histo[i]; |
507 |
< |
sum += (j -= HISTEP) * tms->histo[i]; |
507 |
> |
sum += (double)(j -= HISTEP) * tms->histo[i]; |
508 |
|
} |
509 |
|
threshold = histot*0.005 + .5; |
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) |
514 |
> |
if (tms->flags & TM_F_LINEAR || threshold < 4 || |
515 |
> |
tms->hbrmax - tms->hbrmin < TM_BRTSCALE*logLddyn) |
516 |
|
goto linearmap; |
516 |
– |
/* allocate space for mapping */ |
517 |
– |
if (!tmNewMap(tms)) |
518 |
– |
returnErr(TM_E_NOMEM); |
517 |
|
/* clamp histogram */ |
518 |
|
histo = (int *)malloc(histlen*sizeof(int)); |
519 |
|
cumf = (float *)malloc((histlen+2)*sizeof(float)); |
553 |
|
goto linearmap; |
554 |
|
} |
555 |
|
} while (trimmings > threshold); |
556 |
+ |
/* allocate space for mapping */ |
557 |
+ |
if (!tmNewMap(tms)) |
558 |
+ |
returnErr(TM_E_NOMEM); |
559 |
|
/* assign tone-mapping */ |
560 |
|
for (i = tms->mbrmax-tms->mbrmin+1; i--; ) { |
561 |
|
j = d = (double)i/(tms->mbrmax-tms->mbrmin)*histlen; |