This patch (committed) fixes a couple of bugs in the SinglePixelPackedSampleModel class. First, the bit mask needs to be converted as an unsigned long in the constructor. Second, the equals() method hadn't been implemented for this class.

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

        * java/awt/image/SinglePixelPackedSampleModel.java
        (SinglePixelPackageSampleModel(int, int, int, int, int[])): Convert
        mask correctly as an unsigned integer,
        (equals): New method override.

I have a new Mauve test for the bit mask bug, the equals() method is already covered in Mauve (the existing checks were failing).

Regards,

Dave
Index: java/awt/image/SinglePixelPackedSampleModel.java
===================================================================
RCS file: 
/sources/classpath/classpath/java/awt/image/SinglePixelPackedSampleModel.java,v
retrieving revision 1.11
diff -u -r1.11 SinglePixelPackedSampleModel.java
--- java/awt/image/SinglePixelPackedSampleModel.java    13 Jul 2006 13:55:32 
-0000      1.11
+++ java/awt/image/SinglePixelPackedSampleModel.java    13 Jul 2006 15:39:06 
-0000
@@ -36,6 +36,8 @@
 
 package java.awt.image;
 
+import java.util.Arrays;
+
 import gnu.java.awt.BitMaskExtent;
 import gnu.java.awt.Buffers;
 
@@ -104,9 +106,11 @@
     BitMaskExtent extent = new BitMaskExtent();
     for (int b = 0; b < numBands; b++)
       {
-       extent.setMask(bitMasks[b]);
-       sampleSize[b] = extent.bitWidth;
-       bitOffsets[b] = extent.leastSignificantBit;
+        // the mask is an unsigned integer
+        long mask = bitMasks[b] & 0xFFFFFFFFL;
+        extent.setMask(mask);
+        sampleSize[b] = extent.bitWidth;
+        bitOffsets[b] = extent.leastSignificantBit;
       }
   }
 
@@ -566,6 +570,55 @@
   }
   
   /**
+   * Tests this sample model for equality with an arbitrary object.  This 
+   * method returns <code>true</code> if and only if:
+   * <ul>
+   *   <li><code>obj</code> is not <code>null</code>;
+   *   <li><code>obj</code> is an instance of 
+   *       <code>SinglePixelPackedSampleModel</code>;
+   *   <li>both models have the same:
+   *     <ul>
+   *       <li><code>dataType</code>;
+   *       <li><code>width</code>;
+   *       <li><code>height</code>;
+   *       <li><code>numBands</code>;
+   *       <li><code>scanlineStride</code>;
+   *       <li><code>bitMasks</code>;
+   *       <li><code>bitOffsets</code>.
+   *     </ul>
+   *   </li>
+   * </ul>
+   * 
+   * @param obj  the object (<code>null</code> permitted)
+   * 
+   * @return <code>true</code> if this model is equal to <code>obj</code>, and
+   *     <code>false</code> otherwise.
+   */
+  public boolean equals(Object obj) 
+  {
+    if (this == obj) 
+      return true;
+    if (! (obj instanceof SinglePixelPackedSampleModel)) 
+      return false;
+    SinglePixelPackedSampleModel that = (SinglePixelPackedSampleModel) obj;
+    if (this.dataType != that.dataType)
+      return false;
+    if (this.width != that.width)
+      return false;
+    if (this.height != that.height)
+      return false;
+    if (this.numBands != that.numBands)
+      return false;
+    if (this.scanlineStride != that.scanlineStride)
+      return false;
+    if (!Arrays.equals(this.bitMasks, that.bitMasks))
+      return false;
+    if (!Arrays.equals(this.bitOffsets, that.bitOffsets)) 
+      return false;
+    return true;
+  }
+  
+  /**
    * Creates a String with some information about this SampleModel.
    * @return A String describing this SampleModel.
    * @see java.lang.Object#toString()

Reply via email to