Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4090 breaks support for Apple Silicon for formats that don't need TurboJPEG #4109

Closed
petebankhead opened this issue Oct 18, 2023 · 4 comments · Fixed by #4115
Closed

#4090 breaks support for Apple Silicon for formats that don't need TurboJPEG #4109

petebankhead opened this issue Oct 18, 2023 · 4 comments · Fixed by #4115
Labels
bug Something isn't working
Milestone

Comments

@petebankhead
Copy link
Contributor

Hi,

#4090 seems to break the use of

ImageReader reader = new ImageReader();

on Apple Silicon - even for formats that otherwise worked without problem (e.g. CMU-1.svs, LuCa tiff images).

The issue seems to be that the try/catch block doesn't handle the RuntimeException thrown whenever it is not possible to load TurboJPEG:

try {
reader = c[i].newInstance();
reader.setMetadataOptions(opt);
}
catch (IllegalAccessException exc) { }
catch (InstantiationException exc) { }

The workaround is to pass a ClassList that has been already been checked to exclude classes that can't be instantiated, e.g. using

        private static ClassList<IFormatReader> getDefaultClassList() {
		ClassList<IFormatReader> classes = new ClassList<>(IFormatReader.class);
		for (var cls : ImageReader.getDefaultReaderClasses().getClasses()) {
			try {
				var instance = cls.getConstructor().newInstance();
				if (instance != null)
					classes.addClass(cls);
			} catch (Throwable t) {
				logger.debug("Cannot instantiate reader class " + cls.getName() + ": " + t.getMessage());
			}
		}
		return classes;
	}

...

ImageReader reader = new ImageReader(getDefaultClassList());

Adding code like this should be enough for us to be able to include 7.0.1 in QuPath - but since Bio-Formats is the now only dependency we have without Apple Silicon support, it would be even better if #3756 and #3858 could be addressed :) The QuPath Apple Silicon builds are now faster and more reliable on M1/M2 Macs (due in part to some OpenCV changes), so will be recommended with the caveat that most .czi images won't work.

petebankhead added a commit to petebankhead/qupath that referenced this issue Oct 18, 2023
@dgault dgault added this to the 7.1.0 milestone Oct 19, 2023
@dgault
Copy link
Member

dgault commented Oct 19, 2023

Thanks @petebankhead for raising this issue, we will look at resolving this for the next release.

@imagesc-bot
Copy link

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/bioformats-7-0-1-apple-arm-processor-regression/88713/2

@CGDogan
Copy link
Contributor

CGDogan commented Nov 22, 2023

For QuPath, you can remove the need for Rosetta by simply following the steps in #4042 or just copying the binary. Once you compile it with the steps I've given on any Mac computer or copy my binary, all you need to do is to unzip the bioformats-package.jar, copy the turbojpeg binary in the correct new folder, then rezip it (you need a zip tool, java's jar tool won't work) Needless to say, you would then need to distribute the turbojpeg source code to comply with GPL. I use this without problems on my Apple Silicon. I'm sure QuPath users would find it useful meanwhile.

@sbesson sbesson added the bug Something isn't working label Nov 22, 2023
@imagesc-bot
Copy link

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/files-not-opening-on-macbook-illegalstateexception/89115/6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants