Hi, This patch fixes some problems when using java2d with subimages/subrasters (ie, the image scanline != image width, or the image's 0,0 origin does not correspond to the data buffer's 0 position).
Cheers, Francis 2006-11-24 Francis Kung <[EMAIL PROTECTED]> * gnu/java/awt/peer/gtk/BufferedImageGraphics.java (constructor): Check sample model when setting fastCM flag. (updateBufferedImage): Check scanline and sample model offsets before copying data directly into the image data buffer.
Index: gnu/java/awt/peer/gtk/BufferedImageGraphics.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java,v retrieving revision 1.18 diff -u -r1.18 BufferedImageGraphics.java --- gnu/java/awt/peer/gtk/BufferedImageGraphics.java 22 Nov 2006 16:46:16 -0000 1.18 +++ gnu/java/awt/peer/gtk/BufferedImageGraphics.java 24 Nov 2006 16:31:50 -0000 @@ -58,6 +58,7 @@ import java.awt.image.ImageProducer; import java.awt.image.Raster; import java.awt.image.RenderedImage; +import java.awt.image.SinglePixelPackedSampleModel; import java.util.WeakHashMap; /** @@ -110,7 +111,9 @@ imageHeight = bi.getHeight(); locked = false; - if(bi.getColorModel().equals(CairoSurface.cairoCM_opaque)) + if (!(image.getSampleModel() instanceof SinglePixelPackedSampleModel)) + hasFastCM = false; + else if(bi.getColorModel().equals(CairoSurface.cairoCM_opaque)) { hasFastCM = true; hasAlpha = false; @@ -219,18 +222,44 @@ if( y + height > imageHeight ) height = imageHeight - y; - // The setRGB method assumes (or should assume) that pixels are NOT - // alpha-premultiplied, but Cairo stores data with premultiplication - // (thus the pixels returned in getPixels are premultiplied). - // This is ignored for consistency, however, since in - // CairoGrahpics2D.drawImage we also use non-premultiplied data if(!hasFastCM) - image.setRGB(x, y, width, height, pixels, - x + y * imageWidth, imageWidth); + { + image.setRGB(x, y, width, height, pixels, + x + y * imageWidth, imageWidth); + // The setRGB method assumes (or should assume) that pixels are NOT + // alpha-premultiplied, but Cairo stores data with premultiplication + // (thus the pixels returned in getPixels are premultiplied). + // This is ignored for consistency, however, since in + // CairoGrahpics2D.drawImage we also use non-premultiplied data + + } else - System.arraycopy(pixels, y * imageWidth, - ((DataBufferInt)image.getRaster().getDataBuffer()). - getData(), y * imageWidth, height * imageWidth); + { + int[] db = ((DataBufferInt)image.getRaster().getDataBuffer()). + getData(); + + // This should not fail, as we check the image sample model when we + // set the hasFastCM flag + SinglePixelPackedSampleModel sm = (SinglePixelPackedSampleModel)image.getSampleModel() ; + + int minX = image.getRaster().getSampleModelTranslateX(); + int minY = image.getRaster().getSampleModelTranslateY(); + + if (sm.getScanlineStride() == imageWidth && minX == 0) + { + System.arraycopy(pixels, y * imageWidth, + db, y * imageWidth - minY, + height * imageWidth); + } + else + { + int scanline = sm.getScanlineStride(); + for (int i = y; i < height; i++) + System.arraycopy(pixels, i * imageWidth + x, db, + (i - minY) * scanline + x - minX, width); + + } + } } /**