summaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorRuben Brunk <rubenbrunk@google.com>2013-04-02 13:15:57 -0700
committerRuben Brunk <rubenbrunk@google.com>2013-04-02 15:39:41 -0700
commit0cea1fca1ac717b0bf6f4f75c2e41e8549bc97e2 (patch)
treead6a4d9ec120d857b72de9671777f78a8e76262a /tests/src
parent187a09a330f9c62783741b85b86b12610b2f595d (diff)
downloadandroid_packages_apps_Snap-0cea1fca1ac717b0bf6f4f75c2e41e8549bc97e2.tar.gz
android_packages_apps_Snap-0cea1fca1ac717b0bf6f4f75c2e41e8549bc97e2.tar.bz2
android_packages_apps_Snap-0cea1fca1ac717b0bf6f4f75c2e41e8549bc97e2.zip
Speed improvements for ExifOutputStream.
Change-Id: I7d3ee9c157aefe67734e7b49cfa7868254c134ef
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java55
-rw-r--r--tests/src/com/android/gallery3d/exif/ExifXmlDataTestCase.java13
2 files changed, 68 insertions, 0 deletions
diff --git a/tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java b/tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java
index 8c4fc3dea..1286c5801 100644
--- a/tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java
+++ b/tests/src/com/android/gallery3d/exif/ExifOutputStreamTest.java
@@ -18,6 +18,7 @@ package com.android.gallery3d.exif;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.util.Log;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -131,6 +132,60 @@ public class ExifOutputStreamTest extends ExifXmlDataTestCase {
}
}
+ public void testOutputSpeed() throws Exception {
+ final String LOGTAG = "testOutputSpeed";
+ InputStream imageInputStream = null;
+ OutputStream imageOutputStream = null;
+ try {
+ try {
+ imageInputStream = getImageInputStream();
+ // Read the image data
+ Bitmap bmp = BitmapFactory.decodeStream(imageInputStream);
+ // The image is invalid
+ if (bmp == null) {
+ return;
+ }
+ imageInputStream.close();
+ int nLoops = 20;
+ long totalReadDuration = 0;
+ long totalWriteDuration = 0;
+ for (int i = 0; i < nLoops; i++) {
+ imageInputStream = reopenFileStream();
+ // Read exif data
+ long startTime = System.nanoTime();
+ ExifData exifData = new ExifReader(mInterface).read(imageInputStream);
+ long endTime = System.nanoTime();
+ long duration = endTime - startTime;
+ totalReadDuration += duration;
+ Log.v(LOGTAG, " read time: " + duration);
+ imageInputStream.close();
+
+ // Encode the image with the exif data
+ imageOutputStream = (OutputStream) new FileOutputStream(mTmpFile);
+ ExifOutputStream exifOutputStream = new ExifOutputStream(imageOutputStream,
+ mInterface);
+ exifOutputStream.setExifData(exifData);
+ startTime = System.nanoTime();
+ bmp.compress(Bitmap.CompressFormat.JPEG, 90, exifOutputStream);
+ endTime = System.nanoTime();
+ duration = endTime - startTime;
+ totalWriteDuration += duration;
+ Log.v(LOGTAG, " write time: " + duration);
+ exifOutputStream.close();
+ }
+ Log.v(LOGTAG, "======================= normal");
+ Log.v(LOGTAG, "avg read time: " + totalReadDuration / nLoops);
+ Log.v(LOGTAG, "avg write time: " + totalWriteDuration / nLoops);
+ Log.v(LOGTAG, "=======================");
+ } finally {
+ Util.closeSilently(imageInputStream);
+ Util.closeSilently(imageOutputStream);
+ }
+ } catch (Exception e) {
+ throw new Exception(getImageTitle(), e);
+ }
+ }
+
@Override
public void tearDown() throws Exception {
super.tearDown();
diff --git a/tests/src/com/android/gallery3d/exif/ExifXmlDataTestCase.java b/tests/src/com/android/gallery3d/exif/ExifXmlDataTestCase.java
index 5f200ea92..da860208b 100644
--- a/tests/src/com/android/gallery3d/exif/ExifXmlDataTestCase.java
+++ b/tests/src/com/android/gallery3d/exif/ExifXmlDataTestCase.java
@@ -92,4 +92,17 @@ public class ExifXmlDataTestCase extends InstrumentationTestCase {
return String.format(RES_ID_TITLE, mImageResourceId);
}
}
+
+ protected InputStream reopenFileStream() throws Exception {
+ try {
+ if (mImagePath != null) {
+ return new FileInputStream(mImagePath);
+ } else {
+ Resources res = getInstrumentation().getContext().getResources();
+ return res.openRawResource(mImageResourceId);
+ }
+ } catch (Exception e) {
+ throw new Exception(getImageTitle(), e);
+ }
+ }
}