65 |
|
free((void *)fcs->lumap); |
66 |
|
fcs->mbrmin = tmCvLuminance(Lwmin); |
67 |
|
fcs->mbrmax = tmCvLuminance(Lwmax); |
68 |
+ |
if (fcs->mbrmin >= fcs->mbrmax) { |
69 |
+ |
fcs->lumap = NULL; |
70 |
+ |
return(TM_E_ILLEGAL); |
71 |
+ |
} |
72 |
|
fcs->lumap = (BYTE *)malloc(sizeof(BYTE)*(fcs->mbrmax - fcs->mbrmin + 1)); |
73 |
|
if (fcs->lumap == NULL) |
74 |
|
return(TM_E_NOMEM); |
81 |
|
int |
82 |
|
fcLinearMapping(FCstruct *fcs, TMstruct *tms, double pctile) |
83 |
|
{ |
84 |
< |
int i; |
84 |
> |
int i, histlen; |
85 |
|
int32 histot, cnt; |
86 |
< |
TMbright wbrmin, wbrmax; |
86 |
> |
int brt0; |
87 |
|
|
88 |
|
if ((fcs == NULL) | (tms == NULL) || (tms->histo == NULL) | |
89 |
|
(0 > pctile) | (pctile >= 50)) |
90 |
|
return(TM_E_ILLEGAL); |
91 |
+ |
i = (tms->hbrmin-MINBRT)/HISTEP; |
92 |
+ |
brt0 = MINBRT + HISTEP/2 + i*HISTEP; |
93 |
+ |
histlen = (tms->hbrmax-MINBRT)/HISTEP + 1 - i; |
94 |
|
histot = 0; |
95 |
< |
for (i = tms->hbrmax - tms->hbrmin; i >= 0; ) |
96 |
< |
histot += tms->histo[i--]; |
95 |
> |
for (i = histlen; i--; ) |
96 |
> |
histot += tms->histo[i]; |
97 |
|
cnt = histot * pctile / 100; |
98 |
< |
for (i = tms->hbrmax - tms->hbrmin; i >= 0; i--) |
98 |
> |
for (i = histlen; i--; ) |
99 |
|
if ((cnt -= tms->histo[i]) < 0) |
100 |
|
break; |
101 |
< |
if (i < 0) |
101 |
> |
if (i <= 0) |
102 |
|
return(TM_E_TMFAIL); |
103 |
< |
return(fcFixedLinear(fcs, tmLuminance(tms->hbrmin + i))); |
103 |
> |
return(fcFixedLinear(fcs, tmLuminance(brt0 + i*HISTEP))); |
104 |
|
} |
105 |
|
|
106 |
|
/* Compute logarithmic false color map */ |
107 |
|
int |
108 |
|
fcLogMapping(FCstruct *fcs, TMstruct *tms, double pctile) |
109 |
|
{ |
110 |
< |
int i; |
110 |
> |
int i, histlen; |
111 |
|
int32 histot, cnt; |
112 |
< |
TMbright wbrmin, wbrmax; |
112 |
> |
int brt0, wbrmin, wbrmax; |
113 |
|
|
114 |
|
if ((fcs == NULL) | (tms == NULL) || (tms->histo == NULL) | |
115 |
|
(0 > pctile) | (pctile >= 50)) |
116 |
|
return(TM_E_ILLEGAL); |
117 |
+ |
i = (tms->hbrmin-MINBRT)/HISTEP; |
118 |
+ |
brt0 = MINBRT + HISTEP/2 + i*HISTEP; |
119 |
+ |
histlen = (tms->hbrmax-MINBRT)/HISTEP + 1 - i; |
120 |
|
histot = 0; |
121 |
< |
for (i = tms->hbrmax - tms->hbrmin; i >= 0; ) |
122 |
< |
histot += tms->histo[i--]; |
121 |
> |
for (i = histlen; i--; ) |
122 |
> |
histot += tms->histo[i]; |
123 |
|
cnt = histot * pctile / 100; |
124 |
< |
for (i = 0; i <= tms->hbrmax - tms->hbrmin; i++) |
124 |
> |
for (i = 0; i < histlen; i++) |
125 |
|
if ((cnt -= tms->histo[i]) < 0) |
126 |
|
break; |
127 |
< |
if (i >= tms->hbrmax - tms->hbrmin) |
127 |
> |
if (i >= histlen) |
128 |
|
return(TM_E_TMFAIL); |
129 |
< |
wbrmin = tms->hbrmin + i; |
129 |
> |
wbrmin = brt0 + i*HISTEP; |
130 |
|
cnt = histot * pctile / 100; |
131 |
< |
for (i = tms->hbrmax - tms->hbrmin; i >= 0; i--) |
131 |
> |
for (i = histlen; i--; ) |
132 |
|
if ((cnt -= tms->histo[i]) < 0) |
133 |
|
break; |
134 |
< |
if (i < 0) |
134 |
> |
wbrmax = brt0 + i*HISTEP; |
135 |
> |
if (wbrmax <= wbrmin) |
136 |
|
return(TM_E_TMFAIL); |
126 |
– |
wbrmax = tms->hbrmin + i; |
137 |
|
return(fcFixedLog(fcs, tmLuminance(wbrmin), tmLuminance(wbrmax))); |
138 |
|
} |
139 |
|
|