diff options
author | Chien Yang <[email protected]> | 2007-03-16 17:59:20 +0000 |
---|---|---|
committer | Chien Yang <[email protected]> | 2007-03-16 17:59:20 +0000 |
commit | 48f2ad8638b490854eebcfa07ea59b811189efd9 (patch) | |
tree | 106550f5f085131a1282234fe2da2e0b79e76b86 /src/classes | |
parent | a6cd0ac1ac0e96d99c6216d1a3450c8e365ceda7 (diff) |
1) Fixed Issue 461 : ClassCastException thrown when using filters with NioImageBuffer
2) Minor clean up; removed unuse variables.
Note: This isn't a Complete fix to auto mipmap. It will be addressed in Issue 126 and 408.
git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@798 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src/classes')
4 files changed, 34 insertions, 301 deletions
diff --git a/src/classes/share/javax/media/j3d/ImageComponent2DRetained.java b/src/classes/share/javax/media/j3d/ImageComponent2DRetained.java index 5053098..c5b6a67 100644 --- a/src/classes/share/javax/media/j3d/ImageComponent2DRetained.java +++ b/src/classes/share/javax/media/j3d/ImageComponent2DRetained.java @@ -314,62 +314,6 @@ class ImageComponent2DRetained extends ImageComponentRetained { sendMessage(SUBIMAGE_CHANGED, info); } } - - ImageComponentRetained createNextLevelMipMapImage() { - - int xScale, yScale, newWidth, newHeight; - - if (width > 1) { - newWidth = width >> 1; - xScale = 2; - } else { - newWidth = 1; - xScale = 1; - } - if (height > 1) { - newHeight = height >> 1; - yScale = 2; - } else { - newHeight = 1; - yScale = 1; - } - - // XXXXX Fix to Issue 425 : NullPointerException in automatic mipmap generation - if (imageData == null) { - // This is a byRef, support format and is a RenderedImage case. - // See ImageComponent2DRetained.set(RenderedImage image) - RenderedImage ri = (RenderedImage) getRefImage(0); - - assert !(ri instanceof BufferedImage); - - // Create a buffered image from renderImage - ColorModel cm = ri.getColorModel(); - WritableRaster wRaster = ri.copyData(null); - ri = new BufferedImage(cm, - wRaster, - cm.isAlphaPremultiplied() - ,null); - - - // Create image data object with buffer for image. */ - imageData = createRenderedImageDataObject(null); - copySupportedImageToImageData(ri, 0, imageData); - - } - - assert imageData != null; - // XXXXX - - ImageComponent2DRetained newImage = new ImageComponent2DRetained(); - newImage.processParams(getFormat(), newWidth, newHeight, 1); - newImage.setImageFormatType(getImageFormatType()); - newImage.setUnitsPerPixel(getUnitsPerPixel()); - newImage.imageData = newImage.createRenderedImageDataObject(null); - - newImage.scaleImage(xScale, yScale, 0, this); - - return newImage; - } void clearLive(int refCount) { super.clearLive(refCount); diff --git a/src/classes/share/javax/media/j3d/ImageComponent3DRetained.java b/src/classes/share/javax/media/j3d/ImageComponent3DRetained.java index 0e32fb2..ed8c575 100644 --- a/src/classes/share/javax/media/j3d/ImageComponent3DRetained.java +++ b/src/classes/share/javax/media/j3d/ImageComponent3DRetained.java @@ -361,37 +361,4 @@ class ImageComponent3DRetained extends ImageComponentRetained { sendMessage(SUBIMAGE_CHANGED, info); } } - - ImageComponentRetained createNextLevelMipMapImage() { - - int xScale, yScale, newWidth, newHeight; - - if (width > 1) { - newWidth = width >> 1; - xScale = 2; - } else { - newWidth = 1; - xScale = 1; - } - if (height > 1) { - newHeight = height >> 1; - yScale = 2; - } else { - newHeight = 1; - yScale = 1; - } - - ImageComponent3DRetained newImage = new ImageComponent3DRetained(); - newImage.processParams(getFormat(), newWidth, newHeight, depth); - newImage.setImageFormatType(getImageFormatType()); - newImage.setUnitsPerPixel(getUnitsPerPixel()); - newImage.imageData = newImage.createRenderedImageDataObject(null); - - for (int i = 0; i < depth; i++) { - newImage.scaleImage(xScale, yScale, i, this); - } - - return newImage; - - } } diff --git a/src/classes/share/javax/media/j3d/ImageComponentRetained.java b/src/classes/share/javax/media/j3d/ImageComponentRetained.java index 8d0b056..80112ec 100644 --- a/src/classes/share/javax/media/j3d/ImageComponentRetained.java +++ b/src/classes/share/javax/media/j3d/ImageComponentRetained.java @@ -129,8 +129,6 @@ abstract class ImageComponentRetained extends NodeComponentRetained { // of any changes of this ImageComponent. ArrayList userList = new ArrayList(); - abstract ImageComponentRetained createNextLevelMipMapImage(); - /** * Retrieves the width of this image component object. * @return the width of this image component object @@ -2096,179 +2094,6 @@ abstract class ImageComponentRetained extends NodeComponentRetained { } - void scaleImage(int xScale, int yScale, int depthIndex, ImageComponentRetained origImage) { - - byte[] dstByteBuffer = null; - byte[] srcByteBuffer = null; - int[] dstIntBuffer = null; - int[] srcIntBuffer = null; - int dStart, sStart; - - switch(imageData.getType()) { - case TYPE_BYTE_ARRAY: - dstByteBuffer = imageData.getAsByteArray(); - srcByteBuffer = origImage.imageData.getAsByteArray(); - dStart = depthIndex * width * height * unitsPerPixel; - sStart = depthIndex * origImage.width * origImage.height * unitsPerPixel; - scaleImage(xScale, yScale, dStart, sStart, origImage, dstByteBuffer, srcByteBuffer); - break; - case TYPE_INT_ARRAY: - dstIntBuffer = imageData.getAsIntArray(); - srcIntBuffer = origImage.imageData.getAsIntArray(); - dStart = depthIndex * width * height * unitsPerPixel; - sStart = depthIndex * origImage.width * origImage.height * unitsPerPixel; - scaleImage(xScale, yScale, dStart, sStart, origImage, dstIntBuffer, srcIntBuffer); - break; - default: - assert false; - } - - } - - void scaleImage(int xScale, int yScale, int dStart, int sStart, ImageComponentRetained origImage, - byte[] dData, byte[] sData) { - - int dOffset = 0; - int sOffset = 0; - int sLineIncr = unitsPerPixel * origImage.width; - int sPixelIncr = unitsPerPixel << 1; - - assert ((xScale != 1) || (yScale != 1)); - - if (yScale == 1) { - for (int x = 0; x < width; x++) { - for (int k = 0; k < unitsPerPixel; k++) { - dData[dStart + dOffset + k] = (byte) - (((int)(sData[sStart + sOffset + k] & 0xff) + - (int)(sData[sStart + sOffset + k - + unitsPerPixel] & 0xff) + 1) >> 1); - } - dOffset += unitsPerPixel; - sOffset += sPixelIncr; - } - } else if (xScale == 1) { - for (int y = 0; y < height; y++) { - for (int k = 0; k < unitsPerPixel; k++) { - dData[dStart + dOffset + k] = (byte) - (((int)(sData[sStart + sOffset + k] & 0xff) + - (int)(sData[sStart + sOffset + k - + sLineIncr] & 0xff) + 1) >> 1); - } - dOffset += unitsPerPixel; - sOffset += sLineIncr; - } - } else { - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - for (int k = 0; k < unitsPerPixel; k++) { - dData[dStart + dOffset + k] = (byte) - (((int)(sData[sStart + sOffset + k] & 0xff) + - (int)(sData[sStart + sOffset + k - + unitsPerPixel] & 0xff) + - (int)(sData[sStart + sOffset + k - + sLineIncr] & 0xff) + - (int)(sData[sStart + sOffset + k + sLineIncr + - + unitsPerPixel] & 0xff) + 2) >> 2); - } - dOffset += unitsPerPixel; - sOffset += sPixelIncr; - } - sOffset += sLineIncr; - } - } - } - - void scaleImage(int xScale, int yScale, int dStart, int sStart, ImageComponentRetained origImage, - int[] dData, int[] sData) { - - int dOffset = 0; - int sOffset = 0; - int sLineIncr = origImage.width; - int sPixelIncr = 2; - - assert ((xScale != 1) || (yScale != 1)); - - int sTemp1, sTemp2; - int[] comp = new int[4]; - if (yScale == 1) { - for (int x = 0; x < width; x++) { - sTemp1 = sData[sStart + sOffset]; - sTemp2 = sData[sStart + sOffset + 1]; - // Unpack and compute - for (int k = 0; k < numberOfComponents; k++) { - comp[k] = ((sTemp1 & 0xff) + (sTemp2 & 0xff) + 1) >> 1; - sTemp1 = sTemp1 >> 8; - sTemp2 = sTemp2 >> 8; - } - // Pack back computed value. - sTemp1 = comp[numberOfComponents - 1]; - if(numberOfComponents > 1) { - for (int k = numberOfComponents - 2; k >= 0; k--) { - sTemp1 = (sTemp1 << 8) + comp[k]; - } - } - dData[dStart + dOffset] = sTemp1; - - dOffset += 1; - sOffset += sPixelIncr; - } - } else if (xScale == 1) { - for (int y = 0; y < height; y++) { - sTemp1 = sData[sStart + sOffset]; - sTemp2 = sData[sStart + sOffset + sLineIncr]; - // Unpack and compute - for (int k = 0; k < numberOfComponents; k++) { - comp[k] = ((sTemp1 & 0xff) + (sTemp2 & 0xff) + 1) >> 1; - sTemp1 = sTemp1 >> 8; - sTemp2 = sTemp2 >> 8; - } - // Pack back computed value. - sTemp1 = comp[numberOfComponents - 1]; - if(numberOfComponents > 1) { - for (int k = numberOfComponents - 2; k >= 0; k--) { - sTemp1 = (sTemp1 << 8) + comp[k]; - } - } - dData[dStart + dOffset] = sTemp1; - - dOffset += 1; - sOffset += sLineIncr; - } - } else { - int sTemp3, sTemp4; - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - sTemp1 = sData[sStart + sOffset]; - sTemp2 = sData[sStart + sOffset + 1]; - sTemp3 = sData[sStart + sOffset + sLineIncr]; - sTemp4 = sData[sStart + sOffset + sLineIncr + 1]; - // Unpack and compute - for (int k = 0; k < numberOfComponents; k++) { - comp[k] = ((sTemp1 & 0xff) + (sTemp2 & 0xff) + - (sTemp3 & 0xff) + (sTemp4 & 0xff) + 2) >> 2; - sTemp1 = sTemp1 >> 8; - sTemp2 = sTemp2 >> 8; - sTemp3 = sTemp3 >> 8; - sTemp4 = sTemp4 >> 8; - } - // Pack back computed value. - sTemp1 = comp[numberOfComponents - 1]; - if(numberOfComponents > 1) { - for (int k = numberOfComponents - 2; k >= 0; k--) { - sTemp1 = (sTemp1 << 8) + comp[k]; - } - } - dData[dStart + dOffset] = sTemp1; - - dOffset += 1; - sOffset += sPixelIncr; - } - sOffset += sLineIncr; - } - } - } - - // Add a user to the userList synchronized void addUser(NodeComponentRetained node) { userList.add(node); diff --git a/src/classes/share/javax/media/j3d/TextureRetained.java b/src/classes/share/javax/media/j3d/TextureRetained.java index eb13480..43aef4d 100644 --- a/src/classes/share/javax/media/j3d/TextureRetained.java +++ b/src/classes/share/javax/media/j3d/TextureRetained.java @@ -68,17 +68,19 @@ abstract class TextureRetained extends NodeComponentRetained { int format = Texture.RGB; // Texture format int width = 1; // Width in pixels (2**n) int height = 1; // Height in pixels (2**m) - private boolean widthOrHeightIsNPOT = false; // true if width or height is non power of two - ImageComponentRetained images[][]; // Array of images (one for each mipmap level) - boolean imagesLoaded = false; // TRUE if all mipmap levels are loaded - int mipmapLevels; // Number of MIPMAP levels needed - int maxLevels = 0; // maximum number of levels needed for - // the mipmapMode of this texture - int maxMipMapLevels = 0; // maximum number of mipmap levels that - // can be defined for this texture + // true if width or height is non power of two + private boolean widthOrHeightIsNPOT = false; + // Array of images (one for each mipmap level) + ImageComponentRetained images[][]; + // maximum number of levels needed for the mipmapMode of this texture + int maxLevels = 0; + // maximum number of mipmap levels that can be defined for this texture + private int maxMipMapLevels = 0; + // true if hardware auto mipmap generation is requested. + private boolean useAutoMipMapGeneration = false; + int numFaces = 1; // For CubeMap, it is 6 - int baseLevel = 0; int maximumLevel = 0; float minimumLod = -1000.0f; @@ -206,7 +208,7 @@ abstract class TextureRetained extends NodeComponentRetained { maximumLevel = 0; maxLevels = 1; } - + images = new ImageComponentRetained[numFaces][maxLevels]; for (int j = 0; j < numFaces; j++) { @@ -214,8 +216,6 @@ abstract class TextureRetained extends NodeComponentRetained { images[j][i] = null; } } - imagesLoaded = false; - } final int getFormat() { @@ -1897,7 +1897,6 @@ abstract class TextureRetained extends NodeComponentRetained { mirrorTexture.boundaryColor.set(boundaryColor); mirrorTexture.enable = enable; mirrorTexture.userSpecifiedEnable = enable; - mirrorTexture.imagesLoaded = imagesLoaded; mirrorTexture.enable = enable; mirrorTexture.numFaces = numFaces; mirrorTexture.resourceCreationMask = 0x0; @@ -1952,30 +1951,28 @@ abstract class TextureRetained extends NodeComponentRetained { // implicit mipmap generation if (mipmapMode == Texture.BASE_LEVEL && - (minFilter == Texture.NICEST || - minFilter == Texture.MULTI_LEVEL_POINT || - minFilter == Texture.MULTI_LEVEL_LINEAR)) { - mirrorTexture.maxLevels = maxMipMapLevels; - - if ((mirrorTexture.images == null) || - (mirrorTexture.images.length < numFaces) || - (mirrorTexture.images[0].length < mirrorTexture.maxLevels)) { - mirrorTexture.images = - new ImageComponentRetained[numFaces][mirrorTexture.maxLevels]; - } - - for (int j = 0; j < numFaces; j++) { - mirrorTexture.images[j][0] = images[j][0]; - - // add texture to the userList of the images - if (images[j][0] != null) { - images[j][0].addUser(mirrorTexture); - } - - for (int i = 1; i < mirrorTexture.maxLevels; i++) { - mirrorTexture.images[j][i] = - mirrorTexture.images[j][i-1].createNextLevelMipMapImage(); - } + (minFilter == Texture.NICEST || + minFilter == Texture.MULTI_LEVEL_POINT || + minFilter == Texture.MULTI_LEVEL_LINEAR)) { + // TODO : Should this be 1 ? --- Chien. + // mirrorTexture.maxLevels = maxMipMapLevels; + mirrorTexture.maxLevels = 1; + mirrorTexture.useAutoMipMapGeneration = true; + + if ((mirrorTexture.images == null) || + (mirrorTexture.images.length < numFaces) || + !(mirrorTexture.images[0].length == mirrorTexture.maxLevels)) { + mirrorTexture.images = + new ImageComponentRetained[numFaces][mirrorTexture.maxLevels]; + } + + for (int j = 0; j < numFaces; j++) { + mirrorTexture.images[j][0] = images[j][0]; + + // add texture to the userList of the images + if (images[j][0] != null) { + images[j][0].addUser(mirrorTexture); + } } } else { |