summaryrefslogtreecommitdiffstats
path: root/jni
diff options
context:
space:
mode:
authormbansal <mayank.bansal@sri.com>2011-09-07 20:04:58 -0400
committerWei-Ta Chen <weita@google.com>2011-09-09 10:39:01 -0700
commite1178a73fd5756771d25d0b8375452450f509e99 (patch)
treea5b77b36515e498f221b2427819efa651587fab1 /jni
parentb332a22d55a38ee35008d98da3519730d1fa086b (diff)
downloadpackages_apps_LegacyCamera-e1178a73fd5756771d25d0b8375452450f509e99.zip
packages_apps_LegacyCamera-e1178a73fd5756771d25d0b8375452450f509e99.tar.gz
packages_apps_LegacyCamera-e1178a73fd5756771d25d0b8375452450f509e99.tar.bz2
Updates to allow cancellation of mosaic computation from a UI trigger.
1) reportProgress now takes a new boolean parameter that can be used to break out of the mosaic computation loop at the library level. 2) Added a cancel button to the progressDialog and a new Handler message to handle the button click so that the user can be taken back to the capture stage. 3) Updates to address the code review. Change-Id: I0768da55dd6ccd9b1464d456ab41973779734c65
Diffstat (limited to 'jni')
-rw-r--r--jni/feature_mos/src/mosaic/Blend.cpp24
-rw-r--r--jni/feature_mos/src/mosaic/Blend.h5
-rw-r--r--jni/feature_mos/src/mosaic/Mosaic.cpp22
-rw-r--r--jni/feature_mos/src/mosaic/Mosaic.h3
-rw-r--r--jni/feature_mos_jni.cpp50
5 files changed, 81 insertions, 23 deletions
diff --git a/jni/feature_mos/src/mosaic/Blend.cpp b/jni/feature_mos/src/mosaic/Blend.cpp
index ee67d5a..cc146a8 100644
--- a/jni/feature_mos/src/mosaic/Blend.cpp
+++ b/jni/feature_mos/src/mosaic/Blend.cpp
@@ -91,7 +91,7 @@ void Blend::AlignToMiddleFrame(MosaicFrame **frames, int frames_size)
int Blend::runBlend(MosaicFrame **frames, int frames_size,
ImageType &imageMosaicYVU, int &mosaicWidth, int &mosaicHeight,
- float &progress)
+ float &progress, bool &cancelComputation)
{
int ret;
int numCenters;
@@ -185,7 +185,7 @@ int Blend::runBlend(MosaicFrame **frames, int frames_size,
// Do merging and blending :
ret = DoMergeAndBlend(frames, numCenters, width, height, *imgMos, fullRect,
- cropping_rect, progress);
+ cropping_rect, progress, cancelComputation);
if (m_wb.blendingType == BLEND_TYPE_HORZ)
CropFinalMosaic(*imgMos, cropping_rect);
@@ -207,7 +207,7 @@ int Blend::runBlend(MosaicFrame **frames, int frames_size,
mosaicHeight = Mheight;
}
- return BLEND_RET_OK;
+ return ret;
}
@@ -256,7 +256,7 @@ int Blend::FillFramePyramid(MosaicFrame *mb)
int Blend::DoMergeAndBlend(MosaicFrame **frames, int nsite,
int width, int height, YUVinfo &imgMos, MosaicRect &rect,
- MosaicRect &cropping_rect, float &progress)
+ MosaicRect &cropping_rect, float &progress, bool &cancelComputation)
{
m_pMosaicYPyr = NULL;
m_pMosaicUPyr = NULL;
@@ -280,6 +280,14 @@ int Blend::DoMergeAndBlend(MosaicFrame **frames, int nsite,
site_idx = 0;
for(CSite *csite = m_AllSites; csite < esite; csite++)
{
+ if(cancelComputation)
+ {
+ if (m_pMosaicVPyr) free(m_pMosaicVPyr);
+ if (m_pMosaicUPyr) free(m_pMosaicUPyr);
+ if (m_pMosaicYPyr) free(m_pMosaicYPyr);
+ return BLEND_RET_CANCELLED;
+ }
+
mb = csite->getMb();
mb->vcrect = mb->brect;
@@ -294,6 +302,14 @@ int Blend::DoMergeAndBlend(MosaicFrame **frames, int nsite,
site_idx = 0;
for(CSite *csite = m_AllSites; csite < esite; csite++)
{
+ if(cancelComputation)
+ {
+ if (m_pMosaicVPyr) free(m_pMosaicVPyr);
+ if (m_pMosaicUPyr) free(m_pMosaicUPyr);
+ if (m_pMosaicYPyr) free(m_pMosaicYPyr);
+ return BLEND_RET_CANCELLED;
+ }
+
mb = csite->getMb();
diff --git a/jni/feature_mos/src/mosaic/Blend.h b/jni/feature_mos/src/mosaic/Blend.h
index 013fbbf..c878be4 100644
--- a/jni/feature_mos/src/mosaic/Blend.h
+++ b/jni/feature_mos/src/mosaic/Blend.h
@@ -68,6 +68,7 @@ public:
static const int BLEND_RET_ERROR = -1;
static const int BLEND_RET_OK = 0;
static const int BLEND_RET_ERROR_MEMORY = 1;
+ static const int BLEND_RET_CANCELLED = -2;
Blend();
~Blend();
@@ -75,7 +76,7 @@ public:
int initialize(int blendingType, int frame_width, int frame_height);
int runBlend(MosaicFrame **frames, int frames_size, ImageType &imageMosaicYVU,
- int &mosaicWidth, int &mosaicHeight, float &progress);
+ int &mosaicWidth, int &mosaicHeight, float &progress, bool &cancelComputation);
protected:
@@ -105,7 +106,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, float &progress);
+ int DoMergeAndBlend(MosaicFrame **frames, int nsite, int width, int height, YUVinfo &imgMos, MosaicRect &rect, MosaicRect &cropping_rect, float &progress, bool &cancelComputation);
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 988ec28..3dc1e1d 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(float &progress)
+int Mosaic::createMosaic(float &progress, bool &cancelComputation)
{
printf("Creating mosaic\n");
@@ -172,14 +172,28 @@ int Mosaic::createMosaic(float &progress)
}
+ int ret;
+
// Blend the mosaic (alignment has already been done)
if (blender != NULL)
{
- blender->runBlend((MosaicFrame **) frames, frames_size, imageMosaicYVU,
- mosaicWidth, mosaicHeight, progress);
+ ret = blender->runBlend((MosaicFrame **) frames, frames_size, imageMosaicYVU,
+ mosaicWidth, mosaicHeight, progress, cancelComputation);
}
- return MOSAIC_RET_OK;
+ switch(ret)
+ {
+ case Blend::BLEND_RET_ERROR:
+ case Blend::BLEND_RET_ERROR_MEMORY:
+ ret = MOSAIC_RET_ERROR;
+ break;
+ case Blend::BLEND_RET_CANCELLED:
+ ret = MOSAIC_RET_CANCELLED;
+ break;
+ case Blend::BLEND_RET_OK:
+ ret = MOSAIC_RET_OK;
+ }
+ return ret;
}
ImageType Mosaic::getMosaic(int &width, int &height)
diff --git a/jni/feature_mos/src/mosaic/Mosaic.h b/jni/feature_mos/src/mosaic/Mosaic.h
index 25abc43..ecf0536 100644
--- a/jni/feature_mos/src/mosaic/Mosaic.h
+++ b/jni/feature_mos/src/mosaic/Mosaic.h
@@ -112,7 +112,7 @@ public:
* \param progress Variable to set the current progress in.
* \return Return code signifying success or failure.
*/
- int createMosaic(float &progress);
+ int createMosaic(float &progress, bool &cancelComputation);
/*!
* Obtains the resulting mosaic and its dimensions.
@@ -141,6 +141,7 @@ public:
*/
static const int MOSAIC_RET_OK = 1;
static const int MOSAIC_RET_ERROR = -1;
+ static const int MOSAIC_RET_CANCELLED = -2;
protected:
diff --git a/jni/feature_mos_jni.cpp b/jni/feature_mos_jni.cpp
index 1c163ab..84647b9 100644
--- a/jni/feature_mos_jni.cpp
+++ b/jni/feature_mos_jni.cpp
@@ -67,9 +67,10 @@ 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];
+// Variables to be able to cancel the mosaic computation when the GUI says so.
+bool gCancelComputation[NR];
int c;
-int ret;
int width=0, height=0;
int mosaicWidth=0, mosaicHeight=0;
@@ -207,19 +208,21 @@ int AddFrame(int mID, int k, float* trs1d)
return ret_code;
}
-void Finalize(int mID)
+int Finalize(int mID)
{
double t0, t1, time_c;
t0 = now_ms();
// Create the mosaic
- ret = mosaic[mID]->createMosaic(gProgress[mID]);
+ int ret = mosaic[mID]->createMosaic(gProgress[mID], gCancelComputation[mID]);
t1 = now_ms();
time_c = t1 - t0;
LOGV("CreateMosaic: %g ms",time_c);
// Get back the result
resultYVU = mosaic[mID]->getMosaic(mosaicWidth, mosaicHeight);
+
+ return ret;
}
void YUV420toYVU24(ImageType yvu24, ImageType yuv420sp, int width, int height)
@@ -532,23 +535,33 @@ JNIEXPORT void JNICALL Java_com_android_camera_panorama_Mosaic_reset(
gProgress[LR] = 0.0;
gProgress[HR] = 0.0;
+ gCancelComputation[LR] = false;
+ gCancelComputation[HR] = false;
+
Init(LR,MAX_FRAMES_LR);
}
JNIEXPORT jint JNICALL Java_com_android_camera_panorama_Mosaic_reportProgress(
- JNIEnv* env, jobject thiz, jboolean hires)
+ JNIEnv* env, jobject thiz, jboolean hires, jboolean cancel_computation)
{
if(bool(hires))
+ gCancelComputation[HR] = cancel_computation;
+ else
+ gCancelComputation[LR] = cancel_computation;
+
+ if(bool(hires))
return (jint) gProgress[HR];
else
return (jint) gProgress[LR];
}
-JNIEXPORT void JNICALL Java_com_android_camera_panorama_Mosaic_createMosaic(
+JNIEXPORT jint JNICALL Java_com_android_camera_panorama_Mosaic_createMosaic(
JNIEnv* env, jobject thiz, jboolean value)
{
high_res = bool(value);
+ int ret;
+
if(high_res)
{
double t0, t1, time_c;
@@ -560,28 +573,41 @@ JNIEXPORT void JNICALL Java_com_android_camera_panorama_Mosaic_createMosaic(
for(int k = 0; k < frame_number_HR; k++)
{
+ if (gCancelComputation[HR])
+ break;
AddFrame(HR, k, NULL);
gProgress[HR] += TIME_PERCENT_ALIGN/frame_number_HR;
}
- gProgress[HR] = TIME_PERCENT_ALIGN;
+ if (gCancelComputation[HR])
+ {
+ ret = Mosaic::MOSAIC_RET_CANCELLED;
+ }
+ else
+ {
+ gProgress[HR] = TIME_PERCENT_ALIGN;
- t1 = now_ms();
- time_c = t1 - t0;
- LOGV("AlignAll [HR]: %g ms",time_c);
+ t1 = now_ms();
+ time_c = t1 - t0;
+ LOGV("AlignAll [HR]: %g ms",time_c);
- Finalize(HR);
+ ret = Finalize(HR);
- gProgress[HR] = 100.0;
+ gProgress[HR] = 100.0;
+ }
high_res = false;
}
else
{
gProgress[LR] = TIME_PERCENT_ALIGN;
- Finalize(LR);
+
+ ret = Finalize(LR);
+
gProgress[LR] = 100.0;
}
+
+ return (jint) ret;
}
JNIEXPORT jintArray JNICALL Java_com_android_camera_panorama_Mosaic_getFinalMosaic(