KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

35     public byte [] lutData;
36
37     /**
38      * This int array is the input table values from the user
39      */

40     public int [] tableValues;
41
42     /*
43      * The number of the input table's elements
44      */

45     private int n;
46
47     /*
48      * The input is an int array which will be used
49      * later to construct the lut data
50      */

51     public TableTransfer(int [] tableValues){
52         this.tableValues = tableValues;
53         this.n = tableValues.length;
54     }
55
56     /*
57      * This method will build the lut data. Each entry's
58      * value will increase/decrease between the nearby
59      * intervals.
60      */

61     private void buildLutData(){
62         lutData = new byte [256];
63         int j;
64         float fi, r;
65         int ffi, cfi;
66
67         /*for (j=0; j<n; j++){
68             System.out.println("tableValues[" + j + "] = " + tableValues[j]);
69             }*/

70
71         for (j=0; j<=255; j++){
72             fi = j*(n-1)/255f;
73             ffi = (int)Math.floor(fi);
74             cfi = (ffi + 1)>(n-1)?(n-1):(ffi+1);
75             r = fi - ffi;
76             lutData[j] = (byte)((int)((tableValues[ffi] + r*(tableValues[cfi] - tableValues[ffi])))&0xff);
77             // System.out.println("[" + j + "] : " + ffi + "/" + cfi + "/" + r);
78
}
79         
80         /*for(j=0; j<=255; j++){
81             System.out.print("[" + j + "] = " + (0xff & lutData[j]) + " ");
82             }
83
84         System.out.println();
85         System.out.println();*/

86     }
87
88     /**
89      * This method will return the lut data in order
90      * to construct a LookUpTable object
91      */

92     public byte [] getLookupTable(){
93         buildLutData();
94         return lutData;
95     }
96 }
97
Popular Tags