0N/A/*
2362N/A * Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.awt.image;
0N/A
0N/A
0N/A/**
0N/A * This class defines a lookup table object. The output of a
0N/A * lookup operation using an object of this class is interpreted
0N/A * as an unsigned byte quantity. The lookup table contains byte
0N/A * data arrays for one or more bands (or components) of an image,
0N/A * and it contains an offset which will be subtracted from the
0N/A * input values before indexing the arrays. This allows an array
0N/A * smaller than the native data size to be provided for a
0N/A * constrained input. If there is only one array in the lookup
0N/A * table, it will be applied to all bands.
0N/A *
0N/A * @see ShortLookupTable
0N/A * @see LookupOp
0N/A */
0N/Apublic class ByteLookupTable extends LookupTable {
0N/A
0N/A /**
0N/A * Constants
0N/A */
0N/A
0N/A byte data[][];
0N/A
0N/A /**
0N/A * Constructs a ByteLookupTable object from an array of byte
0N/A * arrays representing a lookup table for each
0N/A * band. The offset will be subtracted from input
0N/A * values before indexing into the arrays. The number of
0N/A * bands is the length of the data argument. The
0N/A * data array for each band is stored as a reference.
0N/A * @param offset the value subtracted from the input values
0N/A * before indexing into the arrays
0N/A * @param data an array of byte arrays representing a lookup
0N/A * table for each band
0N/A * @throws IllegalArgumentException if <code>offset</code> is
0N/A * is less than 0 or if the length of <code>data</code>
0N/A * is less than 1
0N/A */
0N/A public ByteLookupTable(int offset, byte data[][]) {
0N/A super(offset,data.length);
0N/A numComponents = data.length;
0N/A numEntries = data[0].length;
0N/A this.data = new byte[numComponents][];
0N/A // Allocate the array and copy the data reference
0N/A for (int i=0; i < numComponents; i++) {
0N/A this.data[i] = data[i];
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Constructs a ByteLookupTable object from an array
0N/A * of bytes representing a lookup table to be applied to all
0N/A * bands. The offset will be subtracted from input
0N/A * values before indexing into the array.
0N/A * The data array is stored as a reference.
0N/A * @param offset the value subtracted from the input values
0N/A * before indexing into the array
0N/A * @param data an array of bytes
0N/A * @throws IllegalArgumentException if <code>offset</code> is
0N/A * is less than 0 or if the length of <code>data</code>
0N/A * is less than 1
0N/A */
0N/A public ByteLookupTable(int offset, byte data[]) {
0N/A super(offset,data.length);
0N/A numComponents = 1;
0N/A numEntries = data.length;
0N/A this.data = new byte[1][];
0N/A this.data[0] = data;
0N/A }
0N/A
0N/A /**
0N/A * Returns the lookup table data by reference. If this ByteLookupTable
0N/A * was constructed using a single byte array, the length of the returned
0N/A * array is one.
0N/A * @return the data array of this <code>ByteLookupTable</code>.
0N/A */
0N/A public final byte[][] getTable(){
0N/A return data;
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of samples of a pixel, translated with the lookup
0N/A * table. The source and destination array can be the same array.
0N/A * Array <code>dst</code> is returned.
0N/A *
0N/A * @param src the source array.
0N/A * @param dst the destination array. This array must be at least as
0N/A * long as <code>src</code>. If <code>dst</code> is
0N/A * <code>null</code>, a new array will be allocated having the
0N/A * same length as <code>src</code>.
0N/A * @return the array <code>dst</code>, an <code>int</code> array of
0N/A * samples.
0N/A * @exception ArrayIndexOutOfBoundsException if <code>src</code> is
0N/A * longer than <code>dst</code> or if for any element
0N/A * <code>i</code> of <code>src</code>,
0N/A * <code>src[i]-offset</code> is either less than zero or
0N/A * greater than or equal to the length of the lookup table
0N/A * for any band.
0N/A */
0N/A public int[] lookupPixel(int[] src, int[] dst){
0N/A if (dst == null) {
0N/A // Need to alloc a new destination array
0N/A dst = new int[src.length];
0N/A }
0N/A
0N/A if (numComponents == 1) {
0N/A // Apply one LUT to all bands
0N/A for (int i=0; i < src.length; i++) {
0N/A int s = src[i] - offset;
0N/A if (s < 0) {
0N/A throw new ArrayIndexOutOfBoundsException("src["+i+
0N/A "]-offset is "+
0N/A "less than zero");
0N/A }
0N/A dst[i] = (int) data[0][s];
0N/A }
0N/A }
0N/A else {
0N/A for (int i=0; i < src.length; i++) {
0N/A int s = src[i] - offset;
0N/A if (s < 0) {
0N/A throw new ArrayIndexOutOfBoundsException("src["+i+
0N/A "]-offset is "+
0N/A "less than zero");
0N/A }
0N/A dst[i] = (int) data[i][s];
0N/A }
0N/A }
0N/A return dst;
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of samples of a pixel, translated with the lookup
0N/A * table. The source and destination array can be the same array.
0N/A * Array <code>dst</code> is returned.
0N/A *
0N/A * @param src the source array.
0N/A * @param dst the destination array. This array must be at least as
0N/A * long as <code>src</code>. If <code>dst</code> is
0N/A * <code>null</code>, a new array will be allocated having the
0N/A * same length as <code>src</code>.
0N/A * @return the array <code>dst</code>, an <code>int</code> array of
0N/A * samples.
0N/A * @exception ArrayIndexOutOfBoundsException if <code>src</code> is
0N/A * longer than <code>dst</code> or if for any element
0N/A * <code>i</code> of <code>src</code>,
0N/A * <code>(src[i]&0xff)-offset</code> is either less than
0N/A * zero or greater than or equal to the length of the
0N/A * lookup table for any band.
0N/A */
0N/A public byte[] lookupPixel(byte[] src, byte[] dst){
0N/A if (dst == null) {
0N/A // Need to alloc a new destination array
0N/A dst = new byte[src.length];
0N/A }
0N/A
0N/A if (numComponents == 1) {
0N/A // Apply one LUT to all bands
0N/A for (int i=0; i < src.length; i++) {
0N/A int s = (src[i]&0xff) - offset;
0N/A if (s < 0) {
0N/A throw new ArrayIndexOutOfBoundsException("src["+i+
0N/A "]-offset is "+
0N/A "less than zero");
0N/A }
0N/A dst[i] = data[0][s];
0N/A }
0N/A }
0N/A else {
0N/A for (int i=0; i < src.length; i++) {
0N/A int s = (src[i]&0xff) - offset;
0N/A if (s < 0) {
0N/A throw new ArrayIndexOutOfBoundsException("src["+i+
0N/A "]-offset is "+
0N/A "less than zero");
0N/A }
0N/A dst[i] = data[i][s];
0N/A }
0N/A }
0N/A return dst;
0N/A }
0N/A
0N/A}