⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagecomponentretained.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        imageType = evaluateImageType(ri);                switch(numberOfComponents) {            case 4:                if(imageType == BufferedImage.TYPE_4BYTE_ABGR) {                                        // TODO : This approach will lead to a very slow path                    // for unsupported case.                    if(abgrSupported) {                        imageFormatType = ImageFormatType.TYPE_BYTE_ABGR;                    } else {                        // Unsupported format on HW, switch to slow copy.                        imageFormatType = ImageFormatType.TYPE_BYTE_RGBA;                        isSupported = false;                    }                    unitsPerPixel = 4;                } else if(imageType == BufferedImage.TYPE_INT_ARGB) {                    imageFormatType = ImageFormatType.TYPE_INT_ARGB;                    unitsPerPixel = 1;                } else if(is4ByteRGBA(ri)) {                    imageFormatType = ImageFormatType.TYPE_BYTE_RGBA;                    unitsPerPixel = 4;                } else {                    // System.err.println("Image format is unsupported --- Case 4");                    // Convert unsupported format to TYPE_BYTE_RGBA.                    imageFormatType = ImageFormatType.TYPE_BYTE_RGBA;                    isSupported = false;                    unitsPerPixel = 4;                }                break;                            case 3:                if(imageType == BufferedImage.TYPE_3BYTE_BGR) {                    imageFormatType = ImageFormatType.TYPE_BYTE_BGR;                    unitsPerPixel = 3;                } else if(imageType == BufferedImage.TYPE_INT_BGR) {                    imageFormatType = ImageFormatType.TYPE_INT_BGR;                    unitsPerPixel = 1;                } else if(imageType == BufferedImage.TYPE_INT_RGB) {                    imageFormatType = ImageFormatType.TYPE_INT_RGB;                    unitsPerPixel = 1;                } else if(is3ByteRGB(ri)) {                    imageFormatType = ImageFormatType.TYPE_BYTE_RGB;                    unitsPerPixel = 3;                } else {                    // System.err.println("Image format is unsupported --- Case 3");                    // Convert unsupported format to TYPE_BYTE_RGB.                    imageFormatType = ImageFormatType.TYPE_BYTE_RGB;                    isSupported = false;                    unitsPerPixel = 3;                }                break;                            case 2:                // System.err.println("Image format is unsupported --- Case 2");                // Convert unsupported format to TYPE_BYTE_LA.                imageFormatType = ImageFormatType.TYPE_BYTE_LA;                isSupported = false;                unitsPerPixel = 2;                break;                            case 1:                if(imageType == BufferedImage.TYPE_BYTE_GRAY) {                    imageFormatType = ImageFormatType.TYPE_BYTE_GRAY;                    unitsPerPixel = 1;                } else {                    // System.err.println("Image format is unsupported --- Case 1");                    // Convert unsupported format to TYPE_BYTE_GRAY.                    imageFormatType = ImageFormatType.TYPE_BYTE_GRAY;                    isSupported = false;                    unitsPerPixel = 1;                }                break;                            default:                throw new AssertionError();        }                return isSupported;    }        /*     * This method assume that the following members have been initialized :     * width, height, depth, imageFormatType, and unitsPerPixel.     */    ImageData createNioImageBufferDataObject(NioImageBuffer nioImageBuffer) {         switch(imageFormatType) {            case TYPE_BYTE_GRAY:            case TYPE_BYTE_LA:            case TYPE_BYTE_RGB:            case TYPE_BYTE_BGR:            case TYPE_BYTE_RGBA:            case TYPE_BYTE_ABGR:                if(nioImageBuffer != null) {                    return new ImageData(ImageDataType.TYPE_BYTE_BUFFER,                            width * height * depth * unitsPerPixel,                            width, height, nioImageBuffer);                } else {                    // This is needed only if abgr is unsupported.                    return new ImageData(ImageDataType.TYPE_BYTE_BUFFER,                            width * height * depth * unitsPerPixel,                            width, height);                }            case TYPE_INT_RGB:            case TYPE_INT_BGR:            case TYPE_INT_ARGB:                return new ImageData(ImageDataType.TYPE_INT_BUFFER,                        width * height * depth * unitsPerPixel,                        width, height, nioImageBuffer);            default:                throw new AssertionError();        }    }        /*     * This method assume that the following members have been initialized :     * depth, imageType, imageFormatType, and unitsPerPixel.     */    ImageData createRenderedImageDataObject(RenderedImage byRefImage, int dataWidth, int dataHeight) {        switch(imageFormatType) {            case TYPE_BYTE_GRAY:            case TYPE_BYTE_LA:            case TYPE_BYTE_RGB:            case TYPE_BYTE_BGR:            case TYPE_BYTE_RGBA:            case TYPE_BYTE_ABGR:                if(byRefImage != null) {                    return new ImageData(ImageDataType.TYPE_BYTE_ARRAY,                            dataWidth * dataHeight * depth * unitsPerPixel,                            dataWidth, dataHeight, byRefImage);                } else {                    return new ImageData(ImageDataType.TYPE_BYTE_ARRAY,                            dataWidth * dataHeight * depth * unitsPerPixel,                            dataWidth, dataHeight);                }            case TYPE_INT_RGB:            case TYPE_INT_BGR:            case TYPE_INT_ARGB:                if(byRefImage != null) {                    return new ImageData(ImageDataType.TYPE_INT_ARRAY,                            dataWidth * dataHeight * depth * unitsPerPixel,                            dataWidth, dataHeight, byRefImage);                } else {                    return new ImageData(ImageDataType.TYPE_INT_ARRAY,                            dataWidth * dataHeight * depth * unitsPerPixel,                            dataWidth, dataHeight);                }            default:                throw new AssertionError();        }    }        private void updateImageDataPowerOfTwo(int depthIndex) {        assert enforceNonPowerOfTwoSupport;        BufferedImage bufImage = imageData.createBufferedImage(depthIndex);        BufferedImage scaledImg = powerOfTwoATOp.filter(bufImage, null);        copySupportedImageToImageData(scaledImg, 0, imageDataPowerOfTwo);    }        /*     * This method assume that the following members have been initialized :     *  width, height, depth, imageType, imageFormatType, and bytesPerPixel.     */    ImageData createRenderedImageDataObject(RenderedImage byRefImage) {                return createRenderedImageDataObject(byRefImage, width, height);            }            /**     * Copy specified region of image data from RenderedImage to     * ImageComponent's imageData object     */    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();	// tile origin x offset        int yoff = ri.getTileGridYOffset();	// tile origin y offset        int minTileX = ri.getMinTileX();	// min tile x index        int minTileY = ri.getMinTileY();	// min tile y index        tilew = ri.getTileWidth();		// tile width in pixels        tileh = ri.getTileHeight();		// tile height in pixels                // determine the first tile of the image        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;        }                // determine the pixel offset of the upper-left corner of the        // first tile        int startXTile = minTileX * tilew + xoff;        int startYTile = minTileY * tileh + yoff;                // image dimension in the first tile        int curw = (startXTile + tilew - srcX);        int curh = (startYTile + tileh - srcY);                // check if the to-be-copied region is less than the tile image        // if so, update the to-be-copied dimension of this tile        if (curw > copyWidth) {            curw = copyWidth;        }                if (curh > copyHeight) {            curh = copyHeight;        }                // save the to-be-copied width of the left most tile        int startw = curw;                // temporary variable for dimension of the to-be-copied region        int tmpw = copyWidth;        int tmph = copyHeight;                // offset of the first pixel of the tile to be copied; offset is        // relative to the upper left corner of the title        int x = srcX - startXTile;        int y = srcY - startYTile;                // determine the number of tiles in each direction that the        // image spans        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;          // nbytes per line in dst image buffer        int sign;		// -1 for going down        int dstLineUnits;	// sign * lineUnits        int tileStart;		// destination buffer offset        // at the next left most tile                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) {            // destination buffer offset            tileStart = (depthIndex * dataWidth * dataHeight + dstY * dataWidth + dstX) * unitsPerPixel;            sign = 1;            dstLineUnits = lineUnits;        } else {            // destination buffer offset            tileStart = (depthIndex * dataWidth * dataHeight + (dataHeight - dstY - 1) * dataWidth + dstX) * unitsPerPixel;            sign = -1;            dstLineUnits = -lineUnits;        }        /*        System.err.println("tileStart= " + tileStart + " dstLineUnits= " + dstLineUnits);        System.err.println("startw= " + startw); */                // allocate memory for a pixel        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;	// destination buffer offset            tmpw = copyWidth;	        // reset the width to be copied            curw = startw;		// reset the width to be copied of            // the left most tile            x = srcX - startXTile;	// reset the starting x offset of            // the left most tile                        for (m = minTileX; m < minTileX+numXTiles; m++) {                                // retrieve the raster for the next tile                ras = ri.getTile(m,n);                                srcOffset = (y * tilew + x) * unitsPerPixel;                dstOffset = dstBegin;                                copyUnits = curw * unitsPerPixel;                                //System.err.println("curh = "+curh+" curw = "+curw);                //System.err.println("x = "+x+" y = "+y);                                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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -