This patch (committed) fixes a couple of bugs in the createCompatibleSampleModel() method:

- due to a typo, we were incrementing 'i' rather than 'j' in one of the loops (thanks to Paul Jenner for noticing this), which was resulting in an IllegalArgumentException; - the scanlineStride should be equal to the new sample model width, not the old scanlineStride.

Here is the ChangeLog entry:

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

        * java/awt/image/BandedSampleModel.java
        (createCompatibleSampleModel): Fixed typo in loop increment, set
        correct scanlineStride, and updated API docs.

Regards,

Dave
Index: java/awt/image/BandedSampleModel.java
===================================================================
RCS file: /sources/classpath/classpath/java/awt/image/BandedSampleModel.java,v
retrieving revision 1.8
diff -u -r1.8 BandedSampleModel.java
--- java/awt/image/BandedSampleModel.java       18 Jul 2006 16:36:29 -0000      
1.8
+++ java/awt/image/BandedSampleModel.java       26 Jul 2006 06:19:15 -0000
@@ -107,10 +107,15 @@
    * Creates a new <code>SampleModel</code> that is compatible with this
    * model and has the specified width and height.
    * 
-   * @param w  the width (in pixels).
-   * @param h  the height (in pixels).
+   * @param w  the width (in pixels, must be greater than zero).
+   * @param h  the height (in pixels, must be greater than zero).
    * 
    * @return The new sample model.
+   * 
+   * @throws IllegalArgumentException if <code>w</code> or <code>h</code> is
+   *     not greater than zero.
+   * @throws IllegalArgumentException if <code>w * h</code> exceeds 
+   *     <code>Integer.MAX_VALUE</code>.
    */
   public SampleModel createCompatibleSampleModel(int w, int h)
   {
@@ -125,28 +130,27 @@
     // 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;
-         }
+      for (int j = i + 1; j < bandOffsets.length; j++)
+        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;
+        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);
+    return new BandedSampleModel(dataType, w, h, w, bankIndices, newoffsets);
   }
 
 

Reply via email to