home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Web / Utilities / wwwcount-2.3 / combine / opaqim.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-02  |  3.0 KB  |  125 lines

  1. /*
  2.  *  OpaqueImage () - changes the color of an opaque pixel to the asked color
  3.  *
  4.  *  RCS:
  5.  *      $Revision: 2.3 $
  6.  *      $Date: 1996/05/03 02:21:34 $
  7.  *
  8.  *  Security:
  9.  *      Unclassified
  10.  *
  11.  *  Description:
  12.  *      From ImageMagick
  13.  *
  14.  *  Input Parameters:
  15.  *      type    identifier  description
  16.  *
  17.  *      text
  18.  *
  19.  *  Output Parameters:
  20.  *      type    identifier  description
  21.  *
  22.  *      text
  23.  *
  24.  *  Return Values:
  25.  *      value   description
  26.  *
  27.  *  Side Effects:
  28.  *      text
  29.  *
  30.  *  Limitations and Comments:
  31.  *      text
  32.  *
  33.  *  Development History:
  34.  *      who                 when        why
  35.  *      muquit@semcor.com   19-Feb-96   first cut
  36.  */
  37. #include "combine.h"
  38.  
  39. #if __STDC__ || defined(sgi) || defined(_AIX)
  40. void OpaqueImage (Image *image,
  41.     unsigned char sred,unsigned char sgreen,unsigned char sblue,
  42.     unsigned char pred,unsigned char pgreen,unsigned char pblue)
  43. #else
  44. void OpaqueImage (image,sred,sgreen,sblue,pred,pgreen,pblue)
  45. Image
  46.     *image;
  47. unsigned char
  48.     sred,
  49.     sgreen,
  50.     sblue;
  51. unsigned char
  52.     pred,
  53.     pgreen,
  54.     pblue;
  55. #endif
  56. {
  57. #define DeltaX  16
  58.  
  59.     register Runlength
  60.         *p;
  61.  
  62.     register int
  63.         i;
  64.  
  65.     p=image->pixels;
  66.     switch(image->class)
  67.     {
  68.         case DirectClass:
  69.         {
  70.             for (i=0; i < image->packets; i++)
  71.             {
  72.                 if (((int) p->red < (int) (sred+DeltaX)) &&
  73.                     ((int) p->red > (int) (sred-DeltaX)) &&
  74.                     ((int) p->green < (int) (sgreen+DeltaX)) &&
  75.                     ((int) p->green > (int) (sgreen-DeltaX)) &&
  76.                     ((int) p->blue < (int) (sblue+DeltaX)) &&
  77.                     ((int) p->blue > (int) (sblue-DeltaX)))
  78.                 {
  79.                     p->red=pred;
  80.                     p->green=pgreen;
  81.                     p->blue=pblue;
  82.                 }
  83.                p++;
  84.                 
  85.              }
  86.             break;
  87.         }
  88.         case PseudoClass:
  89.         {
  90.             double
  91.                 distance_squared,
  92.                 min_distance;
  93.  
  94.             int
  95.                 distance;
  96.  
  97.             register int
  98.                 index;
  99.  
  100.              min_distance=3.0*(MaxRGB+1)*(MaxRGB+1);
  101.              index=0;
  102.  
  103.              for (i=0; i < image->colors; i++)
  104.              {
  105.                 distance=(int) sred-(int) image->colormap[i].red;
  106.                 distance_squared=(unsigned int) (distance*distance);
  107.                 distance=(int) sgreen-(int) image->colormap[i].green;
  108.                 distance_squared+=(unsigned int) (distance*distance);
  109.                 distance=(int) sblue-(int) image->colormap[i].blue;
  110.                 distance_squared+=(unsigned int) (distance*distance);
  111.                 if (distance_squared < min_distance)
  112.                 {
  113.                     min_distance=distance_squared;
  114.                     index=i;
  115.                 }
  116.              }
  117.  
  118.              image->colormap[index].red=pred;
  119.              image->colormap[index].green=pgreen;
  120.              image->colormap[index].blue=pblue;
  121.              break;
  122.         }
  123.     }
  124. }
  125.