home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / HighlightFilter.java < prev    next >
Text File  |  1997-07-30  |  3KB  |  83 lines

  1. // $Header: z:/admin/metro_examples/java/demo/ImageMap/rcs/HighlightFilter.java 1.1 1997/02/06 00:30:09 IPGIntel-2 Exp $ 
  2. /*
  3.  * @(#)HighlightFilter.java    1.4 96/12/06
  4.  *
  5.  * Copyright (c) 1994-1996 Sun Microsystems, Inc. All Rights Reserved.
  6.  *
  7.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  8.  * modify and redistribute this software in source and binary code form,
  9.  * provided that i) this copyright notice and license appear on all copies of
  10.  * the software; and ii) Licensee does not utilize the software in a manner
  11.  * which is disparaging to Sun.
  12.  *
  13.  * This software is provided "AS IS," without a warranty of any kind. ALL
  14.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  15.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  16.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  17.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  18.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  19.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  20.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  21.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  22.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  23.  * POSSIBILITY OF SUCH DAMAGES.
  24.  *
  25.  * This software is not designed or intended for use in on-line control of
  26.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  27.  * the design, construction, operation or maintenance of any nuclear
  28.  * facility. Licensee represents and warrants that it will not use or
  29.  * redistribute the Software for such purposes.
  30.  */
  31.  
  32. import java.applet.Applet;
  33. import java.awt.Image;
  34. import java.awt.Graphics;
  35. import java.awt.Rectangle;
  36. import java.util.StringTokenizer;
  37. import java.util.Vector;
  38. import java.util.Hashtable;
  39. import java.net.URL;
  40. import java.awt.image.*;
  41. import java.net.MalformedURLException;
  42.  
  43. /**
  44.  * An image filter to highlight an image by brightening or darkening
  45.  * the pixels in the images.
  46.  *
  47.  * @author     Jim Graham
  48.  * @version     1.4, 12/06/96
  49.  */
  50. class HighlightFilter extends RGBImageFilter {
  51.     boolean brighter;
  52.     int percent;
  53.  
  54.     public HighlightFilter(boolean b, int p) {
  55.     brighter = b;
  56.     percent = p;
  57.     canFilterIndexColorModel = true;
  58.     }
  59.  
  60.     public int filterRGB(int x, int y, int rgb) {
  61.     int r = (rgb >> 16) & 0xff;
  62.     int g = (rgb >> 8) & 0xff;
  63.     int b = (rgb >> 0) & 0xff;
  64.     if (brighter) {
  65.         r = (255 - ((255 - r) * (100 - percent) / 100));
  66.         g = (255 - ((255 - g) * (100 - percent) / 100));
  67.         b = (255 - ((255 - b) * (100 - percent) / 100));
  68.     } else {
  69.         r = (r * (100 - percent) / 100);
  70.         g = (g * (100 - percent) / 100);
  71.         b = (b * (100 - percent) / 100);
  72.     }
  73.     if (r < 0) r = 0;
  74.     if (r > 255) r = 255;
  75.     if (g < 0) g = 0;
  76.     if (g > 255) g = 255;
  77.     if (b < 0) b = 0;
  78.     if (b > 255) b = 255;
  79.     return (rgb & 0xff000000) | (r << 16) | (g << 8) | (b << 0);
  80.     }
  81. }
  82.  
  83.