Question

I am building a java ImageIO wrapper around the OpenJPEG native library.

I have a working ImageReader implementation. However, I am unable to get the ImageIO library to load my implementation automatically. Instead, I have to manually register the class, and then it works.

Does anyone have any ideas on how to get ImageIO.scanForPlugins to work properly?

If you want to take a look at the code, just clone my branch from here

https://github.com/CodecCentral/openjpeg/tree/java_imageio

There are two maven projects inside: one for the reader, and one for a simple viewer that links to the reader.

You can also find sample Jpeg2000 files here:

https://github.com/CodecCentral/openjpeg-data

Was it helpful?

Solution

You seem to be missing the META-INF/services/ resources needed for the service registry to pick up your Spi classes.

The resources are text files, and need to be named after the Spi class they implement (one for writer and one for reader), and contain one single line with the exact name of your Spi implementation class.

You need the following files (in java_imageio/wrapping/java/openjp2/src/main/resources):

/META-INF/services/javax.imageio.spi.ImageReaderSpi

# File content (comments allowed)
org.openJpeg.JP2KOpenJpegImageReaderSpi

/META-INF/services/javax.imageio.spi.ImageWriterSpi

# File content (comments allowed)
org.openJpeg.JP2KOpenJpegImageWriterSpi

Some additional comments: While not directly related to registration, I browsed your source code, and there might be some other issues with your Spi class.

  • For inputTypes you list File, byte[] and URL. While these types might be okay, ImageIO will likely require you to support ImageInputStream as well (most readers only support this), for normal operation. See the static read methods on ImageIO, and how they are implemented.
  • The canDecodeInput is supposed to look into the file/stream contents to recognize format "magic" identifiers or header structure. If you simply return true, your reader will try to decode any File, byte[] and URL regardless of content, not giving other readers a chance to properly read them. And again, I think you have to support ImageInputStream as input for normal operation.
  • (I assume the hardcoded JNI paths are only temporay.. :-)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top