/Users/lyon/j4p/src/j2d/hpp/HppFilter3ImageProcessor.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.ImageProcessorInterface; 
10   import j2d.ShortImageBean; 
11    
12   import java.awt.*; 
13    
14   public class HppFilter3ImageProcessor 
15           implements ImageProcessorInterface { 
16       private HppFilter3Interface f = null; 
17    
18    
19       public HppFilter3ImageProcessor(HppFilter3Interface _f) { 
20           f = _f; 
21       } 
22    
23       public Image process(Image img) { 
24           ShortImageBean sib = new ShortImageBean(img); 
25           short r[][] = sib.getR(); 
26           short g[][] = sib.getG(); 
27           short b[][] = sib.getB(); 
28           short red, green, blue; 
29           for (int x = 0; x < r.length; x++) 
30               for (int y = 0; y < r[0].length; y++) { 
31                   red = f.getR(r[x][y], g[x][y], b[x][y]); 
32                   green = f.getG(r[x][y], g[x][y], b[x][y]); 
33                   blue = f.getB(r[x][y], g[x][y], b[x][y]); 
34    
35                   r[x][y] = clip(red); 
36                   g[x][y] = clip(green); 
37                   b[x][y] = clip(blue); 
38               } 
39           return sib.getImage(); 
40       } 
41    
42       private static final short clip(short s) { 
43           if (s < 0) return 0; 
44           if (s > 255) return 255; 
45           return s; 
46       } 
47    
48   } 
49