1 36 37 40 41 import java.applet.Applet ; 42 import java.awt.Image ; 43 import java.awt.Graphics ; 44 import java.awt.Rectangle ; 45 import java.util.StringTokenizer ; 46 import java.util.Vector ; 47 import java.util.Hashtable ; 48 import java.net.URL ; 49 import java.awt.image.*; 50 import java.net.MalformedURLException ; 51 52 59 class HighlightFilter extends RGBImageFilter { 60 boolean brighter; 61 int percent; 62 63 public HighlightFilter(boolean b, int p) { 64 brighter = b; 65 percent = p; 66 canFilterIndexColorModel = true; 67 } 68 69 public int filterRGB(int x, int y, int rgb) { 70 int r = (rgb >> 16) & 0xff; 71 int g = (rgb >> 8) & 0xff; 72 int b = (rgb >> 0) & 0xff; 73 if (brighter) { 74 r = (255 - ((255 - r) * (100 - percent) / 100)); 75 g = (255 - ((255 - g) * (100 - percent) / 100)); 76 b = (255 - ((255 - b) * (100 - percent) / 100)); 77 } else { 78 r = (r * (100 - percent) / 100); 79 g = (g * (100 - percent) / 100); 80 b = (b * (100 - percent) / 100); 81 } 82 if (r < 0) r = 0; 83 if (r > 255) r = 255; 84 if (g < 0) g = 0; 85 if (g > 255) g = 255; 86 if (b < 0) b = 0; 87 if (b > 255) b = 255; 88 return (rgb & 0xff000000) | (r << 16) | (g << 8) | (b << 0); 89 } 90 } 91 92 | Popular Tags |