KickJava   Java API By Example, From Geeks To Geeks.

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


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  * GammaTransfer.java
23  *
24  * This class defines the Gamma 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: GammaTransfer.java,v 1.6 2004/08/18 07:13:48 vhardy Exp $
30  */

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

35     public byte [] lutData;
36
37     /**
38      * The amplitude of the Gamma function
39      */

40     public float amplitude;
41
42     /**
43      * The exponent of the Gamma function
44      */

45     public float exponent;
46
47     /**
48      * The offset of the Gamma function
49      */

50     public float offset;
51
52     /**
53      * Three floats as the input for the Gamma function
54      */

55     public GammaTransfer(float amplitude, float exponent, float offset){
56         this.amplitude = amplitude;
57         this.exponent = exponent;
58         this.offset = offset;
59     }
60
61     /*
62      * This method will build the lut data. Each entry's
63      * value is in form of "amplitude*pow(C, exponent) + offset"
64      */

65     private void buildLutData(){
66         lutData = new byte [256];
67         int j, v;
68         for (j=0; j<=255; j++){
69             v = (int)Math.round(255*(amplitude*Math.pow(j/255f, exponent)+offset));
70             if(v > 255){
71                 v = (byte)0xff;
72             }
73             else if(v < 0){
74                 v = (byte)0x00;
75             }
76             lutData[j] = (byte)(v & 0xff);
77         }
78     }
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