KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > image > ConcreteComponentTransferFunction


1 /*
2
3    Copyright 2001 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.ext.awt.image;
19
20
21
22 /**
23  * This class implements the interface expected from a component
24  * transfer function.
25  *
26  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
27  * @version $Id: ConcreteComponentTransferFunction.java,v 1.3 2004/08/18 07:13:48 vhardy Exp $
28  */

29 public class ConcreteComponentTransferFunction implements ComponentTransferFunction {
30     private int type;
31     private float slope;
32     private float[] tableValues;
33     private float intercept;
34     private float amplitude;
35     private float exponent;
36     private float offset;
37
38     /**
39      * Instances should be created through the various
40      * factory methods.
41      */

42     private ConcreteComponentTransferFunction(){
43     }
44
45     /**
46      * Returns an instance initialized as an identity
47      * transfer function
48      */

49     public static ComponentTransferFunction getIdentityTransfer(){
50         ConcreteComponentTransferFunction f = new ConcreteComponentTransferFunction();
51         f.type = IDENTITY;
52         return f;
53     }
54
55     /**
56      * Returns a table transfer function
57      */

58     public static ComponentTransferFunction
59         getTableTransfer(float tableValues[]){
60         ConcreteComponentTransferFunction f = new ConcreteComponentTransferFunction();
61         f.type = TABLE;
62         
63         if(tableValues == null){
64             throw new IllegalArgumentException JavaDoc();
65         }
66
67         if(tableValues.length < 2){
68             throw new IllegalArgumentException JavaDoc();
69         }
70
71         f.tableValues = new float[tableValues.length];
72         System.arraycopy(tableValues, 0,
73                          f.tableValues, 0,
74                          tableValues.length);
75
76         return f;
77     }
78
79     /**
80      * Returns a discrete transfer function
81      */

82     public static ComponentTransferFunction
83         getDiscreteTransfer(float tableValues[]){
84         ConcreteComponentTransferFunction f = new ConcreteComponentTransferFunction();
85         f.type = DISCRETE;
86         
87         if(tableValues == null){
88             throw new IllegalArgumentException JavaDoc();
89         }
90
91         if(tableValues.length < 2){
92             throw new IllegalArgumentException JavaDoc();
93         }
94
95         f.tableValues = new float[tableValues.length];
96         System.arraycopy(tableValues, 0,
97                          f.tableValues, 0,
98                          tableValues.length);
99
100         return f;
101     }
102
103     /**
104      * Returns a linear transfer function
105      */

106     public static ComponentTransferFunction
107         getLinearTransfer(float slope, float intercept){
108         ConcreteComponentTransferFunction f = new ConcreteComponentTransferFunction();
109         f.type = LINEAR;
110         f.slope = slope;
111         f.intercept = intercept;
112
113         return f;
114     }
115
116     /**
117      * Returns a gamma function
118      */

119     public static ComponentTransferFunction
120         getGammaTransfer(float amplitude,
121                          float exponent,
122                          float offset){
123         ConcreteComponentTransferFunction f = new ConcreteComponentTransferFunction();
124         f.type = GAMMA;
125         f.amplitude = amplitude;
126         f.exponent = exponent;
127         f.offset = offset;
128
129         return f;
130     }
131         
132     /**
133      * Returns the type of this transfer function
134      */

135     public int getType(){
136         return type;
137     }
138
139     /**
140      * Returns the slope value for this transfer function
141      */

142     public float getSlope(){
143         return slope;
144     }
145
146     /**
147      * Returns the table values for this transfer function
148      */

149     public float[] getTableValues(){
150         return tableValues;
151     }
152
153     /**
154      * Returns the intercept value for this transfer function
155      */

156     public float getIntercept(){
157         return intercept;
158     }
159
160     /**
161      * Returns the amplitude value for this transfer function
162      */

163     public float getAmplitude(){
164         return amplitude;
165     }
166
167     /**
168      * Returns the exponent value for this transfer function
169      */

170     public float getExponent(){
171         return exponent;
172     }
173
174     /**
175      * Returns the offset value for this transfer function
176      */

177     public float getOffset(){
178         return offset;
179     }
180 }
181
182
Popular Tags