summaryrefslogtreecommitdiff
path: root/java/awt/image
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2005-01-14 10:24:02 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2005-01-14 10:24:02 +0000
commitc61f399b1d3c471a8e459a4a2be645f95560f088 (patch)
tree14e7f5759d2cded647d22e019435a770b8ed69e5 /java/awt/image
parent451c55a31fbc6b949f7609dd90932bb2a0d91a19 (diff)
downloadclasspath-c61f399b1d3c471a8e459a4a2be645f95560f088.tar.gz
2005-01-14 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of September 2004 HEAD patches to generics branch.
Diffstat (limited to 'java/awt/image')
-rw-r--r--java/awt/image/AffineTransformOp.java13
-rw-r--r--java/awt/image/BandedSampleModel.java538
-rw-r--r--java/awt/image/BufferedImage.java26
-rw-r--r--java/awt/image/ColorModel.java89
-rw-r--r--java/awt/image/ComponentColorModel.java32
-rw-r--r--java/awt/image/ComponentSampleModel.java16
-rw-r--r--java/awt/image/CropImageFilter.java5
-rw-r--r--java/awt/image/DataBuffer.java231
-rw-r--r--java/awt/image/DataBufferByte.java105
-rw-r--r--java/awt/image/DataBufferDouble.java105
-rw-r--r--java/awt/image/DataBufferFloat.java105
-rw-r--r--java/awt/image/DataBufferInt.java108
-rw-r--r--java/awt/image/DataBufferShort.java105
-rw-r--r--java/awt/image/DataBufferUShort.java97
-rw-r--r--java/awt/image/DirectColorModel.java16
-rw-r--r--java/awt/image/IndexColorModel.java170
-rw-r--r--java/awt/image/MemoryImageSource.java4
-rw-r--r--java/awt/image/MultiPixelPackedSampleModel.java387
-rw-r--r--java/awt/image/PackedColorModel.java6
-rw-r--r--java/awt/image/PixelGrabber.java70
-rw-r--r--java/awt/image/Raster.java55
-rw-r--r--java/awt/image/RasterOp.java5
-rw-r--r--java/awt/image/RescaleOp.java210
-rw-r--r--java/awt/image/SinglePixelPackedSampleModel.java10
24 files changed, 2413 insertions, 95 deletions
diff --git a/java/awt/image/AffineTransformOp.java b/java/awt/image/AffineTransformOp.java
index 6219635fa..45a896b31 100644
--- a/java/awt/image/AffineTransformOp.java
+++ b/java/awt/image/AffineTransformOp.java
@@ -1,6 +1,6 @@
/* AffineTransformOp.java -- This class performs affine
- * transformation between two images or rasters in 2
- * dimensions. Copyright (C) 2004 Free Software Foundation
+ transformation between two images or rasters in 2 dimensions.
+ Copyright (C) 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -38,11 +38,12 @@ exception statement from your version. */
package java.awt.image;
-import java.awt.*;
-import java.awt.Graphics;
import java.awt.Graphics2D;
-import java.awt.geom.*;
-
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
/**
* This class performs affine transformation between two images or
diff --git a/java/awt/image/BandedSampleModel.java b/java/awt/image/BandedSampleModel.java
new file mode 100644
index 000000000..cf5dcbac8
--- /dev/null
+++ b/java/awt/image/BandedSampleModel.java
@@ -0,0 +1,538 @@
+/* Copyright (C) 2004 Free Software Foundation
+
+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;
+
+/**
+ * MultiPixelPackedSampleModel provides a single band model that supports
+ * multiple pixels in a single unit. Pixels have 2^n bits and 2^k pixels fit
+ * per data element.
+ *
+ * @author Jerry Quinn <jlquinn@optonline.net>
+ */
+public final class BandedSampleModel extends ComponentSampleModel
+{
+ private int scanlineStride;
+ private int[] bitMasks;
+ private int[] bitOffsets;
+ private int[] sampleSize;
+ private int dataBitOffset;
+ private int elemBits;
+ private int numberOfBits;
+ private int numElems;
+
+ public BandedSampleModel(int dataType, int w, int h, int numBands)
+ {
+ super(dataType, w, h, 1, w, new int[numBands]);
+ }
+
+ public BandedSampleModel(int dataType, int w, int h, int scanlineStride,
+ int[] bankIndices, int[] bandOffsets)
+ {
+ super(dataType, w, h, 1, scanlineStride, bankIndices, bandOffsets);
+ }
+
+ public SampleModel createCompatibleSampleModel(int w, int h)
+ {
+ // NOTE: blackdown 1.4.1 sets all offsets to 0. Sun's 1.4.2 docs
+ // disagree.
+
+ // Compress offsets so minimum is 0, others w*scanlineStride
+ int[] newoffsets = new int[bandOffsets.length];
+ int[] order = new int[bandOffsets.length];
+ for (int i=0; i < bandOffsets.length; i++)
+ order[i] = i;
+ // FIXME: This is N^2, but not a big issue, unless there's a lot of
+ // bands...
+ for (int i=0; i < bandOffsets.length; i++)
+ for (int j=i+1; j < bandOffsets.length; i++)
+ if (bankIndices[order[i]] > bankIndices[order[j]]
+ || (bankIndices[order[i]] == bankIndices[order[j]]
+ && bandOffsets[order[i]] > bandOffsets[order[j]]))
+ {
+ int t = order[i]; order[i] = order[j]; order[j] = t;
+ }
+ int bank = 0;
+ int offset = 0;
+ for (int i=0; i < bandOffsets.length; i++)
+ {
+ if (bankIndices[order[i]] != bank)
+ {
+ bank = bankIndices[order[i]];
+ offset = 0;
+ }
+ newoffsets[order[i]] = offset;
+ offset += w * scanlineStride;
+ }
+
+ return new BandedSampleModel(dataType, w, h, scanlineStride, bankIndices, newoffsets);
+ }
+
+
+ public SampleModel createSubsetSampleModel(int[] bands)
+ {
+ int[] newoff = new int[bands.length];
+ int[] newbanks = new int[bands.length];
+ for (int i=0; i < bands.length; i++)
+ {
+ int b = bands[i];
+ newoff[i] = bandOffsets[b];
+ newbanks[i] = bankIndices[b];
+ }
+
+ if (bands.length > bankIndices.length)
+ throw new
+ RasterFormatException("BandedSampleModel createSubsetSampleModel too"
+ +" many bands");
+
+ return new BandedSampleModel(dataType, width, height, scanlineStride,
+ newbanks, newoff);
+ }
+
+ /**
+ * Extract all samples of one pixel and return in an array of transfer type.
+ *
+ * Extracts the pixel at x, y from data and stores samples into the array
+ * obj. If obj is null, a new array of getTransferType() is created.
+ *
+ * @param x The x-coordinate of the pixel rectangle to store in <code>obj</code>.
+ * @param y The y-coordinate of the pixel rectangle to store in <code>obj</code>.
+ * @param obj The primitive array to store the pixels into or null to force creation.
+ * @param data The DataBuffer that is the source of the pixel data.
+ * @return The primitive array containing the pixel data.
+ * @see java.awt.image.SampleModel#getDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)
+ */
+ public Object getDataElements(int x, int y, Object obj,
+ DataBuffer data)
+ {
+ int pixel = getSample(x, y, 0, data);
+ switch (getTransferType())
+ {
+ case DataBuffer.TYPE_BYTE:
+ {
+ byte[] b = (byte[])obj;
+ if (b == null) b = new byte[numBands];
+ for (int i=0; i < numBands; i++)
+ b[i] = (byte)getSample(x, y, i, data);
+ return b;
+ }
+ case DataBuffer.TYPE_SHORT:
+ case DataBuffer.TYPE_USHORT:
+ {
+ short[] b = (short[])obj;
+ if (b == null) b = new short[numBands];
+ for (int i=0; i < numBands; i++)
+ b[i] = (short)getSample(x, y, i, data);
+ return b;
+ }
+ case DataBuffer.TYPE_INT:
+ {
+ int[] b = (int[])obj;
+ if (b == null) b = new int[numBands];
+ for (int i=0; i < numBands; i++)
+ b[i] = getSample(x, y, i, data);
+ return b;
+ }
+ case DataBuffer.TYPE_FLOAT:
+ {
+ float[] b = (float[])obj;
+ if (b == null) b = new float[numBands];
+ for (int i=0; i < numBands; i++)
+ b[i] = getSampleFloat(x, y, i, data);
+ return b;
+ }
+ case DataBuffer.TYPE_DOUBLE:
+ {
+ double[] b = (double[])obj;
+ if (b == null) b = new double[numBands];
+ for (int i=0; i < numBands; i++)
+ b[i] = getSample(x, y, i, data);
+ return b;
+ }
+
+ default:
+ // Seems like the only sensible thing to do.
+ throw new ClassCastException();
+ }
+ }
+
+ public int[] getPixel(int x, int y, int[] iArray, DataBuffer data)
+ {
+ if (iArray == null) iArray = new int[numBands];
+ for (int i=0; i < numBands; i++)
+ iArray[i] = getSample(x, y, 0, data);
+
+ return iArray;
+ }
+
+ /**
+ * Copy pixels from a region into an array.
+ *
+ * Copies the samples of the pixels in the rectangle starting at x, y that
+ * is w pixels wide and h scanlines high. When there is more than one band,
+ * the samples stored in order before the next pixel. This ordering isn't
+ * well specified in Sun's docs as of 1.4.2.
+ *
+ * If iArray is null, a new array is allocated, filled, and returned.
+ *
+ * @param x The x-coordinate of the pixel rectangle to store in
+ * <code>iArray</code>.
+ * @param y The y-coordinate of the pixel rectangle to store in
+ * <code>iArray</code>.
+ * @param w The width in pixels of the rectangle.
+ * @param h The height in pixels of the rectangle.
+ * @param iArray The int array to store the pixels into or null to force
+ * creation.
+ * @param data The DataBuffer that is the source of the pixel data.
+ * @return The primitive array containing the pixel data.
+ */
+ public int[] getPixels(int x, int y, int w, int h, int[] iArray,
+ DataBuffer data)
+ {
+ if (iArray == null) iArray = new int[w*h*numBands];
+ int outOffset = 0;
+ for (y=0; y<h; y++)
+ {
+ for (x=0; x<w;)
+ {
+ for (int b=0; b < numBands; b++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + x;
+ iArray[outOffset++] =
+ data.getElem(bankIndices[b], offset);
+ }
+ }
+ }
+ return iArray;
+ }
+
+ public int getSample(int x, int y, int b, DataBuffer data)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + x;
+ return data.getElem(bankIndices[b], offset);
+ }
+
+ public float getSampleFloat(int x, int y, int b, DataBuffer data)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + x;
+ return data.getElemFloat(bankIndices[b], offset);
+ }
+
+ public double getSampleDouble(int x, int y, int b, DataBuffer data)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + x;
+ return data.getElemDouble(bankIndices[b], offset);
+ }
+
+ /**
+ * Copy one band's samples from a region into an array.
+ *
+ * Copies from one band the samples of the pixels in the rectangle starting
+ * at x, y that is w pixels wide and h scanlines high.
+ *
+ * If iArray is null, a new array is allocated, filled, and returned.
+ *
+ * @param x The x-coordinate of the pixel rectangle to store in
+ * <code>iArray</code>.
+ * @param y The y-coordinate of the pixel rectangle to store in
+ * <code>iArray</code>.
+ * @param w The width in pixels of the rectangle.
+ * @param h The height in pixels of the rectangle.
+ * @param b The band to retrieve.
+ * @param iArray The int array to store the pixels into or null to force
+ * creation.
+ * @param data The DataBuffer that is the source of the pixel data.
+ * @return The primitive array containing the pixel data.
+ */
+ public int[] getSamples(int x, int y, int w, int h, int b, int[] iArray,
+ DataBuffer data)
+ {
+ if (iArray == null) iArray = new int[w*h];
+ int outOffset = 0;
+ for (y=0; y<h; y++)
+ {
+ for (x=0; x<w;)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + x;
+ iArray[outOffset++] =
+ data.getElem(bankIndices[b], offset);
+ }
+ }
+ return iArray;
+ }
+
+
+ /**
+ * Set the pixel at x, y to the value in the first element of the primitive
+ * array obj.
+ *
+ * @param x The x-coordinate of the data elements in <code>obj</code>.
+ * @param y The y-coordinate of the data elements in <code>obj</code>.
+ * @param obj The primitive array containing the data elements to set.
+ * @param data The DataBuffer to store the data elements into.
+ * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, java.lang.Object, java.awt.image.DataBuffer)
+ */
+ public void setDataElements(int x, int y, Object obj, DataBuffer data)
+ {
+ int transferType = getTransferType();
+ if (getTransferType() != data.getDataType())
+ {
+ throw new IllegalArgumentException("transfer type ("+
+ getTransferType()+"), "+
+ "does not match data "+
+ "buffer type (" +
+ data.getDataType() +
+ ").");
+ }
+
+ int offset = y * scanlineStride + x;
+
+ try
+ {
+ switch (transferType)
+ {
+ case DataBuffer.TYPE_BYTE:
+ {
+ DataBufferByte out = (DataBufferByte) data;
+ byte[] in = (byte[]) obj;
+ for (int i=0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0];
+ return;
+ }
+ case DataBuffer.TYPE_SHORT:
+ {
+ DataBufferShort out = (DataBufferShort) data;
+ short[] in = (short[]) obj;
+ for (int i=0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0];
+ return;
+ }
+ case DataBuffer.TYPE_USHORT:
+ {
+ DataBufferUShort out = (DataBufferUShort) data;
+ short[] in = (short[]) obj;
+ for (int i=0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0];
+ return;
+ }
+ case DataBuffer.TYPE_INT:
+ {
+ DataBufferInt out = (DataBufferInt) data;
+ int[] in = (int[]) obj;
+ for (int i=0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0];
+ return;
+ }
+ case DataBuffer.TYPE_FLOAT:
+ {
+ DataBufferFloat out = (DataBufferFloat) data;
+ float[] in = (float[]) obj;
+ for (int i=0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0];
+ return;
+ }
+ case DataBuffer.TYPE_DOUBLE:
+ {
+ DataBufferDouble out = (DataBufferDouble) data;
+ double[] in = (double[]) obj;
+ for (int i=0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[0];
+ return;
+ }
+ default:
+ throw new ClassCastException("Unsupported data type");
+ }
+ }
+ catch (ArrayIndexOutOfBoundsException aioobe)
+ {
+ String msg = "While writing data elements" +
+ ", x="+x+", y="+y+
+ ", width="+width+", height="+height+
+ ", scanlineStride="+scanlineStride+
+ ", offset="+offset+
+ ", data.getSize()="+data.getSize()+
+ ", data.getOffset()="+data.getOffset()+
+ ": " +
+ aioobe;
+ throw new ArrayIndexOutOfBoundsException(msg);
+ }
+ }
+
+ public void setPixel(int x, int y, int[] iArray, DataBuffer data)
+ {
+ for (int b=0; b < numBands; b++)
+ data.setElem(bankIndices[b], bandOffsets[b] + y * scanlineStride + x,
+ iArray[b]);
+ }
+
+ public void setPixels(int x, int y, int w, int h, int[] iArray,
+ DataBuffer data)
+ {
+ int inOffset = 0;
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = y * scanlineStride + (x + ww);
+ for (int b=0; b < numBands; b++)
+ data.setElem(bankIndices[b], bandOffsets[b] + offset,
+ iArray[inOffset++]);
+ }
+ y++;
+ }
+ }
+
+ public void setSample(int x, int y, int b, int s, DataBuffer data)
+ {
+ data.setElem(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s);
+ }
+
+ public void setSample(int x, int y, int b, float s, DataBuffer data)
+ {
+ data.setElemFloat(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s);
+ }
+
+ public void setSample(int x, int y, int b, double s, DataBuffer data)
+ {
+ data.setElemDouble(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s);
+ }
+
+ public void setSamples(int x, int y, int w, int h, int b, int[] iArray,
+ DataBuffer data)
+ {
+ int inOffset = 0;
+
+ switch (getTransferType())
+ {
+ case DataBuffer.TYPE_BYTE:
+ {
+ DataBufferByte out = (DataBufferByte) data;
+ byte[] bank = out.getData(bankIndices[b]);
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + (x + ww);
+ bank[offset] = (byte)iArray[inOffset++];
+ }
+ y++;
+ }
+ return;
+ }
+ case DataBuffer.TYPE_SHORT:
+ {
+ DataBufferShort out = (DataBufferShort) data;
+ short[] bank = out.getData(bankIndices[b]);
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + (x + ww);
+ bank[offset] = (short)iArray[inOffset++];
+ }
+ y++;
+ }
+ return;
+ }
+ case DataBuffer.TYPE_USHORT:
+ {
+ DataBufferShort out = (DataBufferShort) data;
+ short[] bank = out.getData(bankIndices[b]);
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + (x + ww);
+ bank[offset] = (short)iArray[inOffset++];
+ }
+ y++;
+ }
+ return;
+ }
+ case DataBuffer.TYPE_INT:
+ {
+ DataBufferInt out = (DataBufferInt) data;
+ int[] bank = out.getData(bankIndices[b]);
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + (x + ww);
+ bank[offset] = iArray[inOffset++];
+ }
+ y++;
+ }
+ return;
+ }
+ case DataBuffer.TYPE_FLOAT:
+ case DataBuffer.TYPE_DOUBLE:
+ break;
+ default:
+ throw new ClassCastException("Unsupported data type");
+ }
+
+ // Default implementation probably slower for float and double
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + (x + ww);
+ data.setElem(bankIndices[b], offset, iArray[inOffset++]);
+ }
+ y++;
+ }
+ }
+
+ /**
+ * Creates a String with some information about this SampleModel.
+ * @return A String describing this SampleModel.
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ StringBuffer result = new StringBuffer();
+ result.append(getClass().getName());
+ result.append("[");
+ result.append("scanlineStride=").append(scanlineStride);
+ for(int i=0; i < bitMasks.length; i+=1)
+ {
+ result.append(", mask[").append(i).append("]=0x").append(Integer.toHexString(bitMasks[i]));
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+}
diff --git a/java/awt/image/BufferedImage.java b/java/awt/image/BufferedImage.java
index b18779af1..723eeeb77 100644
--- a/java/awt/image/BufferedImage.java
+++ b/java/awt/image/BufferedImage.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 2000, 2002, 2003 Free Software Foundation
+/* BufferedImage.java --
+ Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,6 +38,8 @@ exception statement from your version. */
package java.awt.image;
+import gnu.java.awt.ComponentDataBlitOp;
+
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
@@ -45,11 +48,10 @@ import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Transparency;
import java.awt.color.ColorSpace;
-import java.util.Hashtable;
-import java.util.Vector;
import java.util.HashSet;
+import java.util.Hashtable;
import java.util.Iterator;
-import gnu.java.awt.ComponentDataBlitOp;
+import java.util.Vector;
/**
* A buffered image always starts at coordinates (0, 0).
@@ -59,7 +61,7 @@ import gnu.java.awt.ComponentDataBlitOp;
* height of the image. This tile is always considered to be checked
* out.
*
- * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
+ * @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
*/
public class BufferedImage extends Image
implements WritableRenderedImage
@@ -79,20 +81,20 @@ public class BufferedImage extends Image
TYPE_BYTE_BINARY = 12,
TYPE_BYTE_INDEXED = 13;
- final static int[] bits3 = { 8, 8, 8 };
- final static int[] bits4 = { 8, 8, 8 };
- final static int[] bits1byte = { 8 };
- final static int[] bits1ushort = { 16 };
+ static final int[] bits3 = { 8, 8, 8 };
+ static final int[] bits4 = { 8, 8, 8 };
+ static final int[] bits1byte = { 8 };
+ static final int[] bits1ushort = { 16 };
- final static int[] masks_int = { 0x00ff0000,
+ static final int[] masks_int = { 0x00ff0000,
0x0000ff00,
0x000000ff,
DataBuffer.TYPE_INT };
- final static int[] masks_565 = { 0xf800,
+ static final int[] masks_565 = { 0xf800,
0x07e0,
0x001f,
DataBuffer.TYPE_USHORT};
- final static int[] masks_555 = { 0x7c00,
+ static final int[] masks_555 = { 0x7c00,
0x03e0,
0x001f,
DataBuffer.TYPE_USHORT};
diff --git a/java/awt/image/ColorModel.java b/java/awt/image/ColorModel.java
index 87ab94291..238bec1de 100644
--- a/java/awt/image/ColorModel.java
+++ b/java/awt/image/ColorModel.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation
+/* ColorModel.java --
+ Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,11 +38,12 @@ exception statement from your version. */
package java.awt.image;
-import java.util.Arrays;
+import gnu.java.awt.Buffers;
+
import java.awt.Point;
import java.awt.Transparency;
import java.awt.color.ColorSpace;
-import gnu.java.awt.Buffers;
+import java.util.Arrays;
/**
* A color model operates with colors in several formats:
@@ -76,8 +78,8 @@ import gnu.java.awt.Buffers;
*
* </ul>
*
- * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
- * @author C. Brian Jones <cbj@gnu.org>
+ * @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
+ * @author C. Brian Jones (cbj@gnu.org)
*/
public abstract class ColorModel implements Transparency
{
@@ -508,40 +510,89 @@ public abstract class ColorModel implements Transparency
* <code>(pixel == cm.getDataElement(cm.getComponents(pixel, null,
* 0), 0))</code>.
*
- * This method is typically overriden in subclasses to provide a
- * more efficient implementation.
+ * This method is overriden in subclasses since this abstract class throws
+ * UnsupportedOperationException().
*
- * @param arrays of unnormalized component samples of single
- * pixel. The scale and multiplication state of the samples are
- * according to the color model. Each component sample is stored
- * as a separate element in the array.
+ * @param components Array of unnormalized component samples of single
+ * pixel. The scale and multiplication state of the samples are according
+ * to the color model. Each component sample is stored as a separate element
+ * in the array.
+ * @param offset Position of the first value of the pixel in components.
*
* @return pixel value encoded according to the color model.
*/
public int getDataElement(int[] components, int offset)
{
- // subclasses has to implement this method.
+ // subclasses have to implement this method.
throw new UnsupportedOperationException();
}
+ /**
+ * Converts the normalized component samples from an array to a pixel
+ * value. I.e. composes the pixel from component samples, but does not
+ * perform any color conversion or scaling of the samples.
+ *
+ * This method is typically overriden in subclasses to provide a
+ * more efficient implementation. The method provided by this abstract
+ * class converts the components to unnormalized form and returns
+ * getDataElement(int[], int).
+ *
+ * @param components Array of normalized component samples of single pixel.
+ * The scale and multiplication state of the samples are according to the
+ * color model. Each component sample is stored as a separate element in the
+ * array.
+ * @param offset Position of the first value of the pixel in components.
+ *
+ * @return pixel value encoded according to the color model.
+ * @since 1.4
+ */
public int getDataElement (float[] components, int offset)
{
- // subclasses has to implement this method.
- throw new UnsupportedOperationException();
+ return
+ getDataElement(getUnnormalizedComponents(components, offset, null, 0),
+ 0);
}
public Object getDataElements(int[] components, int offset, Object obj)
{
- // subclasses has to implement this method.
+ // subclasses have to implement this method.
throw new UnsupportedOperationException();
}
- public int getDataElements (float[] components, Object obj)
+ /**
+ * Converts the normalized component samples from an array to an array of
+ * TransferType values. I.e. composes the pixel from component samples, but
+ * does not perform any color conversion or scaling of the samples.
+ *
+ * If obj is null, a new array of TransferType is allocated and returned.
+ * Otherwise the results are stored in obj and obj is returned. If obj is
+ * not long enough, ArrayIndexOutOfBounds is thrown. If obj is not an array
+ * of primitives, ClassCastException is thrown.
+ *
+ * This method is typically overriden in subclasses to provide a
+ * more efficient implementation. The method provided by this abstract
+ * class converts the components to unnormalized form and returns
+ * getDataElement(int[], int, Object).
+ *
+ * @param components Array of normalized component samples of single pixel.
+ * The scale and multiplication state of the samples are according to the
+ * color model. Each component sample is stored as a separate element in the
+ * array.
+ * @param offset Position of the first value of the pixel in components.
+ * @param obj Array of TransferType or null.
+ *
+ * @return pixel value encoded according to the color model.
+ * @throws ArrayIndexOutOfBounds
+ * @throws ClassCastException
+ * @since 1.4
+ */
+ public Object getDataElements(float[] components, int offset, Object obj)
{
- // subclasses has to implement this method.
- throw new UnsupportedOperationException();
+ return
+ getDataElements(getUnnormalizedComponents(components, offset, null, 0),
+ 0, obj);
}
-
+
public boolean equals(Object obj)
{
if (!(obj instanceof ColorModel)) return false;
diff --git a/java/awt/image/ComponentColorModel.java b/java/awt/image/ComponentColorModel.java
index 24d8b8ea6..3b3447953 100644
--- a/java/awt/image/ComponentColorModel.java
+++ b/java/awt/image/ComponentColorModel.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 2000, 2002, 2004 Free Software Foundation
+/* ComponentColorModel.java --
+ Copyright (C) 2000, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,9 +38,10 @@ exception statement from your version. */
package java.awt.image;
+import gnu.java.awt.Buffers;
+
import java.awt.Point;
import java.awt.color.ColorSpace;
-import gnu.java.awt.Buffers;
public class ComponentColorModel extends ColorModel
{
@@ -60,6 +62,32 @@ public class ComponentColorModel extends ColorModel
transparency, transferType);
}
+ /**
+ * Construct a new ComponentColorModel.
+ *
+ * This constructor makes all bits of each sample significant, so for a
+ * transferType of DataBuffer.BYTE, the bits per sample is 8, etc. If
+ * both hasAlpha and isAlphaPremultiplied are true, color samples are
+ * assumed to be premultiplied by the alpha component. Transparency may be
+ * one of OPAQUE, BITMASK, or TRANSLUCENT.
+ *
+ * @param colorSpace The colorspace for this color model.
+ * @param hasAlpha True if there is an alpha component.
+ * @param isAlphaPremultiplied True if colors are already multiplied by
+ * alpha.
+ * @param transparency The type of alpha values.
+ * @param transferType Data type of pixel sample values.
+ * @since 1.4
+ */
+ public ComponentColorModel(ColorSpace colorSpace,
+ boolean hasAlpha,
+ boolean isAlphaPremultiplied,
+ int transparency, int transferType)
+ {
+ this(colorSpace, null, hasAlpha, isAlphaPremultiplied,
+ transparency, transferType);
+ }
+
public int getRed(int pixel)
{
if (getNumComponents()>1) throw new IllegalArgumentException();
diff --git a/java/awt/image/ComponentSampleModel.java b/java/awt/image/ComponentSampleModel.java
index c7b08b919..f121296f1 100644
--- a/java/awt/image/ComponentSampleModel.java
+++ b/java/awt/image/ComponentSampleModel.java
@@ -41,6 +41,21 @@ import gnu.java.awt.Buffers;
/* FIXME: This class does not yet support data type TYPE_SHORT */
/**
+ * ComponentSampleModel supports a flexible organization of pixel samples in
+ * memory, permitting pixel samples to be interleaved by band, by scanline,
+ * and by pixel.
+ *
+ * A DataBuffer for this sample model has K banks of data. Pixels have N
+ * samples, so there are N bands in the DataBuffer. Each band is completely
+ * contained in one bank of data, but a bank may contain more than one band.
+ * Each pixel sample is stored in a single data element.
+ *
+ * Within a bank, each band begins at an offset stored in bandOffsets. The
+ * banks containing the band is given by bankIndices. Within the bank, there
+ * are three dimensions - band, pixel, and scanline. The dimension ordering
+ * is controlled by bandOffset, pixelStride, and scanlineStride, which means
+ * that any combination of interleavings is supported.
+ *
* @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
*/
public class ComponentSampleModel extends SampleModel
@@ -86,6 +101,7 @@ public class ComponentSampleModel extends SampleModel
this.bandOffsets = bandOffsets;
this.bankIndices = bankIndices;
+ this.numBanks = 0;
for (int b=0; b<bankIndices.length; b++)
this.numBanks = Math.max(this.numBanks, bankIndices[b]+1);
diff --git a/java/awt/image/CropImageFilter.java b/java/awt/image/CropImageFilter.java
index c9a170b9b..a006d26d8 100644
--- a/java/awt/image/CropImageFilter.java
+++ b/java/awt/image/CropImageFilter.java
@@ -1,5 +1,5 @@
/* CropImageFilter.java -- Java class for cropping image filter
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,11 +38,10 @@ exception statement from your version. */
package java.awt.image;
-import java.util.Hashtable;
import java.awt.Rectangle;
+import java.util.Hashtable;
/**
- * <br>
* Currently this filter does almost nothing and needs to be implemented.
*
* @author C. Brian Jones (cbj@gnu.org)
diff --git a/java/awt/image/DataBuffer.java b/java/awt/image/DataBuffer.java
index 967e1a26c..b921953ec 100644
--- a/java/awt/image/DataBuffer.java
+++ b/java/awt/image/DataBuffer.java
@@ -45,12 +45,45 @@ package java.awt.image;
*/
public abstract class DataBuffer
{
+ /**
+ * A constant representng a data type that uses <code>byte</code> primitives
+ * as the storage unit.
+ */
public static final int TYPE_BYTE = 0;
+
+ /**
+ * A constant representng a data type that uses <code>short</code>
+ * primitives as the storage unit.
+ */
public static final int TYPE_USHORT = 1;
+
+ /**
+ * A constant representng a data type that uses <code>short</code>
+ * primitives as the storage unit.
+ */
public static final int TYPE_SHORT = 2;
+
+ /**
+ * A constant representng a data type that uses <code>int</code>
+ * primitives as the storage unit.
+ */
public static final int TYPE_INT = 3;
+
+ /**
+ * A constant representng a data type that uses <code>float</code>
+ * primitives as the storage unit.
+ */
public static final int TYPE_FLOAT = 4;
+
+ /**
+ * A constant representng a data type that uses <code>double</code>
+ * primitives as the storage unit.
+ */
public static final int TYPE_DOUBLE = 5;
+
+ /**
+ * A constant representng an undefined data type.
+ */
public static final int TYPE_UNDEFINED = 32;
/** The type of the data elements stored in the data buffer. */
@@ -68,18 +101,57 @@ public abstract class DataBuffer
/** Offset into each bank. */
protected int[] offsets;
+ /**
+ * Creates a new <code>DataBuffer</code> with the specified data type and
+ * size. The <code>dataType</code> should be one of the constants
+ * {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, {@link #TYPE_USHORT},
+ * {@link #TYPE_INT}, {@link #TYPE_FLOAT} and {@link #TYPE_DOUBLE}.
+ * <p>
+ * The physical (array-based) storage is allocated by a subclass.
+ *
+ * @param dataType the data type.
+ * @param size the number of elements in the buffer.
+ */
protected DataBuffer(int dataType, int size)
{
this.dataType = dataType;
this.size = size;
}
+ /**
+ * Creates a new <code>DataBuffer</code> with the specified data type,
+ * size and number of banks. The <code>dataType</code> should be one of
+ * the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT},
+ * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and
+ * {@link #TYPE_DOUBLE}.
+ * <p>
+ * The physical (array-based) storage is allocated by a subclass.
+ *
+ * @param dataType the data type.
+ * @param size the number of elements in the buffer.
+ * @param numBanks the number of data banks.
+ */
protected DataBuffer(int dataType, int size, int numBanks) {
this(dataType, size);
banks = numBanks;
offsets = new int[numBanks];
}
+ /**
+ * Creates a new <code>DataBuffer</code> with the specified data type,
+ * size and number of banks. An offset (which applies to all banks) is
+ * also specified. The <code>dataType</code> should be one of
+ * the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT},
+ * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and
+ * {@link #TYPE_DOUBLE}.
+ * <p>
+ * The physical (array-based) storage is allocated by a subclass.
+ *
+ * @param dataType the data type.
+ * @param size the number of elements in the buffer.
+ * @param numBanks the number of data banks.
+ * @param offset the offset to the first element for all banks.
+ */
protected DataBuffer(int dataType, int size, int numBanks, int offset) {
this(dataType, size, numBanks);
@@ -88,6 +160,24 @@ public abstract class DataBuffer
this.offset = offset;
}
+ /**
+ * Creates a new <code>DataBuffer</code> with the specified data type,
+ * size and number of banks. An offset (which applies to all banks) is
+ * also specified. The <code>dataType</code> should be one of
+ * the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT},
+ * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and
+ * {@link #TYPE_DOUBLE}.
+ * <p>
+ * The physical (array-based) storage is allocated by a subclass.
+ *
+ * @param dataType the data type.
+ * @param size the number of elements in the buffer.
+ * @param numBanks the number of data banks.
+ * @param offsets the offsets to the first element for all banks.
+ *
+ * @throws ArrayIndexOutOfBoundsException if
+ * <code>numBanks != offsets.length</code>.
+ */
protected DataBuffer(int dataType, int size, int numBanks, int[] offsets) {
this(dataType, size);
if (numBanks != offsets.length)
@@ -99,6 +189,17 @@ public abstract class DataBuffer
offset = offsets[0];
}
+ /**
+ * Returns the size (number of bits) of the specified data type. Valid types
+ * are defined by the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT},
+ * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and
+ * {@link #TYPE_DOUBLE}.
+ *
+ * @param dataType the data type.
+ * @return The number of bits for the specified data type.
+ * @throws IllegalArgumentException if <code>dataType < 0</code> or
+ * <code>dataType > TYPE_DOUBLE</code>.
+ */
public static int getDataTypeSize(int dataType) {
// Maybe this should be a lookup table instead.
switch (dataType)
@@ -118,21 +219,45 @@ public abstract class DataBuffer
}
}
+ /**
+ * Returns the type of the data elements in the data buffer. Valid types
+ * are defined by the constants {@link #TYPE_BYTE}, {@link #TYPE_SHORT},
+ * {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and
+ * {@link #TYPE_DOUBLE}.
+ *
+ * @return The type.
+ */
public int getDataType()
{
return dataType;
}
+ /**
+ * Returns the size of the data buffer.
+ *
+ * @return The size.
+ */
public int getSize()
{
return size;
}
+ /**
+ * Returns the element offset for the first data bank.
+ *
+ * @return The element offset.
+ */
public int getOffset()
{
return offset;
}
+ /**
+ * Returns the offsets for all the data banks used by this
+ * <code>DataBuffer</code>.
+ *
+ * @return The offsets.
+ */
public int[] getOffsets()
{
if (offsets == null)
@@ -144,60 +269,166 @@ public abstract class DataBuffer
return offsets;
}
+ /**
+ * Returns the number of data banks for this <code>DataBuffer</code>.
+ * @return The number of data banks.
+ */
public int getNumBanks()
{
return banks;
}
+ /**
+ * Returns an element from the first data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int i)
{
return getElem(0, i);
}
+ /**
+ * Returns an element from a particular data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public abstract int getElem(int bank, int i);
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int i, int val)
{
setElem(0, i, val);
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public abstract void setElem(int bank, int i, int val);
+ /**
+ * Returns an element from the first data bank, converted to a
+ * <code>float</code>. The offset (specified in the constructor) is added
+ * to <code>i</code> before accessing the underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public float getElemFloat(int i)
{
return getElem(i);
}
+ /**
+ * Returns an element from a particular data bank, converted to a
+ * <code>float</code>. The offset (specified in the constructor) is
+ * added to <code>i</code> before accessing the underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public float getElemFloat(int bank, int i)
{
return getElem(bank, i);
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElemFloat(int i, float val)
{
setElem(i, (int) val);
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElemFloat(int bank, int i, float val)
{
setElem(bank, i, (int) val);
}
+ /**
+ * Returns an element from the first data bank, converted to a
+ * <code>double</code>. The offset (specified in the constructor) is added
+ * to <code>i</code> before accessing the underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public double getElemDouble(int i)
{
return getElem(i);
}
+ /**
+ * Returns an element from a particular data bank, converted to a
+ * <code>double</code>. The offset (specified in the constructor) is
+ * added to <code>i</code> before accessing the underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public double getElemDouble(int bank, int i)
{
return getElem(bank, i);
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElemDouble(int i, double val)
{
setElem(i, (int) val);
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElemDouble(int bank, int i, double val)
{
setElem(bank, i, (int) val);
diff --git a/java/awt/image/DataBufferByte.java b/java/awt/image/DataBufferByte.java
index 84df55106..fd16f11ac 100644
--- a/java/awt/image/DataBufferByte.java
+++ b/java/awt/image/DataBufferByte.java
@@ -54,12 +54,25 @@ public final class DataBufferByte extends DataBuffer
private byte[] data;
private byte[][] bankData;
+ /**
+ * Creates a new data buffer with a single data bank containing the
+ * specified number of <code>byte</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ */
public DataBufferByte(int size)
{
super(TYPE_BYTE, size);
data = new byte[size];
}
+ /**
+ * Creates a new data buffer with the specified number of data banks,
+ * each containing the specified number of <code>byte</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ * @param numBanks the number of data banks.
+ */
public DataBufferByte(int size, int numBanks)
{
super(TYPE_BYTE, size, numBanks);
@@ -67,18 +80,49 @@ public final class DataBufferByte extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data bank.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ */
public DataBufferByte(byte[] dataArray, int size)
{
super(TYPE_BYTE, size);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data bank, with
+ * the specified offset to the first element.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ * @param offset the offset to the first element in the array.
+ */
public DataBufferByte(byte[] dataArray, int size, int offset)
{
super(TYPE_BYTE, size, 1, offset);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data banks.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferByte(byte[][] dataArray, int size)
{
super(TYPE_BYTE, size, dataArray.length);
@@ -86,6 +130,17 @@ public final class DataBufferByte extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data banks, with
+ * the specified offsets to the first element in each bank.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ * @param offsets the offsets to the first element in each data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferByte(byte[][] dataArray, int size, int[] offsets)
{
super(TYPE_BYTE, size, dataArray.length, offsets);
@@ -93,37 +148,87 @@ public final class DataBufferByte extends DataBuffer
data = bankData[0];
}
+ /**
+ * Returns the first data bank.
+ *
+ * @return The first data bank.
+ */
public byte[] getData()
{
return data;
}
+ /**
+ * Returns a data bank.
+ *
+ * @param bank the bank index.
+ * @return A data bank.
+ */
public byte[] getData(int bank)
{
return bankData[bank];
}
+ /**
+ * Returns the array underlying this <code>DataBuffer</code>.
+ *
+ * @return The data banks.
+ */
public byte[][] getBankData()
{
return bankData;
}
+ /**
+ * Returns an element from the first data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int i)
{
return data[i+offset] & 0xff; // get unsigned byte as int
}
+ /**
+ * Returns an element from a particular data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int bank, int i)
{
// get unsigned byte as int
return bankData[bank][i+offsets[bank]] & 0xff;
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int i, int val)
{
data[i+offset] = (byte) val;
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int bank, int i, int val)
{
bankData[bank][i+offsets[bank]] = (byte) val;
diff --git a/java/awt/image/DataBufferDouble.java b/java/awt/image/DataBufferDouble.java
index b1291f416..2d90ac863 100644
--- a/java/awt/image/DataBufferDouble.java
+++ b/java/awt/image/DataBufferDouble.java
@@ -58,12 +58,25 @@ public final class DataBufferDouble
private double[] data;
private double[][] bankData;
+ /**
+ * Creates a new data buffer with a single data bank containing the
+ * specified number of <code>double</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ */
public DataBufferDouble(int size)
{
super(TYPE_DOUBLE, size);
data = new double[size];
}
+ /**
+ * Creates a new data buffer with the specified number of data banks,
+ * each containing the specified number of <code>double</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ * @param numBanks the number of data banks.
+ */
public DataBufferDouble(int size, int numBanks)
{
super(TYPE_DOUBLE, size, numBanks);
@@ -71,18 +84,49 @@ public final class DataBufferDouble
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data bank.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ */
public DataBufferDouble(double[] dataArray, int size)
{
super(TYPE_DOUBLE, size);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data bank, with
+ * the specified offset to the first element.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ * @param offset the offset to the first element in the array.
+ */
public DataBufferDouble(double[] dataArray, int size, int offset)
{
super(TYPE_DOUBLE, size, 1, offset);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data banks.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferDouble(double[][] dataArray, int size)
{
super(TYPE_DOUBLE, size, dataArray.length);
@@ -90,6 +134,17 @@ public final class DataBufferDouble
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data banks, with
+ * the specified offsets to the first element in each bank.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ * @param offsets the offsets to the first element in each data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferDouble(double[][] dataArray, int size, int[] offsets)
{
super(TYPE_DOUBLE, size, dataArray.length, offsets);
@@ -97,36 +152,86 @@ public final class DataBufferDouble
data = bankData[0];
}
+ /**
+ * Returns the first data bank.
+ *
+ * @return The first data bank.
+ */
public double[] getData()
{
return data;
}
+ /**
+ * Returns a data bank.
+ *
+ * @param bank the bank index.
+ * @return A data bank.
+ */
public double[] getData(int bank)
{
return bankData[bank];
}
+ /**
+ * Returns the array underlying this <code>DataBuffer</code>.
+ *
+ * @return The data banks.
+ */
public double[][] getBankData()
{
return bankData;
}
+ /**
+ * Returns an element from the first data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int i)
{
return (int) data[i+offset];
}
+ /**
+ * Returns an element from a particular data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int bank, int i)
{
return (int) bankData[bank][i+offsets[bank]];
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int i, int val)
{
data[i+offset] = (double) val;
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int bank, int i, int val)
{
bankData[bank][i+offsets[bank]] = (double) val;
diff --git a/java/awt/image/DataBufferFloat.java b/java/awt/image/DataBufferFloat.java
index b2d88c16b..da614789a 100644
--- a/java/awt/image/DataBufferFloat.java
+++ b/java/awt/image/DataBufferFloat.java
@@ -56,12 +56,25 @@ public final class DataBufferFloat
private float[] data;
private float[][] bankData;
+ /**
+ * Creates a new data buffer with a single data bank containing the
+ * specified number of <code>float</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ */
public DataBufferFloat(int size)
{
super(TYPE_FLOAT, size);
data = new float[size];
}
+ /**
+ * Creates a new data buffer with the specified number of data banks,
+ * each containing the specified number of <code>float</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ * @param numBanks the number of data banks.
+ */
public DataBufferFloat(int size, int numBanks)
{
super(TYPE_FLOAT, size, numBanks);
@@ -69,18 +82,49 @@ public final class DataBufferFloat
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data bank.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ */
public DataBufferFloat(float[] dataArray, int size)
{
super(TYPE_FLOAT, size);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data bank, with
+ * the specified offset to the first element.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ * @param offset the offset to the first element in the array.
+ */
public DataBufferFloat(float[] dataArray, int size, int offset)
{
super(TYPE_FLOAT, size, 1, offset);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data banks.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferFloat(float[][] dataArray, int size)
{
super(TYPE_FLOAT, size, dataArray.length);
@@ -88,6 +132,17 @@ public final class DataBufferFloat
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data banks, with
+ * the specified offsets to the first element in each bank.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ * @param offsets the offsets to the first element in each data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferFloat(float[][] dataArray, int size, int[] offsets)
{
super(TYPE_FLOAT, size, dataArray.length, offsets);
@@ -95,36 +150,86 @@ public final class DataBufferFloat
data = bankData[0];
}
+ /**
+ * Returns the first data bank.
+ *
+ * @return The first data bank.
+ */
public float[] getData()
{
return data;
}
+ /**
+ * Returns a data bank.
+ *
+ * @param bank the bank index.
+ * @return A data bank.
+ */
public float[] getData(int bank)
{
return bankData[bank];
}
+ /**
+ * Returns the array underlying this <code>DataBuffer</code>.
+ *
+ * @return The data banks.
+ */
public float[][] getBankData()
{
return bankData;
}
+ /**
+ * Returns an element from the first data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int i)
{
return (int) data[i+offset];
}
+ /**
+ * Returns an element from a particular data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int bank, int i)
{
return (int) bankData[bank][i+offsets[bank]];
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int i, int val)
{
data[i+offset] = (float) val;
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int bank, int i, int val)
{
bankData[bank][i+offsets[bank]] = (float) val;
diff --git a/java/awt/image/DataBufferInt.java b/java/awt/image/DataBufferInt.java
index 54308fefd..87922c5c1 100644
--- a/java/awt/image/DataBufferInt.java
+++ b/java/awt/image/DataBufferInt.java
@@ -54,12 +54,25 @@ public final class DataBufferInt extends DataBuffer
private int[] data;
private int[][] bankData;
+ /**
+ * Creates a new data buffer with a single data bank containing the
+ * specified number of <code>int</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ */
public DataBufferInt(int size)
{
super(TYPE_INT, size);
data = new int[size];
}
+ /**
+ * Creates a new data buffer with the specified number of data banks,
+ * each containing the specified number of <code>int</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ * @param numBanks the number of data banks.
+ */
public DataBufferInt(int size, int numBanks)
{
super(TYPE_INT, size, numBanks);
@@ -67,18 +80,49 @@ public final class DataBufferInt extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data bank.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ */
public DataBufferInt(int[] dataArray, int size)
{
super(TYPE_INT, size);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data bank, with
+ * the specified offset to the first element.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ * @param offset the offset to the first element in the array.
+ */
public DataBufferInt(int[] dataArray, int size, int offset)
{
super(TYPE_INT, size, 1, offset);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data banks.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferInt(int[][] dataArray, int size)
{
super(TYPE_INT, size, dataArray.length);
@@ -86,6 +130,17 @@ public final class DataBufferInt extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data banks, with
+ * the specified offsets to the first element in each bank.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ * @param offsets the offsets to the first element in each data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferInt(int[][] dataArray, int size, int[] offsets)
{
super(TYPE_INT, size, dataArray.length, offsets);
@@ -93,39 +148,88 @@ public final class DataBufferInt extends DataBuffer
data = bankData[0];
}
+ /**
+ * Returns the first data bank.
+ *
+ * @return The first data bank.
+ */
public int[] getData()
{
return data;
}
+ /**
+ * Returns a data bank.
+ *
+ * @param bank the bank index.
+ * @return A data bank.
+ */
public int[] getData(int bank)
{
return bankData[bank];
}
+ /**
+ * Returns the array underlying this <code>DataBuffer</code>.
+ *
+ * @return The data banks.
+ */
public int[][] getBankData()
{
return bankData;
}
+ /**
+ * Returns an element from the first data bank. The <code>offset</code> is
+ * added to the specified index before accessing the underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int i)
{
return data[i+offset];
}
+ /**
+ * Returns an element from a particular data bank. The <code>offset</code>
+ * is added to the specified index before accessing the underlying data
+ * array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int bank, int i)
{
// get unsigned int as int
return bankData[bank][i+offsets[bank]];
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int i, int val)
{
- data[i+offset] = (int) val;
+ data[i+offset] = val;
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int bank, int i, int val)
{
- bankData[bank][i+offsets[bank]] = (int) val;
+ bankData[bank][i+offsets[bank]] = val;
}
}
diff --git a/java/awt/image/DataBufferShort.java b/java/awt/image/DataBufferShort.java
index 7a5c39424..4dad5fbc3 100644
--- a/java/awt/image/DataBufferShort.java
+++ b/java/awt/image/DataBufferShort.java
@@ -54,12 +54,25 @@ public final class DataBufferShort extends DataBuffer
private short[] data;
private short[][] bankData;
+ /**
+ * Creates a new data buffer with a single data bank containing the
+ * specified number of <code>short</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ */
public DataBufferShort(int size)
{
super(TYPE_SHORT, size);
data = new short[size];
}
+ /**
+ * Creates a new data buffer with the specified number of data banks,
+ * each containing the specified number of <code>short</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ * @param numBanks the number of data banks.
+ */
public DataBufferShort(int size, int numBanks)
{
super(TYPE_SHORT, size, numBanks);
@@ -67,18 +80,49 @@ public final class DataBufferShort extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data bank.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ */
public DataBufferShort(short[] dataArray, int size)
{
super(TYPE_SHORT, size);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data bank, with
+ * the specified offset to the first element.
+ * <p>
+ * Note: there is no exception when <code>dataArray</code> is
+ * <code>null</code>, but in that case an exception will be thrown
+ * later if you attempt to access the data buffer.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ * @param offset the offset to the first element in the array.
+ */
public DataBufferShort(short[] dataArray, int size, int offset)
{
super(TYPE_SHORT, size, 1, offset);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data banks.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferShort(short[][] dataArray, int size)
{
super(TYPE_SHORT, size, dataArray.length);
@@ -86,6 +130,17 @@ public final class DataBufferShort extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data banks, with
+ * the specified offsets to the first element in each bank.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ * @param offsets the offsets to the first element in each data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferShort(short[][] dataArray, int size, int[] offsets)
{
super(TYPE_SHORT, size, dataArray.length, offsets);
@@ -93,36 +148,86 @@ public final class DataBufferShort extends DataBuffer
data = bankData[0];
}
+ /**
+ * Returns the first data bank.
+ *
+ * @return The first data bank.
+ */
public short[] getData()
{
return data;
}
+ /**
+ * Returns a data bank.
+ *
+ * @param bank the bank index.
+ * @return A data bank.
+ */
public short[] getData(int bank)
{
return bankData[bank];
}
+ /**
+ * Returns the array underlying this <code>DataBuffer</code>.
+ *
+ * @return The data banks.
+ */
public short[][] getBankData()
{
return bankData;
}
+ /**
+ * Returns an element from the first data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int i)
{
return data[i+offset];
}
+ /**
+ * Returns an element from a particular data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int bank, int i)
{
return bankData[bank][i+offsets[bank]];
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int i, int val)
{
data[i+offset] = (short) val;
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int bank, int i, int val)
{
bankData[bank][i+offsets[bank]] = (short) val;
diff --git a/java/awt/image/DataBufferUShort.java b/java/awt/image/DataBufferUShort.java
index e11b4ab10..a1abb26c5 100644
--- a/java/awt/image/DataBufferUShort.java
+++ b/java/awt/image/DataBufferUShort.java
@@ -54,12 +54,25 @@ public final class DataBufferUShort extends DataBuffer
private short[] data;
private short[][] bankData;
+ /**
+ * Creates a new data buffer with a single data bank containing the
+ * specified number of <code>short</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ */
public DataBufferUShort(int size)
{
super(TYPE_USHORT, size);
data = new short[size];
}
+ /**
+ * Creates a new data buffer with the specified number of data banks,
+ * each containing the specified number of <code>short</code> elements.
+ *
+ * @param size the number of elements in the data bank.
+ * @param numBanks the number of data banks.
+ */
public DataBufferUShort(int size, int numBanks)
{
super(TYPE_USHORT, size, numBanks);
@@ -67,18 +80,41 @@ public final class DataBufferUShort extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data bank.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ */
public DataBufferUShort(short[] dataArray, int size)
{
super(TYPE_USHORT, size);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data bank, with
+ * the specified offset to the first element.
+ *
+ * @param dataArray the data bank.
+ * @param size the number of elements in the data bank.
+ * @param offset the offset to the first element in the array.
+ */
public DataBufferUShort(short[] dataArray, int size, int offset)
{
super(TYPE_USHORT, size, 1, offset);
data = dataArray;
}
+ /**
+ * Creates a new data buffer backed by the specified data banks.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferUShort(short[][] dataArray, int size)
{
super(TYPE_USHORT, size, dataArray.length);
@@ -86,6 +122,17 @@ public final class DataBufferUShort extends DataBuffer
data = bankData[0];
}
+ /**
+ * Creates a new data buffer backed by the specified data banks, with
+ * the specified offsets to the first element in each bank.
+ *
+ * @param dataArray the data banks.
+ * @param size the number of elements in the data bank.
+ * @param offsets the offsets to the first element in each data bank.
+ *
+ * @throws NullPointerException if <code>dataArray</code> is
+ * <code>null</code>.
+ */
public DataBufferUShort(short[][] dataArray, int size, int[] offsets)
{
super(TYPE_USHORT, size, dataArray.length, offsets);
@@ -93,37 +140,87 @@ public final class DataBufferUShort extends DataBuffer
data = bankData[0];
}
+ /**
+ * Returns the first data bank.
+ *
+ * @return The first data bank.
+ */
public short[] getData()
{
return data;
}
+ /**
+ * Returns a data bank.
+ *
+ * @param bank the bank index.
+ * @return A data bank.
+ */
public short[] getData(int bank)
{
return bankData[bank];
}
+ /**
+ * Returns the array underlying this <code>DataBuffer</code>.
+ *
+ * @return The data banks.
+ */
public short[][] getBankData()
{
return bankData;
}
+ /**
+ * Returns an element from the first data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int i)
{
return data[i+offset] & 0xffff; // get unsigned short as int
}
+ /**
+ * Returns an element from a particular data bank. The offset (specified in
+ * the constructor) is added to <code>i</code> before accessing the
+ * underlying data array.
+ *
+ * @param bank the bank index.
+ * @param i the element index.
+ * @return The element.
+ */
public int getElem(int bank, int i)
{
// get unsigned short as int
return bankData[bank][i+offsets[bank]] & 0xffff;
}
+ /**
+ * Sets an element in the first data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int i, int val)
{
data[i+offset] = (short) val;
}
+ /**
+ * Sets an element in a particular data bank. The offset (specified in the
+ * constructor) is added to <code>i</code> before updating the underlying
+ * data array.
+ *
+ * @param bank the data bank index.
+ * @param i the element index.
+ * @param val the new element value.
+ */
public void setElem(int bank, int i, int val)
{
bankData[bank][i+offsets[bank]] = (short) val;
diff --git a/java/awt/image/DirectColorModel.java b/java/awt/image/DirectColorModel.java
index 3ac43cf25..7fa6e8974 100644
--- a/java/awt/image/DirectColorModel.java
+++ b/java/awt/image/DirectColorModel.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 1999, 2000, 2002 Free Software Foundation
+/* DirectColorModel.java --
+ Copyright (C) 1999, 2000, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,13 +38,14 @@ exception statement from your version. */
package java.awt.image;
+import gnu.java.awt.Buffers;
+
import java.awt.Point;
import java.awt.Transparency;
import java.awt.color.ColorSpace;
-import gnu.java.awt.Buffers;
/**
- * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
+ * @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
* @author C. Brian Jones (cbj@gnu.org)
* @author Mark Benvenuto (mcb54@columbia.edu)
*/
@@ -162,7 +164,7 @@ public class DirectColorModel extends PackedColorModel
return extractAndScaleSample(pixel, 3);
}
- private final int extractAndNormalizeSample(int pixel, int component)
+ private int extractAndNormalizeSample(int pixel, int component)
{
int value = extractAndScaleSample(pixel, component);
if (hasAlpha() && isAlphaPremultiplied())
@@ -170,7 +172,7 @@ public class DirectColorModel extends PackedColorModel
return value;
}
- private final int extractAndScaleSample(int pixel, int component)
+ private int extractAndScaleSample(int pixel, int component)
{
int field = pixel & getMask(component);
int to8BitShift =
@@ -303,7 +305,7 @@ public class DirectColorModel extends PackedColorModel
* @param highBit the position of the most significant bit in the
* val parameter.
*/
- private final int valueToField(int val, int component, int highBit)
+ private int valueToField(int val, int component, int highBit)
{
int toFieldShift =
getComponentSize(component) + shifts[component] - highBit;
@@ -317,7 +319,7 @@ public class DirectColorModel extends PackedColorModel
* Converts a 16 bit value to the correct field bits based on the
* information derived from the field masks.
*/
- private final int value16ToField(int val, int component)
+ private int value16ToField(int val, int component)
{
int toFieldShift = getComponentSize(component) + shifts[component] - 16;
return (toFieldShift>0) ?
diff --git a/java/awt/image/IndexColorModel.java b/java/awt/image/IndexColorModel.java
index 9ceb0bf09..8bc8b9dd1 100644
--- a/java/awt/image/IndexColorModel.java
+++ b/java/awt/image/IndexColorModel.java
@@ -38,7 +38,29 @@ exception statement from your version. */
package java.awt.image;
+import java.awt.color.ColorSpace;
+import java.math.BigInteger;
+
/**
+ * Color model similar to pseudo visual in X11.
+ *
+ * This color model maps linear pixel values to actual RGB and alpha colors.
+ * Thus, pixel values are indexes into the color map. Each color component is
+ * an 8-bit unsigned value.
+ *
+ * The IndexColorModel supports a map of valid pixels, allowing the
+ * representation of holes in the the color map. The valid map is represented
+ * as a BigInteger where each bit indicates the validity of the map entry with
+ * the same index.
+ *
+ * Colors can have alpha components for transparency support. If alpha
+ * component values aren't given, color values are opaque. The model also
+ * supports a reserved pixel value to represent completely transparent colors,
+ * no matter what the actual color component values are.
+ *
+ * IndexColorModel supports anywhere from 1 to 16 bit index values. The
+ * allowed transfer types are DataBuffer.TYPE_BYTE and DataBuffer.TYPE_USHORT.
+ *
* @author C. Brian Jones (cbj@gnu.org)
*/
public class IndexColorModel extends ColorModel
@@ -47,6 +69,7 @@ public class IndexColorModel extends ColorModel
private boolean opaque;
private int trans = -1;
private int[] rgb;
+ private BigInteger validBits = new BigInteger("0");
/**
* Each array much contain <code>size</code> elements. For each
@@ -127,6 +150,10 @@ public class IndexColorModel extends ColorModel
| (blues[i] & 0xff));
}
}
+
+ // Generate a bigint with 1's for every pixel
+ validBits.setBit(size);
+ validBits.subtract(new BigInteger("1"));
}
/**
@@ -167,6 +194,79 @@ public class IndexColorModel extends ColorModel
map_size = size;
opaque = !hasAlpha;
this.trans = trans;
+ // Generate a bigint with 1's for every pixel
+ validBits.setBit(size);
+ validBits.subtract(new BigInteger("1"));
+ }
+
+ /**
+ * Each array much contain <code>size</code> elements. For each
+ * array, the i-th color is described by reds[i], greens[i],
+ * blues[i], alphas[i], unless alphas is not specified, then all the
+ * colors are opaque except for the transparent color.
+ *
+ * @param bits the number of bits needed to represent <code>size</code> colors
+ * @param size the number of colors in the color map
+ * @param cmap packed color components
+ * @param start the offset of the first color component in <code>cmap</code>
+ * @param hasAlpha <code>cmap</code> has alpha values
+ * @param trans the index of the transparent color
+ * @param transferType DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT
+ */
+ public IndexColorModel (int bits, int size, byte[] cmap, int start,
+ boolean hasAlpha, int trans, int transferType)
+ {
+ super(bits * 4, // total bits, sRGB, four channels
+ nArray(bits, 4), // bits for each channel
+ ColorSpace.getInstance(ColorSpace.CS_sRGB), // sRGB
+ true, // has alpha
+ false, // not premultiplied
+ TRANSLUCENT, transferType);
+ if (transferType != DataBuffer.TYPE_BYTE
+ && transferType != DataBuffer.TYPE_USHORT)
+ throw new IllegalArgumentException();
+ map_size = size;
+ opaque = !hasAlpha;
+ this.trans = trans;
+ // Generate a bigint with 1's for every pixel
+ validBits.setBit(size);
+ validBits.subtract(new BigInteger("1"));
+ }
+
+ /**
+ * Construct an IndexColorModel using a colormap with holes.
+ *
+ * The IndexColorModel is built from the array of ints defining the
+ * colormap. Each element contains red, green, blue, and alpha
+ * components. The ColorSpace is sRGB. The transparency value is
+ * automatically determined.
+ *
+ * This constructor permits indicating which colormap entries are valid,
+ * using the validBits argument. Each entry in cmap is valid if the
+ * corresponding bit in validBits is set.
+ *
+ * @param bits the number of bits needed to represent <code>size</code> colors
+ * @param size the number of colors in the color map
+ * @param cmap packed color components
+ * @param start the offset of the first color component in <code>cmap</code>
+ * @param transferType DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT
+ */
+ public IndexColorModel (int bits, int size, int[] cmap, int start,
+ int transferType, BigInteger validBits)
+ {
+ super(bits * 4, // total bits, sRGB, four channels
+ nArray(bits, 4), // bits for each channel
+ ColorSpace.getInstance(ColorSpace.CS_sRGB), // sRGB
+ true, // has alpha
+ false, // not premultiplied
+ TRANSLUCENT, transferType);
+ if (transferType != DataBuffer.TYPE_BYTE
+ && transferType != DataBuffer.TYPE_USHORT)
+ throw new IllegalArgumentException();
+ map_size = size;
+ opaque = false;
+ this.trans = -1;
+ this.validBits = validBits;
}
public final int getMapSize ()
@@ -279,11 +379,79 @@ public class IndexColorModel extends ColorModel
return 0;
}
- //pixel_bits is number of bits to be in generated mask
+ /**
+ * Get the RGB color values of all pixels in the map using the default
+ * RGB color model.
+ *
+ * @param rgb The destination array.
+ */
+ public final void getRGBs (int[] rgb)
+ {
+ System.arraycopy(this.rgb, 0, rgb, 0, map_size);
+ }
+
+ //pixel_bits is number of bits to be in generated mask
private int generateMask (int offset)
{
return (((2 << pixel_bits ) - 1) << (pixel_bits * offset));
}
+ /** Return true if pixel is valid, false otherwise. */
+ public boolean isValid(int pixel)
+ {
+ return validBits.testBit(pixel);
+ }
+
+ /** Return true if all pixels are valid, false otherwise. */
+ public boolean isValid()
+ {
+ // Generate a bigint with 1's for every pixel
+ BigInteger allbits = new BigInteger("0");
+ allbits.setBit(map_size);
+ allbits.subtract(new BigInteger("1"));
+ return allbits.equals(validBits);
+ }
+
+ /**
+ * Returns a BigInteger where each bit represents an entry in the color
+ * model. If the bit is on, the entry is valid.
+ */
+ public BigInteger getValidPixels()
+ {
+ return validBits;
+ }
+
+ /**
+ * Construct a BufferedImage with rgb pixel values from a Raster.
+ *
+ * Constructs a new BufferedImage in which each pixel is an RGBA int from
+ * a Raster with index-valued pixels. If this model has no alpha component
+ * or transparent pixel, the type of the new BufferedImage is TYPE_INT_RGB.
+ * Otherwise the type is TYPE_INT_ARGB. If forceARGB is true, the type is
+ * forced to be TYPE_INT_ARGB no matter what.
+ *
+ * @param raster The source of pixel values.
+ * @param forceARGB True if type must be TYPE_INT_ARGB.
+ * @return New BufferedImage with RBGA int pixel values.
+ */
+ public BufferedImage convertToIntDiscrete(Raster raster, boolean forceARGB)
+ {
+ int type = forceARGB ? BufferedImage.TYPE_INT_ARGB
+ : ((opaque && trans == -1) ? BufferedImage.TYPE_INT_RGB :
+ BufferedImage.TYPE_INT_ARGB);
+
+ // FIXME: assuming that raster has only 1 band since pixels are supposed
+ // to be int indexes.
+ // FIXME: it would likely be more efficient to fetch a complete array,
+ // but it would take much more memory.
+ // FIXME: I'm not sure if transparent pixels or alpha values need special
+ // handling here.
+ BufferedImage im = new BufferedImage(raster.width, raster.height, type);
+ for (int x = raster.minX; x < raster.width + raster.minX; x++)
+ for (int y = raster.minY; y < raster.height + raster.minY; y++)
+ im.setRGB(x, y, rgb[raster.getSample(x, y, 0)]);
+
+ return im;
+ }
}
diff --git a/java/awt/image/MemoryImageSource.java b/java/awt/image/MemoryImageSource.java
index 1228ed78f..8de4b842a 100644
--- a/java/awt/image/MemoryImageSource.java
+++ b/java/awt/image/MemoryImageSource.java
@@ -1,5 +1,5 @@
/* MemoryImageSource.java -- Java class for providing image data
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,8 +38,6 @@ exception statement from your version. */
package java.awt.image;
-import java.awt.Image;
-import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
diff --git a/java/awt/image/MultiPixelPackedSampleModel.java b/java/awt/image/MultiPixelPackedSampleModel.java
new file mode 100644
index 000000000..0525d37bd
--- /dev/null
+++ b/java/awt/image/MultiPixelPackedSampleModel.java
@@ -0,0 +1,387 @@
+/* Copyright (C) 2004 Free Software Foundation
+
+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;
+
+import gnu.java.awt.Buffers;
+
+/**
+ * MultiPixelPackedSampleModel provides a single band model that supports
+ * multiple pixels in a single unit. Pixels have 2^n bits and 2^k pixels fit
+ * per data element.
+ *
+ * @author Jerry Quinn <jlquinn@optonline.net>
+ */
+public class MultiPixelPackedSampleModel extends SampleModel
+{
+ private int scanlineStride;
+ private int[] bitMasks;
+ private int[] bitOffsets;
+ private int[] sampleSize;
+ private int dataBitOffset;
+ private int elemBits;
+ private int numberOfBits;
+ private int numElems;
+
+ public MultiPixelPackedSampleModel(int dataType, int w, int h,
+ int numberOfBits)
+ {
+ this(dataType, w, h, 0, numberOfBits, 0);
+ }
+
+ public MultiPixelPackedSampleModel(int dataType, int w, int h,
+ int numberOfBits, int scanlineStride,
+ int dataBitOffset)
+ {
+ super(dataType, w, h, 1);
+
+ switch (dataType)
+ {
+ case DataBuffer.TYPE_BYTE:
+ elemBits = 8;
+ break;
+ case DataBuffer.TYPE_USHORT:
+ elemBits = 16;
+ break;
+ case DataBuffer.TYPE_INT:
+ elemBits = 32;
+ break;
+ default:
+ throw new IllegalArgumentException("MultiPixelPackedSampleModel"
+ + " unsupported dataType");
+ }
+
+ this.dataBitOffset = dataBitOffset;
+
+ this.numberOfBits = numberOfBits;
+ if (numberOfBits > elemBits)
+ throw new RasterFormatException("MultiPixelPackedSampleModel pixel size"
+ + " larger than dataType");
+ switch (numberOfBits)
+ {
+ case 1: case 2: case 4: case 8: case 16: case 32: break;
+ default:
+ throw new RasterFormatException("MultiPixelPackedSampleModel pixel"
+ + " size not 2^n bits");
+ }
+ numElems = elemBits / numberOfBits;
+
+ // Compute scan line large enough for w pixels.
+ if (scanlineStride == 0)
+ scanlineStride = ((dataBitOffset + w * numberOfBits) / elemBits) + 1;
+ this.scanlineStride = scanlineStride;
+
+
+ sampleSize = new int[1];
+ sampleSize[0] = numberOfBits;
+
+ bitMasks = new int[numElems];
+ bitOffsets = new int[numElems];
+ for (int i=0; i < numElems; i++)
+ {
+ bitOffsets[i] = numberOfBits * i;
+ bitMasks[i] = ((1 << numberOfBits) - 1) << bitOffsets[i];
+ }
+ }
+
+ public SampleModel createCompatibleSampleModel(int w, int h)
+ {
+ /* FIXME: We can avoid recalculation of bit offsets and sample
+ sizes here by passing these from the current instance to a
+ special private constructor. */
+ return new MultiPixelPackedSampleModel(dataType, w, h, numberOfBits);
+ }
+
+
+ /**
+ * Creates a DataBuffer for holding pixel data in the format and
+ * layout described by this SampleModel. The returned buffer will
+ * consist of one single bank.
+ */
+ public DataBuffer createDataBuffer()
+ {
+ int size;
+
+ // FIXME: The comment refers to SinglePixelPackedSampleModel. See if the
+ // same can be done for MultiPixelPackedSampleModel.
+ // We can save (scanlineStride - width) pixels at the very end of
+ // the buffer. The Sun reference implementation (J2SE 1.3.1 and
+ // 1.4.1_01) seems to do this; tested with Mauve test code.
+ size = scanlineStride * height;
+
+ return Buffers.createBuffer(getDataType(), size);
+ }
+
+
+ public int getNumDataElements()
+ {
+ return 1;
+ }
+
+ public int[] getSampleSize()
+ {
+ return sampleSize;
+ }
+
+ public int getSampleSize(int band)
+ {
+ return sampleSize[0];
+ }
+
+ public int getOffset(int x, int y)
+ {
+ return scanlineStride * y + ((dataBitOffset + x*numberOfBits) / elemBits);
+ }
+
+ public int getBitOffset(int x)
+ {
+ return (dataBitOffset + x*numberOfBits) % elemBits;
+ }
+
+ public int getDataBitOffset()
+ {
+ return dataBitOffset;
+ }
+
+ public int getScanlineStride()
+ {
+ return scanlineStride;
+ }
+
+ public int getPixelBitStride()
+ {
+ return numberOfBits;
+ }
+
+
+ public SampleModel createSubsetSampleModel(int[] bands)
+ {
+ int numBands = bands.length;
+ if (numBands != 1)
+ throw new RasterFormatException("MultiPixelPackedSampleModel only"
+ + " supports one band");
+
+ return new MultiPixelPackedSampleModel(dataType, width, height,
+ numberOfBits, scanlineStride,
+ dataBitOffset);
+ }
+
+ /**
+ * Extract one pixel and return in an array of transfer type.
+ *
+ * Extracts the pixel at x, y from data and stores into the 0th index of the
+ * array obj, since there is only one band. If obj is null, a new array of
+ * getTransferType() is created.
+ *
+ * @param x The x-coordinate of the pixel rectangle to store in <code>obj</code>.
+ * @param y The y-coordinate of the pixel rectangle to store in <code>obj</code>.
+ * @param obj The primitive array to store the pixels into or null to force creation.
+ * @param data The DataBuffer that is the source of the pixel data.
+ * @return The primitive array containing the pixel data.
+ * @see java.awt.image.SampleModel#getDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)
+ */
+ public Object getDataElements(int x, int y, Object obj,
+ DataBuffer data)
+ {
+ int pixel = getSample(x, y, 0, data);
+ switch (getTransferType())
+ {
+ case DataBuffer.TYPE_BYTE:
+ if (obj == null) obj = new byte[1];
+ ((byte[])obj)[0] = (byte)pixel;
+ return obj;
+ case DataBuffer.TYPE_USHORT:
+ if (obj == null) obj = new short[1];
+ ((short[])obj)[0] = (short)pixel;
+ return obj;
+ case DataBuffer.TYPE_INT:
+ if (obj == null) obj = new int[1];
+ ((int[])obj)[0] = pixel;
+ return obj;
+ default:
+ // Seems like the only sensible thing to do.
+ throw new ClassCastException();
+ }
+ }
+
+ public int[] getPixel(int x, int y, int[] iArray, DataBuffer data)
+ {
+ if (iArray == null) iArray = new int[1];
+ iArray[0] = getSample(x, y, 0, data);
+
+ return iArray;
+ }
+
+ public int[] getPixels(int x, int y, int w, int h, int[] iArray,
+ DataBuffer data)
+ {
+ int offset = getOffset(x, y);
+ if (iArray == null) iArray = new int[w*h];
+ int outOffset = 0;
+ for (y=0; y<h; y++)
+ {
+ int lineOffset = offset;
+ for (x=0; x<w;)
+ {
+ int samples = data.getElem(lineOffset++);
+ for (int b=0; b<numElems && x<w; b++)
+ {
+ iArray[outOffset++] = (samples & bitMasks[b]) >>> bitOffsets[b];
+ x++;
+ }
+ }
+ offset += scanlineStride;
+ }
+ return iArray;
+ }
+
+ public int getSample(int x, int y, int b, DataBuffer data)
+ {
+ int pos =
+ ((dataBitOffset + x * numberOfBits) % elemBits) / numberOfBits;
+ int offset = getOffset(x, y);
+ int samples = data.getElem(offset);
+ return (samples & bitMasks[pos]) >>> bitOffsets[pos];
+ }
+
+ /**
+ * Set the pixel at x, y to the value in the first element of the primitive
+ * array obj.
+ *
+ * @param x The x-coordinate of the data elements in <code>obj</code>.
+ * @param y The y-coordinate of the data elements in <code>obj</code>.
+ * @param obj The primitive array containing the data elements to set.
+ * @param data The DataBuffer to store the data elements into.
+ * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, java.lang.Object, java.awt.image.DataBuffer)
+ */
+ public void setDataElements(int x, int y, Object obj, DataBuffer data)
+ {
+ int transferType = getTransferType();
+ if (getTransferType() != data.getDataType())
+ {
+ throw new IllegalArgumentException("transfer type ("+
+ getTransferType()+"), "+
+ "does not match data "+
+ "buffer type (" +
+ data.getDataType() +
+ ").");
+ }
+
+ int offset = getOffset(x, y);
+
+ try
+ {
+ switch (transferType)
+ {
+ case DataBuffer.TYPE_BYTE:
+ {
+ DataBufferByte out = (DataBufferByte) data;
+ byte[] in = (byte[]) obj;
+ out.getData()[offset] = in[0];
+ return;
+ }
+ case DataBuffer.TYPE_USHORT:
+ {
+ DataBufferUShort out = (DataBufferUShort) data;
+ short[] in = (short[]) obj;
+ out.getData()[offset] = in[0];
+ return;
+ }
+ case DataBuffer.TYPE_INT:
+ {
+ DataBufferInt out = (DataBufferInt) data;
+ int[] in = (int[]) obj;
+ out.getData()[offset] = in[0];
+ return;
+ }
+ default:
+ throw new ClassCastException("Unsupported data type");
+ }
+ }
+ catch (ArrayIndexOutOfBoundsException aioobe)
+ {
+ String msg = "While writing data elements" +
+ ", x="+x+", y="+y+
+ ", width="+width+", height="+height+
+ ", scanlineStride="+scanlineStride+
+ ", offset="+offset+
+ ", data.getSize()="+data.getSize()+
+ ", data.getOffset()="+data.getOffset()+
+ ": " +
+ aioobe;
+ throw new ArrayIndexOutOfBoundsException(msg);
+ }
+ }
+
+ public void setPixel(int x, int y, int[] iArray, DataBuffer data)
+ {
+ setSample(x, y, 0, iArray[0], data);
+ }
+
+ public void setSample(int x, int y, int b, int s, DataBuffer data)
+ {
+ int bitpos =
+ ((dataBitOffset + x * numberOfBits) % elemBits) / numberOfBits;
+ int offset = getOffset(x, y);
+
+ s = s << bitOffsets[bitpos];
+ s = s & bitMasks[bitpos];
+
+ int sample = data.getElem(offset);
+ sample |= s;
+ data.setElem(offset, sample);
+ }
+
+ /**
+ * Creates a String with some information about this SampleModel.
+ * @return A String describing this SampleModel.
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ StringBuffer result = new StringBuffer();
+ result.append(getClass().getName());
+ result.append("[");
+ result.append("scanlineStride=").append(scanlineStride);
+ for(int i=0; i < bitMasks.length; i+=1)
+ {
+ result.append(", mask[").append(i).append("]=0x").append(Integer.toHexString(bitMasks[i]));
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+}
diff --git a/java/awt/image/PackedColorModel.java b/java/awt/image/PackedColorModel.java
index 2d8b0e1ab..1f18cf68e 100644
--- a/java/awt/image/PackedColorModel.java
+++ b/java/awt/image/PackedColorModel.java
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2002 Free Software Foundation
+/* Copyright (C) 2000, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -34,11 +34,13 @@ 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;
+import gnu.java.awt.BitMaskExtent;
+
import java.awt.Point;
import java.awt.color.ColorSpace;
-import gnu.java.awt.BitMaskExtent;
/**
* @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
diff --git a/java/awt/image/PixelGrabber.java b/java/awt/image/PixelGrabber.java
index fd5c24a86..da50d1f70 100644
--- a/java/awt/image/PixelGrabber.java
+++ b/java/awt/image/PixelGrabber.java
@@ -1,39 +1,39 @@
/* PixelGrabber.java -- retrieve a subset of an image's data
- Copyright (C) 1999, 2003 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. */
+ Copyright (C) 1999, 2003, 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;
diff --git a/java/awt/image/Raster.java b/java/awt/image/Raster.java
index 4fd194e2a..0db5aa10f 100644
--- a/java/awt/image/Raster.java
+++ b/java/awt/image/Raster.java
@@ -154,6 +154,35 @@ public class Raster
return createWritableRaster(sm, location);
}
+ public static WritableRaster createPackedRaster(int dataType,
+ int w, int h,
+ int bands, int bitsPerBand,
+ Point location)
+ {
+ if (bands <= 0 || (bands * bitsPerBand > getTypeBits(dataType)))
+ throw new IllegalArgumentException();
+
+ SampleModel sm;
+
+ if (bands == 1)
+ sm = new MultiPixelPackedSampleModel(dataType, w, h, bitsPerBand);
+ else
+ {
+ int[] bandMasks = new int[bands];
+ int mask = 0x1;
+ for (int bits = bitsPerBand; --bits != 0;)
+ mask = (mask << 1) | 0x1;
+ for (int i = 0; i < bands; i++)
+ {
+ bandMasks[i] = mask;
+ mask <<= bitsPerBand;
+ }
+
+ sm = new SinglePixelPackedSampleModel(dataType, w, h, bandMasks);
+ }
+ return createWritableRaster(sm, location);
+ }
+
public static WritableRaster
createInterleavedRaster(DataBuffer dataBuffer, int w, int h,
int scanlineStride, int pixelStride,
@@ -329,6 +358,11 @@ public class Raster
return height;
}
+ public final int getNumBands()
+ {
+ return numBands;
+ }
+
public final int getNumDataElements()
{
return numDataElements;
@@ -472,5 +506,24 @@ public class Raster
return result.toString();
}
-
+
+ // Map from datatype to bits
+ private static int getTypeBits(int dataType)
+ {
+ switch (dataType)
+ {
+ case DataBuffer.TYPE_BYTE:
+ return 8;
+ case DataBuffer.TYPE_USHORT:
+ case DataBuffer.TYPE_SHORT:
+ return 16;
+ case DataBuffer.TYPE_INT:
+ case DataBuffer.TYPE_FLOAT:
+ return 32;
+ case DataBuffer.TYPE_DOUBLE:
+ return 64;
+ default:
+ return 0;
+ }
+ }
}
diff --git a/java/awt/image/RasterOp.java b/java/awt/image/RasterOp.java
index 57961808e..84d47c119 100644
--- a/java/awt/image/RasterOp.java
+++ b/java/awt/image/RasterOp.java
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2002 Free Software Foundation
+/* Copyright (C) 2000, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -34,11 +34,12 @@ 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;
+import java.awt.RenderingHints;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
-import java.awt.RenderingHints;
public interface RasterOp {
diff --git a/java/awt/image/RescaleOp.java b/java/awt/image/RescaleOp.java
new file mode 100644
index 000000000..9235e0e14
--- /dev/null
+++ b/java/awt/image/RescaleOp.java
@@ -0,0 +1,210 @@
+/* Copyright (C) 2004 Free Software Foundation
+
+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;
+
+import java.awt.RenderingHints;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.util.Arrays;
+
+/**
+ * @author Jerry Quinn <jlquinn@optonline.net>
+ *
+ */
+public class RescaleOp implements BufferedImageOp, RasterOp
+{
+ private float[] scale;
+ private float[] offsets;
+ private RenderingHints hints = null;
+
+ public RescaleOp(float[] scaleFactors,
+ float[] offsets,
+ RenderingHints hints)
+ {
+ this.scale = scaleFactors;
+ this.offsets = offsets;
+ this.hints = hints;
+ }
+
+ public RescaleOp(float scaleFactor,
+ float offset,
+ RenderingHints hints)
+ {
+ scale = new float[]{ scaleFactor };
+ offsets = new float[]{offset};
+ this.hints = hints;
+ }
+
+ public final float[] getScaleFactors(float[] scaleFactors)
+ {
+ if (scaleFactors == null)
+ scaleFactors = new float[scale.length];
+ System.arraycopy(scale, 0, scaleFactors, 0, scale.length);
+ return scaleFactors;
+ }
+
+ public final float[] getOffsets(float[] offsets)
+ {
+ if (offsets == null)
+ offsets = new float[this.offsets.length];
+ System.arraycopy(this.offsets, 0, offsets, 0, this.offsets.length);
+ return offsets;
+ }
+
+ public final int getNumFactors() { return scale.length; }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.BufferedImageOp#getRenderingHints()
+ */
+ public RenderingHints getRenderingHints() { return hints; }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.BufferedImageOp#filter(java.awt.image.BufferedImage, java.awt.image.BufferedImage)
+ */
+ public BufferedImage filter(BufferedImage src, BufferedImage dst) {
+ // TODO Make sure premultiplied alpha is handled correctly.
+ // TODO See that color conversion is handled.
+ // TODO figure out how to use rendering hints.
+ if (scale.length != offsets.length)
+ throw new IllegalArgumentException();
+
+ ColorModel scm = src.getColorModel();
+ if (dst == null) dst = createCompatibleDestImage(src, null);
+
+ WritableRaster wsrc = src.getRaster();
+ WritableRaster wdst = dst.getRaster();
+
+ // Share constant across colors except alpha
+ if (scale.length == 1 || scale.length == scm.getNumColorComponents())
+ {
+ // Construct a raster that doesn't include an alpha band.
+ int[] subbands = new int[scm.getNumColorComponents()];
+ for (int i=0; i < subbands.length; i++) subbands[i] = i;
+ wsrc =
+ wsrc.createWritableChild(wsrc.minX, wsrc.minY, wsrc.width, wsrc.height,
+ wsrc.minX, wsrc.minY, subbands);
+ }
+ // else all color bands
+
+ filter(wsrc, wdst);
+ return dst;
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.RasterOp#filter(java.awt.image.Raster, java.awt.image.WritableRaster)
+ */
+ public WritableRaster filter(Raster src, WritableRaster dest) {
+ if (dest == null) dest = src.createCompatibleWritableRaster();
+
+ // Required sanity checks
+ if (src.numBands != dest.numBands || scale.length != offsets.length)
+ throw new IllegalArgumentException();
+ if (scale.length != 1 && scale.length != src.numBands)
+ throw new IllegalArgumentException();
+
+ // Create scaling arrays if needed
+ float[] lscale = scale;
+ float[] loff = offsets;
+ if (scale.length == 1)
+ {
+ lscale = new float[src.numBands];
+ Arrays.fill(lscale, scale[0]);
+ loff = new float[src.numBands];
+ Arrays.fill(loff, offsets[0]);
+ }
+
+ // TODO The efficiency here can be improved for various data storage
+ // patterns, aka SampleModels.
+ float[] pixel = new float[src.numBands];
+ for (int y = src.minY; y < src.height- src.minY; y++)
+ for (int x = src.minX; x < src.width - src.minX; x++)
+ {
+ src.getPixel(x, y, pixel);
+ for (int b = 0; b < src.numBands; b++)
+ pixel[b] = pixel[b] * lscale[b] + loff[b];
+ dest.setPixel(x, y, pixel);
+ }
+ return dest;
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.BufferedImageOp#createCompatibleDestImage(java.awt.image.BufferedImage, java.awt.image.ColorModel)
+ */
+ public BufferedImage createCompatibleDestImage(BufferedImage src,
+ ColorModel dstCM)
+ {
+ if (dstCM == null) dstCM = src.getColorModel();
+ WritableRaster wr = src.getRaster().createCompatibleWritableRaster();
+ BufferedImage image
+ = new BufferedImage(dstCM, wr, src.isPremultiplied, null);
+ return image;
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.RasterOp#createCompatibleDestRaster(java.awt.image.Raster)
+ */
+ public WritableRaster createCompatibleDestRaster(Raster src)
+ {
+ return src.createCompatibleWritableRaster();
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.BufferedImageOp#getBounds2D(java.awt.image.BufferedImage)
+ */
+ public Rectangle2D getBounds2D(BufferedImage src)
+ {
+ return src.getRaster().getBounds();
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.RasterOp#getBounds2D(java.awt.image.Raster)
+ */
+ public Rectangle2D getBounds2D(Raster src)
+ {
+ return src.getBounds();
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.BufferedImageOp#getPoint2D(java.awt.geom.Point2D, java.awt.geom.Point2D)
+ */
+ public Point2D getPoint2D(Point2D src, Point2D dst) {
+ if (dst == null) dst = (Point2D) src.clone();
+ else dst.setLocation(src);
+ return dst;
+ }
+
+}
diff --git a/java/awt/image/SinglePixelPackedSampleModel.java b/java/awt/image/SinglePixelPackedSampleModel.java
index 578500dbd..9f49d836d 100644
--- a/java/awt/image/SinglePixelPackedSampleModel.java
+++ b/java/awt/image/SinglePixelPackedSampleModel.java
@@ -59,6 +59,16 @@ public class SinglePixelPackedSampleModel extends SampleModel
int scanlineStride, int[] bitMasks)
{
super(dataType, w, h, bitMasks.length);
+
+ switch (dataType)
+ {
+ case DataBuffer.TYPE_BYTE:
+ case DataBuffer.TYPE_USHORT:
+ case DataBuffer.TYPE_INT:
+ break;
+ default:
+ throw new IllegalArgumentException("SinglePixelPackedSampleModel unsupported dataType");
+ }
this.scanlineStride = scanlineStride;
this.bitMasks = bitMasks;