This patch (committed) fixes some minor bugs in java.awt.image.*:

2006-07-18  David Gilbert  <[EMAIL PROTECTED]>

        * 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.

Mauve tests to follow.

Regards,

Dave
Index: java/awt/image/BandedSampleModel.java
===================================================================
RCS file: /sources/classpath/classpath/java/awt/image/BandedSampleModel.java,v
retrieving revision 1.7
diff -u -r1.7 BandedSampleModel.java
--- java/awt/image/BandedSampleModel.java       13 Jul 2006 13:55:32 -0000      
1.7
+++ java/awt/image/BandedSampleModel.java       18 Jul 2006 16:26:53 -0000
@@ -36,6 +36,8 @@
 
 package java.awt.image;
 
+import gnu.java.awt.Buffers;
+
 /**
  * A sample model that reads each sample value from a separate band in the
  * [EMAIL PROTECTED] DataBuffer}.
@@ -89,6 +91,17 @@
   {
     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
Index: java/awt/image/ByteLookupTable.java
===================================================================
RCS file: /sources/classpath/classpath/java/awt/image/ByteLookupTable.java,v
retrieving revision 1.5
diff -u -r1.5 ByteLookupTable.java
--- java/awt/image/ByteLookupTable.java 2 Jul 2005 20:32:30 -0000       1.5
+++ java/awt/image/ByteLookupTable.java 18 Jul 2006 16:26:53 -0000
@@ -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 @@
    * 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 &lt; 0 or data.length &lt; 
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 @@
    * 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 &lt; 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};
   }
 
Index: java/awt/image/ComponentSampleModel.java
===================================================================
RCS file: 
/sources/classpath/classpath/java/awt/image/ComponentSampleModel.java,v
retrieving revision 1.14
diff -u -r1.14 ComponentSampleModel.java
--- java/awt/image/ComponentSampleModel.java    5 Apr 2006 09:56:14 -0000       
1.14
+++ java/awt/image/ComponentSampleModel.java    18 Jul 2006 16:26:54 -0000
@@ -272,9 +272,7 @@
     // 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 @@
    * 
    * @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));
   }
 
Index: java/awt/image/ShortLookupTable.java
===================================================================
RCS file: /sources/classpath/classpath/java/awt/image/ShortLookupTable.java,v
retrieving revision 1.5
diff -u -r1.5 ShortLookupTable.java
--- java/awt/image/ShortLookupTable.java        2 Jul 2005 20:32:36 -0000       
1.5
+++ java/awt/image/ShortLookupTable.java        18 Jul 2006 16:26:54 -0000
@@ -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 @@
     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 @@
    * 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 &lt; 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 @@
       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 @@
    * @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 @@
       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;
 

Reply via email to