/Users/lyon/j4p/src/gui/Clipper.java

1    package gui; 
2     
3    import j2d.ShortImageBean; 
4     
5    import java.io.Serializable; 
6     
7    public class Clipper implements Serializable { 
8        private static int min = 10000; 
9        private static int max = -10000; 
10       private boolean clipped = false; 
11    
12       public static int getMin() { 
13           return min; 
14       } 
15    
16       public static void setMin(int _min) { 
17           min = _min; 
18       } 
19    
20       public static int getMax() { 
21           return max; 
22       } 
23    
24       public static void setMax(int _max) { 
25           max = _max; 
26       } 
27    
28       public short clip(short i) { 
29           if (i < getMin()) setMin(i); 
30           if (i > getMax()) setMax(i); 
31           if (i < 0) { 
32               setClipped(true); 
33               if (i < getMin()) setMin(i); 
34               return 0; 
35           } 
36           if (i > 255) { 
37               setClipped(true); 
38               return 255; 
39           } 
40           return i; 
41       } 
42    
43       public void clip(ShortImageBean sib) { 
44           clip(sib.getR(), sib.getG(), sib.getB()); 
45       } 
46    
47       public void clip(short r[][], short g[][], short b[][]) { 
48           int width = r.length; 
49           int height = r[0].length; 
50           for (int x = 0; x < width; x++) 
51               for (int y = 0; y < height; y++) { 
52                   r[x][y] = clip(r[x][y]); 
53                   g[x][y] = clip(g[x][y]); 
54                   b[x][y] = clip(b[x][y]); 
55               } 
56       } 
57    
58       public boolean isClipped() { 
59           return clipped; 
60       } 
61    
62       public void setClipped(boolean clipped) { 
63           this.clipped = clipped; 
64       } 
65   }