This fixes an issue with the PixelInterleavedSampleModel that I noticed while playing with OpenJDK's ImageIO and GNU Classpath. In createCompatibleSampleModel, we need to adjust the scanline stride for the new width, otherwise we only get garbage pixels, and we can optimize the band offsets a little.
2008-02-21 Roman Kennke <[EMAIL PROTECTED]> * java/awt/image/PixelInterleavedSampleModel.java (createCompatibleSampleModel): Adjust scanline stride for new width and optimize band offsets. /Roman -- Dipl.-Inform. (FH) Roman Kennke, Software Engineer, http://kennke.org aicas Allerton Interworks Computer Automated Systems GmbH Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany http://www.aicas.com * Tel: +49-721-663 968-0 USt-Id: DE216375633, Handelsregister HRB 109481, AG Karlsruhe Geschäftsführer: Dr. James J. Hunt
Index: java/awt/image/PixelInterleavedSampleModel.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/awt/image/PixelInterleavedSampleModel.java,v retrieving revision 1.3 diff -u -1 -0 -r1.3 PixelInterleavedSampleModel.java --- java/awt/image/PixelInterleavedSampleModel.java 2 Jul 2005 20:32:36 -0000 1.3 +++ java/awt/image/PixelInterleavedSampleModel.java 21 Feb 2008 10:45:19 -0000 @@ -62,23 +62,48 @@ /** * Creates a new <code>SampleModel</code> that is like this one, but * uses the specified width and height. * * @param width the number of pixels in the horizontal direction. * * @param height the number of pixels in the vertical direction. */ public SampleModel createCompatibleSampleModel(int width, int height) { + // Find minimum band offset. + int minBandoff = bandOffsets[0]; + int numBands = bandOffsets.length; + for (int i = 1; i < numBands; i++) + { + if (bandOffsets[i] < minBandoff) + { + minBandoff = bandOffsets[i]; + } + } + // Adjust band offsets so that minimum offset is at 0. + int[] bandOff; + if (minBandoff > 0) + { + bandOff = new int[numBands]; + for (int i = 0; i < numBands; i++) + { + bandOff[i] = bandOffsets[i] - minBandoff; + } + } + else + { + bandOff = bandOffsets; + } + // Adjust scanline stride for new width. return new PixelInterleavedSampleModel(dataType, width, height, - pixelStride, scanlineStride, - bandOffsets); + pixelStride, pixelStride * width, + bandOff); } /** * Creates a new <code>SampleModel</code> that is like this one, but * uses only a subset of its bands. * * @param bands an array whose elements indicate which bands shall * be part of the subset. For example, <code>[0, 2, 3]</code> would * create a SampleModel containing bands #0, #2 and #3.