JAI Migration
Eclipse ImageN offers a migration path for developers migrating from the Java Advanced Imaging Framework:
-
org.eclipse.imagen:imagen-all: includes the core library, bundled with supported operators for which test cases have been provided.The supported operators have been battle tested by the Java Geospatial community and include functionality such as NO_DATA (allowing the operators to skip over areas of an image that are masked out).
-
org.eclipse.imagen:imagen-unsupported-all: includes the core library bundled with supported operators, and unsupported functionality for which no tests are available.Developers are welcome to pick up any unsupported functionality and write tests.
-
org.eclipse.imagen:imagen-legacy-all: includes the core library, bundled with legacy operators only, and unsupported functionality for which no tests are available.Legacy functionality has been identified for removal and will not be avaialble in future releases of ImageN. As an example
codecsupport which has long been superseded by Java and ImageIO. -
In addition to these combined jars, maven projects wishing greater control can depend on only the functionality used as individual module dependencies.
Unsupported functionality is provided “as is”, and requires test case coverage to be fully supported.
Automatic Update
-
Download ant migration scripts:
-
Ant refactoring script for
pom.xml:ant -f pom-update.xml -Dproject.dir=(absolute path to your project directory)This is a best-effort script recognizing
jai_core,jai_codecdependencies used withjai.version.The default
updatetarget runs each step in order:pom1: JAI and JAI-Ext dependencies to ImageNpom2:imagen.versionproperty to ImageN 0.9.3 (use-Dimagen.releasefor another version)pom3:imagen-prefix for artifacts in ImageN 0.9.3
To update a project using ImageN 0.9.2 to ImageN 0.9.3:
ant -f pom-update.xml -Dproject.dir=/home/user/dev/myproject pom2 pom3 -
And refactoring script for
javafiles.ant -f code-update.xml -Dproject.dir=(absolute path to your project directory)The default
updatetarget runs each step in order:update1: JAI and JAI-Ext imports to ImageN 0.4.0update2: JAI class names and constants to ImageN 0.9.0update3: scale2 package changes in ImageN 0.9.3
ImageN projects can run only the steps needed for their upgrade. To update a project using ImageN 0.9.2 to ImageN 0.9.3:
ant -f code-update.xml -Dproject.dir=/home/user/dev/myproject update3 -
This is a simple search and replace refactoring script to fix:
- imports and class references
- class name changes made during transition to ImageN library
- ParameterBlock constants, like “ImageN.ImageReadParam”.
Manual Update
To upgrade:
-
To migrate from a project depending on JAI 1.1.3:
<properties> <jai.version>1.1.3</jai.version> </properties> ... <dependency> <groupId>javax.media</groupId> <artifactId>jai_core</artifactId> <version>1.1.3</version> </dependency> <dependency> <groupId>javax.media</groupId> <artifactId>jai_codec</artifactId> <version>${jai.version}</version> </dependency> -
Replace with Eclipse ImageN dependency:
Replacing:
<properties> <imagen.version>0.9.4-SNAPSHOT</imagen.version> </properties> ... <dependency> <groupId>org.eclipse.imagen</groupId> <artifactId>imagen-legacy-all</artifactId> <version>${imagen.version}</version> </dependency>Note
imagen-legacy-allincludes the original legacy operators, and unsupported functionality such as thejai_codecfor which better replacements are available. -
Source code imports and references to JAI in class names and constants:
import java.awt.Frame; import java.awt.image.renderable.ParameterBlock; import java.io.IOException; import javax.media.jai.Interpolation; import javax.media.jai.JAI; import javax.media.jai.RenderedOp; import com.sun.media.jai.codec.FileSeekableStream; import javax.media.jai.widget.ScrollingImagePanel; public class JAISampleProgram { ... } -
Can be directly replaced (in order):
- Replace
javax.media.jaiwith packageorg.eclipse.imagen - Replace
com.sun.media.jaiwith packageorg.eclipse.imagen.media - Replace
JAIwithImageNclasse - Replace classes containing the JAI with their ImageN equivalent, such as
ParameterBlockJAIwithParameterBlockImageN. Consult the table in the next section as a reference. - Replace parameter block constants, such as
"JAI.ImageReadParam"with"ImageN.ImageReadParam". A complete table is provided in the next section.
import java.awt.Frame; import java.awt.image.renderable.ParameterBlock; import java.io.IOException; import org.eclipse.imagen.Interpolation; import org.eclipse.imagen.ImageN; import org.eclipse.imagen.RenderedOp; import org.eclipse.imagen.media.codec.FileSeekableStream; import org.eclipse.imagen.widget.ScrollingImagePanel; public class ImageNSampleProgram { ... } - Replace
-
Recommended: Once your application compiles change to
org.eclipse.imagen:imagen-alldependency (for core library and supported operators) and add additional unsupported or legacy dependencies as needed.-
Legacy functionality has been identified for removal and will not be available in future releases of ImageN.
-
Unsupported functionality is provided “as is”, and requires test case coverage to be fully supported.
-
ImageN Name Changes
The following classes have been renamed:
| JAI or JAI-Ext Class | ImageN Class |
|---|---|
ColorSpaceJAI | ColorSpaceImageN |
ColorSpaceJAIExt | ColorSpaceImageNExt |
ColorSpaceJAIExtWrapper | ColorSpaceImageNExtWrapper |
IHSColorSpaceJAIExt | IHSColorSpaceImageNExt |
JAI | ImageN |
JAIRMIImageServer | ImageNRMIImageServer |
JAIServerConfigurationSpi | ImageNServerConfigurationSpi |
ParameterBlockJAI | ParameterBlockImageN |
PropertyChangeEventJAI | PropertyChangeEventImageN |
LookupTableJAI | LookupTableImageN |
ComponentSampleModelJAI | ComponentSampleModelImageN |
PropertyChangeSupportJAI | PropertyChangeSupportImageN |
KernelJAI | KernelImageN |
ImageJAI | ImageImageN |
ImageFunctionJAIEXT | ImageFunctionExt |
ImageFunctionJAIEXTWrapper | ImageFunctionExtWrapper |
The following ImageReadDescriptors have been renamed:
| JAI Descriptor | ImageN Descriptor |
|---|---|
JAI.ImageReadParam | ImageN.ImageReadParam |
JAI.ImageReader | ImageN.ImageReader |
JAI.ImageMetadata | ImageN.ImageMetadata |
JAI.StreamMetadata | ImageN.StreamMetadata |
JAI.Thumbnails | ImageN.Thumbnails |
JAI.RenderableInput | ImageN.RenderableInput |
The registry files have been renamed
| JAI or JAI-Ext | ImageN |
|---|---|
META-INF/registryFile.jai | META-INF/registryFile.imagen |
Module artifacts use the imagen- prefix in ImageN 0.9.3:
| ImageN 0.9.2 | ImageN 0.9.3 |
|---|---|
org.eclipse.imagen:affine | org.eclipse.imagen:imagen-affine |
org.eclipse.imagen:jiffle-op | org.eclipse.imagen:imagen-jiffle-op |
Scale2 has been moved to a new package in ImageN 0.9.3:
| ImageN 0.9.2 | ImageN 0.9.3 |
|---|---|
org.eclipse.imagen.media.scale.Scale2* | org.eclipse.imagen.media.scale2.Scale2* |
Shaded Jars
ImageN operations are registered from META-INF/registryFile.imagen in each module jar, and from META-INF/services provider files. When building a fat jar with the maven-shade-plugin, these files must be merged rather than overwritten, otherwise operations go missing at runtime:
java.lang.IllegalArgumentException: ImageRead: No OperationDescriptor is registered in the current operation registry under this name.
Configure the shade plugin transformers:
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/registryFile.imagen</resource>
</transformer>
</transformers>
When migrating replace any AppendingTransformer for META-INF/registryFile.jai or META-INF/registryFile.jaiext with META-INF/registryFile.imagen.
Java Image Formats
Both the Java platform and ImageN include encoding/decoding codecs for image formats:
| Format | Java 8 ImageIO | ImageN Codec | Java 11 ImageIO |
|---|---|---|---|
| BMP | read/write | read/write | read/write |
| FlashPix | |||
| GIF | read/write | read | read/write |
| JPEG | read/write | read/write | |
| PNG | read/write | read/write | read/write |
| PNM | read/write | ||
| TIFF | read/write | ||
| WBMP | read/write | read | read/write |
The ImageN codec module no longer provides FlashPix, JPEG or TIFF support. ImageN requires Java 17, so use ImageIO, or the ImageRead operation, for JPEG and TIFF.
Finalize() removed
Finalizers have been deprecated in Java 18, as they are unpredictable, slow, error-prone, and pose security and resource management risks, making them fundamentally unsafe for modern applications. A number of legacy classes have been updated to no longer implement the finalize method. In some cases, it has been replaced with a more appropriate cleanup method; in others, a suitable method already existed. The table below summarizes these changes:
| Class | Removed Method | Replaced by New Method | Existing Method |
|---|---|---|---|
RMIServerProxy | finalize | dispose | |
RemoteImage | finalize | dispose | |
PlanarImageServerProxy | finalize | dispose | |
FlieLoadRIF | finalize | close | |
SeekableStream | finalize | close | |
SerializableRenderableImage | finalize | dispose | |
SerializableRenderedImage | finalize | dispose |
If your code relies on the classes mentioned above, consider updating it to ensure proper resource cleanup is performed.
The following core classes have been updated:
TileScheduler: it now extendsAutoCloseableSunTileScheduler: it now implementsclosereplacing thefinalizemethod.PlanarImage: thefinalizemethod has been removed.disposemethod already exists to clean up resources.JAI: it now implementsAutoCloseable, implementing aclosemethod that will clean up the tileScheduler.
If your code relies on the classes mentioned above, consider updating it to ensure proper resource cleanup is performed.
JPMS Allowances
ImageN runs on the Java Platform Module System. Each jar is an automatic module, for example org.eclipse.imagen.core or org.eclipse.imagen.legacy.core. The following improvements allow operations to load on both the classpath and the module path.
JaiI18N and Message properties removed
The package-private JaiI18N helper classes have been removed, and ImageN no longer reads exception and descriptor text from org.eclipse.imagen/*.properties resource bundles.
-
Operations following the JAI pattern of a
JaiI18Nclass should replace their own lookups with string literals.private static final String[][] resources = { {"GlobalName", "Rotate"}, {"Description", "Rotates an image."}, ... }; PropertyUtil.getString(String, String)is no longer used and is deprecated, however it still readsorg.eclipse.imagen/<package>.propertiesallowing operations that ship their own bundle keep working.- Legacy codec-core
org.eclipse.imagen.media.codecimpl.util.PropertyUtilis deprecated. Use imagen-coreorg.eclipse.imagen.media.util.PropertyUtil.
Allow-list configuration
ImageN only creates classes it trusts when loading by reflection:
RegistryFileParsercreates the descriptor and factory classes named inMETA-INF/registryFile.imagen.
Other entries are skipped with the warningClass ... is not in the allow-list.Servicecreates theOperationRegistrySpiproviders listed inMETA-INF/services.
Other providers are skipped with the warningSkipped service provider ... not in the allow-list.
Operation libraries contribute trusted classes by implementing RegistryAllowListProvider and ServiceAllowListProvider:
public class ExampleRegistryAllowListProvider implements RegistryAllowListProvider {
@Override
public Set<String> getAllowedRegistryClasses() {
return Set.of("org.example.media.ExampleDescriptor", "org.example.media.ExampleCRIF");
}
}
Applications can add additional classes with a System Property or Environment Variable, as comma-separated fully qualified class names:
| Allow-list | System property | Environment variable |
|---|---|---|
| Registry classes | org.eclipse.imagen.allowedRegistryClasses | ORG_ECLIPSE_IMAGEN_ALLOWED_REGISTRY_CLASSES |
| Service providers | org.eclipse.imagen.allowedServiceProviderClasses | ORG_ECLIPSE_IMAGEN_ALLOWED_SERVICE_PROVIDER_CLASSES |
Each allow-list is read once per JVM, on first use.
For example, GeoTools palette operations without a contributed provider requires:
-Dorg.eclipse.imagen.allowedRegistryClasses=\
org.geotools.image.palette.ColorReductionDescriptor,\
org.geotools.image.palette.ColorInversionDescriptor,\
org.geotools.image.palette.ColorReductionCRIF,\
org.geotools.image.palette.ColorInversionCRIF
Registering operations with OperationRegistrySpi
Operations are normally registered in META-INF/registryFile.imagen. Use an OperationRegistrySpi only to register an operation conditionally. Providers run after every registryFile.imagen has been read, so they can check what is already registered.
To avoid being dependent on classpath order imagen-legacy-core uses this approach: allowing any imagen-* module operation with the same name to take precedence. From LegacyCoreSpi:
public class LegacyCoreSpi implements OperationRegistrySpi {
@Override
public void updateRegistry(OperationRegistry registry) {
register(registry, new AddDescriptor(), PRODUCT, new AddCRIF(), true);
...
}
private static void register(
OperationRegistry registry,
OperationDescriptor descriptor,
String product,
RenderedImageFactory factory,
boolean renderable) {
String name = descriptor.getName();
if (registry.getDescriptor(OperationDescriptor.class, name) != null) {
LOGGER.log(Level.FINE, "Operation {0} already registered, skipping {1}", new Object[] {
name, descriptor.getClass().getName()
});
return;
}
registry.registerDescriptor(descriptor);
if (factory != null) {
registry.registerFactory(RenderedRegistryMode.MODE_NAME, name, product, factory);
if (renderable) {
registry.registerFactory(
RenderableRegistryMode.MODE_NAME, name, product, (ContextualRenderedImageFactory) factory);
}
}
}
}
OperationRegistrySpi providers must be listed in META-INF/services/org.eclipse.imagen.OperationRegistrySpi, and be on the service allow-list, see Allow-list configuration.
Tips for operation implementors
- List each provider in
META-INF/services. ImageN readsOperationRegistrySpiproviders from these files on both the classpath and the module path. -
In a named module, also declare the allow-list providers with
provides, as they are discovered byjava.util.ServiceLoader:module org.example.media { requires org.eclipse.imagen.core; provides org.eclipse.imagen.spi.RegistryAllowListProvider with org.example.media.ExampleRegistryAllowListProvider; provides org.eclipse.imagen.spi.ServiceAllowListProvider with org.example.media.ExampleServiceAllowListProvider; } - Use a unique operation name; when two jars register the same name, the first
registryFile.imagenread wins. - When an operation is installed, register its descriptor, factories and any
PropertyGeneratorup front, not lazily from a factorycreatemethod or a property source. The ImageN thread-safe registry does not allow a thread holding its read lock to perform a write, resulting in anIllegalStateException. This is a change from JAI, which allowed an upgrade from the registry read lock to the write lock. - When shading jars, append
META-INF/registryFile.imagenwith anAppendingTransformerand mergeMETA-INF/serviceswith theServicesResourceTransformer.