01 import java.awt.*; 
02 import java.awt.image.*; 
03 
04 public class GreyScaleFilter extends RGBImageFilter { 
05 
06    public GreyScaleFilter() {
07     canFilterIndexColorModel = true; 
08    } 
09 
10    /* skonvertujeme farebné pixle pomocou 
11    algoritmu odpovedajúcemu RGB špecifikácii */ 
12    public int filterRGB(int x, int y, int pixel) { 
13 
14    // získame priemernú RGB intenzitu 
15    int red = (pixel & 0x00ff0000) >> 16; 
16    int green = (pixel & 0x0000ff00) >> 8; 
17    int blue = pixel & 0x000000ff; 
18 
19    int rgb = (int) (0.299*red + 0.587*green + 0.114*blue); 
20 
21    // vrátime hodnotu pre každý RGB komponent 
22    return (0xff << 24) | (rgb << 16) | (rgb << 8) | rgb; 
23   }   
24 }