summaryrefslogtreecommitdiffstats
path: root/jni
diff options
context:
space:
mode:
authormbansal <mayank.bansal@sri.com>2011-09-20 11:21:09 -0400
committerWei-Ta Chen <weita@google.com>2011-09-21 11:28:16 -0700
commita369cd3153170975a5e5bd6fa5544dcd6f22ee85 (patch)
tree99a89a93b87a53e9ef457021b1c1340f4128d532 /jni
parent9e9aff5145a9c3e1e4e99fbd779cd3b9b3c20848 (diff)
downloadLegacyCamera-a369cd3153170975a5e5bd6fa5544dcd6f22ee85.zip
LegacyCamera-a369cd3153170975a5e5bd6fa5544dcd6f22ee85.tar.gz
LegacyCamera-a369cd3153170975a5e5bd6fa5544dcd6f22ee85.tar.bz2
Bug fixes to the cropping region selection algorithm.
1) The library should now return proper error code for the negative width scenario. 2) Also fixed a round-off issue which lead to improper cropping behavior for low-res output. Bug: 5330440, 5350580 Change-Id: I010be9b8a2b1252c1d2e0528956e512126f6246a
Diffstat (limited to 'jni')
-rw-r--r--jni/feature_mos/src/mosaic/Blend.cpp47
1 files changed, 18 insertions, 29 deletions
diff --git a/jni/feature_mos/src/mosaic/Blend.cpp b/jni/feature_mos/src/mosaic/Blend.cpp
index 7308a53..470fba0 100644
--- a/jni/feature_mos/src/mosaic/Blend.cpp
+++ b/jni/feature_mos/src/mosaic/Blend.cpp
@@ -143,9 +143,10 @@ int Blend::runBlend(MosaicFrame **oframes, MosaicFrame **rframes,
double z, x0, y0, x1, y1, x2, y2, x3, y3;
- // Corners of the first and last frames in mosaic coordinate system
- double xf[4] = {0.0, 0.0, 0.0, 0.0};
- double xl[4] = {0.0, 0.0, 0.0, 0.0};
+ // Corners of the left-most and right-most frames respectively in the
+ // mosaic coordinate system.
+ double xLeftCorners[2] = {2e30, 2e30};
+ double xRightCorners[2] = {-2e30, -2e30};
// Determine the extents of the final mosaic
CSite *csite = m_AllSites ;
@@ -164,20 +165,16 @@ int Blend::runBlend(MosaicFrame **oframes, MosaicFrame **rframes,
FrameToMosaic(mb->trs, mb->width-1.0, mb->height-1.0, x2, y2);
FrameToMosaic(mb->trs, mb->width-1.0, 0.0, x3, y3);
- if(mfit == 0)
+ if(x0 < xLeftCorners[0] || x1 < xLeftCorners[1]) // If either of the left corners is lower
{
- xf[0] = x0;
- xf[1] = x1;
- xf[2] = x3;
- xf[3] = x2;
+ xLeftCorners[0] = x0;
+ xLeftCorners[1] = x1;
}
- if(mfit==frames_size-1)
+ if(x3 > xRightCorners[0] || x2 > xRightCorners[1]) // If either of the right corners is higher
{
- xl[0] = x0;
- xl[1] = x1;
- xl[2] = x3;
- xl[3] = x2;
+ xRightCorners[0] = x3;
+ xRightCorners[1] = x2;
}
// Compute the centroid of the warped region
@@ -200,27 +197,19 @@ int Blend::runBlend(MosaicFrame **oframes, MosaicFrame **rframes,
Mwidth = (unsigned short) (fullRect.right - fullRect.left + 1);
Mheight = (unsigned short) (fullRect.bottom - fullRect.top + 1);
- int xlt, xrt;
-
- if(frames[0]->trs[0][2] < frames[frames_size-1]->trs[0][2]) //left->right mosaic
- {
- xlt = max(xf[0],xf[1]) - fullRect.left;
- xrt = min(xl[2],xl[3]) - fullRect.left;
- }
- else
- {
- xlt = max(xl[0],xl[1]) - fullRect.left;
- xrt = min(xf[2],xf[3]) - fullRect.left;
- }
+ int xLeftMost, xRightMost;
+ // Rounding up, so that we don't include the gray border.
+ xLeftMost = max(0, max(xLeftCorners[0], xLeftCorners[1]) - fullRect.left + 1);
+ xRightMost = min(Mwidth - 1, min(xRightCorners[0], xRightCorners[1]) - fullRect.left - 1);
// Make sure image width is multiple of 4
Mwidth = (unsigned short) ((Mwidth + 3) & ~3);
Mheight = (unsigned short) ((Mheight + 3) & ~3); // Round up.
- if (Mwidth < width || Mheight < height)
+ if (Mwidth < width || Mheight < height || xRightMost <= xLeftMost)
{
- LOGE("RunBlend: aborting - consistency check failed, w=%d, h=%d", Mwidth, Mheight);
+ LOGE("RunBlend: aborting - consistency check failed, w=%d, h=%d, xLeftMost=%d, xRightMost=%d", Mwidth, Mheight, xLeftMost, xRightMost);
return BLEND_RET_ERROR;
}
@@ -245,8 +234,8 @@ int Blend::runBlend(MosaicFrame **oframes, MosaicFrame **rframes,
// cropped out of the computed mosaic to get rid of the gray borders.
MosaicRect cropping_rect;
- cropping_rect.left = xlt;
- cropping_rect.right = xrt;
+ cropping_rect.left = xLeftMost;
+ cropping_rect.right = xRightMost;
// Do merging and blending :
ret = DoMergeAndBlend(frames, numCenters, width, height, *imgMos, fullRect,