| 12 |
|
#include "copyright.h" |
| 13 |
|
|
| 14 |
|
#include <stdio.h> |
| 15 |
+ |
#include <stdlib.h> |
| 16 |
|
#include <math.h> |
| 17 |
|
#include "tmprivat.h" |
| 18 |
|
#include "tmerrmsg.h" |
| 180 |
|
#endif |
| 181 |
|
return(TM_NOBRT); |
| 182 |
|
d = TM_BRTSCALE*log(lum); |
| 183 |
< |
if (d > 0.) |
| 183 |
< |
return((TMbright)(d+.5)); |
| 184 |
< |
return((TMbright)(d-.5)); |
| 183 |
> |
return((TMbright)(d + .5 - (d < 0.))); |
| 184 |
|
} |
| 185 |
|
|
| 186 |
|
|
| 362 |
|
tms->hbrmin = tms->hbrmax = ls[i]; |
| 363 |
|
oldlen = 0; |
| 364 |
|
} else { |
| 365 |
< |
oldorig = (tms->hbrmin-MINBRT)/HISTEP; |
| 366 |
< |
oldlen = (tms->hbrmax-MINBRT)/HISTEP + 1 - oldorig; |
| 365 |
> |
oldorig = HISTI(tms->hbrmin); |
| 366 |
> |
oldlen = HISTI(tms->hbrmax) + 1 - oldorig; |
| 367 |
|
} |
| 368 |
|
for (i = len; i--; ) { |
| 369 |
|
if ((j = ls[i]) < MINBRT) |
| 373 |
|
else if (j > tms->hbrmax) |
| 374 |
|
tms->hbrmax = j; |
| 375 |
|
} |
| 376 |
< |
horig = (tms->hbrmin-MINBRT)/HISTEP; |
| 377 |
< |
hlen = (tms->hbrmax-MINBRT)/HISTEP + 1 - horig; |
| 376 |
> |
horig = HISTI(tms->hbrmin); |
| 377 |
> |
hlen = HISTI(tms->hbrmax) + 1 - horig; |
| 378 |
|
if (hlen > oldlen) { /* (re)allocate histogram */ |
| 379 |
|
int *newhist = (int *)calloc(hlen, sizeof(int)); |
| 380 |
|
if (newhist == NULL) |
| 390 |
|
returnOK; |
| 391 |
|
for (i = len; i--; ) /* add in new counts */ |
| 392 |
|
if (ls[i] >= MINBRT) |
| 393 |
< |
tms->histo[ (ls[i]-MINBRT)/HISTEP - horig ] += wt; |
| 393 |
> |
tms->histo[ HISTI(ls[i]) - horig ] += wt; |
| 394 |
|
returnOK; |
| 395 |
|
} |
| 396 |
|
|
| 418 |
|
} |
| 419 |
|
|
| 420 |
|
|
| 422 |
– |
static int |
| 423 |
– |
tmNewMap( /* allocate new tone-mapping array */ |
| 424 |
– |
TMstruct *tms |
| 425 |
– |
) |
| 426 |
– |
{ |
| 427 |
– |
if (tms->lumap != NULL && (tms->mbrmax - tms->mbrmin) != |
| 428 |
– |
(tms->hbrmax - tms->hbrmin)) { |
| 429 |
– |
free((MEM_PTR)tms->lumap); |
| 430 |
– |
tms->lumap = NULL; |
| 431 |
– |
} |
| 432 |
– |
tms->mbrmin = tms->hbrmin; |
| 433 |
– |
tms->mbrmax = tms->hbrmax; |
| 434 |
– |
if (tms->mbrmin > tms->mbrmax) |
| 435 |
– |
return 0; |
| 436 |
– |
if (tms->lumap == NULL) |
| 437 |
– |
tms->lumap = (unsigned short *)malloc(sizeof(unsigned short)* |
| 438 |
– |
(tms->mbrmax-tms->mbrmin+1)); |
| 439 |
– |
return(tms->lumap != NULL); |
| 440 |
– |
} |
| 441 |
– |
|
| 442 |
– |
|
| 421 |
|
int |
| 422 |
|
tmFixedMapping( /* compute fixed, linear tone-mapping */ |
| 423 |
|
TMstruct *tms, |
| 474 |
|
Ldmin = Ldmax/Lddyn; |
| 475 |
|
logLddyn = log(Lddyn); |
| 476 |
|
Ldavg = sqrt(Ldmax*Ldmin); |
| 477 |
< |
i = (tms->hbrmin-MINBRT)/HISTEP; |
| 478 |
< |
brt0 = MINBRT + HISTEP/2 + i*HISTEP; |
| 479 |
< |
histlen = (tms->hbrmax-MINBRT)/HISTEP + 1 - i; |
| 477 |
> |
i = HISTI(tms->hbrmin); |
| 478 |
> |
brt0 = HISTV(i); |
| 479 |
> |
histlen = HISTI(tms->hbrmax) + 1 - i; |
| 480 |
|
/* histogram total and mean */ |
| 481 |
|
histot = 0; sum = 0; |
| 482 |
|
j = brt0 + histlen*HISTEP; |
| 593 |
|
} |
| 594 |
|
|
| 595 |
|
|
| 618 |
– |
|
| 619 |
– |
|
| 596 |
|
TMstruct * |
| 597 |
|
tmDup( /* duplicate top tone mapping */ |
| 598 |
|
TMstruct *tms |
| 609 |
|
return(NULL); |
| 610 |
|
*tmnew = *tms; /* copy everything */ |
| 611 |
|
if (tmnew->histo != NULL) { /* duplicate histogram */ |
| 612 |
< |
len = (tmnew->hbrmax-MINBRT)/HISTEP + 1 - |
| 637 |
< |
(tmnew->hbrmin-MINBRT)/HISTEP; |
| 612 |
> |
len = HISTI(tmnew->hbrmax) + 1 - HISTI(tmnew->hbrmin); |
| 613 |
|
tmnew->histo = (int *)malloc(len*sizeof(int)); |
| 614 |
|
if (tmnew->histo != NULL) |
| 615 |
|
for (i = len; i--; ) |
| 667 |
|
tmMesofact[i-BMESLOWER] = 256. * |
| 668 |
|
(tmLuminance(i) - LMESLOWER) / |
| 669 |
|
(LMESUPPER - LMESLOWER); |
| 670 |
+ |
} |
| 671 |
+ |
|
| 672 |
+ |
|
| 673 |
+ |
int |
| 674 |
+ |
tmNewMap( /* allocate new tone-mapping array */ |
| 675 |
+ |
TMstruct *tms |
| 676 |
+ |
) |
| 677 |
+ |
{ |
| 678 |
+ |
if (tms->lumap != NULL && (tms->mbrmax - tms->mbrmin) != |
| 679 |
+ |
(tms->hbrmax - tms->hbrmin)) { |
| 680 |
+ |
free((MEM_PTR)tms->lumap); |
| 681 |
+ |
tms->lumap = NULL; |
| 682 |
+ |
} |
| 683 |
+ |
tms->mbrmin = tms->hbrmin; |
| 684 |
+ |
tms->mbrmax = tms->hbrmax; |
| 685 |
+ |
if (tms->mbrmin > tms->mbrmax) |
| 686 |
+ |
return 0; |
| 687 |
+ |
if (tms->lumap == NULL) |
| 688 |
+ |
tms->lumap = (unsigned short *)malloc(sizeof(unsigned short)* |
| 689 |
+ |
(tms->mbrmax-tms->mbrmin+1)); |
| 690 |
+ |
return(tms->lumap != NULL); |
| 691 |
|
} |
| 692 |
|
|
| 693 |
|
|