imagej / imagej-legacy

ImageJ+ImageJ2 compatibility layer
https://imagej.net/libs/imagej-legacy
BSD 2-Clause "Simplified" License
16 stars 25 forks source link

Add support for eager IOPlugins #296

Closed ctrueden closed 1 year ago

ctrueden commented 1 year ago

This is a mechanism by which certain IOPlugins can be labeled with an "eager" attribute in the @Plugin annotation, and then ImageJ Legacy's override of File→Open... will give them a chance to handle files before the original ImageJ goes through its whole pipeline of logic.

This behavior happens even when the "Use SciJava I/O" option is disabled, so plugins should take care to label themselves "eager" only when they really need to go before standard ImageJ logic. This is currently the case e.g. for directories, because the original ImageJ always tries to handle them with Open Image Sequence, but we have cases where we want to handle directories with particular contents, such as N5 and Zarr, with plugins instead.

xulman commented 1 year ago

@ctrueden I think we need this little patch:

index a19500c..afb4d77 100644
--- a/src/main/java/net/imagej/legacy/plugin/DefaultLegacyOpener.java
+++ b/src/main/java/net/imagej/legacy/plugin/DefaultLegacyOpener.java
@@ -141,7 +141,7 @@ public class DefaultLegacyOpener implements LegacyOpener {
                                        logService.debug("Eager format '" + io.getClass().getName() + "' opened nothing.");
                                        return null; // Pass through to original ImageJ.
                                }
-                               handleData(c, data, path, displayResult);
+                               return handleData(c, data, path, displayResult);
                        }
                        catch (final IOException exc) {
                                legacyService.handleException(exc);

otherwise the IJ1 believes we failed opening and (besides the "eager" plugin) something else may get opened too

xulman commented 1 year ago

I just tested it in the production env (official Fiji with replaced imagej-legacy...jar on my Linux and it works well

ctrueden commented 1 year ago

@xulman Thanks for testing, and for the patch! I squashed it in. As soon as the CI passes, I'll merge this. :+1: