home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / lib / eta.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-24  |  2.9 KB  |  111 lines

  1. /*
  2. %    ETA . C
  3. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4.  
  5. This software is copyright (C) by the Lawrence Berkeley Laboratory.
  6. Permission is granted to reproduce this software for non-commercial
  7. purposes provided that this notice is left intact.
  8.  
  9. It is acknowledged that the U.S. Government has rights to this software
  10. under Contract DE-AC03-765F00098 between the U.S.  Department of Energy
  11. and the University of California.
  12.  
  13. This software is provided as a professional and academic contribution
  14. for joint exchange. Thus, it is experimental, and is provided ``as is'',
  15. with no warranties of any kind whatsoever, no support, no promise of
  16. updates, or printed documentation. By using this software, you
  17. acknowledge that the Lawrence Berkeley Laboratory and Regents of the
  18. University of California shall have no liability with respect to the
  19. infringement of other copyrights by any part of this software.
  20.  
  21. For further information about this notice, contact William Johnston,
  22. Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  23. (wejohnston@lbl.gov)
  24.  
  25. For further information about this software, contact:
  26.     Jin Guojun
  27.     Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  28.     g_jin@lbl.gov
  29.  
  30. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  31. %
  32. % AUTHOR:    Jin Guojun, LBL    - 1991
  33. */
  34.  
  35. #include "imagedef.h"
  36.  
  37. #define    HistoSize    256
  38. #define    MaxColors    256
  39. #ifndef    VSC_BASE
  40. #define    VSC_BASE    1
  41. #endif
  42.  
  43. /*==============================================*
  44. *    computing the histogram, return maxvalue    *
  45. *==============================================*/
  46. histogram_calc(bp, bsize, hp)
  47. register byte    *bp;
  48. register int    bsize;
  49. register int    *hp;
  50. {
  51. register int    i;
  52. for (i=0; i<HistoSize; i++)
  53.     hp[i] = 0;
  54. while (bsize--)
  55.     hp[*bp++]++;
  56. for (i=HistoSize; --i & !hp[i];);
  57. return    ++i;
  58. }
  59.  
  60.  
  61. /*=======================================
  62. *    maxout should be float point    *
  63. *    maxdiff is max-min+1        *
  64. *    the 1 is a cell for max.    *
  65. *    lkt always start from 0.    *
  66. *    foreground ELA start at 1    *
  67. =======================================*/
  68. eta_curve(lkt, vsc, maxdiff, type)
  69. LKT    *lkt;
  70. register float    vsc;
  71. {
  72. float    maxout=255.0;
  73. register int    i;
  74. register float    rel_val, scale;
  75.  
  76. register double    tmp;
  77.  
  78.     vsc = VSC_BASE*vsc / (maxdiff-1) + 1;    /* key place */
  79.     if (vsc <= 0.)    vsc = VSC_BASE;
  80.     if (vsc != 1.)    {
  81.         for (i=tmp=maxdiff; i--;)    tmp = tmp*vsc + i;
  82.         scale = maxout / tmp;
  83.     }
  84.     else    scale = maxout / ((maxdiff-1)*maxdiff >> 1);
  85. #ifdef    _DEBUG_
  86.     DEBUGMESSAGE("Scale=%f, C=%f, vsc=%f\n", scale, tmp, vsc);
  87. #endif
  88.  
  89.     if (type)    /* foreground */
  90.         for(i=0, rel_val=0; i<maxdiff; i++)
  91.         {
  92.         rel_val += i * (scale*=vsc);
  93.         lkt[i] = rel_val;
  94.         }
  95.     else for (i=maxdiff, rel_val=maxout; i--;)
  96.         {
  97.         lkt[i] = rel_val;
  98.         rel_val -= (maxdiff-i) * (scale*=vsc);
  99.         }
  100.  
  101.     i = maxdiff - 1;
  102.     if (*lkt > 255){
  103. #    ifdef    _DEBUG_
  104.         msg("lkt[0] = %d\n", *lkt);
  105. #    endif
  106.         *lkt = 255;
  107.     }
  108.     if (lkt[i] > 255)    lkt[i] = 255;
  109.     else if (lkt[i] < 0)    lkt[i] = 0;
  110. }
  111.