SpriteIO._mt.removeImage(bi);
r.dispose();
} else {
throw new JXAException("src is not one of the supported class.");
}
Sprite sp = null;
boolean flushSp = false;
ImageTypeSpecifier type = SpriteIO._getITS(DEFAULT_TYPE);
if (!(src instanceof Sprite)) {
sp = new Sprite(bi, "image/x-png", imageSize = new Dimension(bi.getWidth(null), bi.getHeight(null)));
if (bi instanceof BufferedImage) {
type = SpriteIO._getITS((BufferedImage) bi);
}
flushSp = true;
} else {
sp = (Sprite) src;
type = sp.getFeatures();
imageSize = sp.getSize();
}
sp.setBufferedType(type.getNumComponents() == 3 ? BufferedImage.TYPE_3BYTE_BGR : DEFAULT_TYPE);
BufferedImage data = null;
if (sp != null) {
/**
* provide a shortcut to texture rectangle (no resizing) ^^
*/
if (_EXTtex == ARBTextureRectangle.GL_TEXTURE_RECTANGLE_ARB) {
textureSize = imageSize.getSize();
} else {
textureSize.width = Sf3Texture._getNextPowerOfTwo(imageSize.width);
textureSize.height = Sf3Texture._getNextPowerOfTwo(imageSize.height);
}
sp.setSize(textureSize);
sp.runValidate();
data = sp.toBuffered();
textureSize.setSize(data.getWidth(), data.getHeight());
Raster dataRaster = data.getRaster();
dataBuffer = dataRaster.getDataBuffer();
bands = dataRaster.getNumBands();
if (JXAenvUtils._debug) {
System.out.println("bufferedimage for texture has " + data.getRaster().getDataBuffer().getNumBanks() + " banks");
}
} else {
return null;
}
Buffer pixelBuffer = null;
switch (dataBuffer.getDataType()) {
case DataBuffer.TYPE_BYTE:
pixelBuffer = BufferIO._wrap(((DataBufferByte) dataBuffer).getData()).order(ByteOrder.nativeOrder());
break;
case DataBuffer.TYPE_DOUBLE:
pixelBuffer = BufferIO._wrapd(((DataBufferDouble) dataBuffer).getData());
break;
case DataBuffer.TYPE_FLOAT:
pixelBuffer = BufferIO._wrapf(((DataBufferFloat) dataBuffer).getData());
break;
case DataBuffer.TYPE_INT:
pixelBuffer = BufferIO._wrapi(((DataBufferInt) dataBuffer).getData());
break;
case DataBuffer.TYPE_SHORT:
pixelBuffer = BufferIO._wraps(((DataBufferShort) dataBuffer).getData());
break;
case DataBuffer.TYPE_USHORT:
pixelBuffer = BufferIO._wraps(((DataBufferUShort) dataBuffer).getData());
break;
default:
throw new JXAException("incompatible or unknown BufferedImage type :" + texture.toString());
}
data.flush();
pixelBuffer = _convert2DTexBuffer(pixelBuffer, textureSize, bands, transferMode, dataBuffer.getDataType());
if (pixelBuffer != null) {
/**
* instance Sf3Texture with the filled up pixelBuffer
*/
texture = new Sf3Texture(hashCode, pixelBuffer, textureSize.width, textureSize.height, bands, imageSize, transferMode);
if (JXAenvUtils._debug) {
System.err.println("new Sf3Texture buffer " + BufferIO._getBufferDataTypeName(pixelBuffer) + " size : " + BufferIO._countByteSize(pixelBuffer) + " w/ " + bands + " bands is POT ? : " + (isPOT((float) pixelBuffer.limit() / (float) bands) ? "yes" : "no"));
}
} else {
throw new JXAException("pixel buffer is null, no data could be loaded");
}
if (flushSp) {
sp.clearResource();
}
return texture;
}