home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / saoimage / sao1_07.tar / grphbar.c < prev    next >
C/C++ Source or Header  |  1990-04-20  |  3KB  |  84 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    grphbar.c (Color Graph Bar)
  6.  * Purpose:    Fill a buffer with a color chart of the allocated colors
  7.  * Subroutine:    fill_colorbar()            returns: void
  8.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  9.  *        You may do anything you like with this file except remove
  10.  *        this copyright.  The Smithsonian Astrophysical Observatory
  11.  *        makes no representations about the suitability of this
  12.  *        software for any purpose.  It is provided "as is" without
  13.  *        express or implied warranty.
  14.  * Modified:    {0} Michael VanHilst    initial version           9 May 1989
  15.  *        {n} <who> -- <does what> -- <when>
  16.  */
  17.  
  18. #include "hfiles/define.h"    /* YES, NO, MIN, MAX and more */
  19.  
  20. /*
  21.  * Subroutine:    fill_colorbar
  22.  * Purpose:    Fill byte buffer with bars of increasing value covering
  23.  *        colormap range
  24.  * PostState:    Buffer will contain data to represent a color sweep in one
  25.  *        diirection while repeating itself in the other.  For a
  26.  *        horizontal color bar, there will be vertical stripes of
  27.  *        increasing (or decreasing) colors from left to right.
  28.  * Note:    Positive polarity is from left (horizontal) or top (vertical).
  29.  */
  30. void fill_colorbar ( data, width, height, low, high,
  31.              vertical, descend, pixels )
  32.      unsigned char data[];    /* i/o: space to recieve sweep data */
  33.      int width, height;        /* i: buffer dimensions */
  34.      int low, high;        /* i: limits of the sweep range */
  35.      int vertical;        /* i: 0=horizontal sweep, else vertical */
  36.      int descend;        /* i: descend-val-with-increasing-coord */
  37.      unsigned long pixels[];    /* i: continuous array of pixel values */
  38. {
  39.   double valinc;
  40.   int latitude, longitude;
  41.   int range;
  42.   int row;
  43.   int next_row;
  44.   unsigned char val;
  45.   register unsigned char *buf;
  46.   register int i, bufinc;
  47.  
  48.   /* axis of 0 has horizontal bar, else vertical */
  49.   if( vertical ) {
  50.     /* vertical */
  51.     latitude = height;
  52.     longitude = width;
  53.     bufinc = 1;
  54.     next_row = 0;
  55.   } else {
  56.     /* horizontal */
  57.     latitude = width;
  58.     longitude = height;
  59.     bufinc = width;
  60.     next_row = 1 - (width * height);
  61.   }
  62.   range = high - low;
  63.   if( range < 0 )
  64.     range -= 1;
  65.   else
  66.     range += 1;
  67.   valinc = (double)range / (double)latitude;
  68.   buf = data;
  69.   for( row=0; row<latitude; row++ ) {
  70.     /* non-negative polarity starts at low value and increases */
  71.     if( descend )
  72.       val = (unsigned char)
  73.     pixels[MAX(low, (high - (int)((double)row * valinc)))];
  74.     else
  75.       val = (unsigned char)
  76.     pixels[MIN(high, (low + (int)((double)row * valinc)))];
  77.     for( i=0; i<longitude; i++ ) {
  78.       *buf = val;
  79.       buf += bufinc;
  80.     }
  81.     buf += next_row;
  82.   }
  83. }
  84.