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

Commit

Permalink
Modify writeImpliedFormat. Fixes #86. Fixes #25.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmtheis committed Jun 1, 2015
1 parent 0ae07b4 commit 12e02f6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions tess-two/jni/com_googlecode_leptonica_android/writefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
37 changes: 4 additions & 33 deletions tess-two/src/com/googlecode/leptonica/android/WriteFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
* <p>
* Uses default quality and progressive encoding settings.
*
* @param pixs Source image.
* @param file The file to write.
* @return <code>true</code> 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.
* <p>
* Notes:
* <ol>
* <li>This determines the output format from the filename extension.
* <li>The last two args are ignored except for requests for jpeg files.
* <li>The jpeg default quality is 75.
* </ol>
*
* @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 <code>true</code> 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());
}

/**
Expand All @@ -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);
Expand All @@ -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);
}

0 comments on commit 12e02f6

Please sign in to comment.