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 ShortLookupTable extends LookupTable {
25: private short data[][];
26:
27: public ShortLookupTable(int offset, short[] data) {
28: super (offset, 1);
29: this .data = new short[1][data.length];
30: // The data array stored as a reference
31: this .data[0] = data;
32: }
33:
34: public ShortLookupTable(int offset, short[][] data) {
35: super (offset, data.length);
36: this .data = new short[data.length][data[0].length];
37: for (int i = 0; i < data.length; i++) {
38: // The data array for each band stored as a reference
39: this .data[i] = data[i];
40: }
41: }
42:
43: public final short[][] getTable() {
44: return data;
45: }
46:
47: public short[] lookupPixel(short[] src, short[] dst) {
48: if (dst == null) {
49: dst = new short[src.length];
50: }
51:
52: int offset = getOffset();
53: if (getNumComponents() == 1) {
54: for (int i = 0; i < src.length; i++) {
55: dst[i] = data[0][src[i] - offset];
56: }
57: } else {
58: for (int i = 0; i < getNumComponents(); i++) {
59: dst[i] = data[i][src[i] - offset];
60: }
61: }
62:
63: return dst;
64: }
65:
66: @Override
67: public int[] lookupPixel(int[] src, int[] dst) {
68: if (dst == null) {
69: dst = new int[src.length];
70: }
71:
72: int offset = getOffset();
73: if (getNumComponents() == 1) {
74: for (int i = 0; i < src.length; i++) {
75: dst[i] = data[0][src[i] - offset];
76: }
77: } else {
78: for (int i = 0; i < getNumComponents(); i++) {
79: dst[i] = data[i][src[i] - offset];
80: }
81: }
82:
83: return dst;
84: }
85: }
|