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" |
134 |
|
if (tms->inppri != tms->monpri && |
135 |
|
PRIMEQ(tms->inppri, tms->monpri)) |
136 |
|
tms->inppri = tms->monpri; /* no xform */ |
137 |
< |
comprgb2rgbWBmat(tms->cmat, tms->inppri, tms->monpri); |
137 |
> |
if (!comprgb2rgbWBmat(tms->cmat, tms->inppri, tms->monpri)) |
138 |
> |
returnErr(TM_E_ILLEGAL); |
139 |
|
} |
140 |
|
for (i = 0; i < 3; i++) |
141 |
|
for (j = 0; j < 3; j++) |
142 |
|
tms->cmat[i][j] *= tms->inpsf; |
143 |
|
/* set color divisors */ |
144 |
|
for (i = 0; i < 3; i++) |
145 |
< |
if (tms->clf[i] > .001) |
146 |
< |
tms->cdiv[i] = |
145 |
< |
256.*pow(tms->clf[i], 1./tms->mongam); |
146 |
< |
else |
147 |
< |
tms->cdiv[i] = 1; |
145 |
> |
tms->cdiv[i] = 256.*pow(tms->clf[i] < .001 ? .001 : |
146 |
> |
tms->clf[i], 1./tms->mongam); |
147 |
|
/* notify packages */ |
148 |
|
for (i = tmNumPkgs; i--; ) |
149 |
|
if (tms->pd[i] != NULL && tmPkg[i]->NewSpace != NULL) |
178 |
|
#endif |
179 |
|
return(TM_NOBRT); |
180 |
|
d = TM_BRTSCALE*log(lum); |
181 |
< |
if (d > 0.) |
183 |
< |
return((TMbright)(d+.5)); |
184 |
< |
return((TMbright)(d-.5)); |
181 |
> |
return((TMbright)(d + .5 - (d < 0.))); |
182 |
|
} |
183 |
|
|
184 |
|
|
416 |
|
} |
417 |
|
|
418 |
|
|
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 |
– |
|
419 |
|
int |
420 |
|
tmFixedMapping( /* compute fixed, linear tone-mapping */ |
421 |
|
TMstruct *tms, |
473 |
|
logLddyn = log(Lddyn); |
474 |
|
Ldavg = sqrt(Ldmax*Ldmin); |
475 |
|
i = HISTI(tms->hbrmin); |
476 |
< |
brt0 = MINBRT + HISTEP/2 + i*HISTEP; |
476 |
> |
brt0 = HISTV(i); |
477 |
|
histlen = HISTI(tms->hbrmax) + 1 - i; |
478 |
|
/* histogram total and mean */ |
479 |
|
histot = 0; sum = 0; |
591 |
|
} |
592 |
|
|
593 |
|
|
618 |
– |
|
619 |
– |
|
594 |
|
TMstruct * |
595 |
|
tmDup( /* duplicate top tone mapping */ |
596 |
|
TMstruct *tms |
665 |
|
tmMesofact[i-BMESLOWER] = 256. * |
666 |
|
(tmLuminance(i) - LMESLOWER) / |
667 |
|
(LMESUPPER - LMESLOWER); |
668 |
+ |
} |
669 |
+ |
|
670 |
+ |
|
671 |
+ |
int |
672 |
+ |
tmNewMap( /* allocate new tone-mapping array */ |
673 |
+ |
TMstruct *tms |
674 |
+ |
) |
675 |
+ |
{ |
676 |
+ |
if (tms->lumap != NULL && (tms->mbrmax - tms->mbrmin) != |
677 |
+ |
(tms->hbrmax - tms->hbrmin)) { |
678 |
+ |
free((MEM_PTR)tms->lumap); |
679 |
+ |
tms->lumap = NULL; |
680 |
+ |
} |
681 |
+ |
tms->mbrmin = tms->hbrmin; |
682 |
+ |
tms->mbrmax = tms->hbrmax; |
683 |
+ |
if (tms->mbrmin > tms->mbrmax) |
684 |
+ |
return 0; |
685 |
+ |
if (tms->lumap == NULL) |
686 |
+ |
tms->lumap = (unsigned short *)malloc(sizeof(unsigned short)* |
687 |
+ |
(tms->mbrmax-tms->mbrmin+1)); |
688 |
+ |
return(tms->lumap != NULL); |
689 |
|
} |
690 |
|
|
691 |
|
|