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.3 by greg, Tue Nov 15 20:04:50 2005 UTC vs.
Revision 3.7 by greg, Thu Jan 26 03:33:16 2006 UTC

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