01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: * @author Oleg V. Khaschansky
19: * @version $Revision$
20: *
21: * @date: Oct 14, 2005
22: */package java.awt.image;
23:
24: public class ByteLookupTable extends LookupTable {
25: private byte data[][];
26:
27: public ByteLookupTable(int offset, byte[] data) {
28: super (offset, 1);
29: if (data.length < 1)
30: throw new IllegalArgumentException(
31: "Length of data should not be less then one");
32: this .data = new byte[1][data.length];
33: // The data array stored as a reference
34: this .data[0] = data;
35: }
36:
37: public ByteLookupTable(int offset, byte[][] data) {
38: super (offset, data.length);
39: this .data = new byte[data.length][data[0].length];
40: for (int i = 0; i < data.length; i++) {
41: // The data array for each band stored as a reference
42: this .data[i] = data[i];
43: }
44: }
45:
46: public final byte[][] getTable() {
47: // Returns data by reference
48: return data;
49: }
50:
51: @Override
52: public int[] lookupPixel(int[] src, int[] dst) {
53: if (dst == null) {
54: dst = new int[src.length];
55: }
56:
57: int offset = getOffset();
58: if (getNumComponents() == 1) {
59: for (int i = 0; i < src.length; i++) {
60: dst[i] = data[0][src[i] - offset];
61: }
62: } else {
63: for (int i = 0; i < getNumComponents(); i++) {
64: dst[i] = data[i][src[i] - offset];
65: }
66: }
67:
68: return dst;
69: }
70:
71: public byte[] lookupPixel(byte[] src, byte[] dst) {
72: if (dst == null) {
73: dst = new byte[src.length];
74: }
75:
76: int offset = getOffset();
77: if (getNumComponents() == 1) {
78: for (int i = 0; i < src.length; i++) {
79: dst[i] = data[0][src[i] - offset];
80: }
81: } else {
82: for (int i = 0; i < getNumComponents(); i++) {
83: dst[i] = data[i][src[i] - offset];
84: }
85: }
86:
87: return dst;
88: }
89: }
|