diff options
author | mbansal <mayank.bansal@sri.com> | 2011-09-07 20:04:58 -0400 |
---|---|---|
committer | Wei-Ta Chen <weita@google.com> | 2011-09-09 10:39:01 -0700 |
commit | e1178a73fd5756771d25d0b8375452450f509e99 (patch) | |
tree | a5b77b36515e498f221b2427819efa651587fab1 /jni/feature_mos | |
parent | b332a22d55a38ee35008d98da3519730d1fa086b (diff) | |
download | LegacyCamera-e1178a73fd5756771d25d0b8375452450f509e99.zip LegacyCamera-e1178a73fd5756771d25d0b8375452450f509e99.tar.gz 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/feature_mos')
-rw-r--r-- | jni/feature_mos/src/mosaic/Blend.cpp | 24 | ||||
-rw-r--r-- | jni/feature_mos/src/mosaic/Blend.h | 5 | ||||
-rw-r--r-- | jni/feature_mos/src/mosaic/Mosaic.cpp | 22 | ||||
-rw-r--r-- | jni/feature_mos/src/mosaic/Mosaic.h | 3 |
4 files changed, 43 insertions, 11 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: |