KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

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

49     public DiscreteTransfer(int [] tableValues){
50         this.tableValues = tableValues;
51         this.n = tableValues.length;
52     }
53
54     /*
55      * This method will build the lut data. Each entry
56      * has the value as its index.
57      */

58     private void buildLutData(){
59         lutData = new byte [256];
60         int i, j;
61         for (j=0; j<=255; j++){
62             i = (int)(Math.floor(j*n/255f));
63             if(i == n){
64                 i = n-1;
65             }
66             lutData[j] = (byte)(tableValues[i] & 0xff);
67         }
68     }
69
70     /**
71      * This method will return the lut data in order
72      * to construct a LookUpTable object
73      */

74     public byte [] getLookupTable(){
75         buildLutData();
76         return lutData;
77     }
78 }
79
Popular Tags