diff --git a/.gitignore b/.gitignore index 27f526173..e551f3556 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ build/ .idea/ *.iml javadoc/ +tessdata/ diff --git a/BUILDING.md b/BUILDING.md index 109ea76b9..9f15eb017 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -5,18 +5,20 @@ AAR as an external dependency in your app project. To start the build, import the root directory of this project into Android Studio as an existing Android Studio project, or follow the instructions below to build on the command line. -Note: When building from Android Studio, you may need to set the path to your -NDK installation in the Project Structure dialog (File->Project Structure). - -## _Android Studio and Gradle_ +## _Building with Android Studio_ The Gradle build uses the gradle-stable plugin and the Android NDK to build the Tesseract and Leptonica native C/C++ code through a call to -`ndk-build` in `build.gradle`. After building, the AAR file that is generated -may be [imported][aar-import] into your app project as a dependency on a local -binary package. +`ndk-build` in `build.gradle`. In Android Studio, use + +Build -> Rebuild Project + +to build or rebuild the project. + +Note: When building from Android Studio, you may need to set the path to your +NDK installation in the Project Structure dialog (File->Project Structure). -To build the project from the command line: +## _Building on the Command Line_ _On Mac/Linux:_ @@ -44,7 +46,20 @@ Run the following commands: cd tess gradlew assemble -### Testing +# Importing + +After building, the code that is generated may be imported into your app +project in Android Studio as a module using + +File -> New -> Import Module -> `tess-two` folder + +and then adding the dependency to your app module build.gradle: + + dependencies { + implementation project(':tess-two') + } + +# Testing _On Mac/Linux:_ @@ -58,4 +73,10 @@ _On Windows:_ Note that some tests will fail due to existing issues. -[aar-import]:http://stackoverflow.com/a/28816265/667810 +# Removing + +If you want to remove your app's dependency on the tess-two module, reverse +the import process by removing the module using the Project Structure dialog +(File->Project Structure), manually deleting the tess-two subfolder from your +app project folder, and removing the tess-two reference from your app module +build.gradle. \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 946a3df65..a1b4edf89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,68 @@ # Change Log ## [Unreleased](https://github.com/rmtheis/tess-two/tree/HEAD) -[Full Changelog](https://github.com/rmtheis/tess-two/compare/6.3.0...HEAD) +[Full Changelog](https://github.com/rmtheis/tess-two/compare/9.0.0...HEAD) + +## [9.0.0](https://github.com/rmtheis/tess-two/tree/9.0.0) (2018-04-20) +[Full Changelog](https://github.com/rmtheis/tess-two/compare/8.0.0...9.0.0) + +**Change:** + +- This version fixes and adds back in the 64-bit ABIs, and removes the deprecated armv5 and mips/mips64 ABIs. + +**Implemented enhancements:** + +- Improve developer support for Hindi/Arabic [\#240](https://github.com/rmtheis/tess-two/issues/240) + +**Fixed bugs:** + +- Crashing reported on 64-bit devices [\#197](https://github.com/rmtheis/tess-two/issues/197) + +**Merged pull requests:** + +- Updated repositories. Changed compile to implementation. [\#233](https://github.com/rmtheis/tess-two/pull/233) ([mauriciotogneri](https://github.com/mauriciotogneri)) +- Updated version of SDK, build tools and support libraries [\#231](https://github.com/rmtheis/tess-two/pull/231) ([mauriciotogneri](https://github.com/mauriciotogneri)) + +## [8.0.0](https://github.com/rmtheis/tess-two/tree/8.0.0) (2017-08-13) +[Full Changelog](https://github.com/rmtheis/tess-two/compare/7.0.0...8.0.0) + +**Change:** + +- This version removes the 64-bit ABIs from the default build in order to avoid crashes due to [\#197](https://github.com/rmtheis/tess-two/issues/197) + +**Closed issues:** + +- Build failure with Android Studio 3 and NDK ver. 15.x [\#215](https://github.com/rmtheis/tess-two/issues/215) + +**Merged pull requests:** + +- clone tag 3.04.00 from tessdata [\#217](https://github.com/rmtheis/tess-two/pull/217) ([ivankolev](https://github.com/ivankolev)) +- See issue \#215 [\#216](https://github.com/rmtheis/tess-two/pull/216) ([ivankolev](https://github.com/ivankolev)) + +## [7.0.0](https://github.com/rmtheis/tess-two/tree/7.0.0) (2017-06-12) +[Full Changelog](https://github.com/rmtheis/tess-two/compare/6.3.0...7.0.0) + +**API-breaking change:** + +- ResultIterator getChoicesAndConfidence\(\) is now getSymbolChoicesAndConfidence\(\) + +**Fixed bugs:** + +- ResultIterator crashes with certain character combinations [\#126](https://github.com/rmtheis/tess-two/issues/126) +- ResultIterator returns single Character as Alternatives for Words [\#119](https://github.com/rmtheis/tess-two/issues/119) +- beginDocument\(\) returns false even when successful [\#103](https://github.com/rmtheis/tess-two/issues/103) + +**Closed issues:** + +- Hardcoded path in TessBaseAPITest.java [\#208](https://github.com/rmtheis/tess-two/issues/208) + +**Merged pull requests:** + +- Add missing PageSegMode constant [\#209](https://github.com/rmtheis/tess-two/pull/209) ([Robyer](https://github.com/Robyer)) +- Fix return value of BeginDocument \(fixes \#103\) [\#207](https://github.com/rmtheis/tess-two/pull/207) ([Robyer](https://github.com/Robyer)) +- Improve ResultIterator [\#206](https://github.com/rmtheis/tess-two/pull/206) ([Robyer](https://github.com/Robyer)) +- Update gradle plugin [\#205](https://github.com/rmtheis/tess-two/pull/205) ([Robyer](https://github.com/Robyer)) +- Fix javadocs errors and warnings [\#202](https://github.com/rmtheis/tess-two/pull/202) ([Robyer](https://github.com/Robyer)) ## [6.3.0](https://github.com/rmtheis/tess-two/tree/6.2.0) (2017-04-06) [Full Changelog](https://github.com/rmtheis/tess-two/compare/6.2.0...6.3.0) diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 012cc1951..93b4f47fd 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -32,3 +32,12 @@ Phone/device architecture (armeabi, armeabi-v7a, x86, mips, arm64-v8a, x86_64, m +Link to training data used: + + + +Link to image used as input: + + + + diff --git a/README.md b/README.md index f7bc80fea..121f5b131 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ To use tess-two from your app, edit your app module's `build.gradle` file to add tess-two as an external dependency: dependencies { - compile 'com.rmtheis:tess-two:6.3.0' + implementation 'com.rmtheis:tess-two:9.0.0' } [Javadoc][javadoc] is available. @@ -84,6 +84,12 @@ submitting a pull request through GitHub. See the License for the specific language governing permissions and limitations under the License. +## See Also + +The Google Mobile Vision API team has made available an OCR capability that is +provided to developers through the Google Play Services library: The +[Mobile Vision API][mobile-vision-api] offers a simple API for OCR that +currently works for Latin-based characters. [tesseract-android-tools]: https://github.com/alanv/tesseract-android-tools [tesseract-ocr]: https://github.com/tesseract-ocr/tesseract @@ -93,3 +99,4 @@ submitting a pull request through GitHub. [javadoc]: https://rmtheis.github.io/tess-two/javadoc/index.html [semantic-versioning]: http://semver.org [stackoverflow]: https://stackoverflow.com/ +[mobile-vision-api]: https://developers.google.com/vision/ diff --git a/build.gradle b/build.gradle index 90daee674..d2a6ef4b2 100644 --- a/build.gradle +++ b/build.gradle @@ -2,10 +2,11 @@ buildscript { repositories { + google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:3.1.1' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' } @@ -14,9 +15,10 @@ buildscript { allprojects { group = 'com.rmtheis' - version = '6.3.0' + version = '9.0.0' repositories { + google() jcenter() } } diff --git a/eyes-two/build.gradle b/eyes-two/build.gradle index 2dc45ff77..9c77d1b7a 100644 --- a/eyes-two/build.gradle +++ b/eyes-two/build.gradle @@ -6,14 +6,14 @@ Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) android { - compileSdkVersion 23 - buildToolsVersion '25.0.0' + compileSdkVersion 27 + buildToolsVersion '27.0.3' defaultConfig { minSdkVersion 9 - targetSdkVersion 9 + targetSdkVersion 22 versionCode 1 - versionName "1.0" + versionName '1.0' } sourceSets { @@ -59,6 +59,6 @@ android { } dependencies { - compile project(':tess-two'); - compile fileTree(dir: 'libs', include: ['*.jar']) + implementation project(':tess-two') + implementation fileTree(dir: 'libs', include: ['*.jar']) } diff --git a/eyes-two/src/main/jni/Application.mk b/eyes-two/src/main/jni/Application.mk index 855cbbf61..af9bf9a7b 100644 --- a/eyes-two/src/main/jni/Application.mk +++ b/eyes-two/src/main/jni/Application.mk @@ -1,3 +1,3 @@ -APP_ABI := armeabi armeabi-v7a x86 mips arm64-v8a x86_64 mips64 +APP_ABI := armeabi-v7a x86 arm64-v8a x86_64 APP_OPTIM := release NDK_TOOLCHAIN_VERSION := clang diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f85a41816..08e8ae50e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Apr 02 14:22:01 PDT 2017 +#Thu Apr 19 17:52:32 PDT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/preparetests.cmd b/preparetests.cmd index f0305b0e5..2de2016d2 100644 --- a/preparetests.cmd +++ b/preparetests.cmd @@ -1,20 +1,21 @@ -git clone https://github.com/tesseract-ocr/tessdata.git +for /f %%i in ('adb shell echo $EXTERNAL_STORAGE') do set DIR=%%i -adb shell rm /sdcard/testAddPageToDocument.pdf -adb shell rm /sdcard/testCreate.pdf +git clone -b 3.04.00 https://github.com/tesseract-ocr/tessdata.git + +adb shell rm %DIR%/testAddPageToDocument.pdf +adb shell rm %DIR%/testCreate.pdf adb uninstall com.googlecode.tesseract.android.test -adb shell mkdir /sdcard/tesseract -adb shell mkdir /sdcard/tesseract/tessdata +adb shell mkdir %DIR%/tessdata -adb push -p tessdata/eng.cube.bigrams /sdcard/tesseract/tessdata -adb push -p tessdata/eng.cube.fold /sdcard/tesseract/tessdata -adb push -p tessdata/eng.cube.lm /sdcard/tesseract/tessdata -adb push -p tessdata/eng.cube.nn /sdcard/tesseract/tessdata -adb push -p tessdata/eng.cube.params /sdcard/tesseract/tessdata -adb push -p tessdata/eng.cube.size /sdcard/tesseract/tessdata -adb push -p tessdata/eng.cube.word-freq /sdcard/tesseract/tessdata -adb push -p tessdata/eng.tesseract_cube.nn /sdcard/tesseract/tessdata -adb push -p tessdata/eng.traineddata /sdcard/tesseract/tessdata -adb push -p tess-two/jni/com_googlecode_tesseract_android/src/tessdata/pdf.ttf /sdcard/tesseract/tessdata +adb push -p tessdata/eng.cube.bigrams %DIR%/tessdata +adb push -p tessdata/eng.cube.fold %DIR%/tessdata +adb push -p tessdata/eng.cube.lm %DIR%/tessdata +adb push -p tessdata/eng.cube.nn %DIR%/tessdata +adb push -p tessdata/eng.cube.params %DIR%/tessdata +adb push -p tessdata/eng.cube.size %DIR%/tessdata +adb push -p tessdata/eng.cube.word-freq %DIR%/tessdata +adb push -p tessdata/eng.tesseract_cube.nn %DIR%/tessdata +adb push -p tessdata/eng.traineddata %DIR%/tessdata +adb push -p tess-two/jni/com_googlecode_tesseract_android/src/tessdata/pdf.ttf %DIR%/tessdata diff --git a/preparetests.sh b/preparetests.sh index b8f3b4cf1..76ed94a8c 100755 --- a/preparetests.sh +++ b/preparetests.sh @@ -1,17 +1,18 @@ #!/bin/sh -git clone https://github.com/tesseract-ocr/tessdata.git +DIR="`adb shell echo \\$EXTERNAL_STORAGE`" -adb shell rm /sdcard/testAddPageToDocument.pdf -adb shell rm /sdcard/testCreate.pdf +git clone -b 3.04.00 https://github.com/tesseract-ocr/tessdata.git + +adb shell rm $DIR/testAddPageToDocument.pdf +adb shell rm $DIR/testCreate.pdf adb uninstall com.googlecode.tesseract.android.test -adb shell mkdir /sdcard/tesseract -adb shell mkdir /sdcard/tesseract/tessdata +adb shell mkdir $DIR/tessdata for f in tessdata/eng.*; do - TRAINEDDATA_FILENAME="/sdcard/tesseract/tessdata/`basename $f`" + TRAINEDDATA_FILENAME="$DIR/tessdata/`basename $f`" if [ `adb shell "if [ -f $TRAINEDDATA_FILENAME ]; then echo 1; fi"` ]; then echo "$TRAINEDDATA_FILENAME already present on device" @@ -19,9 +20,9 @@ for f in tessdata/eng.*; do fi echo "Copying $f to device..."; - adb push -p $f /sdcard/tesseract/tessdata + adb push -p $f $DIR/tessdata done -adb push -p tess-two/jni/com_googlecode_tesseract_android/src/tessdata/pdf.ttf /sdcard/tesseract/tessdata +adb push -p tess-two/jni/com_googlecode_tesseract_android/src/tessdata/pdf.ttf $DIR/tessdata # adb shell am instrument -w com.googlecode.tesseract.android.test/android.test.InstrumentationTestRunner diff --git a/tess-two-test/build.gradle b/tess-two-test/build.gradle index 49e45b13a..0394475b8 100644 --- a/tess-two-test/build.gradle +++ b/tess-two-test/build.gradle @@ -1,14 +1,14 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 23 - buildToolsVersion '25.0.0' + compileSdkVersion 27 + buildToolsVersion '27.0.3' defaultConfig { minSdkVersion 9 targetSdkVersion 22 versionCode 1 - versionName "1.0" + versionName '1.0' } sourceSets { @@ -28,7 +28,6 @@ android { } dependencies { - compile project(':tess-two'); - compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' -} + implementation project(':tess-two') + testImplementation 'junit:junit:4.12' +} \ No newline at end of file diff --git a/tess-two-test/src/com/googlecode/tesseract/android/test/TessBaseAPITest.java b/tess-two-test/src/com/googlecode/tesseract/android/test/TessBaseAPITest.java index 24b42526f..1e5277a70 100644 --- a/tess-two-test/src/com/googlecode/tesseract/android/test/TessBaseAPITest.java +++ b/tess-two-test/src/com/googlecode/tesseract/android/test/TessBaseAPITest.java @@ -16,7 +16,6 @@ package com.googlecode.tesseract.android.test; -import android.annotation.SuppressLint; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.Canvas; @@ -26,6 +25,7 @@ import android.graphics.Paint.Style; import android.graphics.Rect; import android.os.AsyncTask; +import android.os.Environment; import android.test.suitebuilder.annotation.SmallTest; import android.text.Html; import android.util.Pair; @@ -47,10 +47,9 @@ import java.util.concurrent.Semaphore; public class TessBaseAPITest extends TestCase { - @SuppressLint("SdCardPath") - static final String TESSBASE_PATH = "/sdcard/tesseract/"; + static final String TESSBASE_PATH = Environment.getExternalStorageDirectory().toString(); static final String DEFAULT_LANGUAGE = "eng"; - private static final String TESSDATA_PATH = TESSBASE_PATH + "tessdata/"; + private static final String TESSDATA_PATH = TESSBASE_PATH + "/tessdata/"; private static final String[] EXPECTED_CUBE_DATA_FILES_ENG = { "eng.cube.bigrams", "eng.cube.fold", @@ -112,7 +111,7 @@ public void testChoiceIterator() { List> choicesAndConfidences; iterator.begin(); do { - choicesAndConfidences = iterator.getChoicesAndConfidence(PageIteratorLevel.RIL_SYMBOL); + choicesAndConfidences = iterator.getSymbolChoicesAndConfidence(); assertNotNull("Invalid result.", choicesAndConfidences); for (Pair choiceAndConfidence : choicesAndConfidences) { diff --git a/tess-two-test/src/com/googlecode/tesseract/android/test/TessPdfRendererTest.java b/tess-two-test/src/com/googlecode/tesseract/android/test/TessPdfRendererTest.java index 39fc0a61d..a5a4a25cf 100644 --- a/tess-two-test/src/com/googlecode/tesseract/android/test/TessPdfRendererTest.java +++ b/tess-two-test/src/com/googlecode/tesseract/android/test/TessPdfRendererTest.java @@ -75,7 +75,7 @@ public void testAddPageToDocument() throws IOException { // Start the PDF writing process. boolean beginSuccess = baseApi.beginDocument(pdfRenderer, "title"); - // assertTrue(beginSuccess); + assertTrue(beginSuccess); // Add a page to the PDF. final Pix pixOne = getTextImage("page one", 640, 480); diff --git a/tess-two/build.gradle b/tess-two/build.gradle index b471e07ba..9a236281c 100644 --- a/tess-two/build.gradle +++ b/tess-two/build.gradle @@ -8,14 +8,14 @@ Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) android { - compileSdkVersion 23 - buildToolsVersion '25.0.0' + compileSdkVersion 27 + buildToolsVersion '27.0.3' defaultConfig { minSdkVersion 9 targetSdkVersion 22 versionCode 1 - versionName "1.0" + versionName '1.0' consumerProguardFiles 'proguard-rules.pro' } @@ -60,7 +60,8 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "com.android.support:support-annotations:27.1.1" } diff --git a/tess-two/jni/Application.mk b/tess-two/jni/Application.mk index 4576c3284..f734e7c37 100644 --- a/tess-two/jni/Application.mk +++ b/tess-two/jni/Application.mk @@ -1,5 +1,5 @@ APP_STL := gnustl_static -APP_ABI := armeabi armeabi-v7a x86 mips arm64-v8a x86_64 mips64 +APP_ABI := armeabi-v7a x86 arm64-v8a x86_64 APP_OPTIM := release APP_PLATFORM := android-9 APP_CPPFLAGS += -fexceptions -frtti diff --git a/tess-two/jni/com_googlecode_leptonica_android/utilities.cpp b/tess-two/jni/com_googlecode_leptonica_android/utilities.cpp index 51d1ca1aa..1bc0dcf04 100644 --- a/tess-two/jni/com_googlecode_leptonica_android/utilities.cpp +++ b/tess-two/jni/com_googlecode_leptonica_android/utilities.cpp @@ -39,7 +39,7 @@ jlong Java_com_googlecode_leptonica_android_AdaptiveMap_nativeBackgroundNormMorp PIX *pixd = pixBackgroundNormMorph(pixs, NULL, (l_int32) reduction, (l_int32) size, (l_int32) bgval); - return (jlong) pixd; + return jlong(pixd); } jlong Java_com_googlecode_leptonica_android_AdaptiveMap_nativePixContrastNorm(JNIEnv *env, @@ -55,7 +55,7 @@ jlong Java_com_googlecode_leptonica_android_AdaptiveMap_nativePixContrastNorm(JN PIX *pixd = pixContrastNorm(NULL, pixs, (l_int32) sizeX, (l_int32) sizeY, (l_int32) minDiff, (l_int32) smoothX, (l_int32) smoothY); - return (jlong) pixd; + return jlong(pixd); } /************ @@ -79,7 +79,7 @@ jlong Java_com_googlecode_leptonica_android_Binarize_nativeOtsuAdaptiveThreshold return (jlong) 0; } - return (jlong) pixd; + return jlong(pixd); } jlong Java_com_googlecode_leptonica_android_Binarize_nativeSauvolaBinarizeTiled(JNIEnv *env, @@ -98,7 +98,7 @@ jlong Java_com_googlecode_leptonica_android_Binarize_nativeSauvolaBinarizeTiled( return (jlong) 0; } - return (jlong) pixd; + return jlong(pixd); } /******** @@ -112,7 +112,7 @@ jlong Java_com_googlecode_leptonica_android_Clip_nativeClipRectangle(JNIEnv *env BOX *box = (BOX *) nativeBox; PIX *pixd; pixd = pixClipRectangle(pixs,box,NULL); - return (jlong) pixd; + return jlong(pixd); } /*********** @@ -124,7 +124,7 @@ jlong Java_com_googlecode_leptonica_android_Convert_nativeConvertTo8(JNIEnv *env PIX *pixs = (PIX *) nativePix; PIX *pixd = pixConvertTo8(pixs, FALSE); - return (jlong) pixd; + return jlong(pixd); } /******** @@ -138,7 +138,7 @@ jlong Java_com_googlecode_leptonica_android_Edge_nativePixSobelEdgeFilter(JNIEnv PIX *pixs = (PIX *) nativePix; PIX *pixd = pixSobelEdgeFilter(pixs, (l_int32) orientFlag); - return (jlong) pixd; + return jlong(pixd); } /*********** @@ -152,7 +152,7 @@ jlong Java_com_googlecode_leptonica_android_Enhance_nativeUnsharpMasking(JNIEnv PIX *pixs = (PIX *) nativePix; PIX *pixd = pixUnsharpMasking(pixs, (l_int32) halfwidth, (l_float32) fract); - return (jlong) pixd; + return jlong(pixd); } /************* @@ -164,7 +164,7 @@ jlong Java_com_googlecode_leptonica_android_GrayQuant_nativePixThresholdToBinary PIX *pixs = (PIX *) nativePix; PIX *pixd = pixThresholdToBinary(pixs, (l_int32) thresh); - return (jlong) pixd; + return jlong(pixd); } /********** @@ -206,7 +206,7 @@ jlong Java_com_googlecode_leptonica_android_MorphApp_nativePixTophat(JNIEnv *env PIX *pixs = (PIX *) nativePix; PIX *pixd = pixTophat(pixs, (l_int32) hsize, (l_int32) vsize, (l_int32) type); - return (jlong) pixd; + return jlong(pixd); } jlong Java_com_googlecode_leptonica_android_MorphApp_nativePixFastTophat(JNIEnv *env, jclass clazz, @@ -215,7 +215,7 @@ jlong Java_com_googlecode_leptonica_android_MorphApp_nativePixFastTophat(JNIEnv PIX *pixs = (PIX *) nativePix; PIX *pixd = pixFastTophat(pixs, (l_int32) xsize, (l_int32) ysize, (l_int32) type); - return (jlong) pixd; + return jlong(pixd); } /********* @@ -225,18 +225,17 @@ jlong Java_com_googlecode_leptonica_android_MorphApp_nativePixFastTophat(JNIEnv jlong Java_com_googlecode_leptonica_android_Scale_nativeScaleGeneral(JNIEnv *env, jclass clazz, jlong nativePix, jfloat scaleX, jfloat scaleY, jfloat sharpfract, jint sharpwidth) { - PIX *pixs = (PIX *) nativePix; - PIX *pixd = pixScaleGeneral(pixs, (l_float32) scaleX, (l_float32) scaleY,(l_float32) sharpfract, (l_int32) sharpwidth); - return (jlong) pixd; + PIX *pixs = (Pix *) nativePix; + return (jlong) pixScaleGeneral(pixs, (l_float32) scaleX, (l_float32) scaleY,(l_float32) sharpfract, (l_int32) sharpwidth); } jlong Java_com_googlecode_leptonica_android_Scale_nativeScale(JNIEnv *env, jclass clazz, jlong nativePix, jfloat scaleX, jfloat scaleY) { - PIX *pixs = (PIX *) nativePix; + PIX *pixs = (Pix *) nativePix; PIX *pixd = pixScale(pixs, (l_float32) scaleX, (l_float32) scaleY); - return (jlong) pixd; + return jlong(pixd); } /******** @@ -291,7 +290,7 @@ jlong Java_com_googlecode_leptonica_android_Rotate_nativeRotate(JNIEnv *env, jcl pixd = pixRotate(pixs, radians, type, L_BRING_IN_WHITE, w, h); } - return (jlong) pixd; + return jlong(pixd); } jlong Java_com_googlecode_leptonica_android_Rotate_nativeRotateOrth(JNIEnv *env, jclass clazz, @@ -300,7 +299,7 @@ jlong Java_com_googlecode_leptonica_android_Rotate_nativeRotateOrth(JNIEnv *env, PIX *pixs = (PIX *) nativePix; PIX *pixd; pixd = pixRotateOrth(pixs,(int)quads); - return (jlong) pixd; + return jlong(pixd); } #ifdef __cplusplus diff --git a/tess-two/jni/com_googlecode_tesseract_android/resultiterator.cpp b/tess-two/jni/com_googlecode_tesseract_android/resultiterator.cpp index 7f2424e97..cac17f0b0 100644 --- a/tess-two/jni/com_googlecode_tesseract_android/resultiterator.cpp +++ b/tess-two/jni/com_googlecode_tesseract_android/resultiterator.cpp @@ -48,21 +48,20 @@ jfloat Java_com_googlecode_tesseract_android_ResultIterator_nativeConfidence(JNI return (jfloat) resultIterator->Confidence(enumLevel); } -jobjectArray Java_com_googlecode_tesseract_android_ResultIterator_nativeGetChoices(JNIEnv *env, - jobject thiz, jlong nativeResultIterator, jint level) { +jobjectArray Java_com_googlecode_tesseract_android_ResultIterator_nativeGetSymbolChoices(JNIEnv *env, + jclass clazz, jlong nativeResultIterator) { - // Get the actual result iterator and level (as C objects) - PageIteratorLevel enumLevel = (PageIteratorLevel) level; + // Get the actual result iterator (as C object) ResultIterator *resultIterator = (ResultIterator *) nativeResultIterator; - // Create a choice iterator to determine to the number of alternatives + // Create a choice iterator to determine the number of alternatives tesseract::ChoiceIterator ci(*resultIterator); int numberOfAlternatives = 0; do { numberOfAlternatives++; } while (ci.Next()); - // Create a string array to hold the results + // Create a string array to hold the choices jobjectArray ret = (jobjectArray) env->NewObjectArray(numberOfAlternatives, env->FindClass("java/lang/String"), env->NewStringUTF("")); // Save each result to the output array @@ -73,7 +72,7 @@ jobjectArray Java_com_googlecode_tesseract_android_ResultIterator_nativeGetChoic const char *utfText = cb.GetUTF8Text(); // Add each string to the object array elements - char newString[strlen(utfText) + 5]; + char newString[strlen(utfText) + 7]; sprintf(newString, "%s|%.2f", utfText, cb.Confidence()); env->SetObjectArrayElement(ret, i, env->NewStringUTF(newString)); @@ -85,13 +84,29 @@ jobjectArray Java_com_googlecode_tesseract_android_ResultIterator_nativeGetChoic return ret; } +jboolean Java_com_googlecode_tesseract_android_ResultIterator_nativeIsAtBeginningOf(JNIEnv *env, + jclass clazz, jlong nativeResultIterator, jint level) { + ResultIterator *resultIterator = (ResultIterator *) nativeResultIterator; + PageIteratorLevel enumLevel = (PageIteratorLevel) level; + + return (jboolean) (resultIterator->IsAtBeginningOf(enumLevel) ? JNI_TRUE : JNI_FALSE); +} + +jboolean Java_com_googlecode_tesseract_android_ResultIterator_nativeIsAtFinalElement(JNIEnv *env, + jclass clazz, jlong nativeResultIterator, jint level, jint element) { + ResultIterator *resultIterator = (ResultIterator *) nativeResultIterator; + PageIteratorLevel enumLevel = (PageIteratorLevel) level; + PageIteratorLevel enumElement = (PageIteratorLevel) element; + + return (jboolean) (resultIterator->IsAtFinalElement(enumLevel, enumElement) ? JNI_TRUE : JNI_FALSE); +} + void Java_com_googlecode_tesseract_android_ResultIterator_nativeDelete(JNIEnv *env, jclass clazz, jlong nativeResultIterator) { ResultIterator *resultIterator = (ResultIterator *) nativeResultIterator; if (resultIterator != 0) { delete resultIterator; } - return; } #ifdef __cplusplus diff --git a/tess-two/jni/com_googlecode_tesseract_android/tessbaseapi.cpp b/tess-two/jni/com_googlecode_tesseract_android/tessbaseapi.cpp index 272255d4c..09f2792f1 100644 --- a/tess-two/jni/com_googlecode_tesseract_android/tessbaseapi.cpp +++ b/tess-two/jni/com_googlecode_tesseract_android/tessbaseapi.cpp @@ -648,15 +648,11 @@ jboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeBeginDocument(J const char *c_title = env->GetStringUTFChars(title, NULL); tesseract::TessPDFRenderer* pdfRenderer = (tesseract::TessPDFRenderer*) jRenderer; - jboolean res = JNI_TRUE; - - if (pdfRenderer->BeginDocument(c_title)) { - res = JNI_FALSE; - } + bool res = pdfRenderer->BeginDocument(c_title); env->ReleaseStringUTFChars(title, c_title); - return res; + return (jboolean) (res ? JNI_TRUE : JNI_FALSE); } jboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeEndDocument(JNIEnv *env, diff --git a/tess-two/jni/libjpeg/Android.mk b/tess-two/jni/libjpeg/Android.mk index db4450959..297dbfd70 100644 --- a/tess-two/jni/libjpeg/Android.mk +++ b/tess-two/jni/libjpeg/Android.mk @@ -56,6 +56,7 @@ LOCAL_SRC_FILES := \ LOCAL_CFLAGS := \ -include stdlib.h \ + -Wno-deprecated-declarations \ -Wno-pointer-sign \ -Wno-implicit-function-declaration diff --git a/tess-two/src/com/googlecode/leptonica/android/Binarize.java b/tess-two/src/com/googlecode/leptonica/android/Binarize.java index 6641c76e0..07e807d4b 100644 --- a/tess-two/src/com/googlecode/leptonica/android/Binarize.java +++ b/tess-two/src/com/googlecode/leptonica/android/Binarize.java @@ -16,6 +16,8 @@ package com.googlecode.leptonica.android; +import android.support.annotation.FloatRange; + /** * Image binarization methods. * @@ -118,8 +120,8 @@ public static Pix otsuAdaptiveThreshold(Pix pixs) { * for standard Otsu). * @return A 1 bpp thresholded PIX image. */ - public static Pix otsuAdaptiveThreshold( - Pix pixs, int sizeX, int sizeY, int smoothX, int smoothY, float scoreFraction) { + public static Pix otsuAdaptiveThreshold(Pix pixs, int sizeX, int sizeY, int smoothX, int smoothY, + @FloatRange(from=0.0, to=1.0) float scoreFraction) { if (pixs == null) throw new IllegalArgumentException("Source pix must be non-null"); if (pixs.getDepth() != 8) @@ -154,7 +156,7 @@ public static Pix sauvolaBinarizeTiled(Pix pixs) { * Notes: *
    *
  1. The window width and height are 2 * whsize + 1. The minimum - * value for whsize is 2; typically it is >= 7. + * value for whsize is 2; typically it is >= 7. *
  2. For nx == ny == 1, this defaults to pixSauvolaBinarize(). *
  3. Why a tiled version? * (a) Because the mean value accumulator is a uint32, overflow @@ -169,7 +171,7 @@ public static Pix sauvolaBinarizeTiled(Pix pixs) { * where: * t = local threshold * m = local mean - * k = @factor (>= 0) [ typ. 0.35 ] + * k = @factor (>= 0) [ typ. 0.35 ] * s = local standard deviation, which is maximized at * 127.5 when half the samples are 0 and half are 255. *
  4. The basic idea of Niblack and Sauvola binarization is that @@ -180,12 +182,13 @@ public static Pix sauvolaBinarizeTiled(Pix pixs) { * * @param pixs An 8 bpp PIX source image. * @param whsize Window half-width for measuring local statistics - * @param factor Factor for reducing threshold due to variance; >= 0 - * @param nx Subdivision into tiles; >= 1 - * @param ny Subdivision into tiles; >= 1 + * @param factor Factor for reducing threshold due to variance; >= 0 + * @param nx Subdivision into tiles; >= 1 + * @param ny Subdivision into tiles; >= 1 * @return A 1 bpp thresholded PIX image. */ - public static Pix sauvolaBinarizeTiled(Pix pixs, int whsize, float factor, int nx, int ny) { + public static Pix sauvolaBinarizeTiled(Pix pixs, int whsize, @FloatRange(from=0.0) float factor, + int nx, int ny) { if (pixs == null) throw new IllegalArgumentException("Source pix must be non-null"); if (pixs.getDepth() != 8) diff --git a/tess-two/src/com/googlecode/leptonica/android/Box.java b/tess-two/src/com/googlecode/leptonica/android/Box.java index 823244106..4f2b44165 100644 --- a/tess-two/src/com/googlecode/leptonica/android/Box.java +++ b/tess-two/src/com/googlecode/leptonica/android/Box.java @@ -17,6 +17,7 @@ package com.googlecode.leptonica.android; import android.graphics.Rect; +import android.support.annotation.Size; import android.util.Log; /** @@ -186,7 +187,7 @@ public int[] getGeometry() { * @param geometry A 4+ element integer array to fill with coordinates. * @return true on success */ - public boolean getGeometry(int[] geometry) { + public boolean getGeometry(@Size(min=4) int[] geometry) { if (mRecycled) throw new IllegalStateException(); diff --git a/tess-two/src/com/googlecode/leptonica/android/Boxa.java b/tess-two/src/com/googlecode/leptonica/android/Boxa.java index 052548e06..ec1a5903d 100644 --- a/tess-two/src/com/googlecode/leptonica/android/Boxa.java +++ b/tess-two/src/com/googlecode/leptonica/android/Boxa.java @@ -17,6 +17,7 @@ package com.googlecode.leptonica.android; import android.graphics.Rect; +import android.support.annotation.Size; import android.util.Log; /** @@ -117,7 +118,7 @@ public int[] getGeometry(int index) { * @param geometry A 4+ element integer array to fill with coordinates. * @return true on success */ - public boolean getGeometry(int index, int[] geometry) { + public boolean getGeometry(int index, @Size(min=4) int[] geometry) { if (mRecycled) throw new IllegalStateException(); diff --git a/tess-two/src/com/googlecode/leptonica/android/Clip.java b/tess-two/src/com/googlecode/leptonica/android/Clip.java index b4fa0bbc7..d742b26ae 100644 --- a/tess-two/src/com/googlecode/leptonica/android/Clip.java +++ b/tess-two/src/com/googlecode/leptonica/android/Clip.java @@ -33,7 +33,6 @@ public class Clip { * This should be simple, but there are choices to be made. The box is * defined relative to the pix coordinates. However, if the box is not * contained within the pix, we have two choices: - *

    *

    (1) clip the box to the pix *

    (2) make a new pix equal to the full box dimensions, * but let rasterop do the clipping and positioning @@ -56,7 +55,7 @@ public class Clip { * @return clipped pix, or null if rectangle doesn't intersect source pix */ public static Pix clipRectangle(Pix source, Box box) { - int result = nativeClipRectangle(source.getNativePix(), + long result = nativeClipRectangle(source.getNativePix(), box.getNativeBox()); if (result != 0) { return new Pix(result); @@ -68,5 +67,5 @@ public static Pix clipRectangle(Pix source, Box box) { // * NATIVE CODE * // *************** - private static native int nativeClipRectangle(long nativePix, long nativeBox); + private static native long nativeClipRectangle(long nativePix, long nativeBox); } \ No newline at end of file diff --git a/tess-two/src/com/googlecode/leptonica/android/Constants.java b/tess-two/src/com/googlecode/leptonica/android/Constants.java index 9dc5b8eec..fb94763e1 100644 --- a/tess-two/src/com/googlecode/leptonica/android/Constants.java +++ b/tess-two/src/com/googlecode/leptonica/android/Constants.java @@ -16,6 +16,12 @@ package com.googlecode.leptonica.android; +import android.support.annotation.IntDef; + +import java.lang.annotation.Retention; + +import static java.lang.annotation.RetentionPolicy.SOURCE; + /** * Leptonica constants. * @@ -46,6 +52,10 @@ public class Constants { * and L_INSERT and L_NOCOPY are always 0. */ + @Retention(SOURCE) + @IntDef({L_INSERT, L_COPY, L_CLONE}) + public @interface StorageFlag {} + /* Stuff it in; no copy, clone or copy-clone */ public static final int L_INSERT = 0; @@ -65,12 +75,21 @@ public class Constants { * Sort flags * *--------------------------------------------------------------------------*/ + @Retention(SOURCE) + @IntDef({L_SORT_INCREASING, L_SORT_DECREASING}) + public @interface SortOrder {} + /* Sort in increasing order */ public static final int L_SORT_INCREASING = 1; /* Sort in decreasing order */ public static final int L_SORT_DECREASING = 2; + @Retention(SOURCE) + @IntDef({L_SORT_BY_X, L_SORT_BY_Y, L_SORT_BY_WIDTH, L_SORT_BY_HEIGHT, L_SORT_BY_MIN_DIMENSION, + L_SORT_BY_MAX_DIMENSION, L_SORT_BY_PERIMETER, L_SORT_BY_ASPECT_RATIO}) + public @interface SortBy {} + /* Sort box or c.c. by horiz location */ public static final int L_SORT_BY_X = 3; diff --git a/tess-two/src/com/googlecode/leptonica/android/Edge.java b/tess-two/src/com/googlecode/leptonica/android/Edge.java index ccce11416..08e7a79e3 100644 --- a/tess-two/src/com/googlecode/leptonica/android/Edge.java +++ b/tess-two/src/com/googlecode/leptonica/android/Edge.java @@ -16,6 +16,12 @@ package com.googlecode.leptonica.android; +import android.support.annotation.IntDef; + +import java.lang.annotation.Retention; + +import static java.lang.annotation.RetentionPolicy.SOURCE; + /** * Edge detection. */ @@ -28,6 +34,9 @@ public class Edge { } // Edge orientation flags + @Retention(SOURCE) + @IntDef({L_HORIZONTAL_EDGES, L_VERTICAL_EDGES, L_ALL_EDGES}) + public @interface EdgeOrientationFlag {} /** Filters for horizontal edges */ public static final int L_HORIZONTAL_EDGES = 0; @@ -52,7 +61,6 @@ public class Edge { * using pixThresholdToBinary(). If the high edge values are to be fg (1), * invert after running pixThresholdToBinary(). *

  5. Label the pixels as follows: - *

    *

    1 4 7 *

    2 5 8 *

    3 6 9 @@ -66,7 +74,7 @@ public class Edge { * L_VERTICAL_EDGES, L_ALL_EDGES) * @return a new Pix image (8bpp, edges are brighter), or null on error */ - public static Pix pixSobelEdgeFilter(Pix pixs, int orientFlag) { + public static Pix pixSobelEdgeFilter(Pix pixs, @EdgeOrientationFlag int orientFlag) { if (pixs == null) throw new IllegalArgumentException("Source pix must be non-null"); if (pixs.getDepth() != 8) diff --git a/tess-two/src/com/googlecode/leptonica/android/JpegIO.java b/tess-two/src/com/googlecode/leptonica/android/JpegIO.java index d6195bc9b..870aa6ad2 100644 --- a/tess-two/src/com/googlecode/leptonica/android/JpegIO.java +++ b/tess-two/src/com/googlecode/leptonica/android/JpegIO.java @@ -18,6 +18,7 @@ import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; +import android.support.annotation.IntRange; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -60,7 +61,8 @@ public static byte[] compressToJpeg(Pix pixs) { * @param progressive Whether to use progressive compression. * @return a compressed JPEG byte array representation of the Pix */ - public static byte[] compressToJpeg(Pix pixs, int quality, boolean progressive) { + public static byte[] compressToJpeg(Pix pixs, @IntRange(from=0, to=100) int quality, + boolean progressive) { if (pixs == null) throw new IllegalArgumentException("Source pix must be non-null"); if (quality < 0 || quality > 100) diff --git a/tess-two/src/com/googlecode/leptonica/android/MorphApp.java b/tess-two/src/com/googlecode/leptonica/android/MorphApp.java index 474525a13..0c64292a4 100644 --- a/tess-two/src/com/googlecode/leptonica/android/MorphApp.java +++ b/tess-two/src/com/googlecode/leptonica/android/MorphApp.java @@ -16,6 +16,12 @@ package com.googlecode.leptonica.android; +import android.support.annotation.IntDef; + +import java.lang.annotation.Retention; + +import static java.lang.annotation.RetentionPolicy.SOURCE; + /** * Composite image processing operations. */ @@ -28,7 +34,9 @@ public class MorphApp { } // Morphological tophat flags - + @Retention(SOURCE) + @IntDef({L_TOPHAT_BLACK, L_TOPHAT_WHITE}) + public @interface TophatType {} public static final int L_TOPHAT_WHITE = 0; public static final int L_TOPHAT_BLACK = 1; @@ -55,7 +63,7 @@ public class MorphApp { * @param type L_TOPHAT_WHITE: image - opening or L_TOPHAT_BLACK: closing - image * @return a new Pix image */ - public static Pix pixTophat(Pix pixs, int hsize, int vsize, int type) { + public static Pix pixTophat(Pix pixs, int hsize, int vsize, @TophatType int type) { if (pixs == null) throw new IllegalArgumentException("Source pix must be non-null"); if (pixs.getDepth() != 8) @@ -122,12 +130,12 @@ public static Pix pixFastTophatWhite(Pix pixs) { *

* * @param pixs Source pix (8bpp) - * @param xsize width of max/min op, smoothing; any integer >= 1 - * @param ysize height of max/min op, smoothing; any integer >= 1 + * @param xsize width of max/min op, smoothing; any integer >= 1 + * @param ysize height of max/min op, smoothing; any integer >= 1 * @param type L_TOPHAT_WHITE: image - min, or L_TOPHAT_BLACK: max - image * @return a new Pix image */ - public static Pix pixFastTophat(Pix pixs, int xsize, int ysize, int type) { + public static Pix pixFastTophat(Pix pixs, int xsize, int ysize, @TophatType int type) { if (pixs == null) throw new IllegalArgumentException("Source pix must be non-null"); if (pixs.getDepth() != 8) diff --git a/tess-two/src/com/googlecode/leptonica/android/Pix.java b/tess-two/src/com/googlecode/leptonica/android/Pix.java index cef205e05..c1a215cb3 100644 --- a/tess-two/src/com/googlecode/leptonica/android/Pix.java +++ b/tess-two/src/com/googlecode/leptonica/android/Pix.java @@ -17,6 +17,8 @@ package com.googlecode.leptonica.android; import android.graphics.Rect; +import android.support.annotation.ColorInt; +import android.support.annotation.Size; /** * Java representation of a native Leptonica PIX object. @@ -125,7 +127,7 @@ public int[] getDimensions() { * @param dimensions An integer array with at least three elements. * @return true on success */ - public boolean getDimensions(int[] dimensions) { + public boolean getDimensions(@Size(min=3) int[] dimensions) { if (mRecycled) throw new IllegalStateException(); @@ -297,7 +299,7 @@ public int getPixel(int x, int y) { * specified coordinate. * @throws IllegalArgumentException If x, y exceeds the image bounds. */ - public void setPixel(int x, int y, int color) { + public void setPixel(int x, int y, @ColorInt int color) { if (mRecycled) throw new IllegalStateException(); diff --git a/tess-two/src/com/googlecode/leptonica/android/Pixa.java b/tess-two/src/com/googlecode/leptonica/android/Pixa.java index e91fe6317..aba993857 100644 --- a/tess-two/src/com/googlecode/leptonica/android/Pixa.java +++ b/tess-two/src/com/googlecode/leptonica/android/Pixa.java @@ -17,6 +17,7 @@ package com.googlecode.leptonica.android; import android.graphics.Rect; +import android.support.annotation.Size; import android.util.Log; import java.io.File; @@ -119,7 +120,7 @@ public Pixa copy() { if (mRecycled) throw new IllegalStateException(); - int nativePixa = nativeCopy(mNativePixa); + long nativePixa = nativeCopy(mNativePixa); if (nativePixa == 0) { throw new OutOfMemoryError(); @@ -138,11 +139,11 @@ public Pixa copy() { * Constants.L_SORT_INCREASING or Constants.L_SORT_DECREASING. * @return a sorted copy of this Pixa */ - public Pixa sort(int field, int order) { + public Pixa sort(@Constants.SortBy int field, @Constants.SortOrder int order) { if (mRecycled) throw new IllegalStateException(); - int nativePixa = nativeSort(mNativePixa, field, order); + long nativePixa = nativeSort(mNativePixa, field, order); if (nativePixa == 0) { throw new OutOfMemoryError(); @@ -211,7 +212,7 @@ public boolean join(Pixa otherPixa) { * @param mode The mode in which to add this Pix, typically * Constants.L_CLONE. */ - public void addPix(Pix pix, int mode) { + public void addPix(Pix pix, @Constants.StorageFlag int mode) { if (mRecycled) throw new IllegalStateException(); @@ -225,7 +226,7 @@ public void addPix(Pix pix, int mode) { * @param mode The mode in which to add this Box, typically * Constants.L_CLONE. */ - public void addBox(Box box, int mode) { + public void addBox(Box box, @Constants.StorageFlag int mode) { if (mRecycled) throw new IllegalStateException(); @@ -240,7 +241,7 @@ public void addBox(Box box, int mode) { * @param mode The mode in which to add this Pix and Box, typically * Constants.L_CLONE. */ - public void add(Pix pix, Box box, int mode) { + public void add(Pix pix, Box box, @Constants.StorageFlag int mode) { if (mRecycled) throw new IllegalStateException(); @@ -355,7 +356,7 @@ public int[] getBoxGeometry(int index) { * elements. * @return true on success */ - public boolean getBoxGeometry(int index, int[] dimensions) { + public boolean getBoxGeometry(int index, @Size(min=4) int[] dimensions) { if (mRecycled) throw new IllegalStateException(); @@ -483,11 +484,11 @@ public void remove() { // * NATIVE CODE * // *************** - private static native int nativeCreate(int size); + private static native long nativeCreate(int size); - private static native int nativeCopy(long nativePixa); + private static native long nativeCopy(long nativePixa); - private static native int nativeSort(long nativePixa, int field, int order); + private static native long nativeSort(long nativePixa, int field, int order); private static native boolean nativeJoin(long nativePixa, long otherPixa); diff --git a/tess-two/src/com/googlecode/leptonica/android/Rotate.java b/tess-two/src/com/googlecode/leptonica/android/Rotate.java index 769bbf055..f04d88286 100644 --- a/tess-two/src/com/googlecode/leptonica/android/Rotate.java +++ b/tess-two/src/com/googlecode/leptonica/android/Rotate.java @@ -16,6 +16,8 @@ package com.googlecode.leptonica.android; +import android.support.annotation.IntRange; + /** * @author alanv@google.com (Alan Viverette) */ @@ -101,13 +103,13 @@ public static Pix rotate(Pix pixs, float degrees, boolean quality, boolean resiz * @param quads 0-3; number of 90 degree cw rotations * @return the rotated source image */ - public static Pix rotateOrth(Pix pixs, int quads) { + public static Pix rotateOrth(Pix pixs, @IntRange(from=0, to=3) int quads) { if (pixs == null) throw new IllegalArgumentException("Source pix must be non-null"); if (quads < 0 || quads > 3) throw new IllegalArgumentException("quads not in {0,1,2,3}"); - int nativePix = nativeRotateOrth(pixs.getNativePix(), quads); + long nativePix = nativeRotateOrth(pixs.getNativePix(), quads); if (nativePix == 0) return null; @@ -119,7 +121,7 @@ public static Pix rotateOrth(Pix pixs, int quads) { // * NATIVE CODE * // *************** - private static native int nativeRotateOrth(long nativePix, int quads); + private static native long nativeRotateOrth(long nativePix, int quads); private static native long nativeRotate(long nativePix, float degrees, boolean quality, boolean resize); diff --git a/tess-two/src/com/googlecode/leptonica/android/WriteFile.java b/tess-two/src/com/googlecode/leptonica/android/WriteFile.java index d77a307e1..03c0dee3d 100644 --- a/tess-two/src/com/googlecode/leptonica/android/WriteFile.java +++ b/tess-two/src/com/googlecode/leptonica/android/WriteFile.java @@ -112,18 +112,19 @@ public static Bitmap writeBitmap(Pix pixs) { throw new IllegalArgumentException("Source pix must be non-null"); final int[] dimensions = pixs.getDimensions(); - final int width = dimensions[Pix.INDEX_W]; - final int height = dimensions[Pix.INDEX_H]; + if (dimensions != null) { + final int width = dimensions[Pix.INDEX_W]; + final int height = dimensions[Pix.INDEX_H]; - final Bitmap.Config config = Bitmap.Config.ARGB_8888; - final Bitmap bitmap = Bitmap.createBitmap(width, height, config); + final Bitmap.Config config = Bitmap.Config.ARGB_8888; + final Bitmap bitmap = Bitmap.createBitmap(width, height, config); - if (nativeWriteBitmap(pixs.getNativePix(), bitmap)) { - return bitmap; - } - - bitmap.recycle(); + if (nativeWriteBitmap(pixs.getNativePix(), bitmap)) { + return bitmap; + } + bitmap.recycle(); + } return null; } diff --git a/tess-two/src/com/googlecode/tesseract/android/PageIterator.java b/tess-two/src/com/googlecode/tesseract/android/PageIterator.java index 6cd8a7c26..5330d7332 100644 --- a/tess-two/src/com/googlecode/tesseract/android/PageIterator.java +++ b/tess-two/src/com/googlecode/tesseract/android/PageIterator.java @@ -60,7 +60,7 @@ public void begin() { * @return {@code false} if the end of the page was reached, {@code true} * otherwise. */ - public boolean next(int level) { + public boolean next(@PageIteratorLevel.Level int level) { return nativeNext(mNativePageIterator, level); } @@ -70,7 +70,7 @@ public boolean next(int level) { * ============= Accessing data ==============. *

* Coordinate system: - *