📄 rasterretained.java
字号:
/* * $RCSfile: RasterRetained.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.9 $ * $Date: 2007/02/09 17:18:17 $ * $State: Exp $ */package javax.media.j3d;import javax.vecmath.*;import java.awt.Point;import java.awt.Dimension;import java.util.ArrayList;import java.awt.image.DataBuffer;import java.awt.image.DataBufferByte;/** * A Retained Raster. */class RasterRetained extends GeometryRetained { /** * Raster type */ int type = Raster.RASTER_COLOR; private int clipMode = Raster.CLIP_POSITION; private Point3f position = new Point3f(); private int xSrcOffset = 0; private int ySrcOffset = 0; private int width = 0; private int height = 0; private int xDstOffset = 0; private int yDstOffset = 0; ImageComponent2DRetained image = null; Texture2DRetained texture = null; DepthComponentRetained depthComponent = null; RasterRetained() { this.geoType = GEO_TYPE_RASTER; } /** * Set the Raster position * @param position new raster position */ final void setPosition(Point3f pos) { geomLock.getLock(); position.x = pos.x; position.y = pos.y; position.z = pos.z; geomLock.unLock(); sendChangedMessage(J3dThread.UPDATE_GEOMETRY, null, null); } /** * Retrieves the Raster's position * @param position the variable to receive the position vector */ final void getPosition(Point3f pos) { pos.x = position.x; pos.y = position.y; pos.z = position.z; } /** * Sets the type of this raster object to one of: RASTER_COLOR, * RASTER_DEPTH, or RASTER_COLOR_DEPTH. * @param type the new type of this raster */ final void setType(int type) { geomLock.getLock(); this.type = type; geomLock.unLock(); } /** * Retrieves the current type of this raster object, one of: RASTER_COLOR, * RASTER_DEPTH, or RASTER_COLOR_DEPTH. * @return type the type of this raster */ final int getType() { return type; } /** * Sets the clipping mode of this raster object. * @param clipMode the new clipping mode of this raster, * one of: CLIP_POSITION or CLIP_IMAGE. The default mode * is CLIP_POSITION. */ final void setClipMode(int clipMode) { geomLock.getLock(); this.clipMode = clipMode; geomLock.unLock(); computeBoundingBox(); if(source.isLive()) { //update the Shape3Ds that refer to this Raster int un = userLists.size(); ArrayList shapeList; Shape3DRetained ms, shape; int sn; for(int i = 0; i < un; i++) { shapeList = (ArrayList)userLists.get(i); sn = shapeList.size(); for(int j = 0; j < sn; j++) { ms = (Shape3DRetained)shapeList.get(j); shape = (Shape3DRetained)ms.sourceNode; shape.setBoundsAutoCompute(false); shape.setBounds(geoBounds); } } } } /** * Retrieves the current clipping mode of this raster object. * @return clipMode the clipping mode of this raster, * one of: CLIP_POSITION or CLIP_IMAGE. */ final int getClipMode() { return clipMode; } /** * Sets the offset within the source array of pixels at which * to start copying. * @param xSrcOffset the x offset within the source array of pixels * at which to start copying * @param ySrcOffset the y offset within the source array of pixels * at which to start copying */ final void setSrcOffset(int xSrcOffset, int ySrcOffset) { geomLock.getLock(); this.xSrcOffset = xSrcOffset; this.ySrcOffset = ySrcOffset; geomLock.unLock(); } /** * Retrieves the current source pixel offset. * @param srcOffset the object that will receive the source offset */ final void getSrcOffset(Point srcOffset) { srcOffset.setLocation(xSrcOffset, ySrcOffset); } /** * Sets the number of pixels to be copied from the pixel array. * @param width the number of columns in the array of pixels to copy * @param height the number of rows in the array of pixels to copy */ final void setSize(int width, int height) { geomLock.getLock(); this.width = width; this.height = height; geomLock.unLock(); } /** * Gets the size of the array of pixels to be copied. * @param size the new size */ final void getSize(Dimension size) { size.setSize(width, height); } /** * Sets the destination pixel offset of the upper-left * corner of the rendered image relative to the transformed position. * @param xDstOffset the x coordinate of the new offset * @param yDstOffset the y coordinate of the new offset */ final void setDstOffset(int xDstOffset, int yDstOffset) { geomLock.getLock(); this.xDstOffset = xDstOffset; this.yDstOffset = yDstOffset; geomLock.unLock(); } /** * Retrieves the current destination pixel offset. * @param dstOffset the object that will receive the destination offset */ final void getDstOffset(Point dstOffset) { dstOffset.setLocation(xDstOffset, yDstOffset); } /** * Initializes the raster image to the specified image. * @param image new ImageCompoent2D object used as the raster image */ final void initImage(ImageComponent2D img) { int texFormat; if(img == null) { image = null; texture = null; return; } image = (ImageComponent2DRetained) img.retained; image.setEnforceNonPowerOfTwoSupport(true); switch(image.getNumberOfComponents()) { case 1: texFormat = Texture.INTENSITY; break; case 2: texFormat = Texture.LUMINANCE_ALPHA; break; case 3: texFormat = Texture.RGB; break; case 4: texFormat = Texture.RGBA; break; default: assert false; return; } Texture2D tex2D = new Texture2D(Texture.BASE_LEVEL, texFormat, img.getWidth(), img.getHeight()); texture = (Texture2DRetained) tex2D.retained; texture.setUseAsRaster(true); // Fix to issue 372 : ImageComponent.set(BufferedImage) ignored when used by Raster image.addUser(texture); texture.initImage(0,img); } /** * Sets the pixel array used to copy pixels to/from a Canvas3D. * This is used when the type is RASTER_COLOR or RASTER_COLOR_DEPTH. * @param image the ImageComponent2D object containing the * color data */ final void setImage(ImageComponent2D img) { if((img != null) && (img.getImageClass() == ImageComponent.ImageClass.NIO_IMAGE_BUFFER)) { throw new IllegalArgumentException(J3dI18N.getString("Background14")); } TextureRetained oldTex = this.texture; if (source.isLive()) { if (this.texture != null) { this.texture.clearLive(refCount); } } // Issue 370: only hold the geomLock while calling initImage // (cannot hold it while sending a message). geomLock.getLock(); initImage(img); geomLock.unLock(); if (source.isLive()) { if (texture != null) { texture.setLive(inBackgroundGroup, refCount); } sendChangedMessage((J3dThread.UPDATE_RENDER|J3dThread.UPDATE_RENDERING_ATTRIBUTES), oldTex, this.texture); } } /** * Retrieves the current pixel array object. * @return image the ImageComponent2D object containing the * color data */ final ImageComponent2D getImage() { return (image == null ? null : (ImageComponent2D)image.source); } /** * Sets the depth image used to copy pixels to/from a Canvas3D. * This is used when the type is RASTER_DEPTH or RASTER_COLOR_DEPTH. * @param depthImage the DepthComponent object containing the * depth (z-buffer) data */ final void setDepthComponent(DepthComponent depthComponent) { geomLock.getLock(); if (this.source.isLive()) { if (this.depthComponent != null) { this.depthComponent.clearLive(refCount); } if (depthComponent != null) { ((DepthComponentRetained)depthComponent.retained).setLive(inBackgroundGroup, refCount); } } if (depthComponent == null) { this.depthComponent = null; } else { this.depthComponent = (DepthComponentRetained)depthComponent.retained; } geomLock.unLock(); } /** * Retrieves the current depth image object. * @return depthImage DepthComponent containing the * depth (z-buffer) data */ final DepthComponent getDepthComponent() { return (depthComponent == null ? null : (DepthComponent)depthComponent.source); } void setLive(boolean inBackgroundGroup, int refCount) { super.doSetLive(inBackgroundGroup, refCount); if (texture != null) { texture.setLive(inBackgroundGroup, refCount); } if (depthComponent != null) { depthComponent.setLive(inBackgroundGroup, refCount); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -