Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Commit

Permalink
Add support annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
rmtheis committed Sep 8, 2017
1 parent 52be81e commit d85ef2d
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion tess-two/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ properties.load(project.rootProject.file('local.properties').newDataInputStream(

android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
buildToolsVersion '25.0.3'

defaultConfig {
minSdkVersion 9
Expand Down Expand Up @@ -61,6 +61,7 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-annotations:25.3.1'
}


Expand Down
9 changes: 6 additions & 3 deletions tess-two/src/com/googlecode/leptonica/android/Binarize.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.googlecode.leptonica.android;

import android.support.annotation.FloatRange;

/**
* Image binarization methods.
*
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -185,7 +187,8 @@ public static Pix sauvolaBinarizeTiled(Pix pixs) {
* @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)
Expand Down
3 changes: 2 additions & 1 deletion tess-two/src/com/googlecode/leptonica/android/Box.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.googlecode.leptonica.android;

import android.graphics.Rect;
import android.support.annotation.Size;
import android.util.Log;

/**
Expand Down Expand Up @@ -186,7 +187,7 @@ public int[] getGeometry() {
* @param geometry A 4+ element integer array to fill with coordinates.
* @return <code>true</code> on success
*/
public boolean getGeometry(int[] geometry) {
public boolean getGeometry(@Size(min=4) int[] geometry) {
if (mRecycled)
throw new IllegalStateException();

Expand Down
3 changes: 2 additions & 1 deletion tess-two/src/com/googlecode/leptonica/android/Boxa.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.googlecode.leptonica.android;

import android.graphics.Rect;
import android.support.annotation.Size;
import android.util.Log;

/**
Expand Down Expand Up @@ -117,7 +118,7 @@ public int[] getGeometry(int index) {
* @param geometry A 4+ element integer array to fill with coordinates.
* @return <code>true</code> on success
*/
public boolean getGeometry(int index, int[] geometry) {
public boolean getGeometry(int index, @Size(min=4) int[] geometry) {
if (mRecycled)
throw new IllegalStateException();

Expand Down
19 changes: 19 additions & 0 deletions tess-two/src/com/googlecode/leptonica/android/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down
11 changes: 10 additions & 1 deletion tess-two/src/com/googlecode/leptonica/android/Edge.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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;
Expand Down Expand Up @@ -65,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)
Expand Down
4 changes: 3 additions & 1 deletion tess-two/src/com/googlecode/leptonica/android/JpegIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 11 additions & 3 deletions tess-two/src/com/googlecode/leptonica/android/MorphApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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;

Expand All @@ -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)
Expand Down Expand Up @@ -127,7 +135,7 @@ public static Pix pixFastTophatWhite(Pix pixs) {
* @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)
Expand Down
6 changes: 4 additions & 2 deletions tess-two/src/com/googlecode/leptonica/android/Pix.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -125,7 +127,7 @@ public int[] getDimensions() {
* @param dimensions An integer array with at least three elements.
* @return <code>true</code> on success
*/
public boolean getDimensions(int[] dimensions) {
public boolean getDimensions(@Size(min=3) int[] dimensions) {
if (mRecycled)
throw new IllegalStateException();

Expand Down Expand Up @@ -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();

Expand Down
11 changes: 6 additions & 5 deletions tess-two/src/com/googlecode/leptonica/android/Pixa.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -138,7 +139,7 @@ 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();

Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -355,7 +356,7 @@ public int[] getBoxGeometry(int index) {
* elements.
* @return <code>true</code> on success
*/
public boolean getBoxGeometry(int index, int[] dimensions) {
public boolean getBoxGeometry(int index, @Size(min=4) int[] dimensions) {
if (mRecycled)
throw new IllegalStateException();

Expand Down
4 changes: 3 additions & 1 deletion tess-two/src/com/googlecode/leptonica/android/Rotate.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.googlecode.leptonica.android;

import android.support.annotation.IntRange;

/**
* @author [email protected] (Alan Viverette)
*/
Expand Down Expand Up @@ -101,7 +103,7 @@ 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -90,7 +90,7 @@ public boolean next(int level) {
* @param level the page iterator level. See {@link PageIteratorLevel}.
* @return the bounding rectangle of the current object at the given level
*/
public int[] getBoundingBox(int level) {
public int[] getBoundingBox(@PageIteratorLevel.Level int level) {
return nativeBoundingBox(mNativePageIterator, level);
}

Expand All @@ -102,7 +102,7 @@ public int[] getBoundingBox(int level) {
* @param level the page iterator level. See {@link PageIteratorLevel}.
* @return the bounding rectangle of the current object at the given level
*/
public Rect getBoundingRect(int level) {
public Rect getBoundingRect(@PageIteratorLevel.Level int level) {
int[] box = getBoundingBox(level);
return new Rect(box[0], box[1], box[2], box[3]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class ResultIterator extends PageIterator {
* @param level the page iterator level. See {@link PageIteratorLevel}.
* @return the text string for the current object at the given level.
*/
public String getUTF8Text(int level) {
public String getUTF8Text(@PageIteratorLevel.Level int level) {
return nativeGetUTF8Text(mNativeResultIterator, level);
}

Expand All @@ -65,7 +65,7 @@ public String getUTF8Text(int level) {
* @param level the page iterator level. See {@link PageIteratorLevel}.
* @return the mean confidence of the current object at the given level.
*/
public float confidence(int level) {
public float confidence(@PageIteratorLevel.Level int level) {
return nativeConfidence(mNativeResultIterator, level);
}

Expand All @@ -77,7 +77,7 @@ public float confidence(int level) {
* @param level the page iterator level. See {@link PageIteratorLevel}.
* @return {@code true} if iterator points to the start of an object at the given level.
*/
public boolean isAtBeginningOf(int level) {
public boolean isAtBeginningOf(@PageIteratorLevel.Level int level) {
return nativeIsAtBeginningOf(mNativeResultIterator, level);
}

Expand All @@ -89,7 +89,8 @@ public boolean isAtBeginningOf(int level) {
* @param element the page iterator level. See {@link PageIteratorLevel}.
* @return {@code true} if iterator points to the last element in a given level.
*/
public boolean isAtFinalElement(int level, int element) {
public boolean isAtFinalElement(@PageIteratorLevel.Level int level,
@PageIteratorLevel.Level int element) {
return nativeIsAtFinalElement(mNativeResultIterator, level, element);
}

Expand Down
Loading

0 comments on commit d85ef2d

Please sign in to comment.