diff --git a/eyes-two/proguard-rules.pro b/eyes-two/proguard-rules.pro index 7a905f84e..1092ca2be 100644 --- a/eyes-two/proguard-rules.pro +++ b/eyes-two/proguard-rules.pro @@ -64,6 +64,3 @@ # -keep public interface mypackage.MyInterface # -keep public class * implements mypackage.MyInterface --keep class com.googlecode.eyesfree.textdetect.HydrogenTextDetector { - private long mNative; -} \ No newline at end of file diff --git a/tess-two/jni/com_googlecode_tesseract_android/tessbaseapi.cpp b/tess-two/jni/com_googlecode_tesseract_android/tessbaseapi.cpp index 44dab2f6c..33103a985 100644 --- a/tess-two/jni/com_googlecode_tesseract_android/tessbaseapi.cpp +++ b/tess-two/jni/com_googlecode_tesseract_android/tessbaseapi.cpp @@ -24,7 +24,6 @@ #include "allheaders.h" #include "renderer.h" -static jfieldID field_mNativeData; static jmethodID method_onProgressValues; struct native_data_t { @@ -111,10 +110,6 @@ bool progressJavaCallback(void* progress_this, int progress, int left, int right return true; } -static inline native_data_t * get_native_data(JNIEnv *env, jobject object) { - return (native_data_t *) (env->GetLongField(object, field_mNativeData)); -} - #ifdef __cplusplus extern "C" { #endif @@ -133,29 +128,29 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) { void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeClassInit(JNIEnv* env, jclass clazz) { - field_mNativeData = env->GetFieldID(clazz, "mNativeData", "J"); method_onProgressValues = env->GetMethodID(clazz, "onProgressValues", "(IIIIIIIII)V"); } -void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeConstruct(JNIEnv* env, +jlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeConstruct(JNIEnv* env, jobject object) { native_data_t *nat = new native_data_t; if (nat == NULL) { LOGE("%s: out of memory!", __FUNCTION__); - return; + return 0; } - env->SetLongField(object, field_mNativeData, (jlong) nat); + return (jlong) nat; } jboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeInit(JNIEnv *env, jobject thiz, + jlong mNativeData, jstring dir, jstring lang) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; const char *c_dir = env->GetStringUTFChars(dir, NULL); const char *c_lang = env->GetStringUTFChars(lang, NULL); @@ -177,11 +172,12 @@ jboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeInit(JNIEnv *en jboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeInitOem(JNIEnv *env, jobject thiz, + jlong mNativeData, jstring dir, jstring lang, jint mode) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; const char *c_dir = env->GetStringUTFChars(dir, NULL); const char *c_lang = env->GetStringUTFChars(lang, NULL); @@ -202,9 +198,11 @@ jboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeInitOem(JNIEnv } jstring Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetInitLanguagesAsString(JNIEnv *env, - jobject thiz) { + jobject thiz, + jlong mNativeData) { + - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; const char *text = nat->api.GetInitLanguagesAsString(); @@ -216,6 +214,7 @@ jstring Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetInitLanguages void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetImageBytes(JNIEnv *env, jobject thiz, + jlong mNativeData, jbyteArray data, jint width, jint height, @@ -234,7 +233,7 @@ void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetImageBytes(JNIEn env->ReleaseByteArrayElements(data, data_array, JNI_ABORT); - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; nat->api.SetImage(imagedata, (int) width, (int) height, (int) bpp, (int) bpl); // Since Tesseract doesn't take ownership of the memory, we keep a pointer in the native @@ -250,12 +249,13 @@ void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetImageBytes(JNIEn void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetImagePix(JNIEnv *env, jobject thiz, + jlong mNativeData, jlong nativePix) { PIX *pixs = (PIX *) nativePix; PIX *pixd = pixClone(pixs); - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; if (pixd) { l_int32 width = pixGetWidth(pixd); l_int32 height = pixGetHeight(pixd); @@ -276,12 +276,13 @@ void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetImagePix(JNIEnv void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetRectangle(JNIEnv *env, jobject thiz, + jlong mNativeData, jint left, jint top, jint width, jint height) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; nat->setTextBoundaries(left, top, width, height); @@ -289,9 +290,10 @@ void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetRectangle(JNIEnv } jstring Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetUTF8Text(JNIEnv *env, - jobject thiz) { + jobject thiz, + jlong mNativeData) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; nat->initStateVariables(env, &thiz); ETEXT_DESC monitor; @@ -311,9 +313,10 @@ jstring Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetUTF8Text(JNIE } void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeStop(JNIEnv *env, - jobject thiz) { + jobject thiz, + jlong mNativeData) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; // Stop by setting a flag that's used by the monitor nat->resetStateVariables(); @@ -321,17 +324,19 @@ void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeStop(JNIEnv *env, } jint Java_com_googlecode_tesseract_android_TessBaseAPI_nativeMeanConfidence(JNIEnv *env, - jobject thiz) { + jobject thiz, + jlong mNativeData) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; return (jint) nat->api.MeanTextConf(); } jintArray Java_com_googlecode_tesseract_android_TessBaseAPI_nativeWordConfidences(JNIEnv *env, - jobject thiz) { + jobject thiz, + jlong mNativeData) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; int *confs = nat->api.AllWordConfidences(); @@ -359,10 +364,11 @@ jintArray Java_com_googlecode_tesseract_android_TessBaseAPI_nativeWordConfidence jboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetVariable(JNIEnv *env, jobject thiz, + jlong mNativeData, jstring var, jstring value) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; const char *c_var = env->GetStringUTFChars(var, NULL); const char *c_value = env->GetStringUTFChars(value, NULL); @@ -376,9 +382,10 @@ jboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetVariable(JNI } void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeClear(JNIEnv *env, - jobject thiz) { + jobject thiz, + jlong mNativeData) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; nat->api.Clear(); @@ -397,9 +404,10 @@ void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeClear(JNIEnv *env, } void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeEnd(JNIEnv *env, - jobject thiz) { + jobject thiz, + jlong mNativeData) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; nat->api.End(); @@ -416,34 +424,38 @@ void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeEnd(JNIEnv *env, void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetDebug(JNIEnv *env, jobject thiz, + jlong mNativeData, jboolean debug) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; nat->debug = (debug == JNI_TRUE) ? TRUE : FALSE; } jint Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetPageSegMode(JNIEnv *env, - jobject thiz) { + jobject thiz, + jlong mNativeData) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; return nat->api.GetPageSegMode(); } void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetPageSegMode(JNIEnv *env, jobject thiz, + jlong mNativeData, jint mode) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; nat->api.SetPageSegMode((tesseract::PageSegMode) mode); } jlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetThresholdedImage(JNIEnv *env, - jobject thiz) { + jobject thiz, + jlong mNativeData) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; PIX *pix = nat->api.GetThresholdedImage(); @@ -451,9 +463,10 @@ jlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetThresholdedImag } jlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetRegions(JNIEnv *env, - jobject thiz) { + jobject thiz, + jlong mNativeData) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; PIXA *pixa = NULL; BOXA *boxa; @@ -465,9 +478,10 @@ jlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetRegions(JNIEnv } jlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetTextlines(JNIEnv *env, - jobject thiz) { + jobject thiz, + jlong mNativeData) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; PIXA *pixa = NULL; BOXA *boxa; @@ -479,9 +493,10 @@ jlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetTextlines(JNIEn } jlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetStrips(JNIEnv *env, - jobject thiz) { + jobject thiz, + jlong mNativeData) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; PIXA *pixa = NULL; BOXA *boxa; @@ -493,9 +508,10 @@ jlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetStrips(JNIEnv * } jlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetWords(JNIEnv *env, - jobject thiz) { + jobject thiz, + jlong mNativeData) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; PIXA *pixa = NULL; BOXA *boxa; @@ -507,9 +523,10 @@ jlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetWords(JNIEnv *e } jlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetConnectedComponents(JNIEnv *env, - jobject thiz) { + jobject thiz, + jlong mNativeData) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; PIXA *pixa = NULL; BOXA *boxa; @@ -520,16 +537,19 @@ jlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetConnectedCompon } jlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetResultIterator(JNIEnv *env, - jobject thiz) { - native_data_t *nat = get_native_data(env, thiz); + jobject thiz, + jlong mNativeData) { + native_data_t *nat = (native_data_t*) mNativeData; return (jlong) nat->api.GetIterator(); } jstring Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetHOCRText(JNIEnv *env, - jobject thiz, jint page) { + jobject thiz, + jlong mNativeData, + jint page) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; nat->initStateVariables(env, &thiz); ETEXT_DESC monitor; @@ -549,9 +569,11 @@ jstring Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetHOCRText(JNIE } jstring Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetBoxText(JNIEnv *env, - jobject thiz, jint page) { + jobject thiz, + jlong mNativeData, + jint page) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; char *text = nat->api.GetBoxText(page); @@ -563,9 +585,10 @@ jstring Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetBoxText(JNIEn } jstring Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetVersion(JNIEnv *env, - jobject thiz) { + jobject thiz, + jlong mNativeData) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; const char *text = nat->api.Version(); jstring result = env->NewStringUTF(text); return result; @@ -573,8 +596,9 @@ jstring Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetVersion(JNIEn void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetInputName(JNIEnv *env, jobject thiz, + jlong mNativeData, jstring name) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; const char *c_name = env->GetStringUTFChars(name, NULL); nat->api.SetInputName(c_name); env->ReleaseStringUTFChars(name, c_name); @@ -582,8 +606,9 @@ void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetInputName(JNIEnv void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetOutputName(JNIEnv *env, jobject thiz, + jlong mNativeData, jstring name) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; const char *c_name = env->GetStringUTFChars(name, NULL); nat->api.SetOutputName(c_name); env->ReleaseStringUTFChars(name, c_name); @@ -591,8 +616,9 @@ void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetOutputName(JNIEn void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeReadConfigFile(JNIEnv *env, jobject thiz, + jlong mNativeData, jstring fileName) { - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; const char *c_file_name = env->GetStringUTFChars(fileName, NULL); nat->api.ReadConfigFile(c_file_name); env->ReleaseStringUTFChars(fileName, c_file_name); @@ -600,9 +626,9 @@ void Java_com_googlecode_tesseract_android_TessBaseAPI_nativeReadConfigFile(JNIE jlong Java_com_googlecode_tesseract_android_TessPdfRenderer_nativeCreate(JNIEnv *env, jobject thiz, - jobject jTessBaseApi, + jlong jTessBaseApi, jstring outputPath) { - native_data_t *nat = get_native_data(env, jTessBaseApi); + native_data_t *nat = (native_data_t*) jTessBaseApi; const char *c_output_path = env->GetStringUTFChars(outputPath, NULL); tesseract::TessPDFRenderer* result = new tesseract::TessPDFRenderer(c_output_path, nat->api.GetDatapath()); @@ -648,13 +674,14 @@ jboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeEndDocument(JNI jboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeAddPageToDocument(JNIEnv *env, jobject thiz, + jlong mNativeData, jlong jPix, jstring jPath, jlong jRenderer) { tesseract::TessPDFRenderer* pdfRenderer = (tesseract::TessPDFRenderer*) jRenderer; - native_data_t *nat = get_native_data(env, thiz); + native_data_t *nat = (native_data_t*) mNativeData; PIX* pix = (PIX*) jPix; const char *inputImage = env->GetStringUTFChars(jPath, NULL); diff --git a/tess-two/proguard-rules.pro b/tess-two/proguard-rules.pro index 08f313b27..3a6a20043 100644 --- a/tess-two/proguard-rules.pro +++ b/tess-two/proguard-rules.pro @@ -64,28 +64,6 @@ # -keep public interface mypackage.MyInterface # -keep public class * implements mypackage.MyInterface --keep class com.googlecode.leptonica.android.Box { - private long mNativeBox; -} --keep class com.googlecode.leptonica.android.Boxa { - private long mNativeBoxa; -} --keep class com.googlecode.leptonica.android.Pix { - private long mNativePix; -} --keep class com.googlecode.leptonica.android.Pixa { - private long mNativePixa; -} -keep class com.googlecode.tesseract.android.TessBaseAPI { - private long mNativeData; protected void onProgressValues(int, int, int, int, int, int, int, int, int); } --keep class com.googlecode.tesseract.android.PageIterator { - private long mNativePageIterator; -} --keep class com.googlecode.tesseract.android.TessPdfRenderer { - private long mNativePdfRenderer; -} --keep class com.googlecode.tesseract.android.ResultIterator { - private long mNativeResultIterator; -} \ No newline at end of file diff --git a/tess-two/src/com/googlecode/tesseract/android/TessBaseAPI.java b/tess-two/src/com/googlecode/tesseract/android/TessBaseAPI.java index 5a56f8387..5ee1eb983 100644 --- a/tess-two/src/com/googlecode/tesseract/android/TessBaseAPI.java +++ b/tess-two/src/com/googlecode/tesseract/android/TessBaseAPI.java @@ -218,7 +218,10 @@ public Rect getCurrentRect() { * method must be invoked to dispose of it. */ public TessBaseAPI() { - nativeConstruct(); + mNativeData = nativeConstruct(); + if (mNativeData == 0) { + throw new RuntimeException("Can't create TessBaseApi object"); + } mRecycled = false; } @@ -232,9 +235,8 @@ public TessBaseAPI() { * @param progressNotifier Callback to receive progress notifications */ public TessBaseAPI(ProgressNotifier progressNotifier) { + this(); this.progressNotifier = progressNotifier; - nativeConstruct(); - mRecycled = false; } /** @@ -320,7 +322,7 @@ public boolean init(String datapath, String language, int ocrEngineMode) { } } - boolean success = nativeInitOem(datapath, language, ocrEngineMode); + boolean success = nativeInitOem(mNativeData, datapath, language, ocrEngineMode); if (success) { mRecycled = false; @@ -341,7 +343,7 @@ public String getInitLanguagesAsString() { if (mRecycled) throw new IllegalStateException(); - return nativeGetInitLanguagesAsString(); + return nativeGetInitLanguagesAsString(mNativeData); } /** @@ -354,7 +356,7 @@ public void clear() { if (mRecycled) throw new IllegalStateException(); - nativeClear(); + nativeClear(mNativeData); } /** @@ -366,7 +368,7 @@ public void clear() { */ public void end() { if (!mRecycled) { - nativeEnd(); + nativeEnd(mNativeData); mRecycled = true; } @@ -399,7 +401,7 @@ public boolean setVariable(String var, String value) { if (mRecycled) throw new IllegalStateException(); - return nativeSetVariable(var, value); + return nativeSetVariable(mNativeData, var, value); } /** @@ -411,7 +413,7 @@ public int getPageSegMode() { if (mRecycled) throw new IllegalStateException(); - return nativeGetPageSegMode(); + return nativeGetPageSegMode(mNativeData); } /** @@ -428,7 +430,7 @@ public void setPageSegMode(int mode) { if (mRecycled) throw new IllegalStateException(); - nativeSetPageSegMode(mode); + nativeSetPageSegMode(mNativeData, mode); } /** @@ -441,7 +443,7 @@ public void setDebug(boolean enabled) { if (mRecycled) throw new IllegalStateException(); - nativeSetDebug(enabled); + nativeSetDebug(mNativeData, enabled); } /** @@ -472,7 +474,7 @@ public void setRectangle(int left, int top, int width, int height) { if (mRecycled) throw new IllegalStateException(); - nativeSetRectangle(left, top, width, height); + nativeSetRectangle(mNativeData, left, top, width, height); } /** @@ -494,7 +496,7 @@ public void setImage(File file) { throw new RuntimeException("Failed to read image file"); } - nativeSetImagePix(image.getNativePix()); + nativeSetImagePix(mNativeData, image.getNativePix()); image.recycle(); } @@ -518,7 +520,7 @@ public void setImage(Bitmap bmp) { throw new RuntimeException("Failed to read bitmap"); } - nativeSetImagePix(image.getNativePix()); + nativeSetImagePix(mNativeData, image.getNativePix()); image.recycle(); } @@ -534,7 +536,7 @@ public void setImage(Pix image) { if (mRecycled) throw new IllegalStateException(); - nativeSetImagePix(image.getNativePix()); + nativeSetImagePix(mNativeData, image.getNativePix()); } /** @@ -554,7 +556,7 @@ public void setImage(byte[] imagedata, int width, int height, int bpp, int bpl) if (mRecycled) throw new IllegalStateException(); - nativeSetImageBytes(imagedata, width, height, bpp, bpl); + nativeSetImageBytes(mNativeData, imagedata, width, height, bpp, bpl); } /** @@ -567,7 +569,7 @@ public String getUTF8Text() { throw new IllegalStateException(); // Trim because the text will have extra line breaks at the end - String text = nativeGetUTF8Text(); + String text = nativeGetUTF8Text(mNativeData); return text != null ? text.trim() : null; } @@ -581,7 +583,7 @@ public int meanConfidence() { if (mRecycled) throw new IllegalStateException(); - return nativeMeanConfidence(); + return nativeMeanConfidence(mNativeData); } /** @@ -596,7 +598,7 @@ public int[] wordConfidences() { if (mRecycled) throw new IllegalStateException(); - int[] conf = nativeWordConfidences(); + int[] conf = nativeWordConfidences(mNativeData); // We shouldn't return null confidences if (conf == null) @@ -617,7 +619,7 @@ public Pix getThresholdedImage() { if (mRecycled) throw new IllegalStateException(); - return new Pix(nativeGetThresholdedImage()); + return new Pix(nativeGetThresholdedImage(mNativeData)); } /** @@ -631,7 +633,7 @@ public Pixa getRegions() { if (mRecycled) throw new IllegalStateException(); - return new Pixa(nativeGetRegions(), 0, 0); + return new Pixa(nativeGetRegions(mNativeData), 0, 0); } /** @@ -647,7 +649,7 @@ public Pixa getTextlines() { if (mRecycled) throw new IllegalStateException(); - return new Pixa(nativeGetTextlines(), 0, 0); + return new Pixa(nativeGetTextlines(mNativeData), 0, 0); } /** @@ -662,7 +664,7 @@ public Pixa getStrips() { if (mRecycled) throw new IllegalStateException(); - return new Pixa(nativeGetStrips(), 0, 0); + return new Pixa(nativeGetStrips(mNativeData), 0, 0); } /** @@ -676,7 +678,7 @@ public Pixa getWords() { if (mRecycled) throw new IllegalStateException(); - return new Pixa(nativeGetWords(), 0, 0); + return new Pixa(nativeGetWords(mNativeData), 0, 0); } /** @@ -692,7 +694,7 @@ public Pixa getConnectedComponents() { if (mRecycled) throw new IllegalStateException(); - return new Pixa(nativeGetConnectedComponents(), 0, 0); + return new Pixa(nativeGetConnectedComponents(mNativeData), 0, 0); } /** @@ -705,7 +707,7 @@ public ResultIterator getResultIterator() { if (mRecycled) throw new IllegalStateException(); - long nativeResultIterator = nativeGetResultIterator(); + long nativeResultIterator = nativeGetResultIterator(mNativeData); if (nativeResultIterator == 0) { return null; @@ -725,7 +727,7 @@ public String getHOCRText(int page){ if (mRecycled) throw new IllegalStateException(); - return nativeGetHOCRText(page); + return nativeGetHOCRText(mNativeData, page); } /** @@ -738,7 +740,7 @@ public void setInputName(String name){ if (mRecycled) throw new IllegalStateException(); - nativeSetInputName(name); + nativeSetInputName(mNativeData, name); } /** @@ -750,7 +752,7 @@ public void setOutputName(String name){ if (mRecycled) throw new IllegalStateException(); - nativeSetOutputName(name); + nativeSetOutputName(mNativeData, name); } /** @@ -765,7 +767,7 @@ public void readConfigFile(String filename) { if (mRecycled) throw new IllegalStateException(); - nativeReadConfigFile(filename); + nativeReadConfigFile(mNativeData, filename); } /** @@ -781,7 +783,7 @@ public String getBoxText(int page){ if (mRecycled) throw new IllegalStateException(); - return nativeGetBoxText(page); + return nativeGetBoxText(mNativeData, page); } /** @@ -790,7 +792,7 @@ public String getBoxText(int page){ * @return the version identifier */ public String getVersion() { - return nativeGetVersion(); + return nativeGetVersion(mNativeData); } /** @@ -800,7 +802,7 @@ public void stop() { if (mRecycled) throw new IllegalStateException(); - nativeStop(); + nativeStop(mNativeData); } /** @@ -839,7 +841,7 @@ protected void onProgressValues(final int percent, final int left, * @return {@code true} on success. {@code false} on failure */ public boolean beginDocument(TessPdfRenderer tessPdfRenderer, String title) { - return nativeBeginDocument(tessPdfRenderer.getNativePdfRenderer(), + return nativeBeginDocument(tessPdfRenderer.getNativePdfRenderer(), title); } @@ -876,10 +878,13 @@ public boolean endDocument(TessPdfRenderer tessPdfRenderer) { */ public boolean addPageToDocument(Pix imageToProcess, String imageToWrite, TessPdfRenderer tessPdfRenderer) { - return nativeAddPageToDocument(imageToProcess.getNativePix(), + return nativeAddPageToDocument(mNativeData, imageToProcess.getNativePix(), imageToWrite, tessPdfRenderer.getNativePdfRenderer()); } + /*package*/ long getNativeData() { + return mNativeData; + } // ****************** // * Native methods * @@ -893,74 +898,74 @@ public boolean addPageToDocument(Pix imageToProcess, String imageToWrite, /** * Initializes native data. Must be called on object construction. */ - private native void nativeConstruct(); + private native long nativeConstruct(); /** * Calls End() and finalizes native data. Must be called on object * destruction. */ - private native void nativeEnd(); + private native void nativeEnd(long mNativeData); - private native boolean nativeInit(String datapath, String language); + private native boolean nativeInit(long mNativeData, String datapath, String language); - private native boolean nativeInitOem(String datapath, String language, int mode); + private native boolean nativeInitOem(long mNativeData, String datapath, String language, int mode); - private native String nativeGetInitLanguagesAsString(); + private native String nativeGetInitLanguagesAsString(long mNativeData); - private native void nativeClear(); + private native void nativeClear(long mNativeData); private native void nativeSetImageBytes( - byte[] imagedata, int width, int height, int bpp, int bpl); + long mNativeData, byte[] imagedata, int width, int height, int bpp, int bpl); - private native void nativeSetImagePix(long nativePix); + private native void nativeSetImagePix(long mNativeData, long nativePix); - private native void nativeSetRectangle(int left, int top, int width, int height); + private native void nativeSetRectangle(long mNativeData, int left, int top, int width, int height); - private native String nativeGetUTF8Text(); + private native String nativeGetUTF8Text(long mNativeData); - private native int nativeMeanConfidence(); + private native int nativeMeanConfidence(long mNativeData); - private native int[] nativeWordConfidences(); + private native int[] nativeWordConfidences(long mNativeData); - private native boolean nativeSetVariable(String var, String value); + private native boolean nativeSetVariable(long mNativeData, String var, String value); - private native void nativeSetDebug(boolean debug); + private native void nativeSetDebug(long mNativeData, boolean debug); - private native int nativeGetPageSegMode(); + private native int nativeGetPageSegMode(long mNativeData); - private native void nativeSetPageSegMode(int mode); + private native void nativeSetPageSegMode(long mNativeData, int mode); - private native long nativeGetThresholdedImage(); + private native long nativeGetThresholdedImage(long mNativeData); - private native long nativeGetRegions(); + private native long nativeGetRegions(long mNativeData); - private native long nativeGetTextlines(); + private native long nativeGetTextlines(long mNativeData); - private native long nativeGetStrips(); + private native long nativeGetStrips(long mNativeData); - private native long nativeGetWords(); + private native long nativeGetWords(long mNativeData); - private native long nativeGetConnectedComponents(); + private native long nativeGetConnectedComponents(long mNativeData); - private native long nativeGetResultIterator(); + private native long nativeGetResultIterator(long mNativeData); - private native String nativeGetBoxText(int page_number); + private native String nativeGetBoxText(long mNativeData, int page_number); - private native String nativeGetHOCRText(int page_number); + private native String nativeGetHOCRText(long mNativeData, int page_number); - private native void nativeSetInputName(String name); + private native void nativeSetInputName(long mNativeData, String name); - private native void nativeSetOutputName(String name); + private native void nativeSetOutputName(long mNativeData, String name); - private native void nativeReadConfigFile(String fileName); + private native void nativeReadConfigFile(long mNativeData, String fileName); - private native String nativeGetVersion(); + private native String nativeGetVersion(long mNativeData); - private native void nativeStop(); + private native void nativeStop(long mNativeData); private native boolean nativeBeginDocument(long rendererPointer, String title); private native boolean nativeEndDocument(long rendererPointer); - private native boolean nativeAddPageToDocument(long nativePix, String imagePath, long rendererPointer); + private native boolean nativeAddPageToDocument(long mNativeData, long nativePix, String imagePath, long rendererPointer); } diff --git a/tess-two/src/com/googlecode/tesseract/android/TessPdfRenderer.java b/tess-two/src/com/googlecode/tesseract/android/TessPdfRenderer.java index 441fca54c..0e6d0e92c 100644 --- a/tess-two/src/com/googlecode/tesseract/android/TessPdfRenderer.java +++ b/tess-two/src/com/googlecode/tesseract/android/TessPdfRenderer.java @@ -46,7 +46,7 @@ public class TessPdfRenderer { * including the ".pdf" extension */ public TessPdfRenderer(TessBaseAPI baseApi, String outputPath) { - this.mNativePdfRenderer = nativeCreate(baseApi, outputPath); + this.mNativePdfRenderer = nativeCreate(baseApi.getNativeData(), outputPath); mRecycled = false; } @@ -69,7 +69,7 @@ public void recycle() { mRecycled = true; } - private static native long nativeCreate(TessBaseAPI tessBaseAPI, String outputPath); + private static native long nativeCreate(long tessBaseAPINativeData, String outputPath); private static native void nativeRecycle(long nativePointer);