📄 imagecomponentretained.java
字号:
/* * $RCSfile: ImageComponentRetained.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.18 $ * $Date: 2007/04/20 23:04:02 $ * $State: Exp $ */package javax.media.j3d;import java.nio.Buffer;import java.util.*;import java.awt.image.*;import java.awt.color.ColorSpace;import java.awt.geom.AffineTransform;import java.awt.image.AffineTransformOp;import java.awt.image.RenderedImage;import java.nio.ByteBuffer;import java.nio.ByteOrder;import java.nio.IntBuffer;import java.util.logging.Level;/** * Abstract class that is used to define 2D or 3D ImageComponent classes * used in a Java 3D scene graph. * This is used for texture images, background images and raster components * of Shape3D nodes. */abstract class ImageComponentRetained extends NodeComponentRetained { // change flag static final int IMAGE_CHANGED = 0x01; static final int SUBIMAGE_CHANGED = 0x02; static final int TYPE_BYTE_BGR = 0x1; static final int TYPE_BYTE_RGB = 0x2; static final int TYPE_BYTE_ABGR = 0x4; static final int TYPE_BYTE_RGBA = 0x8; static final int TYPE_BYTE_LA = 0x10; static final int TYPE_BYTE_GRAY = 0x20; static final int TYPE_USHORT_GRAY = 0x40; static final int TYPE_INT_BGR = 0x80; static final int TYPE_INT_RGB = 0x100; static final int TYPE_INT_ARGB = 0x200; static final int IMAGE_SIZE_512X512 = 262144; enum ImageFormatType { TYPE_UNKNOWN, TYPE_BYTE_BGR, TYPE_BYTE_RGB, TYPE_BYTE_ABGR, TYPE_BYTE_RGBA, TYPE_BYTE_LA, TYPE_BYTE_GRAY, TYPE_USHORT_GRAY, TYPE_INT_BGR, TYPE_INT_RGB, TYPE_INT_ARGB } static final int IMAGE_DATA_TYPE_BYTE_ARRAY = 0x1000; static final int IMAGE_DATA_TYPE_INT_ARRAY = 0x2000; static final int IMAGE_DATA_TYPE_BYTE_BUFFER = 0x4000; static final int IMAGE_DATA_TYPE_INT_BUFFER = 0x8000; enum ImageDataType { TYPE_NULL, TYPE_BYTE_ARRAY, TYPE_INT_ARRAY, TYPE_BYTE_BUFFER, TYPE_INT_BUFFER } private int apiFormat; // The format set by user. int width; // Width of PixelArray int height; // Height of PixelArray int depth; // Depth of PixelArray boolean byReference = false; // Is the imageComponent by reference boolean yUp = false; boolean imageTypeIsSupported; boolean abgrSupported = true; boolean npotSupported = true; private int unitsPerPixel; private int numberOfComponents; // Note : This is unuse for NioImageBuffer. // The image type of the input image. Using the constant in BufferedImage private int imageType; private ImageFormatType imageFormatType = ImageFormatType.TYPE_UNKNOWN; ImageData imageData; private ImageComponent.ImageClass imageClass = ImageComponent.ImageClass.BUFFERED_IMAGE; // To support Non power of 2 (NPOT) image // if enforceNonPowerOfTwoSupport is true (for examples Raster and Background) // and imageData is a non power of 2 image // and graphics driver doesn't support NPOT extension. private ImageData imageDataPowerOfTwo; private AffineTransformOp powerOfTwoATOp; // The following flag means that if the image is non-power-of-two and the // card doesn't support NPOT texture, we will scale the image to a power // of two. private boolean enforceNonPowerOfTwoSupport = false; private boolean usedByOffScreenCanvas = false; // This will store the referenced Images for reference case. // private RenderedImage refImage[] = null; private Object refImage[] = null; // Issue 366: Lock for evaluateExtensions Object evaluateExtLock = new Object(); // Lock used in the "by ref case" GeometryLock geomLock = new GeometryLock(); int tilew = 0; int tileh = 0; int numXTiles = 0; int numYTiles = 0; // lists of Node Components that are referencing this ImageComponent // object. This list is used to notify the referencing node components // of any changes of this ImageComponent. ArrayList userList = new ArrayList(); /** * Retrieves the width of this image component object. * @return the width of this image component object */ int getWidth() { return width; } /** * Retrieves the height of this image component object. * @return the height of this image component object */ int getHeight() { return height; } /** * Retrieves the apiFormat of this image component object. * * @return the apiFormat of this image component object */ int getFormat() { return apiFormat; } void setFormat(int format) { this.apiFormat = format; } void setByReference(boolean byReference) { this.byReference = byReference; } boolean isByReference() { return byReference; } void setYUp( boolean yUp) { this.yUp = yUp; } boolean isYUp() { return yUp; } int getUnitsPerPixel() { return unitsPerPixel; } void setUnitsPerPixel(int ipp) { unitsPerPixel = ipp; } ImageComponent.ImageClass getImageClass() { return imageClass; } void setImageClass(RenderedImage image) { if(image instanceof BufferedImage) { imageClass = ImageComponent.ImageClass.BUFFERED_IMAGE; } else { imageClass = ImageComponent.ImageClass.RENDERED_IMAGE; } } void setImageClass(NioImageBuffer image) { imageClass = ImageComponent.ImageClass.NIO_IMAGE_BUFFER; } void setEnforceNonPowerOfTwoSupport(boolean npot) { this.enforceNonPowerOfTwoSupport = npot; } void setUsedByOffScreen(boolean used) { usedByOffScreenCanvas = used; } boolean getUsedByOffScreen() { return usedByOffScreenCanvas; } int getNumberOfComponents() { return numberOfComponents; } void setNumberOfComponents(int numberOfComponents) { this.numberOfComponents = numberOfComponents; } int getImageDataTypeIntValue() { int idtValue = -1; switch(imageData.imageDataType) { case TYPE_BYTE_ARRAY: idtValue = IMAGE_DATA_TYPE_BYTE_ARRAY; break; case TYPE_INT_ARRAY: idtValue = IMAGE_DATA_TYPE_INT_ARRAY; break; case TYPE_BYTE_BUFFER: idtValue = IMAGE_DATA_TYPE_BYTE_BUFFER; break; case TYPE_INT_BUFFER: idtValue = IMAGE_DATA_TYPE_INT_BUFFER; break; default : assert false; } return idtValue; } int getImageFormatTypeIntValue(boolean powerOfTwoData) { int iftValue = -1; switch(imageFormatType) { case TYPE_BYTE_BGR: iftValue = TYPE_BYTE_BGR; break; case TYPE_BYTE_RGB: iftValue = TYPE_BYTE_RGB; break; case TYPE_BYTE_ABGR: iftValue = TYPE_BYTE_ABGR; break; case TYPE_BYTE_RGBA: if((imageDataPowerOfTwo != null) && (powerOfTwoData)) { iftValue = TYPE_BYTE_ABGR; } else { iftValue = TYPE_BYTE_RGBA; } break; case TYPE_BYTE_LA: iftValue = TYPE_BYTE_LA; break; case TYPE_BYTE_GRAY: iftValue = TYPE_BYTE_GRAY; break; case TYPE_USHORT_GRAY: iftValue = TYPE_USHORT_GRAY; break; case TYPE_INT_BGR: iftValue = TYPE_INT_BGR; break; case TYPE_INT_RGB: iftValue = TYPE_INT_RGB; break; case TYPE_INT_ARGB: iftValue = TYPE_INT_ARGB; break; default: throw new AssertionError(); } return iftValue; } // Note: This method for RenderedImage, can't be used by NioImageBuffer. int getImageType() { return imageType; } void setImageFormatType(ImageFormatType ift) { this.imageFormatType = ift; } ImageFormatType getImageFormatType() { return this.imageFormatType; } void setRefImage(Object image, int index) { this.refImage[index] = image; } Object getRefImage(int index) { return this.refImage[index]; } ImageData getImageData(boolean npotSupportNeeded) { if(npotSupportNeeded) { assert enforceNonPowerOfTwoSupport; if(imageDataPowerOfTwo != null) { return imageDataPowerOfTwo; } } return imageData; } boolean useBilinearFilter() { if(imageDataPowerOfTwo != null) { return true; } return false; } boolean isImageTypeSupported() { return imageTypeIsSupported; } /** * Check if ImageComponent parameters have valid values. */ void processParams(int format, int width, int height, int depth) { if (width < 1) throw new IllegalArgumentException(J3dI18N.getString("ImageComponentRetained0")); if (height < 1) throw new IllegalArgumentException(J3dI18N.getString("ImageComponentRetained1")); if (depth < 1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -