ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/falsecolor.c
(Generate patch)

Comparing ray/src/common/falsecolor.c (file contents):
Revision 3.2 by greg, Tue Nov 15 06:52:38 2005 UTC vs.
Revision 3.9 by greg, Thu Jul 3 03:35:10 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines