summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/panorama/MosaicFrameProcessor.java
diff options
context:
space:
mode:
authorAngus Kong <shkong@google.com>2011-08-08 17:24:47 +0800
committerAngus Kong <shkong@google.com>2011-08-11 16:27:48 +0800
commit142402d57c1689c1342d096c976b9b0826f8ce1a (patch)
tree650ac2d29ec8c84347ced31e6e6c817e760097c4 /src/com/android/camera/panorama/MosaicFrameProcessor.java
parenta18605333f037e5c8ff95584bc932e539ece249e (diff)
downloadLegacyCamera-142402d57c1689c1342d096c976b9b0826f8ce1a.zip
LegacyCamera-142402d57c1689c1342d096c976b9b0826f8ce1a.tar.gz
LegacyCamera-142402d57c1689c1342d096c976b9b0826f8ce1a.tar.bz2
"Retake" and "Ok" buttons can function correctly.
1. "Retake" button brings user back to preview stage without saving the final result. 2. "Ok" button brings user back to preview stage after saving the final result. bug:5031609 bug:5142100 bug:5134202 bug:5133871 Change-Id: I234e242182765cc5624b2fc8444bc38e5a9edf9f
Diffstat (limited to 'src/com/android/camera/panorama/MosaicFrameProcessor.java')
-rw-r--r--src/com/android/camera/panorama/MosaicFrameProcessor.java37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/com/android/camera/panorama/MosaicFrameProcessor.java b/src/com/android/camera/panorama/MosaicFrameProcessor.java
index c5eeac5..6496f11 100644
--- a/src/com/android/camera/panorama/MosaicFrameProcessor.java
+++ b/src/com/android/camera/panorama/MosaicFrameProcessor.java
@@ -18,6 +18,9 @@ package com.android.camera.panorama;
import android.util.Log;
+/**
+ * Class to handle the processing of each frame by Mosaicer.
+ */
public class MosaicFrameProcessor {
private static final boolean LOGV = true;
private static final String TAG = "MosaicFrameProcessor";
@@ -54,7 +57,6 @@ public class MosaicFrameProcessor {
private int mPreviewHeight;
private int mPreviewBufferSize;
-
public interface ProgressListener {
public void onProgress(boolean isFinished, float translationRate,
int traversedAngleX, int traversedAngleY);
@@ -72,14 +74,20 @@ public class MosaicFrameProcessor {
mProgressListener = listener;
}
- public void onResume() {
+ public void initialize() {
setupMosaicer(mPreviewWidth, mPreviewHeight, mPreviewBufferSize);
+ reset();
}
- public void onPause() {
- releaseMosaicer();
+ public void clear() {
+ mMosaicer.freeMosaicMemory();
+
+ for (int i = 0; i < NUM_FRAMES_IN_BUFFER; i++) {
+ mFrames[i] = null;
+ }
}
+
private void setupMosaicer(int previewWidth, int previewHeight, int bufSize) {
Log.v(TAG, "setupMosaicer w, h=" + previewWidth + ',' + previewHeight + ',' + bufSize);
mMosaicer.allocateMosaicMemory(previewWidth, previewHeight);
@@ -94,12 +102,15 @@ public class MosaicFrameProcessor {
}
}
- private void releaseMosaicer() {
- mMosaicer.freeMosaicMemory();
-
- for (int i = 0; i < NUM_FRAMES_IN_BUFFER; i++) {
- mFrames[i] = null;
- }
+ public void reset() {
+ // reset() can be called even if MosaicFrameProcessor is not initialized.
+ // Only counters will be changed.
+ mTotalFrameCount = 0;
+ mFillIn = 0;
+ mLastProcessedFrameTimestamp = 0;
+ mLastProcessFrameIdx = -1;
+ mCurrProcessFrameIdx = -1;
+ mMosaicer.reset();
}
public void createMosaic(boolean highRes) {
@@ -114,6 +125,12 @@ public class MosaicFrameProcessor {
// updates the UI to show progress.
// When done, processes and displays the final mosaic.
public void processFrame(byte[] data) {
+ if (mFrames[mFillIn] == null) {
+ // clear() is called and buffers are cleared, stop computation.
+ // This can happen when the onPause() is called in the activity, but still some frames
+ // are not processed yet and thus the callback may be invoked.
+ return;
+ }
long t1 = System.currentTimeMillis();
mFrameTimestamp[mFillIn] = t1;
System.arraycopy(data, 0, mFrames[mFillIn], 0, data.length);