From 6e2c237c186bb604b2d64f2dfaf3e18a623f08a5 Mon Sep 17 00:00:00 2001 From: David Gault Date: Wed, 15 Nov 2023 17:12:31 +0000 Subject: [PATCH 1/2] Revert "Merge pull request #4090 from CGDogan/patch-5" This reverts commit 9595b6cef8be33208bc3e4704090b3bc04581ebe, reversing changes made to f9f4617e280578c7088df7eb5cee6d1a14677dbc. --- .../src/loci/formats/services/JPEGTurboServiceImpl.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/formats-bsd/src/loci/formats/services/JPEGTurboServiceImpl.java b/components/formats-bsd/src/loci/formats/services/JPEGTurboServiceImpl.java index 3231da2686b..49f82deff58 100644 --- a/components/formats-bsd/src/loci/formats/services/JPEGTurboServiceImpl.java +++ b/components/formats-bsd/src/loci/formats/services/JPEGTurboServiceImpl.java @@ -105,10 +105,8 @@ public JPEGTurboServiceImpl() { logger = Logger.getLogger(NATIVE_LIB_CLASS); logger.setLevel(Level.SEVERE); if (!libraryLoaded) { - libraryLoaded = NativeLibraryUtil.loadNativeLibrary(TJ.class, "turbojpeg"); - if (!libraryLoaded) { - throw new RuntimeException("TurboJPEG could not be loaded"); - } + NativeLibraryUtil.loadNativeLibrary(TJ.class, "turbojpeg"); + libraryLoaded = true; } } From 09957384a3a17bdc892ff8f36568e31232b6aad5 Mon Sep 17 00:00:00 2001 From: David Gault Date: Fri, 17 Nov 2023 11:55:41 +0000 Subject: [PATCH 2/2] JPEGTurboService: Add and implement isLibraryLoaded method --- .../formats-bsd/src/loci/formats/in/TileJPEGReader.java | 1 + .../src/loci/formats/services/JPEGTurboService.java | 2 ++ .../src/loci/formats/services/JPEGTurboServiceImpl.java | 8 ++++++-- .../src/loci/formats/in/HamamatsuVMSReader.java | 1 + .../formats-gpl/src/loci/formats/in/NDPIReader.java | 1 + 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/components/formats-bsd/src/loci/formats/in/TileJPEGReader.java b/components/formats-bsd/src/loci/formats/in/TileJPEGReader.java index a70cb2f9153..db02888542c 100644 --- a/components/formats-bsd/src/loci/formats/in/TileJPEGReader.java +++ b/components/formats-bsd/src/loci/formats/in/TileJPEGReader.java @@ -147,6 +147,7 @@ public void reopenFile() throws IOException { service = null; throw new IOException("Could not initialize JPEG service", se); } + if (!service.isLibraryLoaded()) throw new IOException("JPEG service failed to load Turbo JPEG library"); } } diff --git a/components/formats-bsd/src/loci/formats/services/JPEGTurboService.java b/components/formats-bsd/src/loci/formats/services/JPEGTurboService.java index dfdd4229432..85570cbaf2c 100644 --- a/components/formats-bsd/src/loci/formats/services/JPEGTurboService.java +++ b/components/formats-bsd/src/loci/formats/services/JPEGTurboService.java @@ -58,5 +58,7 @@ byte[] getTile(byte[] buf, int xCoordinate, int yCoordinate, int width, byte[] getTile(int xTile, int yTile) throws IOException; void close() throws IOException; + + boolean isLibraryLoaded(); } diff --git a/components/formats-bsd/src/loci/formats/services/JPEGTurboServiceImpl.java b/components/formats-bsd/src/loci/formats/services/JPEGTurboServiceImpl.java index 49f82deff58..cbe0e2033e3 100644 --- a/components/formats-bsd/src/loci/formats/services/JPEGTurboServiceImpl.java +++ b/components/formats-bsd/src/loci/formats/services/JPEGTurboServiceImpl.java @@ -105,8 +105,7 @@ public JPEGTurboServiceImpl() { logger = Logger.getLogger(NATIVE_LIB_CLASS); logger.setLevel(Level.SEVERE); if (!libraryLoaded) { - NativeLibraryUtil.loadNativeLibrary(TJ.class, "turbojpeg"); - libraryLoaded = true; + libraryLoaded = NativeLibraryUtil.loadNativeLibrary(TJ.class, "turbojpeg"); } } @@ -381,6 +380,11 @@ public void close() throws IOException { header = null; } + @Override + public boolean isLibraryLoaded() { + return libraryLoaded; + } + // -- Helper methods -- private byte[] getFixedHeader() throws IOException { diff --git a/components/formats-gpl/src/loci/formats/in/HamamatsuVMSReader.java b/components/formats-gpl/src/loci/formats/in/HamamatsuVMSReader.java index 34fa3c0d0a8..d54ecbeeba7 100644 --- a/components/formats-gpl/src/loci/formats/in/HamamatsuVMSReader.java +++ b/components/formats-gpl/src/loci/formats/in/HamamatsuVMSReader.java @@ -157,6 +157,7 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) if (service == null) { service = new JPEGTurboServiceImpl(); + if (!service.isLibraryLoaded()) throw new IOException("JPEG service failed to load Turbo JPEG library"); } try { diff --git a/components/formats-gpl/src/loci/formats/in/NDPIReader.java b/components/formats-gpl/src/loci/formats/in/NDPIReader.java index 6da4236d697..32fc44d20df 100644 --- a/components/formats-gpl/src/loci/formats/in/NDPIReader.java +++ b/components/formats-gpl/src/loci/formats/in/NDPIReader.java @@ -329,6 +329,7 @@ public int getOptimalTileHeight() { /* @see loci.formats.FormatReader#initFile(String) */ @Override protected void initFile(String id) throws FormatException, IOException { + if (!service.isLibraryLoaded()) throw new IOException("JPEG service failed to load Turbo JPEG library"); RandomAccessInputStream s = new RandomAccessInputStream(id); use64Bit = s.length() >= Math.pow(2, 32); s.close();