--- ray/src/common/falsecolor.c 2005/11/15 06:52:38 3.2 +++ ray/src/common/falsecolor.c 2008/07/03 03:35:10 3.9 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: falsecolor.c,v 3.2 2005/11/15 06:52:38 greg Exp $"; +static const char RCSid[] = "$Id: falsecolor.c,v 3.9 2008/07/03 03:35:10 greg Exp $"; #endif /* * False color mapping functions. @@ -49,7 +49,7 @@ fcFixedLinear(FCstruct *fcs, double Lwmax) return(TM_E_NOMEM); mult = 255.999/tmLuminance(fcs->mbrmax); for (i = fcs->mbrmin; i <= fcs->mbrmax; i++) - fcs->lumap[i] = (int)(mult * tmLuminance(i)); + fcs->lumap[i - fcs->mbrmin] = (int)(mult * tmLuminance(i)); returnOK; } @@ -65,66 +65,75 @@ fcFixedLog(FCstruct *fcs, double Lwmin, double Lwmax) free((void *)fcs->lumap); fcs->mbrmin = tmCvLuminance(Lwmin); fcs->mbrmax = tmCvLuminance(Lwmax); + if (fcs->mbrmin >= fcs->mbrmax) { + fcs->lumap = NULL; + return(TM_E_ILLEGAL); + } fcs->lumap = (BYTE *)malloc(sizeof(BYTE)*(fcs->mbrmax - fcs->mbrmin + 1)); if (fcs->lumap == NULL) return(TM_E_NOMEM); - for (i = fcs->mbrmin; i <= fcs->mbrmax; i++) - fcs->lumap[i] = 256*(i - fcs->mbrmin) / - (fcs->mbrmax - fcs->mbrmin + 1); + for (i = fcs->mbrmax - fcs->mbrmin; i >= 0; i--) + fcs->lumap[i] = 256L * i / (fcs->mbrmax - fcs->mbrmin + 1); returnOK; } /* Compute linear false color map */ int -fcLinearMapping(FCstruct *fcs, TMstruct *tms, int pctile) +fcLinearMapping(FCstruct *fcs, TMstruct *tms, double pctile) { - int i; + int i, histlen; int32 histot, cnt; - TMbright wbrmin, wbrmax; + int brt0; if ((fcs == NULL) | (tms == NULL) || (tms->histo == NULL) | - (0 > pctile) | (pctile >= 100)) + (0 > pctile) | (pctile >= 50)) return(TM_E_ILLEGAL); + i = HISTI(tms->hbrmin); + brt0 = HISTV(i); + histlen = HISTI(tms->hbrmax) + 1 - i; histot = 0; - for (i = tms->hbrmax - tms->hbrmin; i >= 0; ) - histot += tms->histo[i--]; + for (i = histlen; i--; ) + histot += tms->histo[i]; cnt = histot * pctile / 100; - for (i = tms->hbrmax - tms->hbrmin; i >= 0; i--) + for (i = histlen; i--; ) if ((cnt -= tms->histo[i]) < 0) break; - if (i < 0) + if (i <= 0) return(TM_E_TMFAIL); - return(fcFixedLinear(fcs, tmLuminance(tms->hbrmin + i))); + return(fcFixedLinear(fcs, tmLuminance(brt0 + i*HISTEP))); } /* Compute logarithmic false color map */ int -fcLogMapping(FCstruct *fcs, TMstruct *tms, int pctile) +fcLogMapping(FCstruct *fcs, TMstruct *tms, double pctile) { - int i; + int i, histlen; int32 histot, cnt; - TMbright wbrmin, wbrmax; + int brt0, wbrmin, wbrmax; if ((fcs == NULL) | (tms == NULL) || (tms->histo == NULL) | - (0 > pctile) | (pctile >= 100)) + (.0 > pctile) | (pctile >= 50.)) return(TM_E_ILLEGAL); + i = HISTI(tms->hbrmin); + brt0 = HISTV(i); + histlen = HISTI(tms->hbrmax) + 1 - i; histot = 0; - for (i = tms->hbrmax - tms->hbrmin; i >= 0; ) - histot += tms->histo[i--]; - cnt = histot * pctile / 100; - for (i = 0; i <= tms->hbrmax - tms->hbrmin; i++) + for (i = histlen; i--; ) + histot += tms->histo[i]; + cnt = histot * pctile * .01; + for (i = 0; i < histlen; i++) if ((cnt -= tms->histo[i]) < 0) break; - if (i >= tms->hbrmax - tms->hbrmin) + if (i >= histlen) return(TM_E_TMFAIL); - wbrmin = tms->hbrmin + i; - cnt = histot * pctile / 100; - for (i = tms->hbrmax - tms->hbrmin; i >= 0; i--) + wbrmin = brt0 + i*HISTEP; + cnt = histot * pctile * .01; + for (i = histlen; i--; ) if ((cnt -= tms->histo[i]) < 0) break; - if (i < 0) + wbrmax = brt0 + i*HISTEP; + if (wbrmax <= wbrmin) return(TM_E_TMFAIL); - wbrmax = tms->hbrmin + i; return(fcFixedLog(fcs, tmLuminance(wbrmin), tmLuminance(wbrmax))); } @@ -156,12 +165,16 @@ fcMapPixels(FCstruct *fcs, BYTE *ps, TMbright *ls, int int fcIsLogMap(FCstruct *fcs) { - int midval; + int miderr; if (fcs == NULL || fcs->lumap == NULL) return(-1); - midval = fcs->lumap[(fcs->mbrmax - fcs->mbrmin)/2]; - return((127 <= midval) & (midval <= 129)); + + miderr = (fcs->mbrmax - fcs->mbrmin)/2; + miderr = fcs->lumap[miderr] - + 256L * miderr / (fcs->mbrmax - fcs->mbrmin + 1); + + return((-1 <= miderr) & (miderr <= 1)); } /* Duplicate a false color structure */ @@ -199,45 +212,260 @@ fcDone(FCstruct *fcs) } BYTE fcDefaultScale[256][3] = { /* default false color scale */ - 48,0,68, 45,0,70, 42,0,72, 39,0,74, 36,0,76, 33,0,78, 30,0,81, - 27,0,83, 24,0,85, 21,0,87, 18,0,89, 15,0,91, 13,0,94, 12,0,96, - 11,0,99, 9,0,101, 8,0,104, 7,0,106, 6,0,109, 5,0,111, 4,0,114, - 2,0,116, 1,0,119, 0,0,121, 0,0,122, 0,1,123, 0,1,124, 0,2,125, - 0,2,125, 0,3,126, 0,4,127, 0,4,128, 0,5,129, 0,5,129, 0,6,130, - 0,7,131, 0,9,131, 0,11,132, 0,13,133, 0,16,133, 0,18,134, - 0,20,134, 0,22,135, 0,24,135, 0,26,136, 0,29,136, 0,31,137, - 0,34,137, 0,37,136, 0,41,136, 0,45,135, 0,48,135, 0,52,135, - 0,55,134, 0,59,134, 0,62,134, 0,66,133, 0,69,133, 0,73,132, - 0,76,130, 0,79,127, 0,82,125, 0,85,123, 0,88,120, 0,91,118, - 0,94,115, 0,97,113, 0,101,110, 0,104,108, 0,107,106, 0,109,102, - 0,110,97, 0,111,91, 0,112,86, 0,113,81, 0,115,76, 0,116,71, - 0,117,65, 0,118,60, 0,119,55, 0,120,50, 0,122,45, 0,121,42, - 1,120,39, 1,119,36, 1,119,34, 1,118,31, 2,117,28, 2,116,26, - 2,115,23, 2,115,20, 3,114,18, 3,113,15, 3,112,13, 4,110,13, - 5,108,13, 6,106,13, 7,104,12, 9,102,12, 10,100,12, 11,98,12, - 12,97,12, 13,95,12, 14,93,11, 15,91,11, 17,89,12, 19,86,12, - 22,83,12, 24,81,13, 26,78,13, 29,76,14, 31,73,14, 34,70,15, - 36,68,15, 39,65,16, 41,63,16, 44,60,17, 46,58,17, 49,56,17, - 51,54,17, 54,52,17, 57,50,17, 59,48,17, 62,45,17, 64,43,17, - 67,41,17, 70,39,17, 72,37,17, 74,35,17, 75,34,16, 76,33,16, - 77,32,16, 79,31,15, 80,30,15, 81,29,14, 82,28,14, 83,26,13, - 84,25,13, 85,24,13, 87,23,12, 87,22,12, 88,21,11, 89,20,11, - 90,19,10, 91,18,10, 92,17,9, 93,16,9, 94,15,8, 95,14,8, - 95,13,7, 96,12,7, 97,11,7, 98,11,6, 99,10,6, 99,9,5, 100,9,5, - 101,8,5, 102,8,4, 102,7,4, 103,6,4, 104,6,3, 104,5,3, 105,4,2, - 106,4,2, 107,4,2, 107,3,2, 108,3,2, 109,3,2, 109,2,1, 110,2,1, - 111,2,1, 112,1,1, 112,1,1, 113,1,0, 114,1,0, 115,0,0, 116,0,0, - 117,0,0, 118,0,0, 119,0,0, 121,0,0, 122,0,0, 123,0,0, 124,0,0, - 125,0,0, 126,0,0, 128,0,0, 131,0,0, 134,0,0, 137,0,0, 140,0,0, - 144,0,0, 147,0,0, 150,0,0, 153,0,0, 156,0,0, 159,0,0, 162,0,0, - 165,0,0, 168,0,0, 171,0,0, 174,0,0, 177,0,0, 180,1,0, 183,1,0, - 186,1,0, 189,1,0, 192,1,0, 195,2,0, 198,2,0, 201,5,0, 204,7,0, - 207,9,0, 210,11,0, 213,13,0, 216,15,0, 219,17,0, 222,19,0, - 225,21,0, 228,23,0, 230,25,0, 233,29,0, 235,34,0, 237,39,0, - 239,43,0, 241,48,0, 243,52,0, 245,57,0, 247,61,0, 250,66,0, - 252,71,0, 254,75,0, 255,80,0, 255,88,0, 255,95,1, 255,103,1, - 255,110,1, 255,117,1, 255,125,1, 255,132,2, 255,139,2, 255,147,2, - 255,154,2, 255,162,2, 255,169,3, 255,176,3, 255,183,3, 254,190,4, - 254,198,4, 254,205,4, 254,212,4, 253,219,5, 253,226,5, 253,234,5, - 252,241,6, 252,248,6 + 111,8,132, + 108,7,133, + 105,7,134, + 102,6,136, + 98,6,137, + 93,5,139, + 89,4,141, + 84,3,143, + 79,2,145, + 74,1,148, + 68,0,150, + 63,0,153, + 57,0,155, + 52,0,157, + 46,0,160, + 41,0,162, + 36,0,164, + 31,0,166, + 26,0,168, + 22,0,170, + 18,0,172, + 14,2,174, + 11,4,175, + 8,7,176, + 7,9,177, + 6,11,177, + 5,13,178, + 4,16,178, + 3,18,179, + 2,21,180, + 1,24,180, + 1,28,181, + 0,31,181, + 0,35,182, + 0,38,182, + 0,42,183, + 0,46,184, + 0,50,184, + 0,54,184, + 0,58,185, + 0,63,185, + 0,67,186, + 0,71,186, + 0,76,186, + 0,80,187, + 0,84,187, + 0,89,187, + 0,93,187, + 1,97,187, + 1,102,187, + 1,106,187, + 2,110,187, + 2,114,187, + 3,118,186, + 3,122,186, + 4,126,186, + 4,130,185, + 4,133,185, + 5,137,184, + 5,140,183, + 6,143,182, + 6,146,181, + 6,149,180, + 7,151,179, + 7,154,178, + 7,156,177, + 8,158,175, + 8,161,172, + 9,163,169, + 9,165,165, + 9,167,161, + 9,169,157, + 10,170,153, + 10,172,148, + 10,173,143, + 11,174,138, + 11,174,133, + 11,175,127, + 12,175,122, + 12,176,117, + 13,176,111, + 14,176,106, + 14,176,101, + 15,175,95, + 16,175,90, + 17,175,86, + 18,174,81, + 20,174,77, + 21,173,73, + 22,172,69, + 24,172,66, + 26,171,63, + 28,170,60, + 30,169,58, + 32,168,57, + 34,167,56, + 37,166,55, + 40,165,54, + 42,164,54, + 45,163,54, + 48,162,55, + 52,160,55, + 55,158,56, + 58,157,57, + 62,155,57, + 66,153,59, + 69,152,60, + 73,150,61, + 77,148,63, + 81,146,64, + 84,144,66, + 88,142,67, + 92,139,69, + 96,137,70, + 99,135,72, + 103,133,73, + 107,131,75, + 110,128,76, + 113,126,77, + 117,124,78, + 120,121,79, + 123,119,80, + 126,117,80, + 128,114,81, + 131,112,81, + 133,110,81, + 135,108,80, + 136,106,80, + 137,105,80, + 138,104,79, + 139,102,79, + 140,101,79, + 141,100,78, + 142,98,78, + 143,96,77, + 144,95,76, + 144,93,76, + 145,92,75, + 146,90,74, + 146,89,73, + 147,87,73, + 148,85,72, + 148,84,71, + 149,82,70, + 149,80,69, + 150,79,68, + 150,77,67, + 151,75,66, + 151,73,65, + 151,72,64, + 152,70,63, + 152,68,62, + 153,66,61, + 153,65,60, + 153,63,59, + 154,61,58, + 154,60,57, + 154,58,56, + 154,56,55, + 155,55,54, + 155,53,53, + 155,51,51, + 156,50,50, + 156,48,49, + 156,46,48, + 157,45,47, + 157,43,46, + 157,42,45, + 158,40,44, + 158,39,43, + 158,37,42, + 159,36,41, + 159,34,40, + 159,33,39, + 160,32,38, + 160,31,37, + 161,29,37, + 161,28,36, + 162,27,35, + 162,26,34, + 163,25,33, + 163,24,33, + 164,23,32, + 165,22,31, + 165,21,31, + 168,18,29, + 170,16,28, + 172,13,26, + 175,11,25, + 177,9,24, + 180,7,23, + 183,5,22, + 185,3,21, + 188,2,21, + 191,1,20, + 194,0,19, + 197,0,19, + 199,0,18, + 202,0,17, + 205,0,17, + 207,0,16, + 210,2,16, + 213,3,15, + 215,6,14, + 217,8,13, + 219,11,13, + 220,13,12, + 222,17,11, + 224,20,11, + 226,24,10, + 227,28,9, + 229,32,8, + 231,37,7, + 232,42,6, + 234,47,5, + 236,52,5, + 237,57,4, + 239,63,3, + 240,68,2, + 242,74,2, + 243,79,1, + 245,85,0, + 246,91,0, + 247,96,0, + 248,102,0, + 250,108,0, + 251,113,0, + 252,118,0, + 253,123,0, + 254,128,0, + 254,133,0, + 255,138,0, + 255,143,1, + 255,148,2, + 255,154,3, + 255,159,4, + 255,165,6, + 255,170,7, + 255,176,9, + 255,181,11, + 255,187,13, + 255,192,15, + 255,198,17, + 255,203,20, + 255,208,22, + 255,213,24, + 255,218,26, + 255,223,28, + 255,227,30, + 255,232,32, + 255,236,34, + 254,240,35, + 254,243,37, + 254,246,38, + 254,249,39, + 254,252,40, };