12 |
|
|
13 |
|
#include <stdio.h> |
14 |
|
#include <math.h> |
15 |
+ |
#include <string.h> |
16 |
|
#include "tmprivat.h" |
17 |
|
#include "falsecolor.h" |
18 |
|
|
35 |
|
int |
36 |
|
fcFixedLinear(FCstruct *fcs, double Lwmax) |
37 |
|
{ |
38 |
< |
double v; |
38 |
> |
double mult; |
39 |
|
int i; |
40 |
|
|
41 |
|
if ((fcs == NULL) | (Lwmax <= MINLUM)) |
42 |
|
return(TM_E_ILLEGAL); |
43 |
|
if (fcs->lumap != NULL) |
44 |
|
free((void *)fcs->lumap); |
45 |
< |
v = TM_BRTSCALE * log(Lwmax); |
46 |
< |
fcs->mbrmax = (int)(v<0. ? v-.5 : v+.5); |
46 |
< |
v = TM_BRTSCALE * log(Lwmax/256.); |
47 |
< |
fcs->mbrmin = (int)(v<0. ? v-.5 : v+.5); |
45 |
> |
fcs->mbrmin = tmCvLuminance(Lwmax/256.); |
46 |
> |
fcs->mbrmax = tmCvLuminance(Lwmax); |
47 |
|
fcs->lumap = (BYTE *)malloc(sizeof(BYTE)*(fcs->mbrmax - fcs->mbrmin + 1)); |
48 |
|
if (fcs->lumap == NULL) |
49 |
|
return(TM_E_NOMEM); |
50 |
< |
v = 255.999/tmLuminance(fcs->mbrmax); |
50 |
> |
mult = 255.999/tmLuminance(fcs->mbrmax); |
51 |
|
for (i = fcs->mbrmin; i <= fcs->mbrmax; i++) |
52 |
< |
fcs->lumap[i] = (int)(v * tmLuminance(i)); |
52 |
> |
fcs->lumap[i] = (int)(mult * tmLuminance(i)); |
53 |
|
returnOK; |
54 |
|
} |
55 |
|
|
57 |
|
int |
58 |
|
fcFixedLog(FCstruct *fcs, double Lwmin, double Lwmax) |
59 |
|
{ |
61 |
– |
double v; |
60 |
|
int i; |
61 |
|
|
62 |
|
if ((fcs == NULL) | (Lwmin <= MINLUM) | (Lwmax <= Lwmin)) |
63 |
|
return(TM_E_ILLEGAL); |
64 |
|
if (fcs->lumap != NULL) |
65 |
|
free((void *)fcs->lumap); |
66 |
< |
v = TM_BRTSCALE * log(Lwmin); |
67 |
< |
fcs->mbrmin = (int)(v<0. ? v-.5 : v+.5); |
70 |
< |
v = TM_BRTSCALE * log(Lwmax); |
71 |
< |
fcs->mbrmax = (int)(v<0. ? v-.5 : v+.5); |
66 |
> |
fcs->mbrmin = tmCvLuminance(Lwmin); |
67 |
> |
fcs->mbrmax = tmCvLuminance(Lwmax); |
68 |
|
fcs->lumap = (BYTE *)malloc(sizeof(BYTE)*(fcs->mbrmax - fcs->mbrmin + 1)); |
69 |
|
if (fcs->lumap == NULL) |
70 |
|
return(TM_E_NOMEM); |
125 |
|
if (i < 0) |
126 |
|
return(TM_E_TMFAIL); |
127 |
|
wbrmax = tms->hbrmin + i; |
128 |
< |
return(fcFixedLog(fcs, tmLuminannce(wbrmin), tmLuminance(wbrmax))); |
128 |
> |
return(fcFixedLog(fcs, tmLuminance(wbrmin), tmLuminance(wbrmax))); |
129 |
|
} |
130 |
|
|
131 |
|
/* Apply false color mapping to pixel values */ |
150 |
|
*ps++ = fcs->scale[li][BLU]; |
151 |
|
} |
152 |
|
returnOK; |
153 |
+ |
} |
154 |
+ |
|
155 |
+ |
/* Determine if false color mapping is logarithmic */ |
156 |
+ |
int |
157 |
+ |
fcIsLogMap(FCstruct *fcs) |
158 |
+ |
{ |
159 |
+ |
int midval; |
160 |
+ |
|
161 |
+ |
if (fcs == NULL || fcs->lumap == NULL) |
162 |
+ |
return(-1); |
163 |
+ |
midval = fcs->lumap[(fcs->mbrmax - fcs->mbrmin)/2]; |
164 |
+ |
return((127 <= midval) & (midval <= 129)); |
165 |
+ |
} |
166 |
+ |
|
167 |
+ |
/* Duplicate a false color structure */ |
168 |
+ |
FCstruct * |
169 |
+ |
fcDup(FCstruct *fcs) |
170 |
+ |
{ |
171 |
+ |
FCstruct *fcnew; |
172 |
+ |
|
173 |
+ |
if (fcs == NULL) |
174 |
+ |
return(NULL); |
175 |
+ |
fcnew = fcInit(fcs->scale); |
176 |
+ |
if (fcnew == NULL) |
177 |
+ |
return(NULL); |
178 |
+ |
if (fcs->lumap != NULL) { |
179 |
+ |
fcnew->lumap = (BYTE *)malloc(sizeof(BYTE)*(fcs->mbrmax - |
180 |
+ |
fcs->mbrmin + 1)); |
181 |
+ |
if (fcnew->lumap == NULL) |
182 |
+ |
return(fcnew); |
183 |
+ |
fcnew->mbrmin = fcs->mbrmin; fcnew->mbrmax = fcs->mbrmax; |
184 |
+ |
memcpy((void *)fcnew->lumap, (void *)fcs->lumap, |
185 |
+ |
sizeof(BYTE)*(fcs->mbrmax - fcs->mbrmin + 1)); |
186 |
+ |
} |
187 |
+ |
return(fcnew); |
188 |
|
} |
189 |
|
|
190 |
|
/* Free data associated with the given false color mapping structure */ |