void copySupportedImageToImageData(RenderedImage ri, int depthIndex, ImageData data) {  if (ri instanceof BufferedImage) { if(yUp) {   copyImageByBlock((BufferedImage)ri, depthIndex, data);
void copySupportedImageToImageData(RenderedImage ri, int srcX, int srcY, int dstX, int dstY, int depthIndex, int copyWidth, int copyHeight, ImageData data) {  assert (data != null);  ColorModel cm = ri.getColorModel();  int xoff = ri.getTileGridXOffset(); int yoff = ri.getTileGridYOffset(); int minTileX = ri.getMinTileX(); int minTileY = ri.getMinTileY(); tilew = ri.getTileWidth(); tileh = ri.getTileHeight();   float mt;  mt = (float)(srcX - xoff) / (float)tilew; if (mt < 0) { minTileX = (int)(mt - 1); } else { minTileX = (int)mt; }  mt = (float)(srcY - yoff) / (float)tileh; if (mt < 0) { minTileY = (int)(mt - 1); } else { minTileY = (int)mt; }    int startXTile = minTileX * tilew + xoff; int startYTile = minTileY * tileh + yoff;   int curw = (startXTile + tilew - srcX); int curh = (startYTile + tileh - srcY);    if (curw > copyWidth) { curw = copyWidth; }  if (curh > copyHeight) { curh = copyHeight; }   int startw = curw;   int tmpw = copyWidth; int tmph = copyHeight;    int x = srcX - startXTile; int y = srcY - startYTile;    numXTiles = (copyWidth + x) / tilew; numYTiles = (copyHeight + y) / tileh;  if (((float)(copyWidth + x ) % (float)tilew) > 0) { numXTiles += 1; }  if (((float)(copyHeight + y ) % (float)tileh) > 0) { numYTiles += 1; }  int offset; int w, h, i, j, m, n; int dstBegin; Object pixel = null; java.awt.image.Raster ras; int lineUnits; int sign; int dstLineUnits; int tileStart;   byte[] dstByteBuffer = null; int[] dstIntBuffer = null;  switch(data.getType()) { case TYPE_BYTE_ARRAY: dstByteBuffer = data.getAsByteArray(); break; case TYPE_INT_ARRAY: dstIntBuffer = data.getAsIntArray(); break; default: assert false; }  int dataWidth = data.dataWidth; int dataHeight = data.dataHeight;  lineUnits = dataWidth * unitsPerPixel; if (yUp) {  tileStart = (depthIndex * dataWidth * dataHeight + dstY * dataWidth + dstX) * unitsPerPixel; sign = 1; dstLineUnits = lineUnits; } else {  tileStart = (depthIndex * dataWidth * dataHeight + (dataHeight - dstY - 1) * dataWidth + dstX) * unitsPerPixel; sign = -1; dstLineUnits = -lineUnits; }     ras = ri.getTile(minTileX,minTileY); pixel = getDataElementBuffer(ras);  int srcOffset, dstOffset; int tileLineUnits = tilew * unitsPerPixel; int copyUnits;  for (n = minTileY; n < minTileY+numYTiles; n++) {  dstBegin = tileStart; tmpw = copyWidth; curw = startw;  x = srcX - startXTile;   for (m = minTileX; m < minTileX+numXTiles; m++) {   ras = ri.getTile(m,n);  srcOffset = (y * tilew + x) * unitsPerPixel; dstOffset = dstBegin;  copyUnits = curw * unitsPerPixel;     switch(data.getType()) { case TYPE_BYTE_ARRAY: byte[] srcByteBuffer = ((DataBufferByte)ras.getDataBuffer()).getData(); for (h = 0; h < curh; h++) { System.arraycopy(srcByteBuffer, srcOffset, dstByteBuffer, dstOffset, copyUnits); srcOffset += tileLineUnits; dstOffset += dstLineUnits; } break; case TYPE_INT_ARRAY: int[] srcIntBuffer = ((DataBufferInt)ras.getDataBuffer()).getData(); for (h = 0; h < curh; h++) { System.arraycopy(srcIntBuffer, srcOffset, dstIntBuffer, dstOffset, copyUnits); srcOffset += tileLineUnits; dstOffset += dstLineUnits; } break; default: assert false; }   dstBegin += curw * unitsPerPixel;   x = 0;    tmpw -= curw; if (tmpw < tilew) { curw = tmpw; } else { curw = tilew; } }    tileStart += dataWidth * unitsPerPixel * curh * sign;   y = 0;    tmph -= curh; if (tmph < tileh) { curh = tmph;
    void copySupportedImageToImageData(RenderedImage ri, int depthIndex, ImageData data) {                if (ri instanceof BufferedImage) {            if(yUp) {                /*  Use quick block copy when  ( format is OK, Yup is true, and byRef is false). */                // System.err.println("ImageComponentRetained.copySupportedImageToImageData() : (imageTypeSupported && !byReference && yUp) --- (2 BI)");                copyImageByBlock((BufferedImage)ri, depthIndex, data);            } else {                /*  Use quick inverse line by line copy when (format is OK and Yup is false). */                // System.err.println("ImageComponentRetained.copySupportedImageToImageData() : (imageTypeSupported && !yUp) --- (3 BI)");                copyImageLineByLine((BufferedImage)ri, 0, 0, 0, 0, depthIndex, data.dataWidth, data.dataHeight, data);            }        } else {            // System.err.println("ImageComponentRetained.copySupportedImageToImageData() : (imageTypeSupported && !byReference ) --- (2 RI)");            copySupportedImageToImageData(ri, ri.getMinX(), ri.getMinY(), 0, 0, depthIndex, data.dataWidth, data.dataHeight, data);                         /*              * An alternative approach.              *            // Create a buffered image from renderImage            ColorModel cm = ri.getColorModel();            WritableRaster wRaster = ri.copyData(null);            BufferedImage bi = new BufferedImage(cm,                                                 wRaster,                                                 cm.isAlphaPremultiplied()                                                 ,null);                          copySupportedImageToImageData((BufferedImage)ri, 0, 0, 0, 0, depthIndex, data.dataWidth, data.dataHeight, data);                            *              *              */        }    }