In a previous post, I briefly showed a sample code that leveraged the Java Native Interface library (JNA).

Now that’s it, my first interesting contribution to the JNA was added to the project. It consists in code that speeds up the shaped window example code, by a factor of up to 80 times.

The code I submitted was only speeding up the Windows and Mac OS X implementations. Chris Deckers helped test and debug the code, and someone (Timothy Wall ?) added an optimized version for the X11 implementation.

Besides some anecdotic changes, here are the changes I submitted :

  • reuse GDI ranges as much as possible in the Windows implementation
  • avoid raster data copy for most useful image types (TYPE_BINARY_BYTE and TYPE_INT_*)
  • pack ranges of non transparent pixels along rows, doing kind of a run-length encoding. This means that instead of calling a native function to declare each pixel to be non transparent, we declare tens or hundreds of them at a time. I abstracted the methods of decomposition from raster to consecutive ranges of non-null or non-transparent pixels in the class RasterRangesUtils. This simplified the internals of the WindowUtils class.

In his blog, Timothy Wall was kind enough to mention this performance gain… I’m really happy I could contribute to such an amazing project and I am looking forward to doing it again 😀