/** * Stores the Raster data at the specified location. * * @param dstX The absolute X coordinate of the destination pixel that will receive a copy of the * upper-left pixel of the inRaster * @param dstY The absolute Y coordinate of the destination pixel that will receive a copy of the * upper-left pixel of the inRaster * @param width The number of pixels to store horizontally * @param height The number of pixels to store vertically * @param inRaster Raster of data to place at x,y location. */ private void setDataElements(int dstX, int dstY, int width, int height, Raster inRaster) { // Assume bounds checking has been performed previously if (width <= 0 || height <= 0) { return; } // Write inRaster (minX, minY) to (dstX, dstY) int srcOffX = inRaster.getMinX(); int srcOffY = inRaster.getMinY(); int tdata[] = null; if (inRaster instanceof IntegerComponentRaster && (pixelStride == 1) && (numDataElements == 1)) { IntegerComponentRaster ict = (IntegerComponentRaster) inRaster; if (ict.getNumDataElements() != 1) { throw new ArrayIndexOutOfBoundsException("Number of bands" + " does not match"); } // Extract the raster parameters tdata = ict.getDataStorage(); int tss = ict.getScanlineStride(); int toff = ict.getDataOffset(0); int srcOffset = toff; int dstOffset = dataOffsets[0] + (dstY - minY) * scanlineStride + (dstX - minX); // Fastest case. We can copy scanlines if (ict.getPixelStride() == pixelStride) { width *= pixelStride; // Loop through all of the scanlines and copy the data for (int startY = 0; startY < height; startY++) { System.arraycopy(tdata, srcOffset, data, dstOffset, width); srcOffset += tss; dstOffset += scanlineStride; } markDirty(); return; } } Object odata = null; for (int startY = 0; startY < height; startY++) { odata = inRaster.getDataElements(srcOffX, srcOffY + startY, width, 1, odata); setDataElements(dstX, dstY + startY, width, 1, odata); } }