KickJava   Java API By Example, From Geeks To Geeks.

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


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  * LinearTransfer.java
22  *
23  * This class defines the Linear type transfer function for the
24  * feComponentTransfer filter, as defined in chapter 15, section 11 of the SVG
25  * specification.
26  *
27  * @author <a HREF="mailto:sheng.pei@sun.com">Sheng Pei</a>
28  * @version $Id: LinearTransfer.java,v 1.4 2004/08/18 07:13:49 vhardy Exp $
29  */

30 public class LinearTransfer implements TransferFunction {
31     /**
32      * This byte array stores the lookuptable data
33      */

34     public byte [] lutData;
35
36     /**
37      * The slope of the linear function
38      */

39     public float slope;
40
41     /**
42      * The intercept of the linear function
43      */

44     public float intercept;
45
46     /**
47      * Two floats as the input for the function
48      */

49     public LinearTransfer(float slope, float intercept){
50         this.slope = slope;
51         this.intercept = intercept;
52     }
53
54     /*
55      * This method will build the lut data. Each entry's
56      * value is in form of "slope*C+intercept"
57      */

58     private void buildLutData(){
59         lutData = new byte [256];
60         int j, value;
61         float scaledInt = (intercept*255f)+0.5f;
62         for (j=0; j<=255; j++){
63             value = (int)(slope*j+scaledInt);
64             if(value < 0){
65                 value = 0;
66             }
67             else if(value > 255){
68                 value = 255;
69             }
70             lutData[j] = (byte)(0xff & value);
71         }
72
73         /*System.out.println("Linear : " + slope + " / " + intercept);
74         for(j=0; j<=255; j++){
75             System.out.print("[" + j + "] = " + (0xff & lutData[j]) + " ");
76         }
77
78         System.out.println();*/

79     }
80
81     /**
82      * This method will return the lut data in order
83      * to construct a LookUpTable object
84      */

85     public byte [] getLookupTable(){
86         buildLutData();
87         return lutData;
88     }
89 }
90
Popular Tags