Skip to content

Commit

Permalink
make XImageLoaderFactory optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mstr2 committed Oct 5, 2024
1 parent 11a840f commit d662a78
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import com.sun.javafx.iio.common.ImageTools;
import com.sun.javafx.iio.gif.GIFImageLoaderFactory;
import com.sun.javafx.iio.ios.IosImageLoaderFactory;
import com.sun.javafx.iio.javax.XImageLoader;
import com.sun.javafx.iio.javax.XImageLoaderFactory;
import com.sun.javafx.iio.jpeg.JPEGImageLoaderFactory;
import com.sun.javafx.iio.png.PNGImageLoaderFactory;
import com.sun.javafx.logging.PlatformLogger;
Expand Down Expand Up @@ -180,6 +178,7 @@ public static enum ImageType {
*/
private final HashMap<String, ImageLoaderFactory> loaderFactoriesByMimeSubtype;
private final ImageLoaderFactory[] loaderFactories;
private final ImageLoaderFactory xImageLoaderFactory = tryGetXImageLoaderFactory();
private int maxSignatureLength;

private static final boolean isIOS = PlatformUtil.isIOS();
Expand All @@ -192,6 +191,15 @@ public static ImageStorage getInstance() {
return InstanceHolder.INSTANCE;
}

private static ImageLoaderFactory tryGetXImageLoaderFactory() {
try {
Class<?> factoryClass = Class.forName("com.sun.javafx.iio.javax.XImageLoaderFactory");
return (ImageLoaderFactory)factoryClass.getMethod("getInstance").invoke(null);
} catch (ReflectiveOperationException e) {
return null;
}
}

public ImageStorage() {
if (isIOS) {
//On iOS we have single factory/ native loader
Expand Down Expand Up @@ -415,8 +423,9 @@ public ImageFrame[] loadAll(String input, ImageLoadListener listener,
} else {
// If we don't have a built-in loader factory we try to find an ImageIO loader
// that can load the content of the data URI.
XImageLoader imageLoader = (XImageLoader)XImageLoaderFactory.getInstance()
.createImageLoader(new ByteArrayInputStream(dataUri.getData()));
ImageLoader imageLoader = xImageLoaderFactory != null
? xImageLoaderFactory.createImageLoader(new ByteArrayInputStream(dataUri.getData()))
: null;

if (imageLoader == null) {
throw new IllegalArgumentException(
Expand Down Expand Up @@ -544,9 +553,9 @@ private ImageLoader findImageLoader(InputStream stream, ImageLoadListener listen
stream.mark(Integer.MAX_VALUE);
ImageLoader loader = getLoaderBySignature(stream, listener);

if (loader == null) {
if (loader == null && xImageLoaderFactory != null) {
stream.reset();
loader = XImageLoaderFactory.getInstance().createImageLoader(stream);
loader = xImageLoaderFactory.createImageLoader(stream);
}

return loader;
Expand Down

0 comments on commit d662a78

Please sign in to comment.