📄 imagecomponentretained.java
字号:
srcOffset += tileLineUnits; dstOffset += dstLineUnits; } break; default: assert false; } // advance the destination buffer offset dstBegin += curw * unitsPerPixel; // move to the next tile in x direction x = 0; // determine the width of copy region of the next tile tmpw -= curw; if (tmpw < tilew) { curw = tmpw; } else { curw = tilew; } } // we are done copying an array of tiles in the x direction // advance the tileStart offset tileStart += dataWidth * unitsPerPixel * curh * sign; // move to the next set of tiles in y direction y = 0; // determine the height of copy region for the next set // of tiles tmph -= curh; if (tmph < tileh) { curh = tmph; } else { curh = tileh; } } if((imageData == data) && (imageDataPowerOfTwo != null)) { updateImageDataPowerOfTwo(depthIndex); } } // Quick line by line copy void copyImageLineByLine(BufferedImage bi, int srcX, int srcY, int dstX, int dstY, int depthIndex, int copyWidth, int copyHeight, ImageData data) { assert (data != null); int h; int rowBegin, // src begin row index srcBegin, // src begin offset dstBegin; // dst begin offset int dataWidth = data.dataWidth; int dataHeight = data.dataHeight; int dstUnitsPerRow = dataWidth * unitsPerPixel; // bytes per row in dst image rowBegin = srcY; if (yUp) { dstBegin = (depthIndex * dataWidth * dataHeight + dstY * dataWidth + dstX) * unitsPerPixel; } else { dstBegin = (depthIndex * dataWidth * dataHeight + (dataHeight - dstY - 1) * dataWidth + dstX) * unitsPerPixel; dstUnitsPerRow = - 1 * dstUnitsPerRow; } int copyUnits = copyWidth * unitsPerPixel; int srcWidth = bi.getWidth(); int srcUnitsPerRow = srcWidth * unitsPerPixel; srcBegin = (rowBegin * srcWidth + srcX) * unitsPerPixel; switch(data.getType()) { case TYPE_BYTE_ARRAY: byte[] srcByteBuffer = ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); byte[] dstByteBuffer = data.getAsByteArray(); for (h = 0; h < copyHeight; h++) { System.arraycopy(srcByteBuffer, srcBegin, dstByteBuffer, dstBegin, copyUnits); dstBegin += dstUnitsPerRow; srcBegin += srcUnitsPerRow; } break; case TYPE_INT_ARRAY: int[] srcIntBuffer = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); int[] dstIntBuffer = data.getAsIntArray(); for (h = 0; h < copyHeight; h++) { System.arraycopy(srcIntBuffer, srcBegin, dstIntBuffer, dstBegin, copyUnits); dstBegin += dstUnitsPerRow; srcBegin += srcUnitsPerRow; } break; default: assert false; } if((imageData == data) && (imageDataPowerOfTwo != null)) { updateImageDataPowerOfTwo(depthIndex); } } // Quick block copy for yUp image void copyImageByBlock(BufferedImage bi, int depthIndex, ImageData data) { assert ((data != null) && yUp); int dataWidth = data.dataWidth; int dataHeight = data.dataHeight; int dstBegin; // dst begin offset dstBegin = depthIndex * dataWidth * dataHeight * unitsPerPixel; switch(imageData.getType()) { case TYPE_BYTE_ARRAY: byte[] srcByteBuffer = ((DataBufferByte)bi.getRaster().getDataBuffer()).getData(); byte[] dstByteBuffer = data.getAsByteArray(); System.arraycopy(srcByteBuffer, 0, dstByteBuffer, dstBegin, (dataWidth * dataHeight * unitsPerPixel)); break; case TYPE_INT_ARRAY: int[] srcIntBuffer = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); int[] dstIntBuffer = data.getAsIntArray(); System.arraycopy(srcIntBuffer, 0, dstIntBuffer, dstBegin, (dataWidth * dataHeight * unitsPerPixel)); break; default: assert false; } if((imageData == data) && (imageDataPowerOfTwo != null)) { updateImageDataPowerOfTwo(depthIndex); } } /** * copy complete region of a RenderedImage to ImageComponent's imageData object. */ 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); * * */ } } /* * copy the complete unsupported NioImageBuffer into a supported BYTE_BUFFER format */ void copyUnsupportedNioImageToImageData(NioImageBuffer nioImage, int srcX, int srcY, int dstX, int dstY, int copyWidth, int copyHeight, ImageData iData) { if (MasterControl.isDevLoggable(Level.INFO)) { MasterControl.getDevLogger().info("ImageComponent - Copying Unsupported NioImage, use a different image type"); } assert (iData.getType() == ImageDataType.TYPE_BYTE_BUFFER); assert (getImageFormatType() == ImageFormatType.TYPE_BYTE_RGBA); int length = copyWidth * copyHeight; ByteBuffer srcBuffer = (ByteBuffer) nioImage.getDataBuffer(); srcBuffer.rewind(); ByteBuffer dstBuffer = iData.getAsByteBuffer(); dstBuffer.rewind(); // Do copy and swap. for(int i = 0; i < length; i +=4) { dstBuffer.put(i, srcBuffer.get(i+3)); dstBuffer.put(i+1, srcBuffer.get(i+2)); dstBuffer.put(i+2, srcBuffer.get(i+1)); dstBuffer.put(i+3, srcBuffer.get(i)); } } /* * copy the complete unsupported image into a supported BYTE_ARRAY format */ void copyUnsupportedImageToImageData(RenderedImage ri, int depthIndex, ImageData data) { assert (data.getType() == ImageDataType.TYPE_BYTE_ARRAY); if (MasterControl.isDevLoggable(Level.INFO)) { MasterControl.getDevLogger().info("ImageComponent - Copying Unsupported Image, use a different image type"); } if (ri instanceof BufferedImage) { copyUnsupportedImageToImageData((BufferedImage)ri, 0, 0, 0, 0, depthIndex, data.dataWidth, data.dataHeight, data); } else { copyUnsupportedImageToImageData(ri, ri.getMinX(), ri.getMinY(), 0, 0, depthIndex, data.dataWidth, data.dataHeight, data); } } void copyUnsupportedImageToImageData(BufferedImage bi, int srcX, int srcY, int dstX, int dstY, int depthIndex, int copyWidth, int copyHeight, ImageData data) { int w, h, i, j; int rowBegin, // src begin row index srcBegin, // src begin offset dstBegin, // dst begin offset rowInc, // row increment // -1 --- ydown // 1 --- yup row; rowBegin = srcY; rowInc = 1; assert (data != null); int dataWidth = data.dataWidth; int dataHeight = data.dataHeight; int dstBytesPerRow = dataWidth * unitsPerPixel; // bytes per row in dst image if (yUp) { dstBegin = (depthIndex * dataWidth * dataHeight + dstY * dataWidth + dstX) * unitsPerPixel; } else { dstBegin = (depthIndex * dataWidth * dataHeight + (dataHeight - dstY - 1) * dataWidth + dstX) * unitsPerPixel; dstBytesPerRow = - 1 * dstBytesPerRow; } WritableRaster ras = bi.getRaster(); ColorModel cm = bi.getColorModel(); Object pixel = getDataElementBuffer(ras); byte[] dstBuffer = data.getAsByteArray(); switch(numberOfComponents) { case 4: { for (row = rowBegin, h = 0; h < copyHeight; h++, row += rowInc) { j = dstBegin; for (w = srcX; w < (copyWidth + srcX); w++) { ras.getDataElements(w, row, pixel); dstBuffer[j++] = (byte)cm.getRed(pixel); dstBuffer[j++] = (byte)cm.getGreen(pixel); dstBuffer[j++] = (byte)cm.getBlue(pixel); dstBuffer[j++] = (byte)cm.getAlpha(pixel); } dstBegin += dstBytesPerRow; } } break; case 3: { for (row = rowBegin, h = 0; h < copyHeight; h++, row += rowInc) { j = dstBegin; for (w = srcX; w < (copyWidth + srcX); w++) { ras.getDataElements(w, row, pixel); dstBuffer[j++] = (byte)cm.getRed(pixel); dstBuffer[j++] = (byte)cm.getGreen(pixel); dstBuffer[j++] = (byte)cm.getBlue(pixel); } dstBegin += dstBytesPerRow; } } break; case 2: { for (row = rowBegin, h = 0; h < copyHeight; h++, row += rowInc) { j = dstBegin; for (w = srcX; w < (copyWidth + srcX); w++) { ras.getDataElements(w, row, pixel); dstBuffer[j++] = (byte)cm.getRed(pixel); dstBuffer[j++] = (byte)cm.getAlpha(pixel); } dstBegin += dstBytesPerRow; } } break; case 1: { for (row = rowBegin, h = 0; h < copyHeight; h++, row += rowInc) { j = dstBegin; for (w = srcX; w < (copyWidth + srcX); w++) { ras.getDataElements(w, row, pixel); dstBuffer[j++] = (byte)cm.getRed(pixel); } dstBegin += dstBytesPerRow; } } break; default: assert false; } if((imageData == data) && (imageDataPowerOfTwo != null)) { updateImageDataPowerOfTwo(depthIndex); } } void copyUnsupportedImageToImageData(RenderedImage ri, int srcX, int srcY, int dstX, int dstY, int depthIndex, int copyWidth, int copyHeight, ImageData data) { int w, h, i, j, m, n; int dstBegin; Object pixel = null; java.awt.image.Raster ras; // dst image buffer int sign; // -1 for going down int dstLineBytes; // sign * lineBytes int tileStart; // destination buffer offset // at the next left most tile int offset; ColorModel cm = ri.getColorModel(); int xoff = ri.getTileGridXOffset(); // tile origin x offset int yoff = ri.getTileGridYOffset(); // tile origin y offset
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -