/Users/lyon/j4p/src/j2d/hpp/Threshold3Processor.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 Threshold3Processor implements 
15           HppFilter3Interface, 
16           ImageProcessorInterface { 
17       private double threshold; 
18    
19       public Threshold3Processor(double _b) { 
20           threshold = _b; 
21       } 
22    
23       public Image process(Image img) { 
24           System.out.println("threshold="+threshold); 
25           return new HppFilter3ImageProcessor( 
26                   new Threshold3Processor(threshold) 
27                           ).process(img); 
28       } 
29       public int average(int r, int g, int b){ 
30           return (r + g + b)/3; 
31       } 
32       public short getR(int r, int g, int b) { 
33           return thresholdFunction(average(r,g,b)); 
34       } 
35    
36       public short getG(int r, int g, int b) { 
37           return thresholdFunction(average(r,g,b)); 
38       } 
39    
40       public short getB(int r, int g, int b) { 
41           return thresholdFunction(average(r,g,b)); 
42       } 
43    
44       private short thresholdFunction(double v) { 
45           if (v < threshold) return 0; 
46           return 255; 
47       } 
48    
49   } 
50