Permalink
Browse files

Replace OpenSlide.fileIsValid() with detectVendor()

openslide_can_open() is slow and deprecated.  openslide_detect_vendor()
can return non-null on files that openslide_open() will reject, so we
don't attempt to implement a fileIsValid() method with it.
  • Loading branch information...
1 parent b201413 commit 117011b6b469bf182cba9298318fb26e3259b106 @bgilbert bgilbert committed Oct 30, 2013
Showing with 15 additions and 12 deletions.
  1. +1 −1 README.txt
  2. +8 −5 openslide-jni.c
  3. +3 −3 src/org/openslide/OpenSlide.java
  4. +1 −1 src/org/openslide/OpenSlideJNI.java
  5. +2 −2 src/org/openslide/TestCLI.java
View
@@ -3,7 +3,7 @@ Build requirements
- JDK
- Apache Ant
-- OpenSlide
+- OpenSlide >= 3.4.0
Building on Linux or Mac OS X
-----------------------------
View
@@ -24,17 +24,20 @@
#include <openslide.h>
-static jboolean osj_can_open(JNIEnv *env, jobject obj, jstring filename) {
+static jstring osj_detect_vendor(JNIEnv *env, jobject obj, jstring filename) {
const char *filename2 = (*env)->GetStringUTFChars(env, filename, NULL);
if (filename2 == NULL) {
- return JNI_FALSE;
+ return NULL;
}
- jboolean result = openslide_can_open(filename2);
+ const char *val = openslide_detect_vendor(filename2);
(*env)->ReleaseStringUTFChars(env, filename, filename2);
- return result;
+ if (val == NULL) {
+ return NULL;
+ }
+ return (*env)->NewStringUTF(env, val);
}
static jlong osj_open(JNIEnv *env, jobject obj, jstring filename) {
@@ -190,7 +193,7 @@ static jstring osj_get_version(JNIEnv *env, jobject obj) {
}
static JNINativeMethod methods[] = {
- { "openslide_can_open", "(Ljava/lang/String;)Z", (void *) osj_can_open },
+ { "openslide_detect_vendor", "(Ljava/lang/String;)Ljava/lang/String;", (void *) osj_detect_vendor },
{ "openslide_open", "(Ljava/lang/String;)J", (void *) osj_open },
{ "openslide_get_level_count", "(J)I", (void *) osj_get_level_count },
{ "openslide_get_level_dimensions", "(JI[J)V", (void *) osj_get_level_dimensions },
@@ -40,7 +40,7 @@
private static final FileFilter FILE_FILTER = new FileFilter() {
@Override
public boolean accept(File f) {
- return f.isDirectory() || OpenSlide.fileIsValid(f);
+ return f.isDirectory() || OpenSlide.detectVendor(f) != null;
}
@Override
@@ -84,8 +84,8 @@ public String getDescription() {
final private int hashCodeVal;
- public static boolean fileIsValid(File file) {
- return OpenSlideJNI.openslide_can_open(file.getPath());
+ public static String detectVendor(File file) {
+ return OpenSlideJNI.openslide_detect_vendor(file.getPath());
}
public OpenSlide(File file) throws IOException {
@@ -56,7 +56,7 @@ private OpenSlideJNI() {
}
}
- native static boolean openslide_can_open(String file);
+ native static String openslide_detect_vendor(String file);
native static long openslide_open(String file);
@@ -48,8 +48,8 @@ public static void main(String args[]) throws IOException {
File f = new File(args[0]);
- System.out.printf("openslide_can_open returns %s\n", OpenSlide
- .fileIsValid(f) ? "true" : "false");
+ System.out.printf("openslide_detect_vendor returns %s\n",
+ OpenSlide.detectVendor(f));
OpenSlide osr = new OpenSlide(f);
long w, h;

0 comments on commit 117011b

Please sign in to comment.