NIO BufferedImage. Why not ?

As the subject says, why the Java2D team does not implement a NIO backed BufferedImage (or WritableRaster) ?
It would be so useful in order to access ‘foreing’ framebuffers, VRAM, etc. From the speed point of view it would save us a ‘memcpy()’ for each animation frame in some cases.

Thanks,

Mik

Hi Mik,

This is something we’ve been investigating, but it wouldn’t necessarily help the cases you mention. The work so far has been mostly experimental, so no idea if/when this will ever be integrated.

Chris

Along the same lines, does ImageIO work with NIO yet? (E.g. reading/writing images from/to channels or Buffers)
Is there a plan to get the two to play nice without having to go back and forth with an Array?
How about making javax.imageio.stream.IIOByteBuffer based on ByteBuffer instead of Object?

There are lots of places that need a once over to connect APIs that should just work together… NIO is one of those APIs that needs better support throughout the JDK.

Hey Scott,

Yeah, agreed. Note that JAI already does ship ImageInput/OutputStreams based on NIO FileChannels, as part of their JAI Image I/O Tools package:
http://java.sun.com/products/java-media/jai/forDevelopers/jai-imageio-1_0_01-fcs-docs/index.html

We will continue to look into ways to leverage NIO (esp. ByteBuffers) in the relevant Java 2D and IIO APIs. This is something we’re planning to look into in the Dolphin timeframe.

Thanks,
Chris

Thanks Chris,

and what about a NIO WritableRaster (ok, it’s almost the same as the NIO BufferedImage, bul a bit more low-level).

It would be nice to have a simple NIODataBufferInt (i.e. a DataBuffer that wraps a native array)


		// the RGBA color masks
		int[] bm = new int[]{0x00FF0000,0x0000FF00,0x000000FF,0xFF000000};
		// the colormodel
		ColorModel cm = new DirectColorModel(32,bm[0],bm[1],bm[2],bm[3]);
		// allocate bitmap data
		NIODataBufferInt db = new NIODataBufferInt(pixels,pixels.length,pixoffset);
		WritableRaster wr = WritableRaster.createPackedRaster(db,width,height,rowints,bm,null);
		// the image
		return new BufferedImage(cm,wr,false,null);

that would help true sharing of image data between native and java.