summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/RefocusActivity.java
diff options
context:
space:
mode:
authorByunghun Jeon <bjeon@codeaurora.org>2015-08-31 17:16:28 -0700
committerByunghun Jeon <bjeon@codeaurora.org>2015-09-01 10:50:44 -0700
commit099e45dfaeff30065817ee337440de6dbc873acb (patch)
tree1263a00962ee3bddb7c0e7cc0a5960ab47fa43b3 /src/com/android/camera/RefocusActivity.java
parentc68df0f4b9fdc0037bc8c9a6cc2f5bd20c259fc4 (diff)
downloadandroid_packages_apps_Snap-099e45dfaeff30065817ee337440de6dbc873acb.tar.gz
android_packages_apps_Snap-099e45dfaeff30065817ee337440de6dbc873acb.tar.bz2
android_packages_apps_Snap-099e45dfaeff30065817ee337440de6dbc873acb.zip
SnapdragonCamera: UbiFocus take histogram to get depth at a point
Instead of directly reading one value, take a histogram around the touch point, to get more consistent value Change-Id: I93a7f9f04e08128c31670bcc50988dae53e669c2 CRs-Fixed: 900244
Diffstat (limited to 'src/com/android/camera/RefocusActivity.java')
-rw-r--r--src/com/android/camera/RefocusActivity.java34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/com/android/camera/RefocusActivity.java b/src/com/android/camera/RefocusActivity.java
index 7291f1fe0..ae13b484b 100644
--- a/src/com/android/camera/RefocusActivity.java
+++ b/src/com/android/camera/RefocusActivity.java
@@ -228,6 +228,7 @@ public class RefocusActivity extends Activity {
private int mWidth;
private int mHeight;
private boolean mFail = true;
+ private static final int W_SIZE = 61;
public DepthMap(final String path) {
File file = new File(path);
@@ -253,9 +254,38 @@ public class RefocusActivity extends Activity {
public int getDepth(float x, float y) {
if (mFail || x > 1.0f || y > 1.0f) {
return NAMES.length - 1;
- } else {
- return mData[(int) ((y * mHeight + x) * mWidth)];
}
+
+ int newX = (int) (x * mWidth);
+ int newY = (int) (y * mHeight);
+
+ int[] hist = new int[256];
+ for (int i = 0; i < 256; i++) {
+ hist[i] = 0;
+ }
+
+ int colStart = Math.max(newX - W_SIZE / 2, 0);
+ int colEnd = Math.min(colStart + W_SIZE, mWidth);
+ int rowStart = Math.max(newY - W_SIZE / 2, 0);
+ int rowEnd = Math.min(rowStart + W_SIZE, mHeight);
+
+ for (int col = colStart; col < colEnd; col++) {
+ for (int row = rowStart; row < rowEnd; row++) {
+ int level = mData[row * mWidth + col];
+ hist[level]++;
+ }
+ }
+
+ int depth = NAMES.length - 1;
+ int maxCount = 0;
+ for (int i = 0; i < 256; i++) {
+ int count = hist[i];
+ if (count != 0 && (maxCount == 0 || count > maxCount)) {
+ maxCount = count;
+ depth = i;
+ }
+ }
+ return depth;
}
private int readInteger(int offset) {