summaryrefslogtreecommitdiffstats
path: root/libjava/java/awt/image
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/awt/image')
-rw-r--r--libjava/java/awt/image/BufferedImage.java54
-rw-r--r--libjava/java/awt/image/ByteLookupTable.java162
-rw-r--r--libjava/java/awt/image/ColorModel.java5
-rw-r--r--libjava/java/awt/image/Kernel.java136
-rw-r--r--libjava/java/awt/image/LookupTable.java109
-rw-r--r--libjava/java/awt/image/MemoryImageSource.java45
-rw-r--r--libjava/java/awt/image/RGBImageFilter.java4
-rw-r--r--libjava/java/awt/image/ShortLookupTable.java162
8 files changed, 653 insertions, 24 deletions
diff --git a/libjava/java/awt/image/BufferedImage.java b/libjava/java/awt/image/BufferedImage.java
index 547301da8d8..b18779af146 100644
--- a/libjava/java/awt/image/BufferedImage.java
+++ b/libjava/java/awt/image/BufferedImage.java
@@ -47,6 +47,8 @@ import java.awt.Transparency;
import java.awt.color.ColorSpace;
import java.util.Hashtable;
import java.util.Vector;
+import java.util.HashSet;
+import java.util.Iterator;
import gnu.java.awt.ComponentDataBlitOp;
/**
@@ -442,7 +444,57 @@ public class BufferedImage extends Image
public ImageProducer getSource()
{
- throw new UnsupportedOperationException("not implemented");
+ return new ImageProducer() {
+
+ HashSet consumers = new HashSet();
+
+ public void addConsumer(ImageConsumer ic)
+ {
+ consumers.add(ic);
+ }
+
+ public boolean isConsumer(ImageConsumer ic)
+ {
+ return consumers.contains(ic);
+ }
+
+ public void removeConsumer(ImageConsumer ic)
+ {
+ consumers.remove(ic);
+ }
+
+ public void startProduction(ImageConsumer ic)
+ {
+ int x = 0;
+ int y = 0;
+ int width = getWidth();
+ int height = getHeight();
+ int stride = width;
+ int offset = 0;
+ int[] pixels = getRGB(x, y,
+ width, height,
+ (int[])null, offset, stride);
+ ColorModel model = getColorModel();
+
+ consumers.add(ic);
+
+ Iterator i = consumers.iterator();
+ while(i.hasNext())
+ {
+ ImageConsumer c = (ImageConsumer) i.next();
+ c.setHints(ImageConsumer.SINGLEPASS);
+ c.setDimensions(getWidth(), getHeight());
+ c.setPixels(x, y, width, height, model, pixels, offset, stride);
+ c.imageComplete(ImageConsumer.STATICIMAGEDONE);
+ }
+ }
+
+ public void requestTopDownLeftRightResend(ImageConsumer ic)
+ {
+ startProduction(ic);
+ }
+
+ };
}
public Vector getSources()
diff --git a/libjava/java/awt/image/ByteLookupTable.java b/libjava/java/awt/image/ByteLookupTable.java
new file mode 100644
index 00000000000..572f6e9212d
--- /dev/null
+++ b/libjava/java/awt/image/ByteLookupTable.java
@@ -0,0 +1,162 @@
+/* ByteLookupTable.java -- Java class for a pixel translation table.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.awt.image;
+
+/**
+ * ByteLookupTable represents translation arrays for pixel values. It wraps
+ * one or more data arrays for each layer (or component) in an image, such as
+ * Alpha, R, G, and B. When doing translation, the offset is subtracted from
+ * the pixel values to allow a subset of an array to be used.
+ *
+ * @author <a href="mailto:jlquinn@optonline.net">Jerry Quinn</a>
+ * @version 1.0
+ */
+public class ByteLookupTable extends LookupTable
+{
+ // Array of translation tables.
+ private byte data[][];
+
+ /**
+ * Creates a new <code>ByteLookupTable</code> instance.
+ *
+ * Offset is subtracted from pixel values when looking up in the translation
+ * tables. If data.length is one, the same table is applied to all pixel
+ * components.
+ *
+ * @param offset Offset to be subtracted.
+ * @param data Array of lookup tables.
+ * @exception IllegalArgumentException if offset < 0 or data.length < 1.
+ */
+ public ByteLookupTable(int offset, byte[][] data)
+ throws IllegalArgumentException
+ {
+ super(offset, data.length);
+ this.data = data;
+ }
+
+ /**
+ * Creates a new <code>ByteLookupTable</code> instance.
+ *
+ * Offset is subtracted from pixel values when looking up in the translation
+ * table. The same table is applied to all pixel components.
+ *
+ * @param offset Offset to be subtracted.
+ * @param data Lookup table for all components.
+ * @exception IllegalArgumentException if offset < 0.
+ */
+ public ByteLookupTable(int offset, byte[] data)
+ throws IllegalArgumentException
+ {
+ super(offset, 1);
+ this.data = new byte[][] {data};
+ }
+
+ /** Return the lookup tables. */
+ public final byte[][] getTable()
+ {
+ return data;
+ }
+
+ /**
+ * Return translated values for a pixel.
+ *
+ * For each value in the pixel src, use the value minus offset as an index
+ * in the component array and copy the value there to the output for the
+ * component. If dest is null, the output is a new array, otherwise the
+ * translated values are written to dest. Dest can be the same array as
+ * src.
+ *
+ * For example, if the pixel src is [2, 4, 3], and offset is 1, the output
+ * is [comp1[1], comp2[3], comp3[2]], where comp1, comp2, and comp3 are the
+ * translation arrays.
+ *
+ * @param src Component values of a pixel.
+ * @param dest Destination array for values, or null.
+ * @return Translated values for the pixel.
+ */
+ public int[] lookupPixel(int[] src, int[] dst)
+ throws ArrayIndexOutOfBoundsException
+ {
+ if (dst == null)
+ dst = new int[numComponents];
+
+ if (data.length == 1)
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[0][src[i] - offset];
+ else
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[i][src[i] - offset];
+
+ return dst;
+ }
+
+ /**
+ * Return translated values for a pixel.
+ *
+ * For each value in the pixel src, use the value minus offset as an index
+ * in the component array and copy the value there to the output for the
+ * component. If dest is null, the output is a new array, otherwise the
+ * translated values are written to dest. Dest can be the same array as
+ * src.
+ *
+ * For example, if the pixel src is [2, 4, 3], and offset is 1, the output
+ * is [comp1[1], comp2[3], comp3[2]], where comp1, comp2, and comp3 are the
+ * translation arrays.
+ *
+ * @param src Component values of a pixel.
+ * @param dest Destination array for values, or null.
+ * @return Translated values for the pixel.
+ */
+ public byte[] lookupPixel(byte[] src, byte[] dst)
+ throws ArrayIndexOutOfBoundsException
+ {
+ if (dst == null)
+ dst = new byte[numComponents];
+
+ if (data.length == 1)
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[0][((int)src[i]) - offset];
+ else
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[i][((int)src[i]) - offset];
+
+ return dst;
+
+ }
+}
diff --git a/libjava/java/awt/image/ColorModel.java b/libjava/java/awt/image/ColorModel.java
index c73f4fd4e58..87ab942917a 100644
--- a/libjava/java/awt/image/ColorModel.java
+++ b/libjava/java/awt/image/ColorModel.java
@@ -37,6 +37,7 @@ exception statement from your version. */
package java.awt.image;
+import java.util.Arrays;
import java.awt.Point;
import java.awt.Transparency;
import java.awt.color.ColorSpace;
@@ -551,8 +552,8 @@ public abstract class ColorModel implements Transparency
(transferType == o.transferType) &&
(transparency == o.transparency) &&
(hasAlpha == o.hasAlpha) &&
- (isAlphaPremultiplied == isAlphaPremultiplied) &&
- (bits.equals(o.bits)) &&
+ (isAlphaPremultiplied == o.isAlphaPremultiplied) &&
+ Arrays.equals(bits, o.bits) &&
(cspace.equals(o.cspace));
}
diff --git a/libjava/java/awt/image/Kernel.java b/libjava/java/awt/image/Kernel.java
new file mode 100644
index 00000000000..27d6ddd8fae
--- /dev/null
+++ b/libjava/java/awt/image/Kernel.java
@@ -0,0 +1,136 @@
+/* Kernel.java -- Java class for an image processing kernel
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.awt.image;
+
+/**
+ * Kernel represents an image processing kernel. It gets used to hold
+ * convolution filters among other purposes. It stores an array of float
+ * values representing a 2-dimensional array in row-major order.
+ *
+ * @author <a href="mailto:jlquinn@optonline.net">Jerry Quinn</a>
+ * @version 1.0
+ */
+public class Kernel implements Cloneable
+{
+ private final int width;
+ private final int height;
+ private final float[] data;
+
+ /**
+ * Creates a new <code>Kernel</code> instance.
+ *
+ * @param width The 2D width of data.
+ * @param height The 2D height of data.
+ * @param data The source data array.
+ * @exception IllegalArgumentException if width * height < data.length.
+ */
+ public Kernel(int width, int height, float[] data)
+ throws IllegalArgumentException
+ {
+ this.width = width;
+ this.height = height;
+ if (data.length < width * height || width < 0 || height < 0)
+ throw new IllegalArgumentException();
+ this.data = new float[width * height];
+ System.arraycopy(data, 0, this.data, 0, width * height);
+ }
+
+ /**
+ * Return the X origin: (width - 1) / 2
+ */
+ public final int getXOrigin()
+ {
+ return (width - 1) / 2;
+ }
+
+ /**
+ * Return the Y origin: (height - 1) / 2
+ */
+ public final int getYOrigin()
+ {
+ return (height - 1) / 2;
+ }
+
+ /**
+ * @return The kernel width.
+ */
+ public final int getWidth()
+ {
+ return width;
+ }
+
+ /**
+ * @return The kernel height.
+ */
+ public final int getHeight()
+ {
+ return height;
+ }
+
+ /**
+ * Return the kernel data.
+ *
+ * If data is null, allocates a new array and returns it. Otherwise, the
+ * kernel values are copied into data.
+ *
+ * @param data Array to copy values into, or null.
+ * @return The array with copied values.
+ * @exception IllegalArgumentException if data != null and too small.
+ */
+ public final float[] getKernelData(float[] data)
+ throws IllegalArgumentException
+ {
+ if (data == null)
+ return (float[])this.data.clone();
+
+ if (data.length < this.data.length)
+ throw new IllegalArgumentException();
+
+ System.arraycopy(this.data, 0, data, 0, this.data.length);
+ return data;
+ }
+
+ /**
+ * @return a clone of this Kernel.
+ */
+ public Object clone()
+ {
+ return new Kernel(width, height, data);
+ }
+}
diff --git a/libjava/java/awt/image/LookupTable.java b/libjava/java/awt/image/LookupTable.java
new file mode 100644
index 00000000000..eb89795c2c8
--- /dev/null
+++ b/libjava/java/awt/image/LookupTable.java
@@ -0,0 +1,109 @@
+/* LookupTable.java -- Java class for a pixel translation table.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.awt.image;
+
+/**
+ * LookupTable represents translation arrays for pixel values. It wraps one
+ * or more data arrays for each layer (or component) in an image, such as
+ * Alpha, R, G, and B. When doing translation, the offset is subtracted from
+ * the pixel values to allow a subset of an array to be used.
+ *
+ * @see ByteLookupTable
+ * @see ShortLookupTable
+ *
+ * @author <a href="mailto:jlquinn@optonline.net">Jerry Quinn</a>
+ * @version 1.0
+ */
+public abstract class LookupTable
+{
+ // Not protected since that's part of the public API.
+ int offset;
+ int numComponents;
+
+ /**
+ * Creates a new <code>LookupTable</code> instance.
+ *
+ * If numComponents is 1, the same translation table is used for all pixel
+ * components.
+ *
+ * @param offset Offset to be subtracted.
+ * @param numComponents Number of image components.
+ * @exception IllegalArgumentException if offset < 0 or numComponents < 1.
+ */
+ protected LookupTable(int offset, int numComponents)
+ throws IllegalArgumentException
+ {
+ if (offset < 0 || numComponents < 1)
+ throw new IllegalArgumentException();
+ this.offset = offset;
+ this.numComponents = numComponents;
+ }
+
+ /** Return the number of components. */
+ public int getNumComponents()
+ {
+ return numComponents;
+ }
+
+ /** Return the offset. */
+ public int getOffset()
+ {
+ return offset;
+ }
+
+
+ /**
+ * Return translated values for a pixel.
+ *
+ * For each value in the pixel src, use the value minus offset as an index
+ * in the component array and copy the value there to the output for the
+ * component. If dest is null, the output is a new array, otherwise the
+ * translated values are written to dest. Dest can be the same array as
+ * src.
+ *
+ * For example, if the pixel src is [2, 4, 3], and offset is 1, the output
+ * is [comp1[1], comp2[3], comp3[2]], where comp1, comp2, and comp3 are the
+ * translation arrays.
+ *
+ * @param src Component values of a pixel.
+ * @param dest Destination array for values, or null.
+ * @return Translated values for the pixel.
+ */
+ public abstract int[] lookupPixel(int[] src, int[] dest);
+}
diff --git a/libjava/java/awt/image/MemoryImageSource.java b/libjava/java/awt/image/MemoryImageSource.java
index d86119993ec..ddd5800f14f 100644
--- a/libjava/java/awt/image/MemoryImageSource.java
+++ b/libjava/java/awt/image/MemoryImageSource.java
@@ -41,6 +41,7 @@ package java.awt.image;
import java.awt.Image;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Vector;
public class MemoryImageSource implements ImageProducer
{
@@ -49,7 +50,8 @@ public class MemoryImageSource implements ImageProducer
private int pixeli[], width, height, offset, scansize;
private byte pixelb[];
private ColorModel cm;
- private Hashtable props, consumers = new Hashtable();
+ private Hashtable props = new Hashtable();
+ private Vector consumers = new Vector();
/**
Constructs an ImageProducer from memory
@@ -126,10 +128,10 @@ public class MemoryImageSource implements ImageProducer
* <code>ImageProducer</code>.
*/
public synchronized void addConsumer(ImageConsumer ic) {
- if (consumers.containsKey(ic))
+ if (consumers.contains(ic))
return;
- consumers.put(ic, ic);
+ consumers.addElement(ic);
}
/**
@@ -137,7 +139,7 @@ public class MemoryImageSource implements ImageProducer
* already registered with this <code>ImageProducer</code>.
*/
public synchronized boolean isConsumer(ImageConsumer ic) {
- if (consumers.containsKey(ic))
+ if (consumers.contains(ic))
return true;
return false;
}
@@ -147,7 +149,7 @@ public class MemoryImageSource implements ImageProducer
* registered consumers for this <code>ImageProducer</code>.
*/
public synchronized void removeConsumer(ImageConsumer ic) {
- consumers.remove(ic);
+ consumers.removeElement(ic);
}
/**
@@ -157,16 +159,16 @@ public class MemoryImageSource implements ImageProducer
* registered consumers.
*/
public void startProduction(ImageConsumer ic) {
- if (!(consumers.containsKey(ic))) {
- consumers.put(ic, ic);
+ if (!(consumers.contains(ic))) {
+ consumers.addElement(ic);
}
- Enumeration e = consumers.elements();
- for( ; e.hasMoreElements(); ) {
- ic = (ImageConsumer)e.nextElement();
+
+ Vector list = (Vector) consumers.clone();
+ for(int i = 0; i < list.size(); i++) {
+ ic = (ImageConsumer) list.elementAt(i);
sendPicture( ic );
- ic.imageComplete( ImageConsumer.SINGLEFRAME );
+ ic.imageComplete( ImageConsumer.STATICIMAGEDONE );
}
-
}
/**
@@ -210,9 +212,9 @@ public class MemoryImageSource implements ImageProducer
{
if( animated == true ) {
ImageConsumer ic;
- Enumeration e = consumers.elements();
- for( ; e.hasMoreElements(); ) {
- ic = (ImageConsumer)e.nextElement();
+ Vector list = (Vector) consumers.clone();
+ for(int i = 0; i < list.size(); i++) {
+ ic = (ImageConsumer) list.elementAt(i);
sendPicture( ic );
ic.imageComplete( ImageConsumer.SINGLEFRAME );
}
@@ -227,6 +229,7 @@ public class MemoryImageSource implements ImageProducer
ic.setProperties( props );
}
ic.setDimensions(width, height);
+ ic.setColorModel(cm);
if( pixeli != null ) {
ic.setPixels( 0, 0, width, height, cm, pixeli, offset, scansize );
} else {
@@ -249,9 +252,9 @@ public class MemoryImageSource implements ImageProducer
newPixels();
} else {
ImageConsumer ic;
- Enumeration e = consumers.elements();
- for( ; e.hasMoreElements(); ) {
- ic = (ImageConsumer)e.nextElement();
+ Vector list = (Vector) consumers.clone();
+ for(int i = 0; i < list.size(); i++) {
+ ic = (ImageConsumer) list.elementAt(i);
ic.setHints( ImageConsumer.TOPDOWNLEFTRIGHT );
if( props != null ) {
ic.setProperties( props );
@@ -294,9 +297,9 @@ public class MemoryImageSource implements ImageProducer
newPixels();
} else {
ImageConsumer ic;
- Enumeration e = consumers.elements();
- for( ; e.hasMoreElements(); ) {
- ic = (ImageConsumer)e.nextElement();
+ Vector list = (Vector) consumers.clone();
+ for(int i = 0; i < list.size(); i++) {
+ ic = (ImageConsumer) list.elementAt(i);
ic.setHints( ImageConsumer.TOPDOWNLEFTRIGHT );
if( props != null ) {
ic.setProperties( props );
diff --git a/libjava/java/awt/image/RGBImageFilter.java b/libjava/java/awt/image/RGBImageFilter.java
index 5718024e761..819580e0057 100644
--- a/libjava/java/awt/image/RGBImageFilter.java
+++ b/libjava/java/awt/image/RGBImageFilter.java
@@ -79,6 +79,10 @@ public abstract class RGBImageFilter extends ImageFilter
if( ( model instanceof IndexColorModel) && canFilterIndexColorModel ) {
newmodel = filterIndexColorModel( (IndexColorModel) model );
+ consumer.setColorModel(newmodel);
+ }
+ else {
+ consumer.setColorModel(ColorModel.getRGBdefault());
}
}
diff --git a/libjava/java/awt/image/ShortLookupTable.java b/libjava/java/awt/image/ShortLookupTable.java
new file mode 100644
index 00000000000..223d03bf53b
--- /dev/null
+++ b/libjava/java/awt/image/ShortLookupTable.java
@@ -0,0 +1,162 @@
+/* ShortLookupTable.java -- Java class for a pixel translation table.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.awt.image;
+
+/**
+ * ShortLookupTable represents translation arrays for pixel values. It wraps
+ * one or more data arrays for each layer (or component) in an image, such as
+ * Alpha, R, G, and B. When doing translation, the offset is subtracted from
+ * the pixel values to allow a subset of an array to be used.
+ *
+ * @author <a href="mailto:jlquinn@optonline.net">Jerry Quinn</a>
+ * @version 1.0
+ */
+public class ShortLookupTable extends LookupTable
+{
+ // Array of translation tables.
+ private short data[][];
+
+ /**
+ * Creates a new <code>ShortLookupTable</code> instance.
+ *
+ * Offset is subtracted from pixel values when looking up in the translation
+ * tables. If data.length is one, the same table is applied to all pixel
+ * components.
+ *
+ * @param offset Offset to be subtracted.
+ * @param data Array of lookup tables.
+ * @exception IllegalArgumentException if offset < 0 or data.length < 1.
+ */
+ public ShortLookupTable(int offset, short[][] data)
+ throws IllegalArgumentException
+ {
+ super(offset, data.length);
+ this.data = data;
+ }
+
+ /**
+ * Creates a new <code>ShortLookupTable</code> instance.
+ *
+ * Offset is subtracted from pixel values when looking up in the translation
+ * table. The same table is applied to all pixel components.
+ *
+ * @param offset Offset to be subtracted.
+ * @param data Lookup table for all components.
+ * @exception IllegalArgumentException if offset < 0.
+ */
+ public ShortLookupTable(int offset, short[] data)
+ throws IllegalArgumentException
+ {
+ super(offset, 1);
+ this.data = new short[][] {data};
+ }
+
+ /** Return the lookup tables. */
+ public final short[][] getTable()
+ {
+ return data;
+ }
+
+ /**
+ * Return translated values for a pixel.
+ *
+ * For each value in the pixel src, use the value minus offset as an index
+ * in the component array and copy the value there to the output for the
+ * component. If dest is null, the output is a new array, otherwise the
+ * translated values are written to dest. Dest can be the same array as
+ * src.
+ *
+ * For example, if the pixel src is [2, 4, 3], and offset is 1, the output
+ * is [comp1[1], comp2[3], comp3[2]], where comp1, comp2, and comp3 are the
+ * translation arrays.
+ *
+ * @param src Component values of a pixel.
+ * @param dest Destination array for values, or null.
+ * @return Translated values for the pixel.
+ */
+ public int[] lookupPixel(int[] src, int[] dst)
+ throws ArrayIndexOutOfBoundsException
+ {
+ if (dst == null)
+ dst = new int[numComponents];
+
+ if (data.length == 1)
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[0][src[i] - offset];
+ else
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[i][src[i] - offset];
+
+ return dst;
+ }
+
+ /**
+ * Return translated values for a pixel.
+ *
+ * For each value in the pixel src, use the value minus offset as an index
+ * in the component array and copy the value there to the output for the
+ * component. If dest is null, the output is a new array, otherwise the
+ * translated values are written to dest. Dest can be the same array as
+ * src.
+ *
+ * For example, if the pixel src is [2, 4, 3], and offset is 1, the output
+ * is [comp1[1], comp2[3], comp3[2]], where comp1, comp2, and comp3 are the
+ * translation arrays.
+ *
+ * @param src Component values of a pixel.
+ * @param dest Destination array for values, or null.
+ * @return Translated values for the pixel.
+ */
+ public short[] lookupPixel(short[] src, short[] dst)
+ throws ArrayIndexOutOfBoundsException
+ {
+ if (dst == null)
+ dst = new short[numComponents];
+
+ if (data.length == 1)
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[0][((int)src[i]) - offset];
+ else
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[i][((int)src[i]) - offset];
+
+ return dst;
+
+ }
+}
OpenPOWER on IntegriCloud