1

I have a C++ library that does image processing on rectangular arrays of pixels. I want to pass the output C++ pixels to java so they can most effciently be "drawn" into a java.awt.Graphics2 instance for a canvas as an Image/Raster/(?) object( yeah not the best way but it is a legacy app )

I am looking for the best way to do this for performance, as the image can be "animated" and updates need to be reasonable.

peterk
  • 5,136
  • 6
  • 33
  • 47

1 Answers1

2

The backing store for a Raster object is a DataBuffer, which is an interface you can implement yourself. If you use a DirectByteBuffer you can effectively share a memory region between Java and the native world.

Botje
  • 26,269
  • 3
  • 31
  • 41
  • I will check this out. Hopefully it can do a block copy of an entire scan line at a time when it gets to draw time :) – peterk Aug 22 '23 at 22:53
  • So far the only way I managed to do this is by using the sun.awt.image.ByteInterleavedRaster. which is the only one one can assign an externally allocated byte[]/DataBufferByte to as a buffer and also have it efficiently do the graphics2D.draw(image). efficiently into. – peterk Aug 26 '23 at 02:09