📄 imagecomponentretained.java
字号:
throw new IllegalArgumentException(J3dI18N.getString("ImageComponentRetained2")); // If the format is 8bit per component, we may send it down // to OpenGL directly if its by ref case switch (format) { case ImageComponent.FORMAT_RGB:// same as ImageComponent.FORMAT_RGB8 case ImageComponent.FORMAT_RGB4: // Need to be Deprecated case ImageComponent.FORMAT_RGB5: // Need to be Deprecated case ImageComponent.FORMAT_R3_G3_B2: // Need to be Deprecated numberOfComponents = 3; break; case ImageComponent.FORMAT_RGBA:// same as ImageComponent.FORMAT_RGBA8 case ImageComponent.FORMAT_RGB5_A1: // Need to be Deprecated case ImageComponent.FORMAT_RGBA4: // Need to be Deprecated numberOfComponents = 4; break; case ImageComponent.FORMAT_LUM4_ALPHA4: // Need to be Deprecated case ImageComponent.FORMAT_LUM8_ALPHA8: numberOfComponents = 2; break; case ImageComponent.FORMAT_CHANNEL8: numberOfComponents = 1; break; default: throw new IllegalArgumentException(J3dI18N.getString("ImageComponentRetained3")); } this.setFormat(format); this.width = width; this.height = height; this.depth = depth; refImage = new Object[depth]; } int evaluateImageType(RenderedImage ri) { int imageType = BufferedImage.TYPE_CUSTOM; if (ri instanceof BufferedImage) { imageType = ((BufferedImage)ri).getType(); if(imageType != BufferedImage.TYPE_CUSTOM) { return imageType; } } else { // Fix to Issue 412. Force copy for RenderedImage of type not equal to BufferedImage. return imageType; } // System.err.println("This is a RenderedImage or BufferedImage with TYPE_CUSTOM. It imageType classification may not be correct."); ColorModel cm = ri.getColorModel(); ColorSpace cs = cm.getColorSpace(); SampleModel sm = ri.getSampleModel(); int csType = cs.getType(); boolean isAlphaPre = cm.isAlphaPremultiplied(); if (csType == ColorSpace.TYPE_GRAY && cm instanceof ComponentColorModel) { if (sm.getDataType() == DataBuffer.TYPE_BYTE) { imageType = BufferedImage.TYPE_BYTE_GRAY; } else if (sm.getDataType() == DataBuffer.TYPE_USHORT) { imageType = BufferedImage.TYPE_USHORT_GRAY; } } // RGB , only interested in BYTE ABGR and BGR for now // all others will be copied to a buffered image else if(csType == ColorSpace.TYPE_RGB) { int comparedBit = 0; int smDataType = sm.getDataType(); if(smDataType == DataBuffer.TYPE_BYTE) { comparedBit = 8; } else if(smDataType == DataBuffer.TYPE_INT) { comparedBit = 32; } if(comparedBit != 0) { int numBands = sm.getNumBands(); if (cm instanceof ComponentColorModel && sm instanceof PixelInterleavedSampleModel) { PixelInterleavedSampleModel csm = (PixelInterleavedSampleModel) sm; int[] offs = csm.getBandOffsets(); ComponentColorModel ccm = (ComponentColorModel)cm; int[] nBits = ccm.getComponentSize(); boolean isNBit = true; for (int i=0; i < numBands; i++) { if (nBits[i] != comparedBit) { isNBit = false; break; } } // Handle TYPE_BYTE if( comparedBit == 8) { if (isNBit && offs[0] == numBands-1 && offs[1] == numBands-2 && offs[2] == numBands-3) { if (numBands == 3) { imageType = BufferedImage.TYPE_3BYTE_BGR; } else if (offs[3] == 0) { imageType = (isAlphaPre ? BufferedImage.TYPE_4BYTE_ABGR_PRE : BufferedImage.TYPE_4BYTE_ABGR); } } } //Handle TYPE_INT else { if (isNBit) { if (numBands == 3) { if(offs[0] == numBands-1 && offs[1] == numBands-2 && offs[2] == numBands-3) { imageType = BufferedImage.TYPE_INT_BGR; } else if(offs[0] == 0 && offs[1] == 1 && offs[2] == 2) { imageType = BufferedImage.TYPE_INT_RGB; } } else if(offs[0] == 3 && offs[1] == 0 && offs[2] == 1 && offs[3] == 2) { imageType = (isAlphaPre ? BufferedImage.TYPE_INT_ARGB_PRE : BufferedImage.TYPE_INT_ARGB); } } } } } } return imageType; } // Assume ri's imageType is BufferedImage.TYPE_CUSTOM boolean is3ByteRGB(RenderedImage ri) { boolean value = false; int i; ColorModel cm = ri.getColorModel(); ColorSpace cs = cm.getColorSpace(); SampleModel sm = ri.getSampleModel(); boolean isAlphaPre = cm.isAlphaPremultiplied(); int csType = cs.getType(); if ( csType == ColorSpace.TYPE_RGB) { int numBands = sm.getNumBands(); if ((numBands == 3) && (sm.getDataType() == DataBuffer.TYPE_BYTE)) { if (cm instanceof ComponentColorModel && sm instanceof PixelInterleavedSampleModel) { PixelInterleavedSampleModel csm = (PixelInterleavedSampleModel) sm; int[] offs = csm.getBandOffsets(); ComponentColorModel ccm = (ComponentColorModel)cm; int[] nBits = ccm.getComponentSize(); boolean is8Bit = true; for (i=0; i < numBands; i++) { if (nBits[i] != 8) { is8Bit = false; break; } } if (is8Bit && offs[0] == 0 && offs[1] == 1 && offs[2] == 2) { value = true; } } } } return value; } // Assume ri's imageType is BufferedImage.TYPE_CUSTOM boolean is4ByteRGBA(RenderedImage ri) { boolean value = false; int i; ColorModel cm = ri.getColorModel(); ColorSpace cs = cm.getColorSpace(); SampleModel sm = ri.getSampleModel(); boolean isAlphaPre = cm.isAlphaPremultiplied(); int csType = cs.getType(); if ( csType == ColorSpace.TYPE_RGB) { int numBands = sm.getNumBands(); if ((numBands == 4) && (sm.getDataType() == DataBuffer.TYPE_BYTE)) { if (cm instanceof ComponentColorModel && sm instanceof PixelInterleavedSampleModel) { PixelInterleavedSampleModel csm = (PixelInterleavedSampleModel) sm; int[] offs = csm.getBandOffsets(); ComponentColorModel ccm = (ComponentColorModel)cm; int[] nBits = ccm.getComponentSize(); boolean is8Bit = true; for (i=0; i < numBands; i++) { if (nBits[i] != 8) { is8Bit = false; break; } } if (is8Bit && offs[0] == 0 && offs[1] == 1 && offs[2] == 2 && offs[3] == 3 && !isAlphaPre) { value = true; } } } } return value; } // Note: This method for RenderedImage, can't be used by NioImageBuffer. /* Check if sub-image type matches image type */ boolean isSubImageTypeEqual(RenderedImage ri) { int subImageType = evaluateImageType(ri); // This test is likely too loose, but the specification isn't clear either. // Assuming TYPE_CUSTOM of sub-image == the TYPE_CUSTOM of existing image. if(imageType == subImageType) { return true; } else { return false; } } // This method only support caller of offScreenBuffer and readRaster. void createBlankImageData() { assert (imageData == null); switch(numberOfComponents) { case 4: imageType = BufferedImage.TYPE_INT_ARGB; imageFormatType = ImageFormatType.TYPE_INT_ARGB; unitsPerPixel = 1; break; case 3: imageType = BufferedImage.TYPE_INT_RGB; imageFormatType = ImageFormatType.TYPE_INT_RGB; unitsPerPixel = 1; break; default: // Only valid for 3 and 4 channel case. ( Read back from framebuffer ) assert false; } imageTypeIsSupported = true; imageData = createRenderedImageDataObject(null); } // This method will set imageType, imageFormatType, and unitsPerPixel // as it evaluates NioImageBuffer is supported. It will also reset // abgrSupported. boolean isImageTypeSupported(NioImageBuffer nioImgBuf) { boolean isSupported = true; NioImageBuffer.ImageType nioImageType = nioImgBuf.getImageType(); switch(numberOfComponents) { case 4: switch(nioImageType) { case 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; break; case TYPE_4BYTE_RGBA: imageFormatType = ImageFormatType.TYPE_BYTE_RGBA; unitsPerPixel = 4; break; case TYPE_INT_ARGB: imageFormatType = ImageFormatType.TYPE_INT_ARGB; unitsPerPixel = 1; break; default: throw new IllegalArgumentException(J3dI18N.getString("ImageComponent5")); } break; case 3: switch(nioImageType) { case TYPE_3BYTE_BGR: imageFormatType = ImageFormatType.TYPE_BYTE_BGR; unitsPerPixel = 3; break; case TYPE_3BYTE_RGB: imageFormatType = ImageFormatType.TYPE_BYTE_RGB; unitsPerPixel = 3; break; case TYPE_INT_BGR: imageFormatType = ImageFormatType.TYPE_INT_BGR; unitsPerPixel = 1; break; case TYPE_INT_RGB: imageFormatType = ImageFormatType.TYPE_INT_RGB; unitsPerPixel = 1; break; default: throw new IllegalArgumentException(J3dI18N.getString("ImageComponent5")); } break; case 2: throw new IllegalArgumentException(J3dI18N.getString("ImageComponent5")); case 1: if(nioImageType == NioImageBuffer.ImageType.TYPE_BYTE_GRAY) { imageFormatType = ImageFormatType.TYPE_BYTE_GRAY; unitsPerPixel = 1; } else { throw new IllegalArgumentException(J3dI18N.getString("ImageComponent5")); } break; default: throw new AssertionError(); } return isSupported; } // This method will set imageType, imageFormatType, and unitsPerPixel // as it evaluates RenderedImage is supported. It will also reset // abgrSupported. boolean isImageTypeSupported(RenderedImage ri) { boolean isSupported = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -