home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11.lha / ccs-lib / lib / histgram.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-26  |  3.2 KB  |  106 lines

  1. /*    HISTOGRAM . C
  2. %
  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. % AUTHOR:    Jin Guojun    4/1/91
  32. */
  33.  
  34. #include "function.h"
  35.  
  36. #define    HistoSize    MaxColors
  37.  
  38. /*==============================================*
  39. *    computing the histogram, return maxcnt    *
  40. *==============================================*/
  41. histogram(bp, bsize, histp, img)
  42. register byte    *bp;
  43. int    bsize, *histp;
  44. U_IMAGE    *img;
  45. {
  46. register int    chan, i=HistoSize, j=0, *hp=histp;
  47. int    channels=img?img->dpy_channels:1;
  48.  
  49. for (chan=i*channels; chan--;)
  50.     histp[chan] = j;
  51.     if (channels==1 || img && img->color_form==CFM_SEPLANE)
  52.         for (chan=channels; chan--; bp+=i)
  53.         for (j=bsize; j--; hp[*bp++]++);
  54.     else if (img->color_form == CFM_ILL)    {
  55.         for (i=j; i<img->height; i++)
  56.         for (chan=0; chan<channels; chan++)    {
  57.             hp = histp + chan*HistoSize;
  58.             for (j=img->width; j--; ++hp[*bp++]);
  59.         }
  60.     } else    for (j=bsize; j--;)    /* must be RAS    */
  61.         hp[*bp++]++,    (hp+i)[*bp++]++,    (hp+(i<<1))[*bp++]++;
  62.     for (i=HistoSize*channels, hp=histp; i--;)    /* here j <= 0    */
  63.     if (j < hp[i])    j = hp[i];
  64. #ifdef    _DEBUG_
  65. if (DEBUG3OH)    dump_tbl(hp, HistoSize, 4, "hist");
  66. #endif
  67. return    j;
  68. }
  69.  
  70. dump_tbl(lkt, n, cln, name)
  71. register LKT*    lkt;
  72. char    *name;
  73. {
  74. register int    i;
  75. char    parameter[16];
  76.  
  77. if (cln>4)    i=2;
  78. else    i=4;
  79. sprintf(parameter, "%%%dd[%%0%dX]", 80/cln - i - 2, i);
  80. for (i=0; i<n;){
  81.     message(parameter, lkt[i], lkt[i]);
  82.     if (!(++i % cln))    mesg("\n");
  83. }
  84. message("\n%d members in %s\n", i, name);
  85. }
  86.  
  87. /*===============================================
  88. %    to reset (linearize) look_up table    %
  89. ===============================================*/
  90. void
  91. ResetLKT(lkt, img)
  92. register LKT    *lkt;
  93. register U_IMAGE* img;
  94. {
  95. register int    i, entrances=MaxColors;
  96. register Mregister *mmm = img->color_dpy ? img->marray+img->fn%img->channels :
  97.         img->marray+img->fn;
  98.     if (img->mid_type != HIPS || img->color_dpy)    /* any color display */
  99.         for (i=entrances; i--;)    lkt[i] = i;
  100.     else {
  101.     register int    bottom = mmm->min;
  102.         for (i=bottom; i<entrances; i++)
  103.             lkt[i-bottom] = i; /* linearize lkt */
  104.     }
  105. }
  106.