summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormbansal <mayank.bansal@sri.com>2011-08-23 11:42:36 -0400
committerWei-Ta Chen <weita@google.com>2011-08-24 10:43:01 -0700
commit50b3c890986aadb3780b4da8c0b8dbb0f1422eba (patch)
tree963262c11e8a2e7afc301f9886e0d0d90430db21
parentf26e1ab12cb3f359fe1d6efcbe65344a3a0bf276 (diff)
downloadpackages_apps_LegacyCamera-50b3c890986aadb3780b4da8c0b8dbb0f1422eba.zip
packages_apps_LegacyCamera-50b3c890986aadb3780b4da8c0b8dbb0f1422eba.tar.gz
packages_apps_LegacyCamera-50b3c890986aadb3780b4da8c0b8dbb0f1422eba.tar.bz2
Updates to allow the mosaic library to report the mosaic computation progress (both low-res and high-res).
1) Added a new method to the Mosaic class that reports the percent progress for both LR and HR mosaicers. 2) Added a test function to the activity that logs the reported progress. 3) [REMOVED] Added a test progress-bar to the UI for quick testing of the progress reporting UI. 4) Made minor updates in response to Wei-Ta's review. Change-Id: Iaf8ccf771579a40580a868743a6b53c6b05f14c6
-rw-r--r--jni/feature_mos/src/mosaic/Blend.cpp14
-rw-r--r--jni/feature_mos/src/mosaic/Blend.h10
-rw-r--r--jni/feature_mos/src/mosaic/Mosaic.cpp5
-rw-r--r--jni/feature_mos/src/mosaic/Mosaic.h3
-rw-r--r--jni/feature_mos_jni.cpp26
-rw-r--r--src/com/android/camera/panorama/Mosaic.java9
-rw-r--r--src/com/android/camera/panorama/MosaicFrameProcessor.java4
-rw-r--r--src/com/android/camera/panorama/PanoramaActivity.java34
8 files changed, 94 insertions, 11 deletions
diff --git a/jni/feature_mos/src/mosaic/Blend.cpp b/jni/feature_mos/src/mosaic/Blend.cpp
index 46a4410..5d05abe 100644
--- a/jni/feature_mos/src/mosaic/Blend.cpp
+++ b/jni/feature_mos/src/mosaic/Blend.cpp
@@ -89,7 +89,9 @@ void Blend::AlignToMiddleFrame(MosaicFrame **frames, int frames_size)
}
}
-int Blend::runBlend(MosaicFrame **frames, int frames_size, ImageType &imageMosaicYVU, int &mosaicWidth, int &mosaicHeight)
+int Blend::runBlend(MosaicFrame **frames, int frames_size,
+ ImageType &imageMosaicYVU, int &mosaicWidth, int &mosaicHeight,
+ float &progress)
{
int ret;
int numCenters;
@@ -182,7 +184,8 @@ int Blend::runBlend(MosaicFrame **frames, int frames_size, ImageType &imageMosai
MosaicRect cropping_rect;
// Do merging and blending :
- ret = DoMergeAndBlend(frames, numCenters, width, height, *imgMos, fullRect, cropping_rect);
+ ret = DoMergeAndBlend(frames, numCenters, width, height, *imgMos, fullRect,
+ cropping_rect, progress);
if (m_wb.blendingType == BLEND_TYPE_HORZ)
CropFinalMosaic(*imgMos, cropping_rect);
@@ -252,7 +255,8 @@ int Blend::FillFramePyramid(MosaicFrame *mb)
}
int Blend::DoMergeAndBlend(MosaicFrame **frames, int nsite,
- int width, int height, YUVinfo &imgMos, MosaicRect &rect, MosaicRect &cropping_rect)
+ int width, int height, YUVinfo &imgMos, MosaicRect &rect,
+ MosaicRect &cropping_rect, float &progress)
{
m_pMosaicYPyr = NULL;
m_pMosaicUPyr = NULL;
@@ -298,6 +302,8 @@ int Blend::DoMergeAndBlend(MosaicFrame **frames, int nsite,
ProcessPyramidForThisFrame(csite, mb->vcrect, mb->brect, rect, imgMos, mb->trs, site_idx);
+ progress += TIME_PERCENT_BLEND/nsite;
+
site_idx++;
}
@@ -309,6 +315,8 @@ int Blend::DoMergeAndBlend(MosaicFrame **frames, int nsite,
if (m_pMosaicUPyr) free(m_pMosaicUPyr);
if (m_pMosaicYPyr) free(m_pMosaicYPyr);
+ progress += TIME_PERCENT_FINAL;
+
return BLEND_RET_OK;
}
diff --git a/jni/feature_mos/src/mosaic/Blend.h b/jni/feature_mos/src/mosaic/Blend.h
index b58eef9..050b485 100644
--- a/jni/feature_mos/src/mosaic/Blend.h
+++ b/jni/feature_mos/src/mosaic/Blend.h
@@ -29,6 +29,11 @@
#define BLEND_RANGE_DEFAULT 6
#define BORDER 8
+// Percent of total mosaicing time spent on each of the following operations
+const float TIME_PERCENT_ALIGN = 20.0;
+const float TIME_PERCENT_BLEND = 75.0;
+const float TIME_PERCENT_FINAL = 5.0;
+
//#define LINEAR_INTERP
//#define LOGII(...) //
@@ -69,7 +74,8 @@ public:
int initialize(int blendingType, int frame_width, int frame_height);
- int runBlend(MosaicFrame **frames, int frames_size, ImageType &imageMosaicYVU, int &mosaicWidth, int &mosaicHeight);
+ int runBlend(MosaicFrame **frames, int frames_size, ImageType &imageMosaicYVU,
+ int &mosaicWidth, int &mosaicHeight, float &progress);
protected:
@@ -99,7 +105,7 @@ protected:
void ClipBlendRect(CSite *csite, BlendRect &brect);
void AlignToMiddleFrame(MosaicFrame **frames, int frames_size);
- int DoMergeAndBlend(MosaicFrame **frames, int nsite, int width, int height, YUVinfo &imgMos, MosaicRect &rect, MosaicRect &cropping_rect);
+ int DoMergeAndBlend(MosaicFrame **frames, int nsite, int width, int height, YUVinfo &imgMos, MosaicRect &rect, MosaicRect &cropping_rect, float &progress);
void ComputeMask(CSite *csite, BlendRect &vcrect, BlendRect &brect, MosaicRect &rect, YUVinfo &imgMos, int site_idx);
void ProcessPyramidForThisFrame(CSite *csite, BlendRect &vcrect, BlendRect &brect, MosaicRect &rect, YUVinfo &imgMos, double trs[3][3], int site_idx);
diff --git a/jni/feature_mos/src/mosaic/Mosaic.cpp b/jni/feature_mos/src/mosaic/Mosaic.cpp
index f8f3265..1b50c0c 100644
--- a/jni/feature_mos/src/mosaic/Mosaic.cpp
+++ b/jni/feature_mos/src/mosaic/Mosaic.cpp
@@ -153,7 +153,7 @@ int Mosaic::addFrame(ImageType imageYVU)
}
-int Mosaic::createMosaic()
+int Mosaic::createMosaic(float &progress)
{
printf("Creating mosaic\n");
@@ -167,7 +167,8 @@ int Mosaic::createMosaic()
// Blend the mosaic (alignment has already been done)
if (blender != NULL)
{
- blender->runBlend((MosaicFrame **) frames, frames_size, imageMosaicYVU, mosaicWidth, mosaicHeight);
+ blender->runBlend((MosaicFrame **) frames, frames_size, imageMosaicYVU,
+ mosaicWidth, mosaicHeight, progress);
}
return MOSAIC_RET_OK;
diff --git a/jni/feature_mos/src/mosaic/Mosaic.h b/jni/feature_mos/src/mosaic/Mosaic.h
index c34688c..25abc43 100644
--- a/jni/feature_mos/src/mosaic/Mosaic.h
+++ b/jni/feature_mos/src/mosaic/Mosaic.h
@@ -109,9 +109,10 @@ public:
/*!
* After adding all frames, call this function to perform the final blending.
+ * \param progress Variable to set the current progress in.
* \return Return code signifying success or failure.
*/
- int createMosaic();
+ int createMosaic(float &progress);
/*!
* Obtains the resulting mosaic and its dimensions.
diff --git a/jni/feature_mos_jni.cpp b/jni/feature_mos_jni.cpp
index d82c47d..1c163ab 100644
--- a/jni/feature_mos_jni.cpp
+++ b/jni/feature_mos_jni.cpp
@@ -65,6 +65,8 @@ Mosaic *mosaic[NR] = {NULL,NULL};
ImageType resultYVU = ImageUtils::IMAGE_TYPE_NOIMAGE;
ImageType resultBGR = ImageUtils::IMAGE_TYPE_NOIMAGE;
float gTRS[10];
+// Variables to keep track of the mosaic computation progress for both LR & HR.
+float gProgress[NR];
int c;
int ret;
@@ -211,7 +213,7 @@ void Finalize(int mID)
t0 = now_ms();
// Create the mosaic
- ret = mosaic[mID]->createMosaic();
+ ret = mosaic[mID]->createMosaic(gProgress[mID]);
t1 = now_ms();
time_c = t1 - t0;
LOGV("CreateMosaic: %g ms",time_c);
@@ -527,9 +529,21 @@ JNIEXPORT void JNICALL Java_com_android_camera_panorama_Mosaic_reset(
frame_number_HR = 0;
frame_number_LR = 0;
+ gProgress[LR] = 0.0;
+ gProgress[HR] = 0.0;
+
Init(LR,MAX_FRAMES_LR);
}
+JNIEXPORT jint JNICALL Java_com_android_camera_panorama_Mosaic_reportProgress(
+ JNIEnv* env, jobject thiz, jboolean hires)
+{
+ if(bool(hires))
+ return (jint) gProgress[HR];
+ else
+ return (jint) gProgress[LR];
+}
+
JNIEXPORT void JNICALL Java_com_android_camera_panorama_Mosaic_createMosaic(
JNIEnv* env, jobject thiz, jboolean value)
{
@@ -539,24 +553,34 @@ JNIEXPORT void JNICALL Java_com_android_camera_panorama_Mosaic_createMosaic(
{
double t0, t1, time_c;
+ gProgress[HR] = 0.0;
t0 = now_ms();
Init(HR, frame_number_HR);
+
for(int k = 0; k < frame_number_HR; k++)
{
AddFrame(HR, k, NULL);
+ gProgress[HR] += TIME_PERCENT_ALIGN/frame_number_HR;
}
+ gProgress[HR] = TIME_PERCENT_ALIGN;
+
t1 = now_ms();
time_c = t1 - t0;
LOGV("AlignAll [HR]: %g ms",time_c);
Finalize(HR);
+
+ gProgress[HR] = 100.0;
+
high_res = false;
}
else
{
+ gProgress[LR] = TIME_PERCENT_ALIGN;
Finalize(LR);
+ gProgress[LR] = 100.0;
}
}
diff --git a/src/com/android/camera/panorama/Mosaic.java b/src/com/android/camera/panorama/Mosaic.java
index 80e8263..ef9d367 100644
--- a/src/com/android/camera/panorama/Mosaic.java
+++ b/src/com/android/camera/panorama/Mosaic.java
@@ -156,4 +156,13 @@ public class Mosaic {
* Also re-initializes the native mosaic object to make it ready for capturing a new mosaic.
*/
public native void reset();
+
+ /**
+ * Get the progress status of the mosaic computation process.
+ * @param hires Boolean flag to select whether to report progress of the
+ * low-res or high-res mosaicer.
+ * @return Returns a number from 0-100 where 50 denotes that the mosaic
+ * computation is 50% done.
+ */
+ public native int reportProgress(boolean hires);
}
diff --git a/src/com/android/camera/panorama/MosaicFrameProcessor.java b/src/com/android/camera/panorama/MosaicFrameProcessor.java
index bc7a5a2..2e077fa 100644
--- a/src/com/android/camera/panorama/MosaicFrameProcessor.java
+++ b/src/com/android/camera/panorama/MosaicFrameProcessor.java
@@ -78,6 +78,10 @@ public class MosaicFrameProcessor {
mProgressListener = listener;
}
+ public int reportProgress(boolean hires) {
+ return mMosaicer.reportProgress(hires);
+ }
+
public void initialize() {
setupMosaicer(mPreviewWidth, mPreviewHeight, mPreviewBufferSize);
reset();
diff --git a/src/com/android/camera/panorama/PanoramaActivity.java b/src/com/android/camera/panorama/PanoramaActivity.java
index a36ebc5..4edccd9 100644
--- a/src/com/android/camera/panorama/PanoramaActivity.java
+++ b/src/com/android/camera/panorama/PanoramaActivity.java
@@ -36,12 +36,12 @@ import android.graphics.Rect;
import android.graphics.SurfaceTexture;
import android.graphics.YuvImage;
import android.hardware.Camera;
-import android.hardware.Camera.Parameters;
-import android.hardware.Camera.Size;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
+import android.hardware.Camera.Parameters;
+import android.hardware.Camera.Size;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -52,6 +52,7 @@ import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
+import android.widget.ProgressBar;
import android.widget.TextView;
import java.io.ByteArrayOutputStream;
@@ -379,6 +380,7 @@ public class PanoramaActivity extends Activity implements
MSG_FINAL_MOSAIC_READY, bitmap));
}
});
+ reportProgress(false);
}
}
@@ -442,6 +444,33 @@ public class PanoramaActivity extends Activity implements
stopCapture();
}
+ public void reportProgress(final boolean highRes) {
+ Thread t = new Thread() {
+ @Override
+ public void run() {
+ while(true)
+ {
+ final int progress = mMosaicFrameProcessor.reportProgress(highRes);
+
+ try{
+ Thread.sleep(50);
+ }catch(Exception e) {}
+
+ // Update the progress bar
+ runOnUiThread(new Runnable() {
+ public void run() {
+ //TODO: Set the the progress-bar progress update here...
+ }
+ });
+
+ if(progress>=100)
+ break;
+ }
+ }
+ };
+ t.start();
+ }
+
@OnClickAttr
public void onOkButtonClicked(View v) {
if (mPausing || mThreadRunning || mSurfaceTexture == null) return;
@@ -453,6 +482,7 @@ public class PanoramaActivity extends Activity implements
mMainHandler.sendMessage(mMainHandler.obtainMessage(MSG_RESET_TO_PREVIEW));
}
});
+ reportProgress(true);
}
private void runBackgroundThread(String str, Thread thread) {