From af4b6470b766c0656260377e21b64529fbf61839 Mon Sep 17 00:00:00 2001 From: Chien Yang Date: Wed, 20 Dec 2006 19:13:04 +0000 Subject: Fixed issue 425 : NullPointerException in automatic mipmap generation git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@764 ba19aa83-45c5-6ac9-afd3-db810772062c --- .../javax/media/j3d/ImageComponent2DRetained.java | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/classes/share/javax/media/j3d/ImageComponent2DRetained.java b/src/classes/share/javax/media/j3d/ImageComponent2DRetained.java index 4e2d13b..75835d3 100644 --- a/src/classes/share/javax/media/j3d/ImageComponent2DRetained.java +++ b/src/classes/share/javax/media/j3d/ImageComponent2DRetained.java @@ -332,14 +332,40 @@ class ImageComponent2DRetained extends ImageComponentRetained { } 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; -- cgit v1.2.3