diff options
author | David Gilbert <david.gilbert@object-refinery.com> | 2006-07-18 16:36:26 +0000 |
---|---|---|
committer | David Gilbert <david.gilbert@object-refinery.com> | 2006-07-18 16:36:26 +0000 |
commit | e4f11a19409b623f524b8a8a0ab1696aa1a97456 (patch) | |
tree | 2aff0a5efc002efa70430fce80bead7cee3584de | |
parent | 08cdcc8be455402d2c2b784dfaf8873e7029bad5 (diff) | |
download | classpath-e4f11a19409b623f524b8a8a0ab1696aa1a97456.tar.gz |
2006-07-18 David Gilbert <david.gilbert@object-refinery.com>
* java/awt/image/BandedSampleModel.java
(createDataBuffer): New method override,
* java/awt/image/ByteLookupTable.java
(ByteLookupTable(int, byte[][])): Create new array to hold references,
(ByteLookuptable(int, byte[])): Check for null array,
* java/awt/image/ComponentSampleModel.java
(createDataBuffer): Removed unnecessary braces,
(getSample): Check (x, y) is within bounds,
* java/awt/image/ShortLookupTable.java
(ShortLookupTable(int, short[][])): Create new array to hold references,
(ShortLookupTable(int, short[])): Check for null array,
(getTable): Added API docs,
(lookupPixel): Source reformatting.
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | java/awt/image/BandedSampleModel.java | 13 | ||||
-rw-r--r-- | java/awt/image/ByteLookupTable.java | 17 | ||||
-rw-r--r-- | java/awt/image/ComponentSampleModel.java | 9 | ||||
-rw-r--r-- | java/awt/image/ShortLookupTable.java | 39 |
5 files changed, 75 insertions, 19 deletions
@@ -1,3 +1,19 @@ +2006-07-18 David Gilbert <david.gilbert@object-refinery.com> + + * java/awt/image/BandedSampleModel.java + (createDataBuffer): New method override, + * java/awt/image/ByteLookupTable.java + (ByteLookupTable(int, byte[][])): Create new array to hold references, + (ByteLookuptable(int, byte[])): Check for null array, + * java/awt/image/ComponentSampleModel.java + (createDataBuffer): Removed unnecessary braces, + (getSample): Check (x, y) is within bounds, + * java/awt/image/ShortLookupTable.java + (ShortLookupTable(int, short[][])): Create new array to hold references, + (ShortLookupTable(int, short[])): Check for null array, + (getTable): Added API docs, + (lookupPixel): Source reformatting. + 2006-07-18 Tania Bento <tbento@redhat.com> * java/awt/GridLayout.java diff --git a/java/awt/image/BandedSampleModel.java b/java/awt/image/BandedSampleModel.java index ed6abcf4f..a346cf6af 100644 --- a/java/awt/image/BandedSampleModel.java +++ b/java/awt/image/BandedSampleModel.java @@ -36,6 +36,8 @@ exception statement from your version. */ package java.awt.image; +import gnu.java.awt.Buffers; + /** * A sample model that reads each sample value from a separate band in the * {@link DataBuffer}. @@ -89,6 +91,17 @@ public final class BandedSampleModel extends ComponentSampleModel { super(dataType, w, h, 1, scanlineStride, bankIndices, bandOffsets); } + + /** + * Creates a new data buffer that is compatible with this sample model. + * + * @return The new data buffer. + */ + public DataBuffer createDataBuffer() + { + int size = scanlineStride * height; + return Buffers.createBuffer(getDataType(), size, numBanks); + } /** * Creates a new <code>SampleModel</code> that is compatible with this diff --git a/java/awt/image/ByteLookupTable.java b/java/awt/image/ByteLookupTable.java index df02d0a1b..ecc0023af 100644 --- a/java/awt/image/ByteLookupTable.java +++ b/java/awt/image/ByteLookupTable.java @@ -1,5 +1,5 @@ /* ByteLookupTable.java -- Java class for a pixel translation table. - Copyright (C) 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -60,14 +60,20 @@ public class ByteLookupTable extends LookupTable * components. * * @param offset Offset to be subtracted. - * @param data Array of lookup tables. + * @param data Array of lookup tables (<code>null</code> not permitted). * @exception IllegalArgumentException if offset < 0 or data.length < 1. */ public ByteLookupTable(int offset, byte[][] data) throws IllegalArgumentException { super(offset, data.length); - this.data = data; + + // tests show that Sun's implementation creates a new array to store the + // references from the incoming 'data' array - not sure why, but we'll + // match that behaviour just in case it matters... + this.data = new byte[data.length][]; + for (int i = 0; i < data.length; i++) + this.data[i] = data[i]; } /** @@ -77,13 +83,16 @@ public class ByteLookupTable extends LookupTable * table. The same table is applied to all pixel components. * * @param offset Offset to be subtracted. - * @param data Lookup table for all components. + * @param data Lookup table for all components (<code>null</code> not + * permitted). * @exception IllegalArgumentException if offset < 0. */ public ByteLookupTable(int offset, byte[] data) throws IllegalArgumentException { super(offset, 1); + if (data == null) + throw new NullPointerException("Null 'data' argument."); this.data = new byte[][] {data}; } diff --git a/java/awt/image/ComponentSampleModel.java b/java/awt/image/ComponentSampleModel.java index b4e9450b0..2428cfd00 100644 --- a/java/awt/image/ComponentSampleModel.java +++ b/java/awt/image/ComponentSampleModel.java @@ -272,9 +272,7 @@ public class ComponentSampleModel extends SampleModel // Maybe this value should be precalculated in the constructor? int highestOffset = 0; for (int b = 0; b < numBands; b++) - { - highestOffset = Math.max(highestOffset, bandOffsets[b]); - } + highestOffset = Math.max(highestOffset, bandOffsets[b]); int size = pixelStride * (width - 1) + scanlineStride * (height - 1) + highestOffset + 1; @@ -736,10 +734,15 @@ public class ComponentSampleModel extends SampleModel * * @return The sample value. * + * @throws ArrayIndexOutOfBoundsException if <code>(x, y)</code> is outside + * the bounds <code>[0, 0, width, height]</code>. + * * @see #setSample(int, int, int, int, DataBuffer) */ public int getSample(int x, int y, int b, DataBuffer data) { + if (x < 0 || x >= width || y < 0 || y >= height) + throw new ArrayIndexOutOfBoundsException("(x, y) is out of bounds."); return data.getElem(bankIndices[b], getOffset(x, y, b)); } diff --git a/java/awt/image/ShortLookupTable.java b/java/awt/image/ShortLookupTable.java index 5915a7939..858818cf2 100644 --- a/java/awt/image/ShortLookupTable.java +++ b/java/awt/image/ShortLookupTable.java @@ -1,5 +1,5 @@ /* ShortLookupTable.java -- Java class for a pixel translation table. - Copyright (C) 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -67,7 +67,13 @@ public class ShortLookupTable extends LookupTable throws IllegalArgumentException { super(offset, data.length); - this.data = data; + + // tests show that Sun's implementation creates a new array to store the + // references from the incoming 'data' array - not sure why, but we'll + // match that behaviour just in case it matters... + this.data = new short[data.length][]; + for (int i = 0; i < data.length; i++) + this.data[i] = data[i]; } /** @@ -77,17 +83,25 @@ public class ShortLookupTable extends LookupTable * table. The same table is applied to all pixel components. * * @param offset Offset to be subtracted. - * @param data Lookup table for all components. + * @param data Lookup table for all components (<code>null</code> not + * permitted). * @exception IllegalArgumentException if offset < 0. */ public ShortLookupTable(int offset, short[] data) throws IllegalArgumentException { super(offset, 1); + if (data == null) + throw new NullPointerException("Null 'data' argument."); this.data = new short[][] {data}; } - /** Return the lookup tables. */ + /** + * Return the lookup tables. This is a reference to the actual table, so + * modifying the contents of the returned array will modify the lookup table. + * + * @return The lookup table. + */ public final short[][] getTable() { return data; @@ -117,11 +131,11 @@ public class ShortLookupTable extends LookupTable dst = new int[src.length]; if (data.length == 1) - for (int i=0; i < src.length; i++) - dst[i] = data[0][src[i] - offset]; + for (int i = 0; i < src.length; i++) + dst[i] = data[0][src[i] - offset]; else - for (int i=0; i < src.length; i++) - dst[i] = data[i][src[i] - offset]; + for (int i = 0; i < src.length; i++) + dst[i] = data[i][src[i] - offset]; return dst; } @@ -142,6 +156,7 @@ public class ShortLookupTable extends LookupTable * @param src Component values of a pixel. * @param dst Destination array for values, or null. * @return Translated values for the pixel. + * */ public short[] lookupPixel(short[] src, short[] dst) throws ArrayIndexOutOfBoundsException @@ -150,11 +165,11 @@ public class ShortLookupTable extends LookupTable dst = new short[src.length]; if (data.length == 1) - for (int i=0; i < src.length; i++) - dst[i] = data[0][((int)src[i]) - offset]; + for (int i = 0; i < src.length; i++) + dst[i] = data[0][((int) src[i]) - offset]; else - for (int i=0; i < src.length; i++) - dst[i] = data[i][((int)src[i]) - offset]; + for (int i = 0; i < src.length; i++) + dst[i] = data[i][((int) src[i]) - offset]; return dst; |