From 12e02f6bec15d11fb65945439165e7dd706b06fc Mon Sep 17 00:00:00 2001 From: Robert Theis Date: Sun, 31 May 2015 18:44:45 -0700 Subject: [PATCH] Modify writeImpliedFormat. Fixes #86. Fixes #25. --- .../leptonica/android/test/ReadFileTest.java | 4 +- .../writefile.cpp | 6 +-- .../leptonica/android/WriteFile.java | 37 ++----------------- 3 files changed, 8 insertions(+), 39 deletions(-) diff --git a/tess-two-test/src/com/googlecode/leptonica/android/test/ReadFileTest.java b/tess-two-test/src/com/googlecode/leptonica/android/test/ReadFileTest.java index dd20f7072..229e82c1f 100644 --- a/tess-two-test/src/com/googlecode/leptonica/android/test/ReadFileTest.java +++ b/tess-two-test/src/com/googlecode/leptonica/android/test/ReadFileTest.java @@ -91,7 +91,7 @@ public void testReadFile_jpg() throws IOException { float match = TestUtils.compareImages(pix, bmp); Log.d(TAG, "match=" + match); - assertTrue("Images do not match. match=" + match, (match >= 0.99f)); + assertTrue("Images do not match.", (match >= 0.99f)); fileStream.close(); bmp.recycle(); @@ -111,7 +111,7 @@ public void testReadMem_jpg() throws IOException { float match = TestUtils.compareImages(pix, bmp); Log.d(TAG, "match=" + match); - assertTrue("Images do not match. match=" + match, (match >= 0.99f)); + assertTrue("Images do not match.", (match >= 0.99f)); byteStream.close(); bmp.recycle(); diff --git a/tess-two/jni/com_googlecode_leptonica_android/writefile.cpp b/tess-two/jni/com_googlecode_leptonica_android/writefile.cpp index 2dd59b2c2..1a1e6cfba 100644 --- a/tess-two/jni/com_googlecode_leptonica_android/writefile.cpp +++ b/tess-two/jni/com_googlecode_leptonica_android/writefile.cpp @@ -51,9 +51,7 @@ jint Java_com_googlecode_leptonica_android_WriteFile_nativeWriteBytes8(JNIEnv *e jboolean Java_com_googlecode_leptonica_android_WriteFile_nativeWriteImpliedFormat(JNIEnv *env, jclass clazz, jlong nativePix, - jstring fileName, - jint quality, - jboolean progressive) { + jstring fileName) { PIX *pixs = (PIX *) nativePix; const char *c_fileName = env->GetStringUTFChars(fileName, NULL); @@ -64,7 +62,7 @@ jboolean Java_com_googlecode_leptonica_android_WriteFile_nativeWriteImpliedForma jboolean result = JNI_TRUE; - if (pixWriteImpliedFormat(c_fileName, pixs, (l_int32) quality, (progressive == JNI_TRUE))) { + if (pixWriteImpliedFormat(c_fileName, pixs, 0, JNI_FALSE)) { LOGE("could not write pix data to %s", c_fileName); result = JNI_FALSE; } diff --git a/tess-two/src/com/googlecode/leptonica/android/WriteFile.java b/tess-two/src/com/googlecode/leptonica/android/WriteFile.java index ef1a6555c..4a50968ef 100644 --- a/tess-two/src/com/googlecode/leptonica/android/WriteFile.java +++ b/tess-two/src/com/googlecode/leptonica/android/WriteFile.java @@ -28,12 +28,6 @@ public class WriteFile { System.loadLibrary("lept"); } - /* Default JPEG quality */ - public static final int DEFAULT_QUALITY = 85; - - /* Default JPEG progressive encoding */ - public static final boolean DEFAULT_PROGRESSIVE = true; - /** * Write an 8bpp Pix to a flat byte array. * @@ -82,45 +76,24 @@ public static int writeBytes8(Pix pixs, byte[] data) { /** * Writes a Pix to file using the file extension as the output format; - * supported formats are .jpg or .jpeg for JPEG and .bmp for bitmap. - *

- * Uses default quality and progressive encoding settings. - * - * @param pixs Source image. - * @param file The file to write. - * @return true on success - */ - public static boolean writeImpliedFormat(Pix pixs, File file) { - return writeImpliedFormat(pixs, file, DEFAULT_QUALITY, DEFAULT_PROGRESSIVE); - } - - /** - * Writes a Pix to file using the file extension as the output format; - * supported formats are .jpg or .jpeg for JPEG and .bmp for bitmap. + * the only supported format is .bmp for bitmap. *

* Notes: *

    *
  1. This determines the output format from the filename extension. - *
  2. The last two args are ignored except for requests for jpeg files. - *
  3. The jpeg default quality is 75. *
* * @param pixs Source image. * @param file The file to write. - * @param quality (Only for lossy formats) Quality between 1 - 100, 0 for - * default. - * @param progressive (Only for JPEG) Whether to encode as progressive. * @return true on success */ - public static boolean writeImpliedFormat( - Pix pixs, File file, int quality, boolean progressive) { + public static boolean writeImpliedFormat(Pix pixs, File file) { if (pixs == null) throw new IllegalArgumentException("Source pix must be non-null"); if (file == null) throw new IllegalArgumentException("File must be non-null"); - return nativeWriteImpliedFormat( - pixs.mNativePix, file.getAbsolutePath(), quality, progressive); + return nativeWriteImpliedFormat(pixs.mNativePix, file.getAbsolutePath()); } /** @@ -138,7 +111,6 @@ public static Bitmap writeBitmap(Pix pixs) { final int[] dimensions = pixs.getDimensions(); final int width = dimensions[Pix.INDEX_W]; final int height = dimensions[Pix.INDEX_H]; - //final int depth = dimensions[Pix.INDEX_D]; final Bitmap.Config config = Bitmap.Config.ARGB_8888; final Bitmap bitmap = Bitmap.createBitmap(width, height, config); @@ -158,8 +130,7 @@ public static Bitmap writeBitmap(Pix pixs) { private static native int nativeWriteBytes8(long nativePix, byte[] data); - private static native boolean nativeWriteImpliedFormat( - long nativePix, String fileName, int quality, boolean progressive); + private static native boolean nativeWriteImpliedFormat(long nativePix, String fileName); private static native boolean nativeWriteBitmap(long nativePix, Bitmap bitmap); }