01: /*
02:
03: Licensed to the Apache Software Foundation (ASF) under one or more
04: contributor license agreements. See the NOTICE file distributed with
05: this work for additional information regarding copyright ownership.
06: The ASF licenses this file to You under the Apache License, Version 2.0
07: (the "License"); you may not use this file except in compliance with
08: the License. You may obtain a copy of the License at
09:
10: http://www.apache.org/licenses/LICENSE-2.0
11:
12: Unless required by applicable law or agreed to in writing, software
13: distributed under the License is distributed on an "AS IS" BASIS,
14: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: See the License for the specific language governing permissions and
16: limitations under the License.
17:
18: */
19: package org.apache.batik.ext.awt.image;
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 475477 2006-11-15 22:44:28Z cam $
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: }
|