49 |
|
return(TM_E_NOMEM); |
50 |
|
mult = 255.999/tmLuminance(fcs->mbrmax); |
51 |
|
for (i = fcs->mbrmin; i <= fcs->mbrmax; i++) |
52 |
< |
fcs->lumap[i] = (int)(mult * tmLuminance(i)); |
52 |
> |
fcs->lumap[i - fcs->mbrmin] = (int)(mult * tmLuminance(i)); |
53 |
|
returnOK; |
54 |
|
} |
55 |
|
|
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); |
75 |
< |
for (i = fcs->mbrmin; i <= fcs->mbrmax; i++) |
76 |
< |
fcs->lumap[i] = 256*(i - fcs->mbrmin) / |
73 |
< |
(fcs->mbrmax - fcs->mbrmin + 1); |
75 |
> |
for (i = fcs->mbrmax - fcs->mbrmin; i >= 0; i--) |
76 |
> |
fcs->lumap[i] = 256L * i / (fcs->mbrmax - fcs->mbrmin + 1); |
77 |
|
returnOK; |
78 |
|
} |
79 |
|
|
80 |
|
/* Compute linear false color map */ |
81 |
|
int |
82 |
< |
fcLinearMapping(FCstruct *fcs, TMstruct *tms, int pctile) |
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 >= 100)) |
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, int pctile) |
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 >= 100)) |
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); |
127 |
– |
wbrmax = tms->hbrmin + i; |
137 |
|
return(fcFixedLog(fcs, tmLuminance(wbrmin), tmLuminance(wbrmax))); |
138 |
|
} |
139 |
|
|
208 |
|
} |
209 |
|
|
210 |
|
BYTE fcDefaultScale[256][3] = { /* default false color scale */ |
211 |
< |
48,0,68, 45,0,70, 42,0,72, 39,0,74, 36,0,76, 33,0,78, 30,0,81, |
212 |
< |
27,0,83, 24,0,85, 21,0,87, 18,0,89, 15,0,91, 13,0,94, 12,0,96, |
213 |
< |
11,0,99, 9,0,101, 8,0,104, 7,0,106, 6,0,109, 5,0,111, 4,0,114, |
214 |
< |
2,0,116, 1,0,119, 0,0,121, 0,0,122, 0,1,123, 0,1,124, 0,2,125, |
215 |
< |
0,2,125, 0,3,126, 0,4,127, 0,4,128, 0,5,129, 0,5,129, 0,6,130, |
216 |
< |
0,7,131, 0,9,131, 0,11,132, 0,13,133, 0,16,133, 0,18,134, |
217 |
< |
0,20,134, 0,22,135, 0,24,135, 0,26,136, 0,29,136, 0,31,137, |
218 |
< |
0,34,137, 0,37,136, 0,41,136, 0,45,135, 0,48,135, 0,52,135, |
219 |
< |
0,55,134, 0,59,134, 0,62,134, 0,66,133, 0,69,133, 0,73,132, |
220 |
< |
0,76,130, 0,79,127, 0,82,125, 0,85,123, 0,88,120, 0,91,118, |
221 |
< |
0,94,115, 0,97,113, 0,101,110, 0,104,108, 0,107,106, 0,109,102, |
222 |
< |
0,110,97, 0,111,91, 0,112,86, 0,113,81, 0,115,76, 0,116,71, |
223 |
< |
0,117,65, 0,118,60, 0,119,55, 0,120,50, 0,122,45, 0,121,42, |
224 |
< |
1,120,39, 1,119,36, 1,119,34, 1,118,31, 2,117,28, 2,116,26, |
225 |
< |
2,115,23, 2,115,20, 3,114,18, 3,113,15, 3,112,13, 4,110,13, |
226 |
< |
5,108,13, 6,106,13, 7,104,12, 9,102,12, 10,100,12, 11,98,12, |
227 |
< |
12,97,12, 13,95,12, 14,93,11, 15,91,11, 17,89,12, 19,86,12, |
228 |
< |
22,83,12, 24,81,13, 26,78,13, 29,76,14, 31,73,14, 34,70,15, |
229 |
< |
36,68,15, 39,65,16, 41,63,16, 44,60,17, 46,58,17, 49,56,17, |
230 |
< |
51,54,17, 54,52,17, 57,50,17, 59,48,17, 62,45,17, 64,43,17, |
231 |
< |
67,41,17, 70,39,17, 72,37,17, 74,35,17, 75,34,16, 76,33,16, |
232 |
< |
77,32,16, 79,31,15, 80,30,15, 81,29,14, 82,28,14, 83,26,13, |
233 |
< |
84,25,13, 85,24,13, 87,23,12, 87,22,12, 88,21,11, 89,20,11, |
234 |
< |
90,19,10, 91,18,10, 92,17,9, 93,16,9, 94,15,8, 95,14,8, |
235 |
< |
95,13,7, 96,12,7, 97,11,7, 98,11,6, 99,10,6, 99,9,5, 100,9,5, |
236 |
< |
101,8,5, 102,8,4, 102,7,4, 103,6,4, 104,6,3, 104,5,3, 105,4,2, |
237 |
< |
106,4,2, 107,4,2, 107,3,2, 108,3,2, 109,3,2, 109,2,1, 110,2,1, |
238 |
< |
111,2,1, 112,1,1, 112,1,1, 113,1,0, 114,1,0, 115,0,0, 116,0,0, |
239 |
< |
117,0,0, 118,0,0, 119,0,0, 121,0,0, 122,0,0, 123,0,0, 124,0,0, |
240 |
< |
125,0,0, 126,0,0, 128,0,0, 131,0,0, 134,0,0, 137,0,0, 140,0,0, |
241 |
< |
144,0,0, 147,0,0, 150,0,0, 153,0,0, 156,0,0, 159,0,0, 162,0,0, |
242 |
< |
165,0,0, 168,0,0, 171,0,0, 174,0,0, 177,0,0, 180,1,0, 183,1,0, |
243 |
< |
186,1,0, 189,1,0, 192,1,0, 195,2,0, 198,2,0, 201,5,0, 204,7,0, |
244 |
< |
207,9,0, 210,11,0, 213,13,0, 216,15,0, 219,17,0, 222,19,0, |
245 |
< |
225,21,0, 228,23,0, 230,25,0, 233,29,0, 235,34,0, 237,39,0, |
246 |
< |
239,43,0, 241,48,0, 243,52,0, 245,57,0, 247,61,0, 250,66,0, |
247 |
< |
252,71,0, 254,75,0, 255,80,0, 255,88,0, 255,95,1, 255,103,1, |
248 |
< |
255,110,1, 255,117,1, 255,125,1, 255,132,2, 255,139,2, 255,147,2, |
249 |
< |
255,154,2, 255,162,2, 255,169,3, 255,176,3, 255,183,3, 254,190,4, |
250 |
< |
254,198,4, 254,205,4, 254,212,4, 253,219,5, 253,226,5, 253,234,5, |
251 |
< |
252,241,6, 252,248,6 |
211 |
> |
111,8,132, |
212 |
> |
108,7,133, |
213 |
> |
105,7,134, |
214 |
> |
102,6,136, |
215 |
> |
98,6,137, |
216 |
> |
93,5,139, |
217 |
> |
89,4,141, |
218 |
> |
84,3,143, |
219 |
> |
79,2,145, |
220 |
> |
74,1,148, |
221 |
> |
68,0,150, |
222 |
> |
63,0,153, |
223 |
> |
57,0,155, |
224 |
> |
52,0,157, |
225 |
> |
46,0,160, |
226 |
> |
41,0,162, |
227 |
> |
36,0,164, |
228 |
> |
31,0,166, |
229 |
> |
26,0,168, |
230 |
> |
22,0,170, |
231 |
> |
18,0,172, |
232 |
> |
14,2,174, |
233 |
> |
11,4,175, |
234 |
> |
8,7,176, |
235 |
> |
7,9,177, |
236 |
> |
6,11,177, |
237 |
> |
5,13,178, |
238 |
> |
4,16,178, |
239 |
> |
3,18,179, |
240 |
> |
2,21,180, |
241 |
> |
1,24,180, |
242 |
> |
1,28,181, |
243 |
> |
0,31,181, |
244 |
> |
0,35,182, |
245 |
> |
0,38,182, |
246 |
> |
0,42,183, |
247 |
> |
0,46,184, |
248 |
> |
0,50,184, |
249 |
> |
0,54,184, |
250 |
> |
0,58,185, |
251 |
> |
0,63,185, |
252 |
> |
0,67,186, |
253 |
> |
0,71,186, |
254 |
> |
0,76,186, |
255 |
> |
0,80,187, |
256 |
> |
0,84,187, |
257 |
> |
0,89,187, |
258 |
> |
0,93,187, |
259 |
> |
1,97,187, |
260 |
> |
1,102,187, |
261 |
> |
1,106,187, |
262 |
> |
2,110,187, |
263 |
> |
2,114,187, |
264 |
> |
3,118,186, |
265 |
> |
3,122,186, |
266 |
> |
4,126,186, |
267 |
> |
4,130,185, |
268 |
> |
4,133,185, |
269 |
> |
5,137,184, |
270 |
> |
5,140,183, |
271 |
> |
6,143,182, |
272 |
> |
6,146,181, |
273 |
> |
6,149,180, |
274 |
> |
7,151,179, |
275 |
> |
7,154,178, |
276 |
> |
7,156,177, |
277 |
> |
8,158,175, |
278 |
> |
8,161,172, |
279 |
> |
9,163,169, |
280 |
> |
9,165,165, |
281 |
> |
9,167,161, |
282 |
> |
9,169,157, |
283 |
> |
10,170,153, |
284 |
> |
10,172,148, |
285 |
> |
10,173,143, |
286 |
> |
11,174,138, |
287 |
> |
11,174,133, |
288 |
> |
11,175,127, |
289 |
> |
12,175,122, |
290 |
> |
12,176,117, |
291 |
> |
13,176,111, |
292 |
> |
14,176,106, |
293 |
> |
14,176,101, |
294 |
> |
15,175,95, |
295 |
> |
16,175,90, |
296 |
> |
17,175,86, |
297 |
> |
18,174,81, |
298 |
> |
20,174,77, |
299 |
> |
21,173,73, |
300 |
> |
22,172,69, |
301 |
> |
24,172,66, |
302 |
> |
26,171,63, |
303 |
> |
28,170,60, |
304 |
> |
30,169,58, |
305 |
> |
32,168,57, |
306 |
> |
34,167,56, |
307 |
> |
37,166,55, |
308 |
> |
40,165,54, |
309 |
> |
42,164,54, |
310 |
> |
45,163,54, |
311 |
> |
48,162,55, |
312 |
> |
52,160,55, |
313 |
> |
55,158,56, |
314 |
> |
58,157,57, |
315 |
> |
62,155,57, |
316 |
> |
66,153,59, |
317 |
> |
69,152,60, |
318 |
> |
73,150,61, |
319 |
> |
77,148,63, |
320 |
> |
81,146,64, |
321 |
> |
84,144,66, |
322 |
> |
88,142,67, |
323 |
> |
92,139,69, |
324 |
> |
96,137,70, |
325 |
> |
99,135,72, |
326 |
> |
103,133,73, |
327 |
> |
107,131,75, |
328 |
> |
110,128,76, |
329 |
> |
113,126,77, |
330 |
> |
117,124,78, |
331 |
> |
120,121,79, |
332 |
> |
123,119,80, |
333 |
> |
126,117,80, |
334 |
> |
128,114,81, |
335 |
> |
131,112,81, |
336 |
> |
133,110,81, |
337 |
> |
135,108,80, |
338 |
> |
136,106,80, |
339 |
> |
137,105,80, |
340 |
> |
138,104,79, |
341 |
> |
139,102,79, |
342 |
> |
140,101,79, |
343 |
> |
141,100,78, |
344 |
> |
142,98,78, |
345 |
> |
143,96,77, |
346 |
> |
144,95,76, |
347 |
> |
144,93,76, |
348 |
> |
145,92,75, |
349 |
> |
146,90,74, |
350 |
> |
146,89,73, |
351 |
> |
147,87,73, |
352 |
> |
148,85,72, |
353 |
> |
148,84,71, |
354 |
> |
149,82,70, |
355 |
> |
149,80,69, |
356 |
> |
150,79,68, |
357 |
> |
150,77,67, |
358 |
> |
151,75,66, |
359 |
> |
151,73,65, |
360 |
> |
151,72,64, |
361 |
> |
152,70,63, |
362 |
> |
152,68,62, |
363 |
> |
153,66,61, |
364 |
> |
153,65,60, |
365 |
> |
153,63,59, |
366 |
> |
154,61,58, |
367 |
> |
154,60,57, |
368 |
> |
154,58,56, |
369 |
> |
154,56,55, |
370 |
> |
155,55,54, |
371 |
> |
155,53,53, |
372 |
> |
155,51,51, |
373 |
> |
156,50,50, |
374 |
> |
156,48,49, |
375 |
> |
156,46,48, |
376 |
> |
157,45,47, |
377 |
> |
157,43,46, |
378 |
> |
157,42,45, |
379 |
> |
158,40,44, |
380 |
> |
158,39,43, |
381 |
> |
158,37,42, |
382 |
> |
159,36,41, |
383 |
> |
159,34,40, |
384 |
> |
159,33,39, |
385 |
> |
160,32,38, |
386 |
> |
160,31,37, |
387 |
> |
161,29,37, |
388 |
> |
161,28,36, |
389 |
> |
162,27,35, |
390 |
> |
162,26,34, |
391 |
> |
163,25,33, |
392 |
> |
163,24,33, |
393 |
> |
164,23,32, |
394 |
> |
165,22,31, |
395 |
> |
165,21,31, |
396 |
> |
168,18,29, |
397 |
> |
170,16,28, |
398 |
> |
172,13,26, |
399 |
> |
175,11,25, |
400 |
> |
177,9,24, |
401 |
> |
180,7,23, |
402 |
> |
183,5,22, |
403 |
> |
185,3,21, |
404 |
> |
188,2,21, |
405 |
> |
191,1,20, |
406 |
> |
194,0,19, |
407 |
> |
197,0,19, |
408 |
> |
199,0,18, |
409 |
> |
202,0,17, |
410 |
> |
205,0,17, |
411 |
> |
207,0,16, |
412 |
> |
210,2,16, |
413 |
> |
213,3,15, |
414 |
> |
215,6,14, |
415 |
> |
217,8,13, |
416 |
> |
219,11,13, |
417 |
> |
220,13,12, |
418 |
> |
222,17,11, |
419 |
> |
224,20,11, |
420 |
> |
226,24,10, |
421 |
> |
227,28,9, |
422 |
> |
229,32,8, |
423 |
> |
231,37,7, |
424 |
> |
232,42,6, |
425 |
> |
234,47,5, |
426 |
> |
236,52,5, |
427 |
> |
237,57,4, |
428 |
> |
239,63,3, |
429 |
> |
240,68,2, |
430 |
> |
242,74,2, |
431 |
> |
243,79,1, |
432 |
> |
245,85,0, |
433 |
> |
246,91,0, |
434 |
> |
247,96,0, |
435 |
> |
248,102,0, |
436 |
> |
250,108,0, |
437 |
> |
251,113,0, |
438 |
> |
252,118,0, |
439 |
> |
253,123,0, |
440 |
> |
254,128,0, |
441 |
> |
254,133,0, |
442 |
> |
255,138,0, |
443 |
> |
255,143,1, |
444 |
> |
255,148,2, |
445 |
> |
255,154,3, |
446 |
> |
255,159,4, |
447 |
> |
255,165,6, |
448 |
> |
255,170,7, |
449 |
> |
255,176,9, |
450 |
> |
255,181,11, |
451 |
> |
255,187,13, |
452 |
> |
255,192,15, |
453 |
> |
255,198,17, |
454 |
> |
255,203,20, |
455 |
> |
255,208,22, |
456 |
> |
255,213,24, |
457 |
> |
255,218,26, |
458 |
> |
255,223,28, |
459 |
> |
255,227,30, |
460 |
> |
255,232,32, |
461 |
> |
255,236,34, |
462 |
> |
254,240,35, |
463 |
> |
254,243,37, |
464 |
> |
254,246,38, |
465 |
> |
254,249,39, |
466 |
> |
254,252,40, |
467 |
|
}; |