Skip to content

Commit

Permalink
Merge pull request #4115 from dgault/JPegTurbo-RevertRTE
Browse files Browse the repository at this point in the history
Revert RunTimeException when JPEGTurbo cannot be loaded
  • Loading branch information
melissalinkert authored Nov 27, 2023
2 parents e1aaf58 + 0995738 commit ec22ea2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
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

0 comments on commit ec22ea2

Please sign in to comment.