/** * Copies pixels from Raster srcRaster to this WritableRaster. For each (x, y) address in * srcRaster, the corresponding pixel is copied to address (x+dx, y+dy) in this WritableRaster, * unless (x+dx, y+dy) falls outside the bounds of this raster. srcRaster must have the same * number of bands as this WritableRaster. The copy is a simple copy of source samples to the * corresponding destination samples. For details, see {@link WritableRaster#setRect(Raster)}. * * @param dx The X translation factor from src space to dst space of the copy. * @param dy The Y translation factor from src space to dst space of the copy. * @param srcRaster The Raster from which to copy pixels. */ public void setRect(int dx, int dy, Raster srcRaster) { // Check if we can use fast code if (!(srcRaster instanceof BytePackedRaster) || ((BytePackedRaster) srcRaster).pixelBitStride != pixelBitStride) { super.setRect(dx, dy, srcRaster); return; } int width = srcRaster.getWidth(); int height = srcRaster.getHeight(); int srcOffX = srcRaster.getMinX(); int srcOffY = srcRaster.getMinY(); int dstOffX = dx + srcOffX; int dstOffY = dy + srcOffY; // Clip to this raster if (dstOffX < this.minX) { int skipX = this.minX - dstOffX; width -= skipX; srcOffX += skipX; dstOffX = this.minX; } if (dstOffY < this.minY) { int skipY = this.minY - dstOffY; height -= skipY; srcOffY += skipY; dstOffY = this.minY; } if (dstOffX + width > this.maxX) { width = this.maxX - dstOffX; } if (dstOffY + height > this.maxY) { height = this.maxY - dstOffY; } setDataElements( dstOffX, dstOffY, srcOffX, srcOffY, width, height, (BytePackedRaster) srcRaster); }