Skip to main content

deep copy to bufferedimage

1 reply [Last post]
kamo
Offline
Joined: 2007-11-17
Points: 0

Hello,

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:

--snip--
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();

System.arraycopy(byteDataTmpBuffered,0,byteDataOverlay,0,byteDataOverlay.length);
--snip--

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?

Thanks,
kamo

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Fork Labs

Hello kamo,

You could use operator "format" to change the data type to byte.
Please take a look at operator "autorescale" and "pipeline" from my
project at :

jai-operators.dev.java.net

Regards,

Daniel Léonard

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net