summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2015-09-22 18:17:55 -0700
committerGerrit - the friendly Code Review server <code-review@localhost>2015-09-22 18:17:55 -0700
commitbe517166b384881e43c288cda0427d82b67b2064 (patch)
tree419026226264bb819a677c988ee94cc4d06e0ae8
parent9dd5238e7298875559ea5bd197a785ad0a3a1310 (diff)
parent099e45dfaeff30065817ee337440de6dbc873acb (diff)
downloadandroid_packages_apps_Snap-be517166b384881e43c288cda0427d82b67b2064.tar.gz
android_packages_apps_Snap-be517166b384881e43c288cda0427d82b67b2064.tar.bz2
android_packages_apps_Snap-be517166b384881e43c288cda0427d82b67b2064.zip
Merge "SnapdragonCamera: UbiFocus take histogram to get depth at a point"
-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) {