deep copy to bufferedimage
I'm using JAI to read 32 bit .tiff images with unpremultiplied alpha. I need to draw these images as BufferedImage, but the image I get from PlanarImage.getAsBufferedImage for some reason draws really slow in a graphics2d component.(I assume because it's an unknown type?)
I figured out that if I copy the image to a new TYPE_4BYTE_ABGR, the image draws really fast. However, iterating through the images with getTGB() and setRGB is really slow.
So then I decided to take the raster data and arraycopy it. It works great, other than the fact that the alpha values are lost, all of them are set to x0dc.
Here's the code:
PlanarImage tmpPlanar = JAI.create("fileload","overlay.tif");
BufferedImage tmpBuffered = tmpPlanar.getAsBufferedImage();
BufferedImage overlay = new BufferedImage(tmpBuffered.getWidth(),tmpBuffered.getHeight(),BufferedImage.TYPE_4BYTE_ABGR);
byte byteDataTmpBuffered = ((DataBufferByte)tmpBuffered.getRaster().getDataBuffer()).getData();
byte byteDataOverlay = ((DataBufferByte)overlay.getRaster().getDataBuffer()).getData();
ttmpBuffered: PlanarImage[minX=0 minY=0 width=640 height=480 tileGridXOffset=0 tileGridYOffset=0 tileWidth=640 tileHeight=102 sampleModel=java.awt.image.PixelInterleavedSampleModel@40b0005 colorModel=ColorModel: #pixelBits = 32 numComponents = 4 color space = java.awt.color.ICC_ColorSpace@1a3aa2c transparency = 1 has alpha = true isAlphaPre = false]
What am I messing up? Is there a better way to get a deep copy as a bufferedimage?