/Users/lyon/j4p/src/j2d/hpp/HppFilterImageProcessor.java

1    /* 
2     * Created by DocJava, Inc. 
3     * User: lyon 
4     * Date: Mar 1, 2003 
5     * Time: 9:45:14 AM 
6     */ 
7    package j2d.hpp; 
8     
9    import j2d.ImageUtils; 
10   import j2d.ImageProcessorInterface; 
11    
12   import java.awt.*; 
13   import java.awt.image.BufferedImage; 
14   import java.awt.image.BufferedImageOp; 
15   import java.awt.image.LookupOp; 
16   import java.awt.image.ShortLookupTable; 
17    
18   public class HppFilterImageProcessor 
19           implements ImageProcessorInterface { 
20       private HppFilterInterface f = null; 
21       short lut[][] = new short[3][256]; 
22    
23       public HppFilterImageProcessor(HppFilterInterface _f) { 
24           f = _f; 
25           for (int v = 0; v < 256; v++) { 
26               lut[0][v] = f.getR(v); 
27               lut[1][v] = f.getG(v); 
28               lut[2][v] = f.getB(v); 
29           } 
30       } 
31    
32       public static Image getImage(Image img, HppFilterInterface f) { 
33           HppFilterImageProcessor hbi = new HppFilterImageProcessor(f); 
34           return hbi.process(img); 
35       } 
36    
37       public Image process(Image img) { 
38           return ImageUtils.getImage( 
39                   process( 
40                           ImageUtils.getBufferedImage(img))); 
41       } 
42    
43       public BufferedImage process(BufferedImage image) { 
44           // create filter to invert colors 
45           BufferedImageOp bio = new LookupOp( 
46                   new ShortLookupTable(0, lut), null); 
47    
48           // apply filter to displayImage 
49           return bio.filter(image, null); 
50    
51       } 
52   } 
53