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

1    /* 
2     * Created by DocJava, Inc. 
3     * User: lyon 
4     * Date: Feb 28, 2003 
5     * Time: 7:44:33 AM 
6     */ 
7    package j2d.hpp; 
8     
9    import j2d.ImageProcessorInterface; 
10    
11   import java.awt.*; 
12    
13    
14   public class ThresholdProcessor implements 
15           HppFilterInterface, ImageProcessorInterface { 
16       private double threshold; 
17    
18       public ThresholdProcessor(double _b) { 
19    
20           threshold = _b; 
21    
22       } 
23    
24       public Image process(Image img) { 
25           return new HppFilterImageProcessor( 
26                   new ThresholdProcessor(threshold) 
27           ).process(img); 
28       } 
29    
30       public short getR(int r) { 
31           return thresholdFunction(r); 
32       } 
33    
34       public short getG(int g) { 
35           return thresholdFunction(g); 
36       } 
37    
38       public short getB(int b) { 
39           return thresholdFunction(b); 
40       } 
41    
42       private short thresholdFunction(double v) { 
43           if (v < threshold) return 0; 
44           return 255; 
45       } 
46    
47   } 
48