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

Revert RunTimeException when JPEGTurbo cannot be loaded #4115

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ public JPEGTurboServiceImpl() {
logger.setLevel(Level.SEVERE);
if (!libraryLoaded) {
libraryLoaded = NativeLibraryUtil.loadNativeLibrary(TJ.class, "turbojpeg");
if (!libraryLoaded) {
throw new RuntimeException("TurboJPEG could not be loaded");
}
}
}

Expand Down Expand Up @@ -383,6 +380,11 @@ public void close() throws IOException {
header = null;
}

@Override
public boolean isLibraryLoaded() {
return libraryLoaded;
}

// -- Helper methods --

private byte[] getFixedHeader() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions components/formats-gpl/src/loci/formats/in/NDPIReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down